mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-10 20:22:36 +01:00
Tag addressed messages with the results of callbacks._addressed. Also,
reorder the calling of addressedRes and res in PrivmsgCommandAndRegexp so that addressedRes are run first.
This commit is contained in:
parent
11c12e9062
commit
7217b01cd2
@ -64,7 +64,7 @@ import supybot.ircmsgs as ircmsgs
|
|||||||
import supybot.ircutils as ircutils
|
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):
|
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.
|
||||||
@ -144,6 +144,15 @@ def addressed(nick, msg, prefixChars=None, nicks=None,
|
|||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
def addressed(nick, msg, **kwargs):
|
||||||
|
payload = msg.addressed
|
||||||
|
if payload is not None:
|
||||||
|
return payload
|
||||||
|
else:
|
||||||
|
payload = _addressed(nick, msg, **kwargs)
|
||||||
|
msg.tag('addressed', payload)
|
||||||
|
return payload
|
||||||
|
|
||||||
def canonicalName(command):
|
def canonicalName(command):
|
||||||
"""Turn a command into its canonical form.
|
"""Turn a command into its canonical form.
|
||||||
|
|
||||||
@ -1364,10 +1373,6 @@ class PrivmsgCommandAndRegexp(Privmsg):
|
|||||||
if msg.isError:
|
if msg.isError:
|
||||||
self.log.debug('%s not running due to msg.isError.', self.name())
|
self.log.debug('%s not running due to msg.isError.', self.name())
|
||||||
return
|
return
|
||||||
for (r, name) in self.res:
|
|
||||||
for m in r.finditer(msg.args[1]):
|
|
||||||
proxy = self.Proxy(irc, msg)
|
|
||||||
self.callCommand(name, proxy, msg, m, catchErrors=True)
|
|
||||||
s = addressed(irc.nick, msg)
|
s = addressed(irc.nick, msg)
|
||||||
if s:
|
if s:
|
||||||
for (r, name) in self.addressedRes:
|
for (r, name) in self.addressedRes:
|
||||||
@ -1376,6 +1381,10 @@ class PrivmsgCommandAndRegexp(Privmsg):
|
|||||||
for m in r.finditer(s):
|
for m in r.finditer(s):
|
||||||
proxy = self.Proxy(irc, msg)
|
proxy = self.Proxy(irc, msg)
|
||||||
self.callCommand(name, proxy, msg, m, catchErrors=True)
|
self.callCommand(name, proxy, msg, m, catchErrors=True)
|
||||||
|
for (r, name) in self.res:
|
||||||
|
for m in r.finditer(msg.args[1]):
|
||||||
|
proxy = self.Proxy(irc, msg)
|
||||||
|
self.callCommand(name, proxy, msg, m, catchErrors=True)
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
@ -196,6 +196,10 @@ class FunctionsTestCase(SupyTestCase):
|
|||||||
try:
|
try:
|
||||||
original = conf.supybot.reply.whenNotAddressed()
|
original = conf.supybot.reply.whenNotAddressed()
|
||||||
conf.supybot.reply.whenNotAddressed.setValue(True)
|
conf.supybot.reply.whenNotAddressed.setValue(True)
|
||||||
|
# need to recreate the msg objects since the old ones have already
|
||||||
|
# been tagged
|
||||||
|
msg1 = ircmsgs.privmsg('#foo', '@bar')
|
||||||
|
msg2 = ircmsgs.privmsg('#foo', 'bar')
|
||||||
self.assertEqual(callbacks.addressed('blah', msg1), 'bar')
|
self.assertEqual(callbacks.addressed('blah', msg1), 'bar')
|
||||||
self.assertEqual(callbacks.addressed('blah', msg2), 'bar')
|
self.assertEqual(callbacks.addressed('blah', msg2), 'bar')
|
||||||
finally:
|
finally:
|
||||||
@ -204,6 +208,9 @@ class FunctionsTestCase(SupyTestCase):
|
|||||||
def testAddressedWithMultipleNicks(self):
|
def testAddressedWithMultipleNicks(self):
|
||||||
msg = ircmsgs.privmsg('#foo', 'bar: baz')
|
msg = ircmsgs.privmsg('#foo', 'bar: baz')
|
||||||
self.assertEqual(callbacks.addressed('bar', msg), 'baz')
|
self.assertEqual(callbacks.addressed('bar', msg), 'baz')
|
||||||
|
# need to recreate the msg objects since the old ones have already
|
||||||
|
# been tagged
|
||||||
|
msg = ircmsgs.privmsg('#foo', 'bar: baz')
|
||||||
self.assertEqual(callbacks.addressed('biff', msg, nicks=['bar']),
|
self.assertEqual(callbacks.addressed('biff', msg, nicks=['bar']),
|
||||||
'baz')
|
'baz')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user