From 303de618c3dff34e2f7c86f8706c0acc8f8bbbf2 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sun, 13 Sep 2015 02:44:19 -0500 Subject: [PATCH] Don't greet a user if they leave immediately after joining. --- commands/welcome.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/commands/welcome.py b/commands/welcome.py index 2169283..afa0d3c 100644 --- a/commands/welcome.py +++ b/commands/welcome.py @@ -29,7 +29,7 @@ class Welcome(Command): """Welcome people who enter certain channels.""" name = "welcome" commands = ["welcome", "greet"] - hooks = ["join", "msg"] + hooks = ["join", "part", "msg"] def setup(self): try: @@ -40,12 +40,13 @@ class Welcome(Command): self._throttle = False self._last_join = 0 + self._pending = [] def check(self, data): if data.is_command and data.command in self.commands: return True try: - if data.line[1] != "JOIN": + if data.line[1] != "JOIN" and data.line[1] != "PART": return False except IndexError: pass @@ -58,6 +59,11 @@ class Welcome(Command): self.process_command(data) return + if data.line[1] == "PART": + if (data.chan, data.nick) in self._pending: + self._pending.remove((data.chan, data.nick)) + return + this_join = time() if this_join - self._last_join < 5: self._throttle = True @@ -77,11 +83,20 @@ class Welcome(Command): def _callback(self, data): """Internal callback function.""" + self._pending.append((data.chan, data.nick)) sleep(2) + if data.chan in self.disabled or self._throttle: return + if (data.chan, data.nick) not in self._pending: + return self.say(data.chan, self.channels[data.chan].format(nick=data.nick)) + try: + self._pending.remove((data.chan, data.nick)) + except ValueError: + pass # Could be a race condition + def process_command(self, data): """Handle this when it is an explicit command, not a channel join.""" if data.args: