示例#1
0
 def on_pubmsg(self, connection, event):
     source = event.source.split('!')[0]
     chan = None
     if source in self.ignore_list:
         return
     for ch in self.channel_list:
         if event.target == ch.name:
             chan = ch
     chan.last_speaker = source
     # --- DEBUG ONLY ---#
     # connection.privmsg(event.target, '%s: %s' % (source, ' '.join(event.arguments)))
     #------------------#
     args = event.arguments[0].split()
     # Check for any urls in the arguments
     url_args = [arg for arg in args if arg.startswith('http')]
     if len(args) < 1:
         return
     #Look for triggered commands
     if args[0].startswith("!"):
         cmd_class = CommandFactory.factory(args[0], connection, event, chan, self.start_time)
         if cmd_class:
             cmd_class.resolve()
     #Last-Ten Quote Voting handler
     elif chan.is_valid_vote(args, source):
         choice = int(args[1])
         choice_idx = choice - 1
         if 0 < choice <= len(chan.quote_bets):  # PYTHON WOOH
             # Check if someone else already picked it
             if not chan.quote_bets[choice_idx]['who']:
                 chan.quote_bets[choice_idx]['who'] = source
                 vote_response = '\x02{}\x0f chose \x02{}\x0f'.format(source, chan.quote_bets[choice_idx]['src'])
             else:
                 vote_response = '\x02{}\x0f was already chosen by \x02{}\x0f'.format(
                     chan.quote_bets[choice_idx]['who'], source)
             connection.privmsg(event.target, vote_response)
     # Grab/display <title> text for URLs
     elif len(url_args) > 0:
         for arg in url_args:
             soup = make_soup(arg, event.target, self.cfg)
             if soup and soup.title and soup.title.string:
                 title = re.sub(r'\s+', r' ', soup.title.string).strip()
                 good_title = ""
                 for char in title:
                     try:
                         good_title += char.decode('utf-8')
                     except UnicodeEncodeError:
                         continue
                 connection.privmsg(event.target, '[title] {}'.format(good_title))
     # He should only look for things like 'botsnack' if there's nothing else to do!
     else:
         self.match_keyword_list(connection, event, args)