Example #1
0
 def _on_part(self, c, e):
     if not self._match_list(e.target, self.channels): return
     m = {'channel': e.target,
          'nick': nm_to_n(e.source)}
     self._add_times(m)
     m = self._strip(m)
     self.write(self._part_f % m)
Example #2
0
File: log.py Project: maw/kibot
 def _on_part(self, c, e):
     if not self._match_list(e.target, self.channels): return
     m = {'channel': e.target,
          'nick': nm_to_n(e.source)}
     self._add_times(m)
     m = self._strip(m)
     self.write(self._part_f % m)
Example #3
0
    def _pubmsg_ping_notify_handler(self, c, e):
        m = re.match(self._ping_re, e.args[0])
        if not m: return

        # it matched
        pingee = m.group(1)

        userid = self.bot.ircdb.get_userid(nick=pingee)
        if not self.notify_list.get(userid): return

        pinger = nm_to_n(e.source)
        channel = e.target
        now = time.strftime('%c', time.localtime())

        nicks = self.bot.ircdb.get_nicks(userid=userid)

        if nicks == [pingee]:
            msg = '%s pinged you on %s on %s' % \
                  (pinger, channel, now)
        else:
            msg = '%s pinged you (%s) on %s on %s' % \
                  (pinger, pingee, channel, now)

        for nick in nicks:
            self.bot.conn.privmsg(nick, msg)
Example #4
0
 def _on_topic(self, c, e):
     if is_channel(e.target) and self._match_list(e.target, self.channels):
         m = {'nick': nm_to_n(e.source),
              'channel': e.target,
              'topic': e.args[0]}
         self._add_times(m)
         m = self._strip(m)
         self.write(self._topic_f % m)
Example #5
0
File: log.py Project: maw/kibot
 def _on_topic(self, c, e):
     if is_channel(e.target) and self._match_list(e.target, self.channels):
         m = {'nick': nm_to_n(e.source),
              'channel': e.target,
              'topic': e.args[0]}
         self._add_times(m)
         m = self._strip(m)
         self.write(self._topic_f % m)
Example #6
0
    def _on_mode(self, c, e):
        """handler for mode changes
        This method is more complex than the others.  First, it ONLY handles
        channel mode changes.  This includes bans, ops, voice, topic lock,
        etc.  Non-channel modes are ignored.

        For each mode individually, the following things happen:
        1) if the instance has a method called _handle_mode_X (where
           X is the specific mode) it will be called with the following
           args: connection_object, event_object, source_nick,
                 target_channel, sign, mode, arg

           For example, if seth gives michael ops on #dhg, you would
           see this: (<conn>, <event>, 'seth', '#dhg', '+', 'o', 'michael')

           if the function returns None (this is what happens when
           there is no explicit "return") then processing goes on to
           the next "chunk".  Otherwise, processing continues to (2)

        2) The standard "m" dict is formed.

        3) if the instance has an attribute called _mode_X_f then it
           will be used as the format string for writing the mode.
           Otherwise, the attribute _mode_f will be used.  Therefore,
           you should define _mode_f as a "generic mode" format, which
           you can override with _mode_X_f attributes or _handle_mode_X
           methods.

        Note that this happens for each perm "chunk".  A single mode
        command can contain may chunks.  For example:
          /mode #dhg +ov michael michael
        This will first be processed with
          (sign, mode, arg) = ('+', 'o', 'michael')
        and then
          (sign, mode, arg) = ('+', 'v', 'michael')

        m contains the following keys:
          utime, htime, source, channel, sign, mode, arg, raw
        where raw is (for example) '+v michael'
        """
        if not (is_channel(e.target) and
                self._match_list(e.target, self.channels)): return
        t = e.target
        s = nm_to_n(e.source)
        string_modes = ' '.join(e.args)
        modes = parse_channel_modes(string_modes)
        m = {'source': s, 'channel': t}
        self._add_times(m)
        for sign, mode, arg in modes:
            meth = getattr(self, '_handle_mode_' + mode, None)
            if meth is not None:
                if not meth(c, e, s, t, sign, mode, arg): continue

            raw = '%s%s %s' % (sign, mode, arg)
            new = {'sign': sign, 'mode': mode, 'arg': arg, 'raw': raw}
            m.update(self._strip(new))
            format = getattr(self, '_mode_%s_f' % mode, self._mode_f)
            self.write(format % m)
