From d8f41d45acf5e701f8aa62fb0c8e6d0ecba352ae Mon Sep 17 00:00:00 2001 From: Nicolas Coevoet Date: Tue, 13 Jan 2015 20:38:23 +0100 Subject: [PATCH] various fix --- config.py | 3 +++ plugin.py | 27 ++++++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/config.py b/config.py index c13582e..d0298af 100644 --- a/config.py +++ b/config.py @@ -148,6 +148,9 @@ conf.registerChannelValue(ChanTracker, 'keepOp', conf.registerChannelValue(ChanTracker, 'kickMode', registry.CommaSeparatedListOfStrings(['b'], """bot will kick affected users when mode is triggered, use if with caution, if an op bans *!*@*, bot will kick everyone on the channel""")) + +conf.registerChannelValue(ChanTracker, 'kickMax', +registry.Integer(-1,"""if > 0, disable kick if affected users > kickMax, avoid to cleanup entire channel with ban like *!*@*""")) conf.registerChannelValue(ChanTracker, 'kickMessage', registry.String("You are banned from this channel", """bot kick reason""")) diff --git a/plugin.py b/plugin.py index 125c98f..8f9fc96 100644 --- a/plugin.py +++ b/plugin.py @@ -71,15 +71,15 @@ def matchHostmask (pattern,n): if host.find('/') != -1: # cloaks if host.startswith('gateway/web/freenode/ip.'): - n.ip = cache[host] = host.split('ip.')[1] + n.ip = cache[n.prefix] = host.split('ip.')[1] else: # trying to get ip if host in cache: - n.ip = cache[host] + n.ip = cache[n.prefix] else: n.setIp(host) if n.ip != None: - cache[host] = n.ip + cache[n.prefix] = n.ip else: try: r = socket.getaddrinfo(host,None) @@ -91,12 +91,10 @@ def matchHostmask (pattern,n): u[item[4][0]] = item[4][0] L.append(item[4][0]) if len(L) == 1: - cache[host] = L[0] + cache[n.prefix] = L[0] n.setIp(L[0]) - else: - cache[host] = None except: - cache[host] = None + t = t if n.ip != None and ircutils.hostmaskPatternEqual(pattern,'%s!%s@%s' % (nick,ident,n.ip)): return '%s!%s@%s' % (nick,ident,n.ip) if ircutils.hostmaskPatternEqual(pattern,n.prefix): @@ -160,7 +158,7 @@ def match (pattern,n,irc): key = pattern + ' :: ' + str(n) if key in cache: return cache[key] - cache[key] = None + #cache[key] = None extprefix = '' extmodes = '' if 'extban' in irc.state.supported: @@ -1047,6 +1045,8 @@ class Nick (object): # [float(timestamp),target,message] def setPrefix (self,prefix): + if self.prefix != prefix: + self.ip = None self.prefix = prefix return self @@ -3030,12 +3030,13 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler): if match(active.value,self.getNick(irc,nick),irc): tolift.append(active) kicked = False - if m in self.registryValue('kickMode',channel=channel) and msg.nick == irc.nick: # and not value.startswith(self.getIrcdExtbans(irc)) works for unreal + if m in self.registryValue('kickMode',channel=channel): # and not value.startswith(self.getIrcdExtbans(irc)) works for unreal if msg.nick == irc.nick or msg.nick == 'ChanServ': - if nick in irc.state.channels[channel].users and nick != irc.nick: - chan.action.enqueue(ircmsgs.kick(channel,nick,self.registryValue('kickMessage',channel=channel))) - self.forceTickle = True - kicked = True + if self.registryValue('kickMax',channel=channel) < 0 or len(item.affects) < self.registryValue('kickMax',channel=channel): + if nick in irc.state.channels[channel].users and nick != irc.nick: + chan.action.enqueue(ircmsgs.kick(channel,nick,self.registryValue('kickMessage',channel=channel))) + self.forceTickle = True + kicked = True if not kicked and m in self.registryValue('modesToAsk',channel=channel) and self.registryValue('doActionAgainstAffected',channel=channel): if msg.nick == irc.nick or msg.nick == 'ChanServ': if nick in irc.state.channels[channel].ops and not nick == irc.nick: