diff --git a/plugins/Factoids/plugin.py b/plugins/Factoids/plugin.py index 856e74f8a..aafde816f 100644 --- a/plugins/Factoids/plugin.py +++ b/plugins/Factoids/plugin.py @@ -245,7 +245,8 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler): if factoids: if number: try: - irc.reply(factoids[number-1][0]) + irc.reply(ircutils.standardSubstitute(irc, msg, + factoids[number-1][0])) self._updateRank(channel, [factoids[number-1]]) except IndexError: irc.error(_('That\'s not a valid number for that key.')) @@ -258,12 +259,15 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler): return ircutils.standardSubstitute(irc, msg, formatter, env) if len(factoids) == 1: - irc.reply(prefixer(factoids[0][0])) + irc.reply(ircutils.standardSubstitute(irc, msg, + prefixer(factoids[0][0]))) else: factoidsS = [] counter = 1 for factoid in factoids: - factoidsS.append(format('(#%i) %s', counter, factoid[0])) + factoidsS.append(format('(#%i) %s', counter, + ircutils.standardSubstitute(irc, msg, + factoid[0]))) counter += 1 irc.replies(factoidsS, prefixer=prefixer, joiner=', or ', onlyPrefixFirst=True) diff --git a/plugins/Factoids/test.py b/plugins/Factoids/test.py index 46782c239..4c56f6698 100644 --- a/plugins/Factoids/test.py +++ b/plugins/Factoids/test.py @@ -174,6 +174,14 @@ class FactoidsTestCase(ChannelPluginTestCase): self.assertNotError('learn foob as barb') self.assertRegexp('whatis foom', 'foo.*foob') + def testStandardSubstitute(self): + self.assertNotError('learn foo as this is $channel, and hour is $hour') + self.assertRegexp('whatis foo', 'this is #test, and hour is \d{1,2}') + self.assertNotError('learn bar as this is $$channel escaped') + self.assertRegexp('whatis bar', 'this is \$channel') + self.assertNotError('learn bar as this is $minute') + self.assertRegexp('whatis bar', '\$channel.*\d{1,2}') + def testAlias(self): self.assertNotError('learn foo as bar') self.assertNotError('alias foo zoog')