Bugfix for nick.atEnd taking precedence over prefixChars.

This commit is contained in:
Jeremy Fincher 2004-10-23 19:26:53 +00:00
parent 1745c6d144
commit d20381336a
2 changed files with 16 additions and 5 deletions

View File

@ -83,6 +83,8 @@ def addressed(nick, msg, prefixChars=None, nicks=None,
assert msg.command == 'PRIVMSG' assert msg.command == 'PRIVMSG'
(target, payload) = msg.args (target, payload) = msg.args
if not payload:
return ''
if prefixChars is None: if prefixChars is None:
prefixChars = get(conf.supybot.reply.whenAddressedBy.chars) prefixChars = get(conf.supybot.reply.whenAddressedBy.chars)
if whenAddressedByNick is None: if whenAddressedByNick is None:
@ -92,6 +94,12 @@ def addressed(nick, msg, prefixChars=None, nicks=None,
whenAddressedByNickAtEnd = get(r) whenAddressedByNickAtEnd = get(r)
if prefixStrings is None: if prefixStrings is None:
prefixStrings = get(conf.supybot.reply.whenAddressedBy.strings) prefixStrings = get(conf.supybot.reply.whenAddressedBy.strings)
# We have to check this before nicks -- try "@google supybot" with supybot
# and whenAddressedBy.nick.atEnd on to see why.
if any(payload.startswith, prefixStrings):
return stripPrefixStrings(payload)
elif payload[0] in prefixChars:
return payload[1:].strip()
if nicks is None: if nicks is None:
nicks = get(conf.supybot.reply.whenAddressedBy.nicks) nicks = get(conf.supybot.reply.whenAddressedBy.nicks)
nicks = map(ircutils.toLower, nicks) nicks = map(ircutils.toLower, nicks)
@ -128,11 +136,7 @@ def addressed(nick, msg, prefixChars=None, nicks=None,
# There should be some separator between the nick and the # There should be some separator between the nick and the
# previous alphanumeric character. # previous alphanumeric character.
return possiblePayload return possiblePayload
if payload and any(payload.startswith, prefixStrings): if conf.supybot.reply.whenNotAddressed():
return stripPrefixStrings(payload)
elif payload and payload[0] in prefixChars:
return payload[1:].strip()
elif conf.supybot.reply.whenNotAddressed():
return payload return payload
else: else:
return '' return ''

View File

@ -212,6 +212,13 @@ class FunctionsTestCase(SupyTestCase):
self.assertEqual(callbacks.addressed('bar', msg, self.assertEqual(callbacks.addressed('bar', msg,
whenAddressedByNickAtEnd=True), whenAddressedByNickAtEnd=True),
'baz') 'baz')
def testAddressedPrefixCharsTakePrecedenceOverNickAtEnd(self):
msg = ircmsgs.privmsg('#foo', '@echo foo')
self.assertEqual(callbacks.addressed('foo', msg,
whenAddressedByNickAtEnd=True,
prefixChars='@'),
'echo foo')
def testReply(self): def testReply(self):