Example #7
0
File: log.py Project: maw/kibot
    def _on_mode(self, c, e):
        """handler for mode changes
        This method is more complex than the others.  First, it ONLY handles
        channel mode changes.  This includes bans, ops, voice, topic lock,
        etc.  Non-channel modes are ignored.

        For each mode individually, the following things happen:
        1) if the instance has a method called _handle_mode_X (where
           X is the specific mode) it will be called with the following
           args: connection_object, event_object, source_nick,
                 target_channel, sign, mode, arg

           For example, if seth gives michael ops on #dhg, you would
           see this: (<conn>, <event>, 'seth', '#dhg', '+', 'o', 'michael')

           if the function returns None (this is what happens when
           there is no explicit "return") then processing goes on to
           the next "chunk".  Otherwise, processing continues to (2)

        2) The standard "m" dict is formed.

        3) if the instance has an attribute called _mode_X_f then it
           will be used as the format string for writing the mode.
           Otherwise, the attribute _mode_f will be used.  Therefore,
           you should define _mode_f as a "generic mode" format, which
           you can override with _mode_X_f attributes or _handle_mode_X
           methods.

        Note that this happens for each perm "chunk".  A single mode
        command can contain may chunks.  For example:
          /mode #dhg +ov michael michael
        This will first be processed with
          (sign, mode, arg) = ('+', 'o', 'michael')
        and then
          (sign, mode, arg) = ('+', 'v', 'michael')

        m contains the following keys:
          utime, htime, source, channel, sign, mode, arg, raw
        where raw is (for example) '+v michael'
        """
        if not (is_channel(e.target) and
                self._match_list(e.target, self.channels)): return
        t = e.target
        s = nm_to_n(e.source)
        string_modes = ' '.join(e.args)
        modes = parse_channel_modes(string_modes)
        m = {'source': s, 'channel': t}
        self._add_times(m)
        for sign, mode, arg in modes:
            meth = getattr(self, '_handle_mode_' + mode, None)
            if meth is not None:
                if not meth(c, e, s, t, sign, mode, arg): continue

            raw = '%s%s %s' % (sign, mode, arg)
            new = {'sign': sign, 'mode': mode, 'arg': arg, 'raw': raw}
            m.update(self._strip(new))
            format = getattr(self, '_mode_%s_f' % mode, self._mode_f)
            self.write(format % m)
Example #8
0
File: log.py Project: maw/kibot
 def _on_kick(self, c, e):
     if not self._match_list(e.target, self.channels): return
     m = {'channel': e.target,
          'source': nm_to_n(e.source),
          'target': e.args[0],
          'message': e.args[1]}
     self._add_times(m)
     m = self._strip(m)
     self.write(self._kick_f % m)
Example #9
0
 def _on_pubnotice(self, c, e):
     if not self._match_list(e.target, self.channels): return
     m = {'target': e.target,
          'source': nm_to_n(e.source),
          'message': e.args[0],
          'type': 'public'}
     self._add_times(m)
     m = self._strip(m)
     self.write(self._pubnotice_f % m)
Example #10
0
File: log.py Project: maw/kibot
 def _on_pubnotice(self, c, e):
     if not self._match_list(e.target, self.channels): return
     m = {'target': e.target,
          'source': nm_to_n(e.source),
          'message': e.args[0],
          'type': 'public'}
     self._add_times(m)
     m = self._strip(m)
     self.write(self._pubnotice_f % m)
Example #11
0
 def _on_kick(self, c, e):
     if not self._match_list(e.target, self.channels): return
     m = {'channel': e.target,
          'source': nm_to_n(e.source),
          'target': e.args[0],
          'message': e.args[1]}
     self._add_times(m)
     m = self._strip(m)
     self.write(self._kick_f % m)
Example #12
0
 def _on_privmsg(self, c, e):
     snick = nm_to_n(e.source)
     if not self._match_list(snick, self.nicks): return
     m = {'target': self.bot.nick,
          'source': snick,
          'message': e.args[0],
          'type': 'private'}
     self._add_times(m)
     m = self._strip(m)
     self.write(self._privmsg_f % m)
Example #13
0
File: log.py Project: maw/kibot
 def _on_privmsg(self, c, e):
     snick = nm_to_n(e.source)
     if not self._match_list(snick, self.nicks): return
     m = {'target': self.bot.nick,
          'source': snick,
          'message': e.args[0],
          'type': 'private'}
     self._add_times(m)
     m = self._strip(m)
     self.write(self._privmsg_f % m)
Example #14
0
File: log.py Project: maw/kibot
    def _on_nick(self, c, e):
        for chan_name, chan_obj in self.bot.ircdb.channels.items():
            if chan_obj.has_user(e.target) and \
                   self._match_list(chan_name, self.channels):
                break # skips else
        else:
            return

        m = {'old': nm_to_n(e.source),
             'new': e.target}
        self._add_times(m)
        m = self._strip(m)
        self.write(self._nick_f % m)
