]> jfr.im git - irc/freenode/Sigyn.git/commitdiff
added invite/part support after inactivity
authorNicolas Coevoet <redacted>
Mon, 18 Dec 2017 16:55:51 +0000 (16:55 +0000)
committerNicolas Coevoet <redacted>
Mon, 18 Dec 2017 16:55:51 +0000 (16:55 +0000)
1  2 
config.py
plugin.py

diff --cc config.py
index 4f77fbc4a83d93d2007860e52ff783bb168aecc5,538dc525a953d7fa7df8121308d8425dc50a7841..270e58ff2fc6b57e266c6d15653248b6b755a523
+++ b/config.py
@@@ -113,6 -111,6 +113,8 @@@ conf.registerGlobalValue(Sigyn, 'saslMe
  
  conf.registerChannelValue(Sigyn, 'lastActionTaken',
       registry.Float(0.0, """store date of last action taken in a channel"""))
++conf.registerChannelValue(Sigyn, 'leaveChannelIfNoActivity',
++     registry.Integer(-1, """leave channel after days of inactivity, -1 to disable"""))
  
  conf.registerGlobalValue(Sigyn, 'announcePermit',
      registry.Integer(-1,"""number of announce permit in logChannel,if triggered the bot will stay quiet for alertPeriod, -1 to disable"""))
diff --cc plugin.py
index 699b36a3e56590af269be2d9778ab8ca4a28348e,f8d6b594608b442fc9e66ab755f9869d0db80e46..3f4689674d4f04426e5aa2b36325da0c1efc95c6
+++ b/plugin.py
@@@ -1398,6 -1398,6 +1398,14 @@@ class Sigyn(callbacks.Plugin,plugins.Ch
  
      def cleanup (self,irc):
          i = self.getIrc(irc)
++        partReason = 'Leaving the channel (no spam or action taken for %s days.) /invite %s %s again if needed'
++        for channel in irc.state.channels:
++            if not channel in self.registryValue('mainChannel') and not channel == self.registryValue('snoopChannel') and not channel == self.registryValue('logChannel') and not channel == self.registryValue('reportChannel') and not channel == self.registryValue('secretChannel'):
++                if self.registryValue('lastActionTaken',channel=channel) > 0.0 and self.registryValue('leaveChannelIfNoActivity',channel=channel) > -1:
++                    if time.time() - self.registryValue('lastActionTaken',channel=channel) > (self.registryValue('leaveChannelIfNoActivity',channel=channel) * 24 * 3600):
++                       irc.queueMsg(ircmsgs.part(channel, partReason % (self.registryValue('leaveChannelIfNoActivity',channel=channel),irc.nick,channel)))
++                       self.setRegistryValue('lastActionTaken',0.0,channel=channel)
++                       self.logChannel(irc,'PART: [%s] due to inactivity for %s days' % (channel,self.registryValue('leaveChannelIfNoActivity',channel=channel)))
          kinds = []
          for kind in i.queues:
              count = 0
            i.toklineresults[nick]['hostmask'] = hostmask
            i.toklineresults[nick]['mask'] = mask
            i.toklineresults[nick]['gecos'] = gecos
-        elif nick in i.tolethal:
-           ident = msg.args[2]
-           hostmask = '%s!%s@%s' % (nick,ident,msg.args[3])
-           mask = self.prefixToMask(irc,hostmask)
-           if not isCloaked('hostmask') and not 'gateway/' in hostmask:
-               channel = '#' + i.tolethal[nick].split('#')[1]
-               if '##' in i.tolethal[nick]:
-                   channel = '##' + i.tolethal[nick].split('##')[1]
-               if i.defcon:
-                   self.kline(irc,hostmask,mask,self.registryValue('klineDuration'),'lethalChannel created %s' % channel)
-                   self.logChannel(irc,'BAD: [%s] %s (lethal channel) --> %s' % (channel,hostmask,mask))
-               else:
-                   self.logChannel(irc,'NOTE: [%s] %s (lethal channel) --> %s' % (channel,hostmask,mask))
-           del i.tolethal[nick]            
 -              
 +
      def do317 (self,irc,msg):
         i = self.getIrc(irc)
         nick = msg.args[1]
                 if 'signon' in i.toklineresults[nick]:
                     found = False
                     for n in self.words:
-                        if len(n) > self.registryValue('wordMinimum') and n in i.toklineresults[nick]['gecos']:
 -                       if len(n) > 3 and i.toklineresults[nick]['gecos'].startswith(n):
 -                           found = True
++                       if len(n) > self.registryValue('wordMinimum') and i.toklineresults[nick]['gecos'].startswith(n):
 +                           found = n
                             break
                     if time.time() - i.toklineresults[nick]['signon'] < self.registryValue('alertPeriod') and found and not 'gateway/' in i.toklineresults[nick]['hostmask'] and not isCloaked(i.toklineresults[nick]['hostmask']):
                         if i.tokline[nick].find('#') != -1:
             del i.tokline[nick]
             del i.toklineresults[nick]
  
++    def doInvite(self, irc, msg):
++       channel = msg.args[1]
++       if channel and not channel in irc.state.channels:
++           self.logChannel(irc,'INVITE: [%s] %s is asking for %s' % (channel,msg.prefix,irc.nick))
++
      def resolveSnoopy (self,irc,account,email,badmail):
         try:
             resolver = dns.resolver.Resolver()
          if ircmsgs.isAction(msg):
              text = ircmsgs.unAction(msg)
          raw = ircutils.stripColor(text)
++        raw = unicode(raw, 'utf-8')
          text = text.lower()
          mask = self.prefixToMask(irc,msg.prefix)
          i = self.getIrc(irc)
          if '##' in text:
              channel = text.split('##')[1]
          i = self.getIrc(irc)
--        if len(self.registryValue('lethalChannels')):
--            for pattern in self.registryValue('lethalChannels'):
--                if len(pattern) and channel in pattern:
-                     i.tolethal[user] = text
 -                    i.tokline[user] = text
--                    irc.sendMsg(ircmsgs.IrcMsg('WHOIS %s %s' % (user,user)))
--                    break
++        if i.defcon:
++            if len(self.registryValue('lethalChannels')) > 0:
++                for pattern in self.registryValue('lethalChannels'):
++                    if len(pattern) and pattern in channel:
++                        self.logChannel(irc,"NOTE: %s created %s" % (user,channel))
++                        break
          if permit < 0:
              return
          q = self.getIrcQueueFor(irc,user,'channel-created',self.registryValue('channelCreationLife'))
                  if i.defcon and self.registryValue('mainChannel') in channel:
                      found = False
                      for n in self.words:
-                         if len(n) > self.registryValue('wordMinimum') and n in msg.nick and n in gecos:
 -                        if len(n) > 3 and msg.nick.startswith(n) and gecos.startswith(n):
 -                           found = True
++                        if len(n) > self.registryValue('wordMinimum') and msg.nick.startswith(n) and gecos.startswith(n):
 +                           found = n
                             break
 -                    if len(msg.nick) > 3 and found and not isCloaked(msg.prefix) and not 'gateway/' in msg.prefix and not account:
 -                        self.kill(irc,msg.nick,msg.prefix)
 -                        self.kline(irc,msg.prefix,mask,self.registryValue('klineDuration'),'nick in badwords in %s' % channel)
 -                        self.logChannel(irc,'BAD: [%s] %s (badword) -> %s' % (channel,msg.prefix,mask))
 +                    if len(msg.nick) > self.registryValue('wordMinimum') and found and not isCloaked(msg.prefix) and not 'gateway/' in msg.prefix and not account:
 +                        self.kill(irc,msg.nick,self.registryValue('killMessage',channel=channel))
 +                        self.kline(irc,msg.prefix,mask,self.registryValue('klineDuration'),'badwords in %s - %s' % (channel,found))
 +                        self.logChannel(irc,'BAD: [%s] %s (badword %s) -> %s' % (channel,found,msg.prefix,mask))
                          self.setRegistryValue('lastActionTaken',time.time(),channel=channel)
                          del chan.nicks[msg.nick]
                          continue