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.
|
||||||
|
|
||||||
@ -261,7 +270,7 @@ class Tokenizer(object):
|
|||||||
self.validChars = self.validChars.translate(string.ascii, '|')
|
self.validChars = self.validChars.translate(string.ascii, '|')
|
||||||
self.quotes = quotes
|
self.quotes = quotes
|
||||||
self.validChars = self.validChars.translate(string.ascii, quotes)
|
self.validChars = self.validChars.translate(string.ascii, quotes)
|
||||||
|
|
||||||
|
|
||||||
def _handleToken(self, token):
|
def _handleToken(self, token):
|
||||||
if token[0] == token[-1] and token[0] in self.quotes:
|
if token[0] == token[-1] and token[0] in self.quotes:
|
||||||
@ -692,7 +701,7 @@ class IrcObjectProxy(RichReplyMethods):
|
|||||||
if len(important) == 1:
|
if len(important) == 1:
|
||||||
return important
|
return important
|
||||||
return cbs
|
return cbs
|
||||||
|
|
||||||
def finalEval(self):
|
def finalEval(self):
|
||||||
assert not self.finalEvaled, 'finalEval called twice.'
|
assert not self.finalEvaled, 'finalEval called twice.'
|
||||||
self.finalEvaled = True
|
self.finalEvaled = True
|
||||||
@ -1147,7 +1156,7 @@ class Privmsg(irclib.IrcCallback):
|
|||||||
return getHelp(command)
|
return getHelp(command)
|
||||||
else:
|
else:
|
||||||
return 'The %s command has no help.' % utils.quoted(name)
|
return 'The %s command has no help.' % utils.quoted(name)
|
||||||
|
|
||||||
def registryValue(self, name, channel=None, value=True):
|
def registryValue(self, name, channel=None, value=True):
|
||||||
plugin = self.name()
|
plugin = self.name()
|
||||||
group = conf.supybot.plugins.get(plugin)
|
group = conf.supybot.plugins.get(plugin)
|
||||||
@ -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')
|
||||||
|
|
||||||
@ -219,7 +226,7 @@ class FunctionsTestCase(SupyTestCase):
|
|||||||
whenAddressedByNickAtEnd=True,
|
whenAddressedByNickAtEnd=True,
|
||||||
prefixChars='@'),
|
prefixChars='@'),
|
||||||
'echo foo')
|
'echo foo')
|
||||||
|
|
||||||
|
|
||||||
def testReply(self):
|
def testReply(self):
|
||||||
prefix = 'foo!bar@baz'
|
prefix = 'foo!bar@baz'
|
||||||
|
Loading…
Reference in New Issue
Block a user