<s> import random <EOL> import eventlet <EOL> from irc . bot import SingleServerIRCBot <EOL> from st2actions . runners . pythonrunner import Action <EOL> eventlet . monkey_patch ( <EOL> os = True , <EOL> select = True , <EOL> socket = True , <EOL> thread = True , <EOL> time = True ) <EOL> __all__ = [ <EOL> '<STR_LIT>' <EOL> ] <EOL> class StackStormActionIRCBot ( SingleServerIRCBot ) : <EOL> def __init__ ( self , server_host , server_port , nickname , channel , message ) : <EOL> server_list = [ ( server_host , server_port ) ] <EOL> super ( StackStormActionIRCBot , self ) . __init__ ( server_list = server_list , <EOL> nickname = nickname , <EOL> realname = nickname ) <EOL> self . _channel = channel <EOL> self . _message = message <EOL> def on_welcome ( self , connection , event ) : <EOL> try : <EOL> connection . join ( self . _channel ) <EOL> self . connection . privmsg ( self . _channel , self . _message ) <EOL> finally : <EOL> self . die ( msg = '<STR_LIT>' ) <EOL> def on_nicknameinuse ( self , connection , event ) : <EOL> new_nickname = '<STR_LIT>' % ( connection . get_nickname ( ) , random . randint ( <NUM_LIT:1> , <NUM_LIT:1000> ) ) <EOL> connection . nick ( new_nickname ) <EOL> class PostMessageAction ( Action ) : <EOL> def run ( self , channel , message ) : <EOL> bot = self . _get_bot ( channel = channel , message = message ) <EOL> bot . start ( ) <EOL> return True <EOL> def _get_bot ( self , channel , message ) : <EOL> split = self . config [ '<STR_LIT>' ] . split ( '<STR_LIT::>' ) <EOL> server_host = split [ <NUM_LIT:0> ] <EOL> server_port = int ( split [ <NUM_LIT:1> ] ) <EOL> nickname = self . config [ '<STR_LIT>' ] <EOL> bot = StackStormActionIRCBot ( server_host = server_host , <EOL> server_port = server_port , <EOL> nickname = nickname , <EOL> channel = channel , <EOL> message = message ) <EOL> return bot </s>
