diff --git a/plugins/MoobotFactoids/plugin.py b/plugins/MoobotFactoids/plugin.py index b4a18e631..ecf56f49f 100755 --- a/plugins/MoobotFactoids/plugin.py +++ b/plugins/MoobotFactoids/plugin.py @@ -325,7 +325,7 @@ class MoobotFactoids(callbacks.Plugin): else: key = ' '.join(tokens) key = self._sanitizeKey(key) - channel = plugins.getChannel(msg.channel) + channel = plugins.getChannel(msg.channel or msg.args[0]) fact = self.db.getFactoid(channel, key) if fact: self.db.updateRequest(channel, key, msg.prefix) @@ -385,7 +385,7 @@ class MoobotFactoids(callbacks.Plugin): def addFactoid(self, irc, msg, tokens): # First, check and see if the entire message matches a factoid key - channel = plugins.getChannel(msg.channel) + channel = plugins.getChannel(msg.channel or msg.args[0]) id = self._getUserId(irc, msg.prefix) try: (key, fact) = self._getKeyAndFactoid(tokens) @@ -401,7 +401,7 @@ class MoobotFactoids(callbacks.Plugin): id = self._getUserId(irc, msg.prefix) (key, regexp) = list(map(' '.join, utils.iter.split('=~'.__eq__, tokens, maxsplit=1))) - channel = plugins.getChannel(msg.channel) + channel = plugins.getChannel(msg.channel or msg.args[0]) # Check and make sure it's in the DB fact = self._getFactoid(irc, channel, key) self._checkNotLocked(irc, channel, key) @@ -422,7 +422,7 @@ class MoobotFactoids(callbacks.Plugin): isAlso = pairs.index(['is', 'also']) key = ' '.join(tokens[:isAlso]) new_text = ' '.join(tokens[isAlso+2:]) - channel = plugins.getChannel(msg.channel) + channel = plugins.getChannel(msg.channel or msg.args[0]) fact = self._getFactoid(irc, channel, key) self._checkNotLocked(irc, channel, key) # It's fair game if we get to here @@ -433,7 +433,7 @@ class MoobotFactoids(callbacks.Plugin): def replaceFactoid(self, irc, msg, tokens): # Must be registered! - channel = plugins.getChannel(msg.channel) + channel = plugins.getChannel(msg.channel or msg.args[0]) id = self._getUserId(irc, msg.prefix) del tokens[0] # remove the "no," try: diff --git a/plugins/MoobotFactoids/test.py b/plugins/MoobotFactoids/test.py index f254e9d80..1bd3ecb67 100644 --- a/plugins/MoobotFactoids/test.py +++ b/plugins/MoobotFactoids/test.py @@ -71,6 +71,34 @@ class OptionListTestCase(SupyTestCase): self._testOptions('^\\%(\\%(foo\\)\\@moo is moo') + self.assertResponse('bar', 'moo is moo') + # Check substitution + self.assertNotError('who is $who') + self.assertResponse('who', ircutils.nickFromHostmask(self.prefix)) + # Check that actions ("\x01ACTION...") don't match + m = ircmsgs.action(self.channel, 'is doing something') + self.irc.feedMsg(m) + self.assertNoResponse(' ', 1) + class FactoidsTestCase(ChannelPluginTestCase): plugins = ('MoobotFactoids', 'User', 'String', 'Utilities', 'Web') config = {'reply.whenNotCommand': False}