Added isCtcp.

This commit is contained in:
Jeremy Fincher 2003-12-10 18:49:45 +00:00
parent 2e5b900da4
commit 3f6d347e2b
2 changed files with 10 additions and 1 deletions

View File

@ -104,6 +104,12 @@ def nickEqual(nick1, nick2):
_nickchars = r'_[]\`^{}|-'
nickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$' % (re.escape(_nickchars),
re.escape(_nickchars)))
def isCtcp(msg):
"""Returns whether or not msg is a CTCP message."""
return msg.command == 'PRIVMSG' and \
msg.args[1].startswith('\x01') and \
msg.args[1].endswith('\x01')
def isNick(s):
"""Returns True if s is a valid IRC nick."""
if re.match(nickRe, s):

View File

@ -55,7 +55,6 @@ class FunctionsTestCase(unittest.TestCase):
'abr-ubr1.sbo-abr.ma.cable.rcn.com'
self.failUnless(ircutils.hostmaskPatternEqual(s, s))
def testIsUserHostmask(self):
self.failUnless(ircutils.isUserHostmask(self.hostmask))
self.failUnless(ircutils.isUserHostmask('a!b@c'))
@ -85,6 +84,10 @@ class FunctionsTestCase(unittest.TestCase):
self.failIf(ircutils.isChannel('foo'))
self.failIf(ircutils.isChannel(''))
def testIsCtcp(self):
self.failUnless(ircutils.isCtcp(ircmsgs.privmsg('foo',
'\x01VERSION\x01')))
def testBold(self):
s = ircutils.bold('foo')
self.assertEqual(s[0], '\x02')