Exemplo n.º 1
0
def getmask(hostmask):
    if hostmask in _hostmaskToBanMask:
        return _hostmaskToBanMask[hostmask]
    (n, u, h) = ircutils.splitHostmask(hostmask)
    if h.find("$") != -1:
        h = h.split("$")[0]
    if h.count(":") > 3:
        a = h.split(":")
        m = a[0] + ":" + a[1] + ":" + a[2] + ":*"
        _hostmaskToBanMask[hostmask] = ircutils.joinHostmask("*", "*", m)
        return _hostmaskToBanMask[hostmask]
    elif h.startswith("gateway/tor-sasl"):
        _hostmaskToBanMask[hostmask] = ircutils.joinHostmask("*", "*", h)
        return _hostmaskToBanMask[hostmask]
    elif h.startswith("gateway/"):
        a = u.split("~")
        if len(a) > 1:
            u = "*" + a[1]
        else:
            u = a[0]
        ha = h.split("/")
        _hostmaskToBanMask[hostmask] = ircutils.joinHostmask("*", u, "%s/%s/%s/*" % (ha[0], ha[1], ha[2]))
        return _hostmaskToBanMask[hostmask]
    elif h.startswith("nat/"):
        a = h.split("/")
        b = u.split("~")
        if len(b) > 1:
            b = "*" + b[1]
        else:
            b = b[0]
        _hostmaskToBanMask[hostmask] = ircutils.joinHostmask("*", b, a[0] + "/" + a[1] + "/*")
        return _hostmaskToBanMask[hostmask]
    else:
        if h.find("/") == -1:
            if not isip(h):
                try:
                    r = socket.getaddrinfo(h, None)
                    if r[0][4][0].count("::") > 3:
                        a = r[0][4][0].split(":")
                        m = a[0] + ":" + a[1] + ":" + a[2] + ":*"
                        _hostmaskToBanMask[hostmask] = ircutils.joinHostmask("*", "*", m)
                        return _hostmaskToBanMask[hostmask]
                    else:
                        _hostmaskToBanMask[hostmask] = ircutils.joinHostmask("*", "*", "*%s" % r[0][4][0])
                        return _hostmaskToBanMask[hostmask]
                except:
                    _hostmaskToBanMask[hostmask] = ircutils.joinHostmask("*", "*", "*%s" % h)
                    return _hostmaskToBanMask[hostmask]
            else:
                _hostmaskToBanMask[hostmask] = ircutils.joinHostmask("*", "*", "*%s" % h)
                return _hostmaskToBanMask[hostmask]
        else:
            _hostmaskToBanMask[hostmask] = ircutils.joinHostmask("*", "*", "*%s" % h)
            return _hostmaskToBanMask[hostmask]
    return None
Exemplo n.º 2
0
 def unstab(self,irc,msg,args,channel,user):
  """<user>
  
  Removes +q from a user in channel"""
  hmask = irc.state.nickToHostmask(user)
  hostmask = ircutils.joinHostmask('*', '*', ircutils.hostFromHostmask(hmask))
  irc.queueMsg(ircmsgs.IrcMsg('MODE {} -q {}'.format(channel,hostmask)))
Exemplo n.º 3
0
 def stab(self,irc,msg,args,channel,user,timer,reason):
  """<user> [seconds] [reason (ignored)]

  Stabs a user, putting them on quiet for a random time up to 10 mins."""

  hmask = irc.state.nickToHostmask(user)
  hostmask = ircutils.joinHostmask('*', '*', ircutils.hostFromHostmask(hmask))
  irc.queueMsg(ircmsgs.IrcMsg('MODE {0} +q {1}'.format(channel,hostmask)))

  t = time.time()
  r = timer
  if not r > 0:
   r = random.randint(30,600)
  expires = t+r

  len={}
  len['m'] = len['s'] = 0

  while r > 59:
   len['m']+=1
   r-=60

  len['s'] = r 

  irc.queueMsg(ircmsgs.IrcMsg('NOTICE {0} :{1} has been quieted for {2}:{3:0>2}'.format(msg.nick,user,len['m'],len['s'])))
  def f():
   irc.queueMsg(ircmsgs.IrcMsg('MODE {0} -q {1}'.format(channel,hostmask)))
  schedule.addEvent(f,expires)
  irc.noReply()
