From ec9e731fa52f345467d43e2d9d99c2366fdc639c Mon Sep 17 00:00:00 2001 From: Matias Wilkman Date: Sun, 8 Oct 2023 20:07:08 +0300 Subject: [PATCH] Ignore trailing whitespace when addressing the bot by nick at end (#1563) --- src/callbacks.py | 4 ++-- test/test_callbacks.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index 28b1fbabf..e9428c872 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -136,8 +136,8 @@ def _addressed(irc, msg, prefixChars=None, nicks=None, continue except ValueError: # split didn't work. continue - elif whenAddressedByNickAtEnd and lowered.endswith(nick): - rest = payload[:-len(nick)] + elif whenAddressedByNickAtEnd and lowered.rstrip().endswith(nick): + rest = payload.rstrip()[:-len(nick)] possiblePayload = rest.rstrip(' \t,;') if possiblePayload != rest: # There should be some separator between the nick and the diff --git a/test/test_callbacks.py b/test/test_callbacks.py index 33c0d561b..6ce9c1569 100644 --- a/test/test_callbacks.py +++ b/test/test_callbacks.py @@ -272,6 +272,12 @@ class FunctionsTestCase(SupyTestCase): self.assertEqual(callbacks.addressed('bar', msg, whenAddressedByNickAtEnd=True), 'baz') + # Test that it still works with trailing whitespace: + msg = ircmsgs.privmsg('#foo', 'baz, bar \t') + self.assertEqual(callbacks.addressed('bar', msg, + whenAddressedByNickAtEnd=True), + 'baz') + def testAddressedPrefixCharsTakePrecedenceOverNickAtEnd(self): irc = getTestIrc()