Beispiel #1
0
 def on_namreply(self, connection, event):
     owner = cast_unicode(event.arguments()[0])
     channel = cast_unicode(event.arguments()[1])
     names = cast_unicode(event.arguments()[-1]).split()
     logging.info("got names for %s: %s", channel, names)
     nameset = self.names[channel]
     for name in names:
         nameset.add(name.lstrip(owner))
Beispiel #2
0
    def on_pubmsg(self, connection, event):
        try:
            text = cast_unicode(event.arguments()[0])
        except IndexError:
            text = u''
        channel = cast_unicode(event.target() or '')
        
        logging.info("pubmsg: %s", text)

        # If you talk to the bot, this is how he responds.
        if self.nick_reg.search(text):
            logging.debug("bloop")
            if text.split(" ")[1] and text.split(" ")[1] == "quit":
                connection.privmsg(channel, "Goodbye.")
                self.on_ping( connection, event )
                sys.exit( 0 ) 
                
            if text.split(" ")[1] and text.split(" ")[1] == "ping":
                connection.privmsg(channel, "Pong.")
                self.on_ping(connection, event)
                return
Beispiel #3
0
 def _dispatcher(self, c, e):
     """dispatch events"""
     etype = e.eventtype()
     logging.debug(u"dispatch: %s: %r : %r : %r", etype, e.target(), e.source(), e.arguments())
     if etype in ('topic', 'part', 'join', 'action', 'quit', 'nick', 'pubmsg'):
         try: 
             source = cast_unicode(e.source().split("!")[0])
         except IndexError:
             source = u''
         try:
             text = cast_unicode(e.arguments()[0])
         except IndexError:
             text = u''
         
         # update names lists
         if etype == 'join':
             channel = e.target()
             logging.info("%s joined %s", source, channel)
             self.names[channel].add(source)
         elif etype == 'part':
             channel = e.target()
             logging.info("%s parted %s", source, channel)
             self.names[channel].remove(source)
         
         # Prepare a message for the buffer
         message_dict = {"channel": e.target() or u'',
                         "name": source,
                         "message": text,
                         "type": etype,
                         "time": datetime.datetime.utcnow() } 
                         
         if etype == "nick":
             message_dict["message"] = e.target()
             before = source
             after = e.target()
             
             found = []
             for channel, nameset in self.names.items():
                 if before in nameset:
                     nameset.remove(before)
                     nameset.add(after)
                     logging.info("%s renamed to %s in %s", before, after, channel)
                     md = dict(message_dict)
                     md['channel'] = channel
                     self.message_cache.append( md )
         elif etype == "quit":
             name = source
             logging.info("%s quit", name)
             for channel, nameset in self.names.items():
                 if name in nameset:
                     nameset.remove(name)
                     md = dict(message_dict)
                     md['channel'] = channel
                     self.message_cache.append( md )
         else:
             # Most of the events are pushed to the buffer. 
             self.message_cache.append( message_dict )
     
     m = "on_" + etype
     if hasattr(self, m):
         getattr(self, m)(c, e)