Exemplo n.º 4
0
    def setUp(self, nick='test', forceSetup=False):
        if not forceSetup and \
                self.__class__ in (PluginTestCase, ChannelPluginTestCase):
            # Necessary because there's a test in here that shouldn\'t run.
            return
        SupyTestCase.setUp(self)
        # Just in case, let's do this.  Too many people forget to call their
        # super methods.
        for irc in world.ircs[:]:
            irc._reallyDie()
        # Set conf variables appropriately.
        conf.supybot.reply.whenAddressedBy.chars.setValue('@')
        conf.supybot.reply.error.detailed.setValue(True)
        conf.supybot.reply.whenNotCommand.setValue(True)
        self.myVerbose = world.myVerbose

        def rmFiles(dir):
            for filename in os.listdir(dir):
                file = os.path.join(dir, filename)
                if os.path.isfile(file):
                    os.remove(file)
                else:
                    shutil.rmtree(file)

        if self.cleanConfDir:
            rmFiles(conf.supybot.directories.conf())
        if self.cleanDataDir:
            rmFiles(conf.supybot.directories.data())
        ircdb.users.reload()
        ircdb.ignores.reload()
        ircdb.channels.reload()
        if self.plugins is None:
            raise ValueError, 'PluginTestCase must have a "plugins" attribute.'
        self.nick = nick
        self.prefix = ircutils.joinHostmask(nick, 'user', 'host.domain.tld')
        self.irc = getTestIrc()
        MiscModule = plugin.loadPluginModule('Misc')
        OwnerModule = plugin.loadPluginModule('Owner')
        ConfigModule = plugin.loadPluginModule('Config')
        _ = plugin.loadPluginClass(self.irc, MiscModule)
        _ = plugin.loadPluginClass(self.irc, OwnerModule)
        _ = plugin.loadPluginClass(self.irc, ConfigModule)
        if isinstance(self.plugins, str):
            self.plugins = [self.plugins]
        else:
            for name in self.plugins:
                if name not in ('Owner', 'Misc', 'Config'):
                    module = plugin.loadPluginModule(name,
                                                     ignoreDeprecation=True)
                    cb = plugin.loadPluginClass(self.irc, module)
        self.irc.addCallback(TestInstance)
        for (name, value) in self.config.iteritems():
            group = conf.supybot
            parts = registry.split(name)
            if parts[0] == 'supybot':
                parts.pop(0)
            for part in parts:
                group = group.get(part)
            self.originals[group] = group()
            group.setValue(value)
Exemplo n.º 5
0
    def makeBanmask(self, hostmask, options=None):
        """Create a banmask from the given hostmask.  If a style of banmask
        isn't specified via options, the value of
        conf.supybot.protocols.irc.banmask is used.

        A variable named 'channel' (defining the channel the ban is taking
        place in) is expected to be in the environment of the caller of this
        function.

        options - A list specifying which parts of the hostmask should
        explicitly be matched: nick, user, host.  If 'exact' is given, then
        only the exact hostmask will be used."""
        assert ircutils.isChannel(dynamic.channel)
        (nick, user, host) = ircutils.splitHostmask(hostmask)
        bnick = '*'
        buser = '******'
        bhost = '*'
        if not options:
            options = get(supybot.protocols.irc.banmask, dynamic.channel)
        for option in options:
            if option == 'nick':
                bnick = nick
            elif option == 'user':
                buser = user
            elif option == 'host':
                bhost = host
            elif option == 'exact':
                return hostmask
        return ircutils.joinHostmask(bnick, buser, bhost)
Exemplo n.º 6
0
    def makeBanmask(self, hostmask, options=None):
        """Create a banmask from the given hostmask.  If a style of banmask
        isn't specified via options, the value of
        conf.supybot.protocols.irc.banmask is used.

        options - A list specifying which parts of the hostmask should
        explicitly be matched: nick, user, host.  If 'exact' is given, then
        only the exact hostmask will be used."""
        channel = dynamic.channel
        assert channel is None or ircutils.isChannel(channel)
        (nick, user, host) = ircutils.splitHostmask(hostmask)
        bnick = '*'
        buser = '******'
        bhost = '*'
        if not options:
            options = get(supybot.protocols.irc.banmask, channel)
        for option in options:
            if option == 'nick':
                bnick = nick
            elif option == 'user':
                buser = user
            elif option == 'host':
                bhost = host
            elif option == 'exact':
                return hostmask
        return ircutils.joinHostmask(bnick, buser, bhost)
