Exemple #1
0
 def userRenamed(self, oldname, newname):
     '''
     Method called when other user has changed their nick.
     '''
     # Notify plugins and log event
     logging.debug("[NICK] %s -> %s", oldname, newname)
     ext.notify(self, 'nick', old = oldname, new = newname)
Exemple #2
0
    def nickChanged(self, nick):
        ''' Method called when bot's nick has changed. '''
        old = self.nickname
        self.nickname = nick

        logging.debug("[NICK] %s -> %s", old, nick)
        ext.notify(self, 'nick', old=old, new=nick)
Exemple #3
0
 def joined(self, channel):
     '''
     Method called when bot has joined a channel.
     '''
     # Notify plugins and log the event
     logging.debug("[JOIN] %s to %s", self.nickname, channel)
     ext.notify(self, 'join', channel = channel, user = self.nickname)
Exemple #4
0
 def userQuit(self, user, message):
     '''
     Method called when other user has disconnected from IRC.
     '''
     # Notify plugins and log event
     logging.debug("[QUIT] %s (%s)", user, message)
     ext.notify(self, 'quit', user = user, message = message)
Exemple #5
0
    def privmsg(self, user, channel, message):
        ''' Method called upon receiving a message on a channel or private message. '''
        if channel == "*":
            logging.debug("[SERVER] %s", message)
            return

        is_priv = channel == self.nickname
        ext.notify(self, 'message', user=user,
                   channel=None if is_priv else channel,
                   message=message, type=ext.MSG_SAY)

        if is_priv:
            is_command = True   # on priv, everything's a command
            if config.cmd_prefix and message.startswith(config.cmd_prefix):
                message = message[len(config.cmd_prefix):]  # remove prefix if present anyway
        else:
            if config.cmd_prefix:
                is_command = message.startswith(config.cmd_prefix)
                if is_command:
                    message = message[len(config.cmd_prefix):]
            else:
                is_command = True   # if no prefix is defined, everything is a command

        logging.info("[%s] <%s/%s> %s",
                     "COMMAND" if is_command else "MESSAGE",
                     user, channel if not is_priv else '__priv__', message)

        if is_command:
            resp = self._command(user, message,
                                 channel=None if is_priv else channel)
            if resp:
                logging.info("[RESPONSE] %s", resp)
                irc.say(self, user if is_priv else channel, resp)
Exemple #6
0
 def topicUpdated(self, user, channel, newTopic):
     '''
     Method called when topic of channel changes or upon joining the channel.
     '''
     # Notify plugins and log message
     logging.debug("[TOPIC] <%s/%s> %s", user, channel, newTopic)
     ext.notify(self, 'topic', channel = channel, topic = newTopic, user = user)
Exemple #7
0
 def privmsg(self, user, channel, message):
     '''
     Method called upon receiving a message on a channel or private message.
     '''
     # Discard server messages
     if channel == "*":  logging.debug("[SERVER] %s", message) ; return
     
     # Notify plugins
     ext.notify(self, 'message',
                user = user, channel = (channel if channel != self.nickname else None),
                message = message, type = ext.MSG_SAY)
     
     # First, check whether this is a private message and whether we shall interpret
     # it as a command invocation
     is_priv = channel == self.nickname
     if is_priv:
         is_command = True   # On priv, everything's a command
         if config.cmd_prefix and message.startswith(config.cmd_prefix): # Prefix is optional; get rid of it if present
             message = message[len(config.cmd_prefix):]
     else:
         if config.cmd_prefix:
             is_command = message.startswith(config.cmd_prefix)
             if is_command:  message = message[len(config.cmd_prefix):]  # Get rid of the prefix if present
         else:
             is_command = True   # If no prefix defined, everything is a command
     
     # Log message/command
     logging.info ("[%s] <%s/%s> %s", "COMMAND" if is_command else "MESSAGE",
                    user, channel if not is_priv else '__priv__', message)
     if is_command:
         resp = self._command(user, message)
         if resp:
             logging.info("[RESPONSE] %s", resp)
             irc.say(self, user if is_priv else channel, resp)
