Browse Source

Don't greet a user if they leave immediately after joining.

pull/10/merge
Ben Kurtovic 9 years ago
parent
commit
303de618c3
1 changed files with 17 additions and 2 deletions
  1. +17
    -2
      commands/welcome.py

+ 17
- 2
commands/welcome.py View File

@@ -29,7 +29,7 @@ class Welcome(Command):
"""Welcome people who enter certain channels.""" """Welcome people who enter certain channels."""
name = "welcome" name = "welcome"
commands = ["welcome", "greet"] commands = ["welcome", "greet"]
hooks = ["join", "msg"]
hooks = ["join", "part", "msg"]


def setup(self): def setup(self):
try: try:
@@ -40,12 +40,13 @@ class Welcome(Command):


self._throttle = False self._throttle = False
self._last_join = 0 self._last_join = 0
self._pending = []


def check(self, data): def check(self, data):
if data.is_command and data.command in self.commands: if data.is_command and data.command in self.commands:
return True return True
try: try:
if data.line[1] != "JOIN":
if data.line[1] != "JOIN" and data.line[1] != "PART":
return False return False
except IndexError: except IndexError:
pass pass
@@ -58,6 +59,11 @@ class Welcome(Command):
self.process_command(data) self.process_command(data)
return 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() this_join = time()
if this_join - self._last_join < 5: if this_join - self._last_join < 5:
self._throttle = True self._throttle = True
@@ -77,11 +83,20 @@ class Welcome(Command):


def _callback(self, data): def _callback(self, data):
"""Internal callback function.""" """Internal callback function."""
self._pending.append((data.chan, data.nick))
sleep(2) sleep(2)

if data.chan in self.disabled or self._throttle: if data.chan in self.disabled or self._throttle:
return return
if (data.chan, data.nick) not in self._pending:
return
self.say(data.chan, self.channels[data.chan].format(nick=data.nick)) 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): def process_command(self, data):
"""Handle this when it is an explicit command, not a channel join.""" """Handle this when it is an explicit command, not a channel join."""
if data.args: if data.args:


Loading…
Cancel
Save