def parse_server(self, server, items):
     mappings = re.sub('\s', '', items['mapping']).split(',')
     if not mappings:
         raise Exception('No mappings for %r' % server)
     bot = RedditBot(items['irc_name'], server)
     self.bots[server] = bot
     channels = []
     for mapping in mappings:
         channel, subs = mapping.split(':', 1)
         norm_subs = '+'.join(sorted(subs.split('+')))
         if not norm_subs:
             raise Exception('No subreddits for %r:%r' % (server, channel))
         channels.append(channel)
         if norm_subs not in self.reddits:
             self.reddits[norm_subs] = RedditUpdater(norm_subs)
         self.reddits[norm_subs].add(bot, channel)
     use_ssl = items['irc_ssl'].lower() in ('1', 'yes', 'true', 'on')
     bot.connect(items['irc_host'],
                 int(items['irc_port']),
                 channel=channels,
                 use_ssl=use_ssl)
     if 'irc_msg' in items:
         bot.MSG_FORMAT = text_type(items['irc_msg'])
     if 'irc_pswd' in items:
         bot.identify(items['irc_pswd'])
Beispiel #2
0
	def bot_poll():
		while True:
			sleep(30)
			time_since_last = datetime.now() - bot.last_event

			if ( time_since_last > timeout):
				print "we look disconnected!"
				bot.disconnect()
				bot.connect( configs['SERVER'] )
				bot.start()
Beispiel #3
0
 def parse_server(self, server, items):
     mappings = re.sub('\s', '', items['mapping']).split(',')
     if not mappings:
         raise Exception('No mappings for %r' % server)
     bot = RedditBot(items['irc_name'], server)
     self.bots[server] = bot
     channels = []
     for mapping in mappings:
         channel, subs = mapping.split(':', 1)
         norm_subs = '+'.join(sorted(subs.split('+')))
         if not norm_subs:
             raise Exception('No subreddits for %r:%r' % (server, channel))
         channels.append(channel)
         if norm_subs not in self.reddits:
             self.reddits[norm_subs] = RedditUpdater(norm_subs)
         self.reddits[norm_subs].add(bot, channel)
     use_ssl = items['irc_ssl'].lower() in ('1', 'yes', 'true', 'on')
     bot.connect(items['irc_host'], int(items['irc_port']),
                 channel=channels,
                 use_ssl=use_ssl)
     bot.identify(items['irc_pswd'])
Beispiel #4
0
 def parse_server(self, server, items):
     mappings = re.sub("\s", "", items["mapping"]).split(",")
     if not mappings:
         raise Exception("No mappings for %r" % server)
     bot = RedditBot(items["irc_name"], server)
     self.bots[server] = bot
     channels = []
     for mapping in mappings:
         channel, subs = mapping.split(":", 1)
         norm_subs = "+".join(sorted(subs.split("+")))
         if not norm_subs:
             raise Exception("No subreddits for %r:%r" % (server, channel))
         channels.append(channel)
         if norm_subs not in self.reddits:
             self.reddits[norm_subs] = RedditUpdater(norm_subs)
         self.reddits[norm_subs].add(bot, channel)
     use_ssl = items["irc_ssl"].lower() in ("1", "yes", "true", "on")
     bot.connect(items["irc_host"], int(items["irc_port"]), channel=channels, use_ssl=use_ssl)
     if "irc_msg" in items:
         bot.MSG_FORMAT = text_type(items["irc_msg"])
     if "irc_pswd" in items:
         bot.identify(items["irc_pswd"])
Beispiel #5
0
                            try: # sandboxing!
                                c.parse_command(command_name, command_args,
                                                event)
                            except Exception as ex:
                                self.send_message(event.target, event.source +
                                                  ", something has caused me " +
                                                  "to run into an error. " +
                                                  "Please bother the " +
                                                  "operator of this bot to " +
                                                  "fix me.")
                                print(traceback.print_exc())
                            had_command = True
                            break;
                    if not had_command:
                        self.send_message(event.target, event.source +
                                      ", sorry, \"!" + command_name + "\" is " +
                                      "not a defined command.")
    
    def on_feed_update(self, entry):
        for c in self.channel_set:
            print(c)
            print(entry.link + ": " + entry.title)
            with threading.Lock():
                self.send_message(c, entry.link + ": " + entry.title)

if __name__ == "__main__":
    import botguy_config
    bot = Botguy(botguy_config.nick, info_file=botguy_config.info_file)
    bot.connect(botguy_config.server, channel=botguy_config.channels)
    bot.start()
Beispiel #6
0
	except:
		print "invalid or incomplete configuration data provided."
		print sys.exc_info()
		sys.exit(1)

	return configs


