Ejemplo n.º 1
0
 def message(self, bot, channel, user, message, type):
     '''
     Called when bot "hears" a message.
     '''
     if not channel: return          # Only interested in channel messages
     nick = irc.get_nick(user)
     
     # Collect messages pertaining to this user
     messages = [] ; files = []
     for recp in self._list_recipients():
         if fnmatch.fnmatch(nick, recp):
             
             # Read messages from file
             file = self._get_filename(recp)
             with open(file) as f:
                 messages.extend(json.load(f))
             files.append(file)
                 
     # Format and send them
     msgs = []
     for message in messages:
         msg_time = datetime.fromtimestamp(message['timestamp'])
         msg_time = msg_time.strftime("%Y-%m-%d %H:%M:%S")
         
         msg = "%s <%s> %s: %s" % (msg_time, message['from'], nick, message['message'])
         msgs.append(msg)
     irc.say(bot, channel, msgs)
     
     # Delete files
     for file in files:  os.unlink(file)
     
     # Log delivery
     log_file = os.path.join(self.dir, "delivery.log")
     with open(log_file, 'a') as log:
         log.writelines(m + "\n" for m in msgs)
Ejemplo n.º 2
0
Archivo: bot.py Proyecto: gflerm/seejoo
    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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def join(self, bot, channel, user):
        '''
        Called when user joins a channel.
        '''
        # Retrieve the nick
        nick = irc.get_nick(user)
        if nick == bot.nickname: return  # Only interested in others joining

        # Check if we have greeting and serve it
        greet = self.greets.get(nick)
        if greet: irc.say(bot, channel, greet)
Ejemplo n.º 5
0
 def join(self, bot, channel, user):
     '''
     Called when user joins a channel.
     '''
     # Retrieve the nick
     nick = irc.get_nick(user)
     if nick == bot.nickname:    return  # Only interested in others joining
     
     # Check if we have greeting and serve it
     greet = self.greets.get(nick)
     if greet:   irc.say(bot, channel, greet)
Ejemplo n.º 6
0
Archivo: bot.py Proyecto: Xion/seejoo
    def signedOn(self):
        ''' Method called upon successful connection to IRC server. '''
        self.factory.resetDelay()
        logging.debug("[CONNECT] Connected to server")

        if config.nickserv_password:
            logging.debug(
                "[CONNECT] Identifying with %s..." % config.nickserv_bot)
            irc.say(self, config.nickserv_bot,
                    "IDENTIFY " + config.nickserv_password,
                    log=False)

        for chan in config.channels:
            self.join(chan)
Ejemplo n.º 7
0
    def message(self, bot, channel, user, message, type):
        """Called when we hear a message being spoken."""
        if not channel or channel == '*':
            return
        # if message comes from server
        if '!' not in user:
            return

        if irc.get_nick(user) == bot.nickname:
            return

        url_match = URL_RE.search(message)
        if url_match:
            result = self._resolve_url(url_match.group(0))
            if result:
                type_, title = result
                irc.say(bot, channel, u"[%s] %s" % (type_, title))
Ejemplo n.º 8
0
Archivo: rss.py Proyecto: Xion/seejoo
    def _announce_feed(self, name, items):
        """ Announces polled feed items to all target channels. """
        feed = self.feeds[name]
        channels = feed.get('announce')
        if not channels or channels in ['everywhere', 'all']:
            channels = self.bot.channels

        for item in items:
            title = item['title']
            if 'filter' in feed and not feed['filter'].match(title):
                continue

            # don't display '(by X)' if there's no author
            author = item.get('authorName')
            by = " (by %s)" % author if author else ""

            item_text = "@ %s -> %s%s -- %s" % (name, title, by, item['link'])
            for channel in channels:
                irc.say(self.bot, channel, item_text)