Example #1
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 #2
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 #3
0
File: irc.py Project: maw/kibot
 def _on_mode(self, c, e):
     mynick = self.bot.nick
     modes = parse_channel_modes(string.join(e.args))
     t = e.target
     if is_channel(t):
         if not self._i_have_op(t): return
         for sign, mode, nick in modes:
             if sign == "+" and mode == "o" and nick == mynick:
                 self._check_all(c, t)
Example #4
0
 def _on_mode(self, c, e):
     mynick = self.bot.nick
     modes = parse_channel_modes(' '.join(e.args))
     t = e.target
     if is_channel(t):
         if not self._i_have_op(t): return
         for sign, mode, nick in modes:
             if sign == "+" and mode == "o" and nick == mynick:
                 self._check_all(c, t)