Example #15
0
    def _on_nick(self, c, e):
        for chan_name, chan_obj in self.bot.ircdb.channels.items():
            if chan_obj.has_user(e.target) and \
                   self._match_list(chan_name, self.channels):
                break # skips else
        else:
            return

        m = {'old': nm_to_n(e.source),
             'new': e.target}
        self._add_times(m)
        m = self._strip(m)
        self.write(self._nick_f % m)
Example #16
0
File: log.py Project: maw/kibot
 def _on_ctcp_action(self, c, e):
     m = {'target': e.target,
          'source': nm_to_n(e.source),
          'message': e.args[0]}
     if is_channel(e.target):
         if not self._match_list(e.target, self.channels): return
         m['type'] = 'public'
         form = self._pubaction_f
     else:
         if not self._match_list(e.target, self.nicks): return
         m['type'] = 'private'
         form = self._privaction_f
     self._add_times(m)
     m = self._strip(m)
     self.write(form % m)
Example #17
0
 def _on_ctcp_action(self, c, e):
     m = {'target': e.target,
          'source': nm_to_n(e.source),
          'message': e.args[0]}
     if is_channel(e.target):
         if not self._match_list(e.target, self.channels): return
         m['type'] = 'public'
         form = self._pubaction_f
     else:
         if not self._match_list(e.target, self.nicks): return
         m['type'] = 'private'
         form = self._privaction_f
     self._add_times(m)
     m = self._strip(m)
     self.write(form % m)
Example #18
0
    def _on_privnotice(self, c, e):
        if e.source is None:
            source = getattr(c, 'real_server_name', c.server)
            if not self._match_list(source, self.servers): return
            format = self._servernotice_f
        else:
            source = nm_to_n(e.source)
            if not self._match_list(source, self.nicks): return
            format = self._privnotice_f

        m = {'target': self.bot.nick,
             'source': source,
             'message': e.args[0],
             'type': 'private'}
        self._add_times(m)
        m = self._strip(m)
        self.write(format % m)
Example #19
0
File: log.py Project: maw/kibot
    def _on_privnotice(self, c, e):
        if e.source is None:
            source = getattr(c, 'real_server_name', c.server)
            if not self._match_list(source, self.servers): return
            format = self._servernotice_f
        else:
            source = nm_to_n(e.source)
            if not self._match_list(source, self.nicks): return
            format = self._privnotice_f

        m = {'target': self.bot.nick,
             'source': source,
             'message': e.args[0],
             'type': 'private'}
        self._add_times(m)
        m = self._strip(m)
        self.write(format % m)
Example #20
0
    def _onlow_quit(self, c, e):
        nick = nm_to_n(e.source)
        for chan_name, chan_obj in self.bot.ircdb.channels.items():
            self.bot.log(0, 'checking %s' % chan_name)
            if chan_obj.has_user(nick) and \
                   self._match_list(chan_name, self.channels):
                self.bot.log(0, 'success')
                break # skips else
            else:
                self.bot.log(0, "%s %s" % (chan_obj.has_user(nick),
                                           self._match_list(chan_name, self.channels)))
                self.bot.log(0, 'failure')
        else:
            return

        m = {'nick': nick,
             'message': e.args[0]}
        self._add_times(m)
        m = self._strip(m)
        self.write(self._quit_f % m)
Example #21
0
File: log.py Project: maw/kibot
    def _onlow_quit(self, c, e):
        nick = nm_to_n(e.source)
        for chan_name, chan_obj in self.bot.ircdb.channels.items():
            self.bot.log(0, 'checking %s' % chan_name)
            if chan_obj.has_user(nick) and \
                   self._match_list(chan_name, self.channels):
                self.bot.log(0, 'success')
                break # skips else
            else:
                self.bot.log(0, "%s %s" % (chan_obj.has_user(nick),
                                           self._match_list(chan_name, self.channels)))
                self.bot.log(0, 'failure')
        else:
            return

        m = {'nick': nick,
             'message': e.args[0]}
        self._add_times(m)
        m = self._strip(m)
        self.write(self._quit_f % m)
Example #22
0
 def _on_ctcp_action(self, c, e):
     nick = nm_to_n(e.source)
     userid = self.bot.ircdb.get_userid(nickmask=e.source)
     channel = e.target
     now = time.time()
     self._update_seen_maps(nick, userid, channel, now)
Example #23
0
 def _pubmsg_seen_handler(self, c, e):
     nick = nm_to_n(e.source)
     userid = self.bot.ircdb.get_userid(nickmask=e.source)
     channel = e.target
     now = time.time()
     self._update_seen_maps(nick, userid, channel, now)
Example #24
0
 def _on_join(self, c, e):
     nick = nm_to_n(e.source)
     userid = self.bot.ircdb.get_userid(nick=nick)
     if userid is None: self._notify(nick, None)