Browse Source

grace period

haliphax 1 year ago
parent
commit
4aa2478315
3 changed files with 55 additions and 9 deletions
  1. 3 1
      README.md
  2. 19 7
      config.py
  3. 33 1
      plugin.py

+ 3 - 1
README.md

@@ -8,8 +8,10 @@ join.
 ## settings
 
 - `supybot.plugins.Greet.enable` (Boolean): Whether or not the plugin is
-  active on the selected channel
+  active on the selected channel (default: False)
 - `supybot.plugins.Greet.message` (String): The message to send to users when
   they join the selected channel
+- `supybot.plugins.Greet.grace` (PositiveInteger): Grace period (in seconds)
+  to avoid re-greeting someone after a kick, part, or join (default: 30)
 
 To set these, use the `config channel` command.

+ 19 - 7
config.py

@@ -1,15 +1,27 @@
 import supybot.conf as conf
 import supybot.registry as registry
 
+
 def configure(advanced):
     conf.registerPlugin('Greet', True)
 
 
 Greet = conf.registerPlugin('Greet')
-conf.registerChannelValue(Greet, 'enable',
-    registry.Boolean(False, """Determines whether or not the bot will send
-    the configured greeting (defined by supybot.plugins.Greet.message)
-    when someone joins the channel."""))
-conf.registerChannelValue(Greet, 'message',
-    registry.String('', """The greeting that is sent to someone when
-    they join the channel."""))
+conf.registerChannelValue(
+    Greet,
+    'enable',
+    registry.Boolean(False, """Determines whether or not the bot will send the
+                            configured greeting (defined by
+                            supybot.plugins.Greet.message) when someone joins
+                            the channel."""))
+conf.registerChannelValue(
+    Greet,
+    'message',
+    registry.String('', """The greeting that is sent to someone when they join
+                        the channel."""))
+conf.registerChannelValue(
+    Greet,
+    'grace',
+    registry.PositiveInteger(30, """The length of the grace period (in seconds)
+                                 for not re-greeting someone after a kick,
+                                 join, or part event."""))

+ 33 - 1
plugin.py

@@ -1,12 +1,16 @@
+from time import time
+
 import supybot.utils as utils
 from supybot.commands import *
 import supybot.plugins as plugins
 import supybot.ircutils as ircutils
 import supybot.callbacks as callbacks
 import supybot.ircmsgs as ircmsgs
+import supybot.schedule as schedule
 
 
 class Greet(callbacks.Plugin):
+
     """
     This plugin greets users with a defined message when they join the
     channel. In order to use this plugin, supybot.plugins.Greet.enable
@@ -14,10 +18,29 @@ class Greet(callbacks.Plugin):
     message you wish to send to users when they join.
     """
 
+    _ignore = set([])
+
     def __init__(self, irc):
         self.__parent = super(Greet, self)
         self.__parent.__init__(irc)
 
+    def _rememberNick(nick):
+        if nick in self._ignore:
+            self._ignore.remove()
+
+    def _ignoreNick(self, irc, msg):
+        channel = msg.args[0]
+
+        if not self.registryValue('enable', channel):
+            return
+
+        delay = self.registryValue('grace', channel)
+
+        if not msg.nick in self._ignore:
+            self._ignore.add(msg.nick)
+            schedule.addEvent(self._rememberNick, time() + delay,
+                              args=(msg.nick,))
+
     def doJoin(self, irc, msg):
         channel = msg.args[0]
 
@@ -25,13 +48,22 @@ class Greet(callbacks.Plugin):
             return
 
         greeting = self.registryValue('message', channel)
+        delay = self.registryValue('grace', channel)
 
         if len(greeting.strip()) == 0:
             self.log.warn('Greeting empty for %s' % channel)
             return
 
-        if not ircutils.strEqual(msg.nick, irc.nick):
+        if (not ircutils.strEqual(msg.nick, irc.nick)
+                and msg.nick not in self._ignore):
+            self._ignore.add(msg.nick)
             irc = callbacks.SimpleProxy(irc, msg)
             irc.queueMsg(ircmsgs.privmsg(msg.nick, greeting))
+            schedule.addEvent(self._rememberNick, time() + delay,
+                              args=(msg.nick,))
+
+    doPart = _ignoreNick
+    doKick = _ignoreNick
+    doQuit = _ignoreNick
 
 Class = Greet