Exemplo n.º 7
0
    def makeBanmask(self, hostmask, options=None):
        """Create a banmask from the given hostmask.  If a style of banmask
        isn't specified via options, the value of
        conf.supybot.protocols.irc.banmask is used.

        A variable named 'channel' (defining the channel the ban is taking
        place in) is expected to be in the environment of the caller of this
        function.

        options - A list specifying which parts of the hostmask should
        explicitly be matched: nick, user, host.  If 'exact' is given, then
        only the exact hostmask will be used."""
        assert ircutils.isChannel(dynamic.channel)
        (nick, user, host) = ircutils.splitHostmask(hostmask)
        bnick = '*'
        buser = '******'
        bhost = '*'
        if not options:
            options = get(supybot.protocols.irc.banmask, dynamic.channel)
        for option in options:
            if option == 'nick':
                bnick = nick
            elif option == 'user':
                buser = user
            elif option == 'host':
                bhost = host
            elif option == 'exact':
                return hostmask
        return ircutils.joinHostmask(bnick, buser, bhost)
 def doPrivmsg(self, irc, msg):
     channel, text = msg.args
     text = text.lower()
     if '#' in channel:
         #print self.regex
         #irc.reply('testing %s against %s' % (text, self._regexString))
         if self.regex.match(text):
             try:
                 hostmask = irc.state.nickToHostmask(msg.nick)
             except KeyError:
                 return
             (nick, user, host) = ircutils.splitHostmask(hostmask)
             user = self._fnUser.sub('*', user)
             banmask = ircutils.joinHostmask('*', user, msg.host)
             if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
                 return
             irc.queueMsg(ban(channel, banmask, 'For swearing. 5 minute timeout'))
             irc.queueMsg(kick(channel, msg.nick, 'For swearing'))
             def unBan():
                 if channel in irc.state.channels and \
                    banmask in irc.state.channels[channel].bans:
                     irc.queueMsg(unban(channel, banmask))
             schedule.addEvent(unBan, time.time()+300)
         elif 'f*g' in text.split():
             try:
                 hostmask = irc.state.nickToHostmask(msg.nick)
             except KeyError:
                 return
             (nick, user, host) = ircutils.splitHostmask(hostmask)
             irc.reply('No thanks %s I don\'t smoke' % user)
     return msg
Exemplo n.º 9
0
    def makeBanmask(self, hostmask, options=None):
        """Create a banmask from the given hostmask.  If a style of banmask
        isn't specified via options, the value of
        conf.supybot.protocols.irc.banmask is used.

        options - A list specifying which parts of the hostmask should
        explicitly be matched: nick, user, host.  If 'exact' is given, then
        only the exact hostmask will be used."""
        channel = dynamic.channel
        assert channel is None or ircutils.isChannel(channel)
        (nick, user, host) = ircutils.splitHostmask(hostmask)
        bnick = '*'
        buser = '******'
        bhost = '*'
        if not options:
            options = get(supybot.protocols.irc.banmask, channel)
        for option in options:
            if option == 'nick':
                bnick = nick
            elif option == 'user':
                buser = user
            elif option == 'host':
                bhost = host
            elif option == 'exact':
                return hostmask
        return ircutils.joinHostmask(bnick, buser, bhost)
Exemplo n.º 10
0
 def setUp(self, nick='test', forceSetup=False):
     if not forceSetup and \
             self.__class__ in (PluginTestCase, ChannelPluginTestCase):
         # Necessary because there's a test in here that shouldn\'t run.
         return
     SupyTestCase.setUp(self)
     # Just in case, let's do this.  Too many people forget to call their
     # super methods.
     for irc in world.ircs[:]:
         irc._reallyDie()
     # Set conf variables appropriately.
     conf.supybot.reply.whenAddressedBy.chars.setValue('@')
     conf.supybot.reply.error.detailed.setValue(True)
     conf.supybot.reply.whenNotCommand.setValue(True)
     self.myVerbose = world.myVerbose
     def rmFiles(dir):
         for filename in os.listdir(dir):
             file = os.path.join(dir, filename)
             if os.path.isfile(file):
                 os.remove(file)
             else:
                 shutil.rmtree(file)
     if self.cleanConfDir:
         rmFiles(conf.supybot.directories.conf())
     if self.cleanDataDir:
         rmFiles(conf.supybot.directories.data())
     ircdb.users.reload()
     ircdb.ignores.reload()
     ircdb.channels.reload()
     if self.plugins is None:
         raise ValueError, 'PluginTestCase must have a "plugins" attribute.'
     self.nick = nick
     self.prefix = ircutils.joinHostmask(nick, 'user', 'host.domain.tld')
     self.irc = getTestIrc()
     MiscModule = plugin.loadPluginModule('Misc')
     OwnerModule = plugin.loadPluginModule('Owner')
     ConfigModule = plugin.loadPluginModule('Config')
     _ = plugin.loadPluginClass(self.irc, MiscModule)
     _ = plugin.loadPluginClass(self.irc, OwnerModule)
     _ = plugin.loadPluginClass(self.irc, ConfigModule)
     if isinstance(self.plugins, str):
         self.plugins = [self.plugins]
     else:
         for name in self.plugins:
             if name not in ('Owner', 'Misc', 'Config'):
                 module = plugin.loadPluginModule(name,
                                                  ignoreDeprecation=True)
                 cb = plugin.loadPluginClass(self.irc, module)
     self.irc.addCallback(TestInstance)
     for (name, value) in self.config.iteritems():
         group = conf.supybot
         parts = registry.split(name)
         if parts[0] == 'supybot':
             parts.pop(0)
         for part in parts:
             group = group.get(part)
         self.originals[group] = group()
         group.setValue(value)
