Beispiel #1
0
    def mode(self, target=None, **kw):
        """MODE

            %%MODE <channel> <modes> <nicks>...
            %%MODE <modes> <nick>
        """
        if target.is_channel:
            super(ServerUserlist, self).mode(target=target, **kw)
        elif kw['data'] is None:
            client = kw['client']
            modes = kw['modes']
            if not modes.startswith(('+', '-')):
                modes = '+' + modes
            modes = utils.parse_modes(modes, noargs=string.ascii_letters)
            for char, mode, tgt in modes:
                meth = getattr(self.context, 'UMODE_' + mode, None)
                if meth is not None:
                    if meth(client, target, char, mode):
                        if char == '+':
                            client.modes.add(mode)
                        elif mode in client.modes:
                            client.modes.remove(mode)
                else:
                    client.fwrite(rfc.ERR_UMODEUNKNOWNFLAG)
        else:
            client.fwrite(rfc.ERR_NOSUCHCHANNEL, channel=target)
Beispiel #2
0
    def mode(self, target=None, **kw):
        """MODE

            %%MODE <channel> <modes> <nicks>...
            %%MODE <modes> <nick>
        """
        if target.is_channel:
            super(ServerUserlist, self).mode(target=target, **kw)
        elif kw['data'] is None:
            client = kw['client']
            modes = kw['modes']
            if not modes.startswith(('+', '-')):
                modes = '+' + modes
            modes = utils.parse_modes(modes, noargs=string.ascii_letters)
            for char, mode, tgt in modes:
                meth = getattr(self.context, 'UMODE_' + mode, None)
                if meth is not None:
                    if meth(client, target, char, mode):
                        if char == '+':
                            client.modes.add(mode)
                        elif mode in client.modes:
                            client.modes.remove(mode)
                else:
                    client.fwrite(rfc.ERR_UMODEUNKNOWNFLAG)
        else:
            client.fwrite(rfc.ERR_NOSUCHCHANNEL, channel=target)
Beispiel #3
0
 def mode(self, target=None, modes=None, data=None, client=None, **kw):
     """Add nicknames to channel.modes"""
     if target[0] not in self.context.server_config['CHANTYPES'] \
        or not data:
         # not a channel or no user target
         return
     noargs = self.context.server_config['CHANMODES'].split(',')[-1]
     if not isinstance(data, list):
         data = [d for d in data.split(' ') if d]
     if not modes.startswith(('+', '-')):
         modes = '+' + modes
     modes = utils.parse_modes(modes, data, noargs)
     prefix = self.context.server_config['PREFIX']
     prefix = dict(zip(*prefix.strip('(').split(')')))
     channel = self.channels[target]
     for char, mode, tgt in modes:
         if mode in prefix:
             nicknames = channel.modes[prefix[mode]]
             if char == '+':
                 nicknames.add(tgt)
             elif tgt in nicknames:
                 nicknames.remove(tgt)
             if client is not None:
                 broadcast = (
                     ':{mask} MODE {target} {char}{mode} {tgt}').format(
                     char=char, mode=mode, target=target, tgt=tgt,
                     **client.data)
                 self.broadcast(client=client, broadcast=broadcast,
                                clients=channel)
Beispiel #4
0
 def mode(self, target=None, modes=None, data=None, client=None, **kw):
     """Add nicknames to channel.modes"""
     if target[0] not in self.context.server_config['CHANTYPES'] \
        or not data:
         # not a channel or no user target
         return
     noargs = self.context.server_config['CHANMODES'].split(',')[-1]
     if not isinstance(data, list):
         data = [d for d in data.split(' ') if d]
     if not modes.startswith(('+', '-')):
         modes = '+' + modes
     modes = utils.parse_modes(modes, data, noargs)
     prefix = self.context.server_config['PREFIX']
     prefix = dict(zip(*prefix.strip('(').split(')')))
     channel = self.channels[target]
     for char, mode, tgt in modes:
         if mode in prefix:
             nicknames = channel.modes[prefix[mode]]
             if char == '+':
                 nicknames.add(tgt)
             elif tgt in nicknames:
                 nicknames.remove(tgt)
             if client is not None:
                 broadcast = (
                     ':{mask} MODE {target} {char}{mode} {tgt}').format(
                     char=char, mode=mode, target=target, tgt=tgt,
                     **client.data)
                 self.broadcast(client=client, broadcast=broadcast,
                                clients=channel)
Beispiel #5
0
 def mode(self, target=None, modes=None, data=None, client=None, **kw):
     """Add nicknames to channel.modes"""
     if target[0] not in self.context.server_config["CHANTYPES"] or not data:
         # not a channel or no user target
         return
     noargs = self.context.server_config["CHANMODES"].split(",")[-1]
     if not isinstance(data, list):
         data = [d for d in data.split(" ") if d]
     if not modes.startswith(("+", "-")):
         modes = "+" + modes
     modes = utils.parse_modes(modes, data, noargs)
     prefix = self.context.server_config["PREFIX"]
     prefix = dict(zip(*prefix.strip("(").split(")")))
     target = self.context.casefold(target)
     channel = self.channels[target]
     for char, mode, tgt in modes:
         if mode in prefix:
             nicknames = channel.modes[prefix[mode]]
             if char == "+":
                 nicknames.add(tgt)
             elif tgt in nicknames:
                 nicknames.remove(tgt)
             if client is not None:
                 broadcast = (":{mask} MODE {target} {char}{mode} {tgt}").format(
                     char=char, mode=mode, target=target, tgt=tgt, **client.data
                 )
                 self.broadcast(client=client, broadcast=broadcast, clients=channel)
Beispiel #6
0
 def mode(self, target=None, modes=None, data=None, **kw):
     """Add nicknames to channel.modes"""
     if target[0] not in self.bot.server_config['CHANTYPES'] or not data:
         # not a channel or no user target
         return
     noargs = self.bot.server_config['CHANMODES'].split(',')[-1]
     data = [d for d in data.split(' ') if d]
     modes = utils.parse_modes(modes, data, noargs)
     prefix = self.bot.server_config['PREFIX']
     prefix = dict(zip(*prefix.strip('(').split(')')))
     channel = self.channels[target]
     for char, mode, target in modes:
         if mode in prefix:
             nicknames = channel.modes[prefix[mode]]
             if char == '+':
                 nicknames.add(target)
             elif target in nicknames:
                 nicknames.remove(target)