Skip to content

Commit

Permalink
trigger: Fix target for QUIT events
Browse files Browse the repository at this point in the history
This was fun to debug! Basically, Soepl encountered an exception
when removing unknown users when they QUIT. While this shouldn't
happen, it should still be handled gracefully.

Since it was an exception, Sopel's response was to try and send
the exception line to the channel (sender) the message came from, but
QUIT events don't come from channels (or users by PRIVMSG)!

Since QUIT was not special-cased, the naive assumption that
the first argument is the "sender" was used, and when Sopel
tried to send the exception line to the "sender", and the sender
had a space in it, this would lead to spam if a user exists with a nick
that is identical to the first word in the QUIT message. Ouch.

The fix special-cases QUIT in pretrigger to never have a "sender".
I also added a test to make sure we parse QUIT correctly.

This solves issue #1026.
  • Loading branch information
Elad Alfassa committed Feb 16, 2016
1 parent 0fa598a commit 52cad16
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sopel/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def __init__(self, own_nick, line):
self.nick = sopel.tools.Identifier(self.nick)

# If we have arguments, the first one is the sender
if self.args:
# Unless it's a QUIT event
if self.args and self.event != 'QUIT':
target = sopel.tools.Identifier(self.args[0])
else:
target = None
Expand Down
14 changes: 14 additions & 0 deletions test/test_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ def test_pm_pretrigger(nick):
assert pretrigger.sender == Identifier('Foo')


def test_quit_pretrigger(nick):
line = ':Foo!foo@example.com QUIT :quit message text'
pretrigger = PreTrigger(nick, line)
assert pretrigger.tags == {}
assert pretrigger.hostmask == 'Foo!foo@example.com'
assert pretrigger.line == line
assert pretrigger.args == ['quit message text']
assert pretrigger.event == 'QUIT'
assert pretrigger.nick == Identifier('Foo')
assert pretrigger.user == 'foo'
assert pretrigger.host == 'example.com'
assert pretrigger.sender is None


def test_tags_pretrigger(nick):
line = '@foo=bar;baz;sopel.chat/special=value :Foo!foo@example.com PRIVMSG #Sopel :Hello, world'
pretrigger = PreTrigger(nick, line)
Expand Down

0 comments on commit 52cad16

Please sign in to comment.