mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-18 08:02:49 +01:00
Added supybot.reply.whenAddressedByNick.atEnd.
This commit is contained in:
parent
28185185dd
commit
3dceea823d
@ -66,7 +66,8 @@ import supybot.ircutils as ircutils
|
|||||||
import supybot.registry as registry
|
import supybot.registry as registry
|
||||||
|
|
||||||
def addressed(nick, msg, prefixChars=None, nicks=None,
|
def addressed(nick, msg, prefixChars=None, nicks=None,
|
||||||
prefixStrings=None, whenAddressedByNick=None):
|
prefixStrings=None, whenAddressedByNick=None,
|
||||||
|
whenAddressedByNickAtEnd=None):
|
||||||
"""If msg is addressed to 'name', returns the portion after the address.
|
"""If msg is addressed to 'name', returns the portion after the address.
|
||||||
Otherwise returns the empty string.
|
Otherwise returns the empty string.
|
||||||
"""
|
"""
|
||||||
@ -86,6 +87,9 @@ def addressed(nick, msg, prefixChars=None, nicks=None,
|
|||||||
prefixChars = get(conf.supybot.reply.whenAddressedBy.chars)
|
prefixChars = get(conf.supybot.reply.whenAddressedBy.chars)
|
||||||
if whenAddressedByNick is None:
|
if whenAddressedByNick is None:
|
||||||
whenAddressedByNick = get(conf.supybot.reply.whenAddressedBy.nick)
|
whenAddressedByNick = get(conf.supybot.reply.whenAddressedBy.nick)
|
||||||
|
if whenAddressedByNickAtEnd is None:
|
||||||
|
r = conf.supybot.reply.whenAddressedBy.nick.atEnd
|
||||||
|
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)
|
||||||
if nicks is None:
|
if nicks is None:
|
||||||
@ -103,7 +107,8 @@ def addressed(nick, msg, prefixChars=None, nicks=None,
|
|||||||
# Ok, not private. Does it start with our nick?
|
# Ok, not private. Does it start with our nick?
|
||||||
elif whenAddressedByNick:
|
elif whenAddressedByNick:
|
||||||
for nick in nicks:
|
for nick in nicks:
|
||||||
if ircutils.toLower(payload).startswith(nick):
|
lowered = ircutils.toLower(payload)
|
||||||
|
if lowered.startswith(nick):
|
||||||
try:
|
try:
|
||||||
(maybeNick, rest) = payload.split(None, 1)
|
(maybeNick, rest) = payload.split(None, 1)
|
||||||
while not ircutils.isNick(maybeNick, strictRfc=True):
|
while not ircutils.isNick(maybeNick, strictRfc=True):
|
||||||
@ -116,6 +121,13 @@ def addressed(nick, 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):
|
||||||
|
rest = payload[:-len(nick)]
|
||||||
|
possiblePayload = rest.rstrip(' \t,;')
|
||||||
|
if possiblePayload != rest:
|
||||||
|
# There should be some separator between the nick and the
|
||||||
|
# previous alphanumeric character.
|
||||||
|
return possiblePayload
|
||||||
if payload and any(payload.startswith, prefixStrings):
|
if payload and any(payload.startswith, prefixStrings):
|
||||||
return stripPrefixStrings(payload)
|
return stripPrefixStrings(payload)
|
||||||
elif payload and payload[0] in prefixChars:
|
elif payload and payload[0] in prefixChars:
|
||||||
|
@ -410,11 +410,13 @@ registerChannelValue(supybot.reply.whenAddressedBy, 'strings',
|
|||||||
them), this variable is a space-separated list of strings, so you can
|
them), this variable is a space-separated list of strings, so you can
|
||||||
set something like '@@ ??' and the bot will reply when a message is
|
set something like '@@ ??' and the bot will reply when a message is
|
||||||
prefixed by either @@ or ??."""))
|
prefixed by either @@ or ??."""))
|
||||||
|
|
||||||
registerChannelValue(supybot.reply.whenAddressedBy, 'nick',
|
registerChannelValue(supybot.reply.whenAddressedBy, 'nick',
|
||||||
registry.Boolean(True, """Determines whether the bot will reply when people
|
registry.Boolean(True, """Determines whether the bot will reply when people
|
||||||
address it by its nick, rather than with a prefix character."""))
|
address it by its nick, rather than with a prefix character."""))
|
||||||
|
registerChannelValue(supybot.reply.whenAddressedBy.nick, 'atEnd',
|
||||||
|
registry.Boolean(False, """Determines whether the bot will reply when people
|
||||||
|
address it by its nick at the end of the message, rather than at the
|
||||||
|
beginning."""))
|
||||||
registerChannelValue(supybot.reply.whenAddressedBy, 'nicks',
|
registerChannelValue(supybot.reply.whenAddressedBy, 'nicks',
|
||||||
registry.SpaceSeparatedSetOfStrings([], """Determines what extra nicks the
|
registry.SpaceSeparatedSetOfStrings([], """Determines what extra nicks the
|
||||||
bot will always respond to when addressed by, even if its current nick is
|
bot will always respond to when addressed by, even if its current nick is
|
||||||
|
@ -203,8 +203,16 @@ class FunctionsTestCase(SupyTestCase):
|
|||||||
|
|
||||||
def testAddressedWithMultipleNicks(self):
|
def testAddressedWithMultipleNicks(self):
|
||||||
msg = ircmsgs.privmsg('#foo', 'bar: baz')
|
msg = ircmsgs.privmsg('#foo', 'bar: baz')
|
||||||
self.failUnless(callbacks.addressed('bar', msg))
|
self.assertEqual(callbacks.addressed('bar', msg), 'baz')
|
||||||
self.failUnless(callbacks.addressed('biff', msg, nicks=['bar']))
|
self.assertEqual(callbacks.addressed('biff', msg, nicks=['bar']),
|
||||||
|
'baz')
|
||||||
|
|
||||||
|
def testAddressedWithNickAtEnd(self):
|
||||||
|
msg = ircmsgs.privmsg('#foo', 'baz, bar')
|
||||||
|
self.assertEqual(callbacks.addressed('bar', msg,
|
||||||
|
whenAddressedByNickAtEnd=True),
|
||||||
|
'baz')
|
||||||
|
|
||||||
|
|
||||||
def testReply(self):
|
def testReply(self):
|
||||||
prefix = 'foo!bar@baz'
|
prefix = 'foo!bar@baz'
|
||||||
|
Loading…
Reference in New Issue
Block a user