class IRCThread(threading.Thread): def __init__(self, host, port, nick, channels, dispatcher): self.connexion = IRCConnection(host, port, nick) self.botInstance = InterChatIRCListener(self.connexion, dispatcher) self.connexion.connect() self.channels = channels threading.Thread.__init__(self) def getConnexion(self): return self.connexion def run(self): for channel in self.channels: self.connexion.join(channel) self.connexion.enter_event_loop() def writeToChannel(self, message, channel): self.botInstance.respond(message,channel);
class MPMBot(IRCBot, GithubMixin, RedmineMixin, TalkbackMixin): """ Subclasses IRCBot to construct a bot that responds to request for commit and ticket information. Queries Redmine instances and Github accounts based on settings.py """ def __init__(self, start=False): self.conn = IRCConnection(HOST, PORT, NICK) self.register_callbacks() if start: self.run() def run(self): """ Start the IRC bot and connect to our channels """ while 1: self.conn.connect() channels = CHANNELS or [] for channel in channels: self.conn.join(channel) self.conn.enter_event_loop() def log(self, text): """ Shortcut to our logger """ self.conn.logger.info(text) def command_patterns(self): """ Define dispatch regexes """ patterns = () for base in MPMBot.mro(): if issubclass(base, IRCBotMixin): func = '%s_command_patterns' % base.__name__[0:-5].lower() if hasattr(self, func): func = getattr(self, func, None) patterns += (func()) return patterns
def command_patterns(self): return ( self.ping('^imitate \S+', self.imitate), self.ping('^cite', self.cite), ('.*', self.log), ) host = 'irc.freenode.net' port = 6667 nick = 'whatyousay' conn = IRCConnection(host, port, nick) markov_bot = MarkovBot(conn) if len(sys.argv) > 1 and sys.argv[1] == '-log': if len(sys.argv) == 3: markov_bot.load_log_file(sys.argv[2]) elif len(sys.argv): markov_bot.load_text_file(sys.argv[2], sys.argv[3]) else: conn.connect() conn.join('#botwars') try: conn.enter_event_loop() except: pass markov_bot.save_data()
def command_patterns(self): return ( self.ping('^imitate \S+', self.imitate), self.ping('^cite', self.cite), ('.*', self.log), ) host = 'irc.yournetwork.net' port = 6667 nick = 'Marvin' conn = IRCConnection(host, port, nick) markov_bot = MarkovBot(conn) if len(sys.argv) > 1 and sys.argv[1] == '-log': if len(sys.argv) == 3: markov_bot.load_log_file(sys.argv[2]) elif len(sys.argv): markov_bot.load_text_file(sys.argv[2], sys.argv[3]) else: conn.connect() conn.join('#yourchannel') try: conn.enter_event_loop() except: pass markov_bot.save_data()