Exemple #8
0
 def userLeft(self, user, channel):
     '''
     Method called when other user has left a channel.
     '''
     # Notify plugins and log event
     logging.debug("[PART] %s from %s", self.nickname, channel)
     ext.notify(self, 'part', user = self.nickname, channel = channel)
Exemple #9
0
 def userJoined(self, user, channel):
     '''
     Method called when other user has joined a channel.
     '''
     # Notify plugins and log event
     logging.debug("[JOIN] %s to %s", user, channel)
     ext.notify(self, 'join', channel = channel, user = user)
Exemple #10
0
 def myInfo(self, servername, version, umodes, cmodes):
     '''
     Method called with information about the server.
     '''
     # Log and notify plugins
     logging.debug("[SERVER] %s running %s; usermodes=%s, channelmodes=%s", servername, version, umodes, cmodes)
     ext.notify(self, 'connect', host = servername)
Exemple #11
0
 def kickedFrom(self, channel, kicker, message):
     ''' Method called when bot is kicked from a channel. '''
     self.channels.remove(channel)
     logging.debug("[KICK] %s from %s by %s (%s)",
                   self.nickname, channel, kicker, message)
     ext.notify(self, 'kick', channel=channel,
                kicker=kicker, kickee=self.nickname, reason=message)
Exemple #12
0
 def kickedFrom(self, channel, kicker, message):
     '''
     Method called when bot is kicked from a channel.
     '''
     # Notify plugins and log event
     logging.debug("[KICK] %s from %s by %s (%s)", self.nickname, channel, kicker, message)
     ext.notify(self, 'kick', channel = channel, kicker = kicker, kickee = self.nickname, reason = message)
Exemple #13
0
 def userKicked(self, kickee, channel, kicker, message):
     '''
     Method called when other user is kicked from a channel.
     '''
     # Notify plugins and log event
     logging.debug("[KICK] %s from %s by %s (%s)", kickee, channel, kicker, message)
     ext.notify(self, 'kick', channel = channel, kicker = kicker, kickee = kickee, reason = message)
Exemple #14
0
 def modeChanged(self, user, channel, set, modes, args):
     '''
     Method called when user changes mode(s) for a channel.
     '''
     # Notify plugins and log the message
     logging.debug("[MODE] %s sets %s%s %s for %s", user, "+" if set else "-", modes, args, channel)
     ext.notify(self, 'mode',
                user = user, channel = channel, set = set, modes = modes, args = args)
Exemple #15
0
    def noticed(self, user, channel, message):
        ''' Method called upon recieving notice message (either channel or private). '''
        is_priv = channel == self.nickname

        logging.debug("[NOTICE] <%s/%s> %s", user,
                      channel if not is_priv else '__priv__', message)
        ext.notify(self, 'message',
                   user=user, channel=(channel if not is_priv else None),
                   message=message, type=ext.MSG_NOTICE)
Exemple #16
0
    def action(self, user, channel, message):
        ''' Method called when user performs and action (/me) in channel. '''
        is_priv = channel == self.nickname

        # Notify plugins and log message
        logging.debug("[ACTION] <%s/%s> %s", user,
                      channel if not is_priv else '__priv__', message)
        ext.notify(self, 'message',
                   user=user, channel=(channel if not is_priv else None),
                   message=message, type=ext.MSG_ACTION)
Exemple #17
0
 def noticed(self, user, channel, message):
     '''
     Method called upon recieving notice message (either channel or private).
     '''
     is_priv = channel == self.nickname
     
     # Notify plugins and log the message
     logging.debug("[NOTICE] <%s/%s> %s", user, channel if not is_priv else '__priv__', message)
     ext.notify(self, 'message',
                user = user, channel = (channel if not is_priv else None),
                message = message, type = ext.MSG_NOTICE)
Exemple #18
0
 def action(self, user, channel, message):
     '''
     Method called when user performs and action (/me) in channel.
     '''
     is_priv = channel == self.nickname
     
     # Notify plugins and log message
     logging.debug("[ACTION] <%s/%s> %s", user, channel if not is_priv else '__priv__', message)
     ext.notify(self, 'message',
                user = user, channel = (channel if not is_priv else None),
                message = message, type = ext.MSG_ACTION)
