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