From 3538f2c7b43f70aa8f83ce6520a86453ee6723aa Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Fri, 24 Oct 2003 22:43:48 +0000 Subject: [PATCH] Made outfilter channel-specific. --- plugins/Fun.py | 30 +++++++++++++++++------------- test/test_Fun.py | 7 ++++--- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/plugins/Fun.py b/plugins/Fun.py index f97987ad0..7f6aab872 100644 --- a/plugins/Fun.py +++ b/plugins/Fun.py @@ -132,39 +132,43 @@ class MyFunProxy(object): class Fun(callbacks.Privmsg): def __init__(self): - self.filtercommands = [] + self.outFilters = ircutils.IrcDict() callbacks.Privmsg.__init__(self) def outFilter(self, irc, msg): if msg.command == 'PRIVMSG': - s = msg.args[1] - for filtercommand in self.filtercommands: - myIrc = MyFunProxy() - filtercommand(myIrc, msg, [s]) - s = myIrc.s - msg = ircmsgs.IrcMsg(msg=msg, args=(msg.args[0], s)) + if msg.args[0] in self.outFilters: + s = msg.args[1] + methods = self.outFilters[msg.args[0]] + for filtercommand in methods: + myIrc = MyFunProxy() + filtercommand(myIrc, msg, [s]) + s = myIrc.s + msg = ircmsgs.IrcMsg(msg=msg, args=(msg.args[0], s)) return msg _filterCommands = ['jeffk', 'leet', 'rot13', 'hexlify', 'binary', 'lithp', 'scramble', 'morse', 'reverse', 'urlquote', 'md5','sha'] - def outfilter(self, irc, msg, args): - """[] + def outfilter(self, irc, msg, args, channel): + """[] [] Sets the outFilter of this plugin to be . If no command is - given, unsets the outFilter. + given, unsets the outFilter. is only necessary if the + message isn't sent in the channel itself. """ command = privmsgs.getArgs(args, needed=0, optional=1) if command: command = callbacks.canonicalName(command) if command in self._filterCommands: - self.filtercommands.append(getattr(self, command)) + method = getattr(self, command) + self.outFilters.setdefault(channel, []).append(method) irc.reply(msg, conf.replySuccess) else: irc.error(msg, 'That\'s not a valid filter command.') else: - self.filtercommands = [] + self.outFilters[channel] = [] irc.reply(msg, conf.replySuccess) - outfilter = privmsgs.checkCapability(outfilter, 'admin') + outfilter = privmsgs.checkChannelCapability(outfilter, 'op') def hexip(self, irc, msg, args): """ diff --git a/test/test_Fun.py b/test/test_Fun.py index 217c8ee31..734e1454a 100644 --- a/test/test_Fun.py +++ b/test/test_Fun.py @@ -35,7 +35,7 @@ import re import utils -class FunTest(PluginTestCase, PluginDocumentation): +class FunTest(ChannelPluginTestCase, PluginDocumentation): plugins = ('Fun',) def testNoErrors(self): self.assertNotError('leet foobar') @@ -98,14 +98,15 @@ class FunTest(PluginTestCase, PluginDocumentation): self.assertNotRegexp('scramble %s' % s, s) def testoutfilter(self): + s = self.nick.encode('rot13') self.assertNotError('outfilter rot13') - self.assertResponse('rot13 foobar', 'foobar') + self.assertResponse('rot13 foobar', '%s: foobar' % s) self.assertNotError('outfilter rot13') self.assertResponse('rot13 foobar', 'sbbone') self.assertNotError('outfilter') self.assertResponse('rot13 foobar', 'sbbone') self.assertNotError('outfilter ROT13') - self.assertResponse('rot13 foobar', 'foobar') + self.assertResponse('rot13 foobar', '%s: foobar' % s) self.assertNotError('outfilter') self.assertResponse('rot13 foobar', 'sbbone')