mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 12:49:24 +01:00
move isCtcp to ircmsgs and fix up a couple things with Infobot
This commit is contained in:
parent
c31512da01
commit
115a3a88ec
@ -212,7 +212,6 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
||||
assert self.msg is not None
|
||||
msg = self.msg
|
||||
isAre = None
|
||||
key = plugins.standardSubstitute(irc, msg, key)
|
||||
if self.db.hasIs(key):
|
||||
isAre = 'is'
|
||||
value = self.db.getIs(key)
|
||||
@ -246,7 +245,7 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
||||
|
||||
_forceRe = re.compile(r'^no[,: -]+', re.I)
|
||||
def doPrivmsg(self, irc, msg):
|
||||
if ircmsgs.isAction(msg):
|
||||
if ircmsgs.isCtcp(msg):
|
||||
return
|
||||
maybeAddressed = callbacks.addressed(irc.nick, msg,
|
||||
whenAddressedByNick=True)
|
||||
@ -316,7 +315,6 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
||||
def doUnknown(self, irc, msg, match):
|
||||
r"^(.+?)\?[?!. ]*$"
|
||||
key = match.group(1)
|
||||
key = plugins.standardSubstitute(irc, msg, key)
|
||||
if self.addressed or self.registryValue('answerUnaddressedQuestions'):
|
||||
self.factoid(key) # Does the dunno'ing for us itself.
|
||||
# TODO: Add invalidCommand.
|
||||
@ -335,8 +333,6 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
||||
not self.registryValue('snarfUnaddressedDefinitions'):
|
||||
return
|
||||
isAre = isAre.lower()
|
||||
key = plugins.standardSubstitute(irc, msg, key)
|
||||
value = plugins.standardSubstitute(irc, msg, value)
|
||||
if isAre in ('was', 'is', 'am'):
|
||||
if self.db.hasIs(key):
|
||||
if also:
|
||||
|
@ -480,7 +480,7 @@ class Relay(callbacks.Privmsg):
|
||||
irc = self._getRealIrc(irc)
|
||||
if channel not in self.registryValue('channels'):
|
||||
return
|
||||
if ircutils.isCtcp(msg) and \
|
||||
if ircmsgs.isCtcp(msg) and \
|
||||
'AWAY' not in text and 'ACTION' not in text:
|
||||
return
|
||||
network = self._getIrcName(irc)
|
||||
|
@ -481,7 +481,7 @@ class IrcObjectProxy(RichReplyMethods):
|
||||
self.finalEval()
|
||||
|
||||
def _callInvalidCommands(self):
|
||||
if ircutils.isCtcp(self.msg):
|
||||
if ircmsgs.isCtcp(self.msg):
|
||||
log.debug('Skipping invalidCommand, msg is CTCP.')
|
||||
return
|
||||
log.debug('Calling invalidCommands.')
|
||||
|
@ -211,11 +211,16 @@ class IrcMsg(object):
|
||||
## pass
|
||||
|
||||
|
||||
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 isAction(msg):
|
||||
"""A predicate returning true if the PRIVMSG in question is an ACTION"""
|
||||
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'
|
||||
if isCtcp(msg):
|
||||
return len(msg.args[1].split(None, 1)) == 2
|
||||
else:
|
||||
return False
|
||||
|
||||
|
@ -127,12 +127,6 @@ def isChannel(s):
|
||||
return (s and s[0] in '#&+!' and len(s) <= 50 and \
|
||||
'\x07' not in s and ',' not in s and ' ' not in s)
|
||||
|
||||
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')
|
||||
|
||||
_patternCache = {}
|
||||
def _hostmaskPatternEqual(pattern, hostmask):
|
||||
"""Returns True if hostmask matches the hostmask pattern pattern."""
|
||||
|
@ -129,6 +129,10 @@ class FunctionsTestCase(SupyTestCase):
|
||||
for msg in msgs:
|
||||
self.failUnless(ircmsgs.isAction(msg))
|
||||
|
||||
def testIsCtcp(self):
|
||||
self.failUnless(ircutils.isCtcp(ircmsgs.privmsg('foo',
|
||||
'\x01VERSION\x01')))
|
||||
|
||||
def testIsActionFalseWhenNoSpaces(self):
|
||||
msg = ircmsgs.IrcMsg('PRIVMSG #foo :\x01ACTIONfoobar\x01')
|
||||
self.failIf(ircmsgs.isAction(msg))
|
||||
|
@ -84,10 +84,6 @@ class FunctionsTestCase(SupyTestCase):
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user