Exemplo n.º 11
0
	def act (self, irc, msg, channel, command, owner):
		tokens = callbacks.tokenize(command)
		#if ircdb.checkCapability(owner, 'owner') or ircdb.checkCapability(owner, '%s,op' % channel):
		#	owner = irc.prefix
		#elif ircdb.checkCapability(irc.prefix, 'owner') or ircdb.checkCapability(irc.prefix, '%s,op' % channel):
		#	owner = irc.prefix
		msg.command = 'PRIVMSG'
		(n,i,h) = ircutils.splitHostmask(owner)
		msg.prefix = ircutils.joinHostmask(irc.nick,i,h)
		self.Proxy(irc.irc, msg, tokens)
Exemplo n.º 12
0
    def unstab(self, irc, msg, args, channel, user):
        """<user>

        Removes +q from a user in channel"""

        hmask = irc.state.nickToHostmask(user)
        hostmask = ircutils.joinHostmask('*', '*',
                                         ircutils.hostFromHostmask(hmask))
        irc.queueMsg(
            ircmsgs.IrcMsg('MODE {0} -q {1}'.format(channel, hostmask)))
Exemplo n.º 13
0
 def act (self, irc, msg, channel, command, owner):
     tokens = callbacks.tokenize(command)
     msg.command = 'PRIVMSG'
     (n,i,h) = ircutils.splitHostmask(owner)
     msg.prefix = ircutils.joinHostmask(irc.nick,i,h)
     
     def d():
         self.Proxy(irc.irc, msg, tokens)
     
     # Wait 30 seconds before sending PM
     schedule.addEvent(d,time.time()+30)
Exemplo n.º 14
0
    def doPrivmsg(self, irc, msg):
        """This is called everytime an IRC message is recieved."""
        (recipients, text) = msg.args
        for channel in recipients.split(','):
            if irc.isChannel(channel):
                enable = self.registryValue('enable', channel=channel)
                if not enable:
                    return
                maxKick = self.registryValue('maxKick', channel=channel)
                self.queueKick.enqueue(msg)
                if self.queueKick.len(msg) > 4:
                    #self.queueKick.reset(msg)
                    self.queueBan.enqueue(msg)
                    maxKickBeforeBan = self.registryValue('maxKickToBan',
                                                          channel=channel)
                    reason = self.registryValue('reasonKick', channel=channel)
                    if self.queueBan.len(msg) > maxKickBeforeBan:
                        #self.queueBan.reset(msg)
                        self.queueLongBan.enqueue(msg)
                        maxBanToLongBan = self.registryValue('maxBanToLongBan',
                                                             channel=channel)
                        duration = int(0)
                        if self.queueLongBan.len(msg) > maxBanToLongBan:
                            #self.queueLongBan.reset(msg)
                            duration = int(
                                self.registryValue('durationLongBan',
                                                   channel=channel))
                        else:
                            duration = int(
                                self.registryValue('durationBan',
                                                   channel=channel))
                        hostmask = irc.state.nickToHostmask(msg.nick)
                        (nick, user, host) = ircutils.splitHostmask(hostmask)
                        banmask = ircutils.joinHostmask('*', '*', host)
                        irc.sendMsg(ircmsgs.ban(channel, banmask))
                        if duration > 0:

                            def ub():
                                if channel in irc.state.channels and banmask in irc.state.channels[
                                        channel].bans:
                                    irc.queueMsg(
                                        ircmsgs.unban(channel, banmask))

                            schedule.addEvent(ub, time.time() + duration)
                        reason = self.registryValue('reasonBan',
                                                    channel=channel)
                        #                        reason = reason % utils.timeElapsed(duration)
                        #                        irc.sendMsg(ircmsgs.IrcMsg('remove %s %s : %s' % (channel, msg.nick, reason)))
                        irc.reply('remove %s %s : %s' %
                                  (channel, msg.nick, reason))
                    self.log.info('remove %s %s : %s' %
                                  (channel, msg.nick, reason))
                    irc.sendMsg(ircmsgs.kick(channel, msg.nick, reason))