if __name__ == "__main__":
	configs = config_parsing()

	timeout = timedelta(0, 180)
	def bot_poll():
		while True:
			sleep(30)
			time_since_last = datetime.now() - bot.last_event

			if ( time_since_last > timeout):
				print "we look disconnected!"
				bot.disconnect()
				bot.connect( configs['SERVER'] )
				bot.start()


	poller = Timer(15.0, bot_poll)
	poller.start()

	bot = DjangoBot( configs['NICK'] )
	bot.connect( configs['SERVER'] )
	bot.start()
Beispiel #7
0
                module = imp.load_source(name, filename)
            except Exception, e:
                print('Error reading module {0}: {1}'.format(name, e))
            else:
                try:
                    clsmembers = inspect.getmembers(module, inspect.isclass)
                    for _class in clsmembers:
                        try:
                            name, path = _class
                            self.register_listener(name, path())
                            self[name].add_handler(path)
                            print("Sucessfully loaded {0}...".format(name))
                        except Exception, e:
                            print("Failed to load {0}: {1}".format(name, e))
                except Exception, e:
                    print("Error getting module classes: {0}".format(e))


if __name__ == "__main__":

    config = Config("config.cfg")
    bot = IRCBot(config)
    bot.load_modules()

    channels = [i for i in config.channels]
    # Let's connect to the host
    bot.connect(config.bot["server"], channel=channels)

    # Start running the bot
    bot.start()
Beispiel #8
0
        # print self.TRIGGERS.viewitems()

    def parse_trigger(self, event):
        if event.message.upper() in self.TRIGGERS:
            print self.TRIGGERS[event.message.upper()]
            kind = self.TRIGGERS[event.message.upper()][0]
            message = self.TRIGGERS[event.message.upper()][1]
            self.response(kind, message, event)

    def start_parse(self, event):
        # We'll handle initial parsing in here.
        # If the message looks like an assignment, pass it to an appropriate method
        # If it looks like it could trigger something, likewise
        # regex at http://cl.ly/3W2W0J2j0P3o for analysis
        if event.message[0].upper() is 'EXITNOW':
            sys.exit(0)
        elif re.match(self.CANON_REGEX, event.message) is not None:
            self.parse_assignment(event, re.match(self.CANON_REGEX, event.message).groupdict(""))
        else:
            # If start_parse was called at all, we should check if it's a trigger
            self.parse_trigger(event)


if __name__ == '__main__':
    bot = Postbox()
    bot.connect('irc.freenode.net', channel=['#ridersofbrohan'])  # TODO: Unhardcode
    # for pair in bot.CHANNELS:
        # bot.connect(pair[1], channel=pair[0])
    print 'Starting...'
    bot.start()
Beispiel #9
0
    self.users[event.source] = token
    self.send_message(event.source, 'logged you in, %s' % event.source)

class Printer(object):
  def process(self, data):
    pprint.pprint(data)
    return getattr(self, data.keys()[0])(data[data.keys()[0]])

  def queue(self, users):
    return 'Queue has %s users: %s' % (len(users), ', '.join(users))

  def game(self, game):
    if game['state'] == 'accepting':
      return ('Offering game %s. Use !accept to confirm or !decline to leave the queue'
          '\n  Waiting on: %s'
          '\n  Accepted by: %s'
          % (game['id'], ', '.join(game['waiting']), ', '.join(game['accepted'])))
    elif game['state'] == 'active':
      return ('Game %s is ready. Join lobby with password %s'
          '\n  Radiant: %s\n  Dire: %s' % (game['password'], ', '.join(game['radiant']), ', '.join(game['dire'])))
  def ratings(self, ratings):
    return ('Rating changes from game %s: %s victory. Game quality: %0.2f'
        '\n  Radiant:' + (''.join(['\n    %s: mu %0.2f %+0.2f | sigma %0.2f %+0.2f' % 
          (u['username'], u['mu'], u['delta_mu'], u['sigma'], u['delta_sigma']) for u in ratings['radiant']])) +
        '\n  Dire:' +    (''.join(['\n    %s: mu %0.2f %+0.2f | sigma %0.2f %+0.2f' % 
          (u['username'], u['mu'], u['delta_mu'], u['sigma'], u['delta_sigma']) for u in ratings['dire']])))

bot = Bot(name)
bot.connect('irc.synirc.net', channel=channel)
bot.start()
Beispiel #10
0
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from ircutils import bot, format

class MyBot(bot.SimpleBot):

    first = True

    def on_welcome(self, event):
        self.send_message('[CYH]Bot', '!C1')

    def on_private_message(self, event):
        if self.first:
            self.first = False
            self.send_message('[CYH]Bot', '!A1 {0}'.format(event.message))
            print event.message

if __name__ == "__main__":
    bot = MyBot('_9258340d85ad')
    bot.connect('irc.idlemonkeys.net', 6667)
    bot.start()