Fixed bug in isAction.

This commit is contained in:
Jeremy Fincher 2003-11-21 22:13:18 +00:00
parent 0cc2c2f49f
commit 966a09437c
2 changed files with 9 additions and 3 deletions

View File

@ -210,9 +210,11 @@ class IrcMsg(object):
def isAction(msg):
"""A predicate returning true if the PRIVMSG in question is an ACTION"""
return msg.command == 'PRIVMSG' and \
msg.args[1].startswith('\x01ACTION') and \
msg.args[1].endswith('\x01')
if msg.command == 'PRIVMSG' and msg.args[1].endswith('\x01'):
L = msg.args[1].split(None, 1)
return len(L) == 2 and L[0] == '\x01ACTION'
else:
return False
_unactionre = re.compile(r'^\x01ACTION (.*)\x01$')
def unAction(msg):

View File

@ -129,6 +129,10 @@ class FunctionsTestCase(unittest.TestCase):
for msg in msgs:
self.failUnless(ircmsgs.isAction(msg))
def testIsActionFalseWhenNoSpaces(self):
msg = ircmsgs.IrcMsg('PRIVMSG #foo :\x01ACTIONfoobar\x01')
self.failIf(ircmsgs.isAction(msg))
def testUnAction(self):
s = 'foo bar baz'
msg = ircmsgs.action('#foo', s)