def main(): irc = IRCConnection(settings.server, settings.nick, port = settings.port) irc.send('JOIN {0}'.format(settings.channel)) crawlers = tuple() for search in settings.searchfor: crawler = twitter.Crawler(search) crawler.search() crawlers += (crawler,) parser = HTMLParser.HTMLParser() while True: for crawler in crawlers: results = crawler.search() for i in results: queryurl = settings.shortener.format('http://twitter.com/{0}/status/{1}'.format(i['from_user'], i['id_str'])) response = urllib2.urlopen(queryurl) url = response.read() encoded = '\x02{0}\x02: {1} - {2}'.format(i['from_user'], parser.unescape(i['text']), url) irc.send('PRIVMSG {0} :{1}'.format(settings.channel, encoded)) time.sleep(1) time.sleep(settings.searchevery)
def _create_bot(self, name, channels): conn = IRCConnection(settings.IRC['SERVER'], settings.IRC['PORT'], settings.IRC['NICK'], settings.IRC['PASSWORD'], self.log_filename) bot_db_logger = DatabaseLogger(settings.DATABASE['HOST'], settings.DATABASE['NAME'], settings.DATABASE['USER'], settings.DATABASE['PASSWORD']) bot = TwitchBot(name, conn, bot_db_logger, Queue.Queue(), self.log_filename) bot.daemon = True bot.connect_and_join_channels(channels) bot.start() return bot
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
for line in fh.readlines(): self.log(sender, line, '', False, None) 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
self.send_user('!status -- get status on workers and tasks') self.send_user('!uptime -- boss uptime') def get_parser(): parser = OptionParser(usage='%prog [options]') parser.add_option('--server', '-s', dest='server', default='irc.freenode.net', help='IRC server to connect to') parser.add_option('--port', '-p', dest='port', default=6667, help='Port to connect on', type='int') parser.add_option('--nick', '-n', dest='nick', default='boss1234', help='Nick to use') parser.add_option('--secret', '-x', dest='secret', default='password') parser.add_option('--channel', '-c', dest='channel', default='#cs460botnet-jlchao2') parser.add_option('--logfile', '-l', dest='logfile') parser.add_option('--verbosity', '-v', dest='verbosity', default=1, type='int') return parser if __name__ == '__main__': parser = get_parser() (options, args) = parser.parse_args() conn = IRCConnection(options.server, options.port, options.nick, options.secret, options.logfile, options.verbosity) conn.connect() bot = BossServerBot(conn, options.secret, options.channel) conn.enter_event_loop()
'-n', dest='nick', default='boss1337', help='Nick to use') parser.add_option('--secret', '-x', dest='secret', default='password') parser.add_option('--channel', '-c', dest='channel', default='#botwars-test') parser.add_option('--logfile', '-f', dest='logfile') parser.add_option('--verbosity', '-v', dest='verbosity', default=1, type='int') return parser if __name__ == '__main__': parser = get_parser() (options, args) = parser.parse_args() conn = IRCConnection(options.server, options.port, options.nick, options.logfile, options.verbosity) conn.connect() bot = BotnetBot(conn, options.secret, options.channel) conn.enter_event_loop()
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 __init__(self, start=False): self.conn = IRCConnection(HOST, PORT, NICK) self.register_callbacks() if start: self.run()
for line in fh.readlines(): self.log(sender, line, '', False, None) 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