Exemplo n.º 15
0
	def doNick (self,irc,msg):
		oldNick = msg.prefix.split('!')[0]
		newNick = msg.args[0]
		for channel in irc.state.channels:
			if ircutils.isChannel(channel):
				chan = self.getChan(irc,channel)
				if oldNick in chan.nicks:
					item = chan.nicks[oldNick]
					(n,i,h) = ircutils.splitHostmask(item[0])
					item[0] = ircutils.joinHostmask(newNick,i,h)
					if 'nick' in chan.kinds:
						text = item[0]
						self.checkAndAct(irc,msg.prefix,chan,'nick',chan.kinds['nick'],'%s %s' % (oldNick,newNick),msg)
					del chan.nicks[oldNick]
					chan.nicks[newNick] = item
Exemplo n.º 16
0
 def doNick (self,irc,msg):
     oldNick = msg.prefix.split('!')[0]
     newNick = msg.args[0]
     for channel in irc.state.channels:
         if ircutils.isChannel(channel):
             chan = self.getChan(irc,channel)
             if oldNick in chan.nicks:
                 item = chan.nicks[oldNick]
                 (n,i,h) = ircutils.splitHostmask(item[0])
                 item[0] = ircutils.joinHostmask(newNick,i,h)
                 if 'nick' in chan.kinds:
                     text = item[0]
                     self.checkAndAct(irc,msg.prefix,chan,'nick',chan.kinds['nick'],'%s %s' % (oldNick,newNick),msg)
                 del chan.nicks[oldNick]
                 chan.nicks[newNick] = item
Exemplo n.º 17
0
 def makeBanmask(bannedHostmask, options):
     (nick, user, host) = ircutils.splitHostmask(bannedHostmask)
     self.log.debug('*** nick: %s', nick)
     self.log.debug('*** user: %s', user)
     self.log.debug('*** host: %s', host)
     bnick = '*'
     buser = '******'
     bhost = '*'
     for option in options:
         if option == 'nick':
             bnick = nick
         elif option == 'user':
             buser = user
         elif option == 'host':
             bhost = host
         elif option == 'exact':
             (bnick, buser, bhost) = \
                            ircutils.splitHostmask(bannedHostmask)
     return ircutils.joinHostmask(bnick, buser, bhost)
Exemplo n.º 18
0
 def makeBanmask(bannedHostmask, options):
     (nick, user, host) = ircutils.splitHostmask(bannedHostmask)
     self.log.debug('*** nick: %s', nick)
     self.log.debug('*** user: %s', user)
     self.log.debug('*** host: %s', host)
     bnick = '*'
     buser = '******'
     bhost = '*'
     for option in options:
         if option == 'nick':
             bnick = nick
         elif option == 'user':
             buser = user
         elif option == 'host':
             bhost = host
         elif option == 'exact':
             (bnick, buser, bhost) = \
                            ircutils.splitHostmask(bannedHostmask)
     return ircutils.joinHostmask(bnick, buser, bhost)
Exemplo n.º 19
0
 def _ban(self, irc, nick, channel):
     try:
         hostmask = irc.state.nickToHostmask(nick)
     except KeyError:
         return
     (nick, user, host) = ircutils.splitHostmask(hostmask)
     user = self._fnUser.sub('*', user)
     banmask = ircutils.joinHostmask('*', user, host)
     if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
         return
     irc.queueMsg(ircmsgs.ban(channel, banmask))
     irc.queueMsg(ircmsgs.kick(channel, nick))
     expiry = self.registryValue('autokban.timeout', channel)
     if expiry > 0:
         expiry += time.time()
         def f():
             if channel in irc.state.channels and \
                banmask in irc.state.channels[channel].bans:
                 irc.queueMsg(ircmsgs.unban(channel, banmask))
         schedule.addEvent(f, expiry)
