Ignore trailing whitespace when addressing the bot by nick at end (#1563)

This commit is contained in:
Matias Wilkman 2023-10-08 20:07:08 +03:00 committed by GitHub
parent 5ccc035021
commit ec9e731fa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -136,8 +136,8 @@ def _addressed(irc, msg, prefixChars=None, nicks=None,
continue continue
except ValueError: # split didn't work. except ValueError: # split didn't work.
continue continue
elif whenAddressedByNickAtEnd and lowered.endswith(nick): elif whenAddressedByNickAtEnd and lowered.rstrip().endswith(nick):
rest = payload[:-len(nick)] rest = payload.rstrip()[:-len(nick)]
possiblePayload = rest.rstrip(' \t,;') possiblePayload = rest.rstrip(' \t,;')
if possiblePayload != rest: if possiblePayload != rest:
# There should be some separator between the nick and the # There should be some separator between the nick and the

View File

@ -272,6 +272,12 @@ class FunctionsTestCase(SupyTestCase):
self.assertEqual(callbacks.addressed('bar', msg, self.assertEqual(callbacks.addressed('bar', msg,
whenAddressedByNickAtEnd=True), whenAddressedByNickAtEnd=True),
'baz') '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): def testAddressedPrefixCharsTakePrecedenceOverNickAtEnd(self):
irc = getTestIrc() irc = getTestIrc()