Exemple #19
0
 def nickChanged(self, nick):
     '''
     Method called when bot's nick has changed.
     '''
     # Remember new nick
     old = self.nickname
     self.nickname = nick
     
     # Notify plugins and log event
     logging.debug("[NICK] %s -> %s", old, nick)
     ext.notify(self, 'nick', old = old, new = nick)
Exemple #20
0
    def _command(self, user, command, channel=None):
        '''Internal function that handles the processing of commands.
        Returns the result of processing as a text response to be "said" by the bot,
        or None if it wasn't actually a command.

        :param channel: Channel where the command was issued
                        (can be None if it was private message command)
        '''
        m = COMMAND_RE.match(command)
        if not m:
            return

        cmd = m.group('cmd')
        args = m.groupdict().get('args')

        # Poll plugins for command result
        resp = ext.notify(self, 'command',
                          channel=channel, user=user, cmd=cmd, args=args)
        if resp:
            return resp

        # Plugins didn't care so find a command and invoke it if present
        cmd_object = ext.get_command(cmd)
        if cmd_object:
            if callable(cmd_object):
                try:
                    resp = cmd_object(args)
                except Exception, e:
                    resp = type(e).__name__ + ": " + str(e)
                resp = [resp]  # Since we expect response to be iterable
            else:
                return ["Invalid command '%s'; likely indicates faulty plugin" % cmd]
Exemple #21
0
 def _command(self, user, command):
     '''
     Internal function that handles the processing of commands. 
     Returns the result of processing as a text response to be "said" by the bot,
     or None if it wasn't actually a command.
     '''
     m = COMMAND_RE.match(command)
     if not m:   return
     
     cmd = m.group('cmd')
     args = m.groupdict().get('args')
     
     # Poll plugins for command result
     resp = ext.notify(self, 'command', user = user, cmd = cmd, args = args)
     if resp:    return resp
         
     # Plugins didn't care so find a command and invoke it if present
     cmd_object = ext.get_command(cmd)
     if cmd_object:
         if callable(cmd_object):    
             try:                    resp = cmd_object(args)
             except Exception, e:    resp = type(e).__name__ + ": " + str(e)
             resp = [resp] # Since we expect response to be iterable
         else:
             return ["Invalid command '%s'; likely indicates faulty plugin" % cmd]
     else:
         # Check whether the command can be unambiguously resolved
         completions = ext._commands.search(cmd).keys()
         if len(completions) == 1:
             command = completions[0]
             if args:    command += " %s" % args
             return self._command(user, command)
         
         # Otherwise, suggest other variants
         suggestions = set()
         for i in range(1, len(cmd) + 1):
             completions = ext._commands.search(cmd[:i]).keys()
             suggestions = suggestions.union(set(completions))
             
         if len(suggestions) == 0:
             resp = ["Unrecognized command '%s'." % cmd]
         else:
             # If there are too many suggestions, filter them out
             MAX_SUGGESTIONS = 5
             suggestions = filter(None, suggestions)
             more = None
             if len(suggestions) > MAX_SUGGESTIONS:
                 more = len(suggestions) - MAX_SUGGESTIONS
                 suggestions = suggestions[:MAX_SUGGESTIONS]
             
             # Format them
             if config.cmd_prefix:
                 suggestions = map(lambda s: config.cmd_prefix + s, suggestions)
             suggestions = str.join(" ", suggestions)
             if more:    suggestions += " ... (%s more)" % more
             
             resp = ["Did you mean one of: %s ?" % suggestions]
                 
     return resp
Exemple #22
0
 def tick(self):
     ''' Method called every second. Provides a way for plugins
     to perform actions based on time.
     '''
     ext.notify(self, 'tick')
Exemple #23
0
 def joined(self, channel):
     ''' Method called when bot has joined a channel. '''
     self.channels.add(channel)
     logging.debug("[JOIN] %s to %s", self.nickname, channel)
     ext.notify(self, 'join', channel=channel, user=self.nickname)
Exemple #24
0
 def left(self, channel):
     ''' Method called when bot has left a channel. '''
     self.channels.remove(channel)
     logging.debug("[PART] %s from %s", self.nickname, channel)
     ext.notify(self, 'part', user=self.nickname, channel=channel)