Exemplo n.º 20
0
    def doPrivmsg(self, irc, msg):
        """This is called everytime an IRC message is recieved."""
        (recipients,text) = msg.args
        for channel in recipients.split(','):
            if irc.isChannel(channel):
                enable = self.registryValue('enable',channel=channel)
                if not enable:
                        return
                maxKick = self.registryValue('maxKick',channel=channel)
                self.queueKick.enqueue(msg)
                if self.queueKick.len(msg) > 4:
                    #self.queueKick.reset(msg)
                    self.queueBan.enqueue(msg)
                    maxKickBeforeBan = self.registryValue('maxKickToBan',channel=channel)
                    reason = self.registryValue('reasonKick',channel=channel)
                    if self.queueBan.len(msg) > maxKickBeforeBan:
                        #self.queueBan.reset(msg)
                        self.queueLongBan.enqueue(msg)
                        maxBanToLongBan = self.registryValue('maxBanToLongBan',channel=channel)
                        duration = int(0)
                        if self.queueLongBan.len(msg) > maxBanToLongBan:
                            #self.queueLongBan.reset(msg)
                            duration = int(self.registryValue('durationLongBan',channel=channel))
                        else:
                            duration = int(self.registryValue('durationBan',channel=channel))
                        hostmask = irc.state.nickToHostmask(msg.nick)
                        (nick, user, host) = ircutils.splitHostmask(hostmask)
                        banmask = ircutils.joinHostmask('*', '*', host)
                        irc.sendMsg(ircmsgs.ban(channel,banmask))
                        if duration > 0:
                            def ub():
                                if channel in irc.state.channels and banmask in irc.state.channels[channel].bans:
                                    irc.queueMsg(ircmsgs.unban(channel, banmask))
                            schedule.addEvent(ub,time.time()+duration)
                        reason = self.registryValue('reasonBan',channel=channel)
#                        reason = reason % utils.timeElapsed(duration)
#                        irc.sendMsg(ircmsgs.IrcMsg('remove %s %s : %s' % (channel, msg.nick, reason)))
                        irc.reply('remove %s %s : %s' % (channel, msg.nick, reason))
                    self.log.info('remove %s %s : %s' % (channel, msg.nick, reason))
                    irc.sendMsg(ircmsgs.kick(channel, msg.nick, reason))
Exemplo n.º 21
0
    def stab(self, irc, msg, args, channel, user, timer, reason):
        """<user> [seconds] [reason (ignored)]

        Stabs a user, putting them on quiet for a random time up to 10 mins."""

        hmask = irc.state.nickToHostmask(user)
        hostmask = ircutils.joinHostmask('*', '*',
                                         ircutils.hostFromHostmask(hmask))
        irc.queueMsg(
            ircmsgs.IrcMsg('MODE {0} +q {1}'.format(channel, hostmask)))

        if timer is not None:
            t = time.time()
            r = timer
            if not timer > 0:
                r = random.randint(30, 600)
            expires = t + r

            len = {}
            len['m'] = len['s'] = 0

            while r > 59:
                len['m'] += 1
                r -= 60

            len['s'] = r

            irc.queueMsg(
                ircmsgs.IrcMsg(
                    'NOTICE +{0} :{1} has been quieted for {2}:{3:0>2}'.format(
                        channel, user, len['m'], len['s'])))

            def f():
                irc.queueMsg(
                    ircmsgs.IrcMsg('MODE {0} -q {1}'.format(channel,
                                                            hostmask)))

            schedule.addEvent(f, expires)
        irc.noReply()
Exemplo n.º 22
0
    def _ban(self, irc, nick, channel):
        try:
            hostmask = irc.state.nickToHostmask(nick)
        except KeyError:
            return
        (nick, user, host) = ircutils.splitHostmask(hostmask)
        user = self._fnUser.sub('*', user)
        banmask = ircutils.joinHostmask('*', user, host)
        if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
            return
        irc.queueMsg(ircmsgs.ban(channel, banmask))
        irc.queueMsg(ircmsgs.kick(channel, nick))
        expiry = self.registryValue('autokban.timeout', channel)
        if expiry > 0:
            expiry += time.time()

            def f():
                if channel in irc.state.channels and \
                   banmask in irc.state.channels[channel].bans:
                    irc.queueMsg(ircmsgs.unban(channel, banmask))

            schedule.addEvent(f, expiry)