]> jfr.im git - irc/freenode/Sigyn.git/commitdiff
added ability to share computed patterns to a sets of channels
authorNicolas Coevoet <redacted>
Thu, 1 Sep 2016 20:33:54 +0000 (20:33 +0000)
committerNicolas Coevoet <redacted>
Thu, 1 Sep 2016 20:33:54 +0000 (20:33 +0000)
config.py
plugin.py

index 6efddebd003a96d38af16a69d0303a7251a579ab..8d6e4168cfa05685119d809a85648f8c12d3dcdc 100644 (file)
--- a/config.py
+++ b/config.py
@@ -273,7 +273,10 @@ conf.registerChannelValue(Sigyn, 'massRepeatMinimum',
 conf.registerChannelValue(Sigyn, 'computedPattern',
     registry.Integer(1,"""minimun number of chars needed to keep it as a spam pattern, -1 to disable"""))
 conf.registerChannelValue(Sigyn, 'computedPatternLife',
-    registry.Integer(1,"""minimun number of chars needed to keep it as a spam pattern, -1 to disable"""))
+    registry.Integer(1,"""life in seconds of computed pattern, -1 to disable"""))
+conf.registerChannelValue(Sigyn, 'shareComputedPatternID',
+    registry.Integer(-1,"""share the temporary pattern created to all channels with the same number, -1 to disable"""))
+
 
 conf.registerChannelValue(Sigyn, 'lowMassRepeatPermit',
     registry.Integer(-1,"""number of mass repeat permit duration massRepeatLife, -1 to disable"""))
index 701f4ba1f2ebd4466cebb7d454164e5a3a791dcf..02b436f5a3ec300905e38646b65a324cfad21928 100644 (file)
--- a/plugin.py
+++ b/plugin.py
@@ -511,7 +511,7 @@ class Sigyn(callbacks.Plugin,plugins.ChannelDBHandler):
     def lspattern (self,irc,msg,args,optlist,pattern):
         """[--deep] <id|pattern>
 
-        returns list patterns which matchs pattern or info about pattern #id, use --deep to search on deactivated patterns"""
+        returns patterns which matchs pattern or info about pattern #id, use --deep to search on deactivated patterns"""
         i = self.getIrc(irc)
         deep = False
         for (option, arg) in optlist:
@@ -520,7 +520,11 @@ class Sigyn(callbacks.Plugin,plugins.ChannelDBHandler):
                 break
         results = i.ls(self.getDb(irc.network),pattern,deep)
         if len(results):
-            irc.replies(results,None,None,False)
+            if deep:
+                for r in results:
+                    irc.queueMsg(ircmsgs.privmsg(msg.nick,r))
+            else:
+                irc.replies(results,None,None,False)
         else:
             irc.reply('no pattern found')
     lspattern = wrap(lspattern,['owner',getopts({'deep': ''}),'text'])
@@ -2057,8 +2061,26 @@ class Sigyn(callbacks.Plugin,plugins.ChannelDBHandler):
                             break
                     if not found:
                         candidate = candidate.strip()
-                        chan.patterns.enqueue(candidate)
-                        self.logChannel(irc,'PATTERN: [%s] added "%s" for %ss (%s)' % (channel,candidate,self.registryValue('computedPatternLife',channel=channel),kind))
+                        shareID = self.registryValue('shareComputedPatternID',channel=channel)
+                        if shareID != -1:
+                            nb = 0
+                            i = self.getIrc(irc)
+                            for chan in i.channels:                                
+                                ch = i.channels[chan]
+                                life = self.registryValue('computedPatternLife',channel=chan)
+                                if shareID != self.registryValue('shareComputedPatternID',channel=chan):
+                                    continue                                                                                                                                                                 
+                                if not ch.patterns:                                                                                                                                                                                                            
+                                    ch.patterns = utils.structures.TimeoutQueue(life)                                                                                                                                                                          
+                                elif ch.patterns.timeout != life:                                                                                                                                                                                              
+                                    ch.patterns.setTimeout(life)                                                                                                                                                                                               
+                                if len(candidate) > self.registryValue('computedPattern',channel=chan):
+                                    ch.patterns.enqueue(candidate)
+                                    nb = nb + 1                                
+                            self.logChannel(irc,'PATTERN: [%s] added "%s" in %s channels' % (channel,candidate,nb,kind))
+                        else:
+                            chan.patterns.enqueue(candidate)
+                            self.logChannel(irc,'PATTERN: [%s] added "%s" for %ss (%s)' % (channel,candidate,self.registryValue('computedPatternLife',channel=channel),kind))
                         # maybe, instead of awaiting for others repeated messages before kline, we could return
                         # and remove others users which matchs ..
                         # return 'repeat pattern creation'
@@ -2125,8 +2147,6 @@ class Sigyn(callbacks.Plugin,plugins.ChannelDBHandler):
                             break
                     if not found:
                         pattern = pattern.strip()
-                        chan.patterns.enqueue(pattern)
-                        self.logChannel(irc,'PATTERN: [%s] added "%s" for %ss (%s)' % (channel,pattern,self.registryValue('computedPatternLife',channel=channel),kind))
                         users = {}
                         users[mask] = True
                         for u in chan.logs:
@@ -2148,6 +2168,27 @@ class Sigyn(callbacks.Plugin,plugins.ChannelDBHandler):
                                         self.logChannel(irc,"BAD: [%s] %s (pattern creation - %s)" % (channel,u,kind))
                                         break
                             users[u] = True
+                        shareID = self.registryValue('shareComputedPatternID',channel=channel)
+                        if shareID != -1:
+                            nb = 0
+                            i = self.getIrc(irc)
+                            for chan in i.channels:
+                                ch = i.channels[chan]
+                                if shareID != self.registryValue('shareComputedPatternID',channel=chan):
+                                    continue                                              
+                                life = self.registryValue('computedPatternLife',channel=chan)
+                                if not ch.patterns:
+                                    ch.patterns = utils.structures.TimeoutQueue(life)
+                                elif ch.patterns.timeout != life:
+                                    ch.patterns.setTimeout(life)
+                                if len(pattern) > self.registryValue('computedPattern',channel=chan):                                                                                                                                
+                                    ch.patterns.enqueue(pattern)
+                                    nb = nb + 1                                                                                                                                                                                              
+                            self.logChannel(irc,'PATTERN: [%s] added "%s" in %s channels (%s)' % (channel,pattern,nb,kind))                            
+                        else:
+                            chan.patterns.enqueue(pattern)
+                            self.logChannel(irc,'PATTERN: [%s] added "%s" for %ss (%s)' % (channel,pattern,self.registryValue('computedPatternLife',channel=channel),kind))
+                            
         logs.enqueue(text)
         if result and pattern:
             return result