From 13c10c899e2a46073952eac1ccc885af70de2e58 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 22 Oct 2003 05:15:41 +0000 Subject: [PATCH] Made outfilters stackable, added md5 and sha as outfilters. --- plugins/Fun.py | 16 +++++++++------- test/test_Fun.py | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/Fun.py b/plugins/Fun.py index 4138fc928..7c03a786e 100644 --- a/plugins/Fun.py +++ b/plugins/Fun.py @@ -132,19 +132,21 @@ class MyFunProxy(object): class Fun(callbacks.Privmsg): def __init__(self): - self.filtercommand = None + self.filtercommands = [] callbacks.Privmsg.__init__(self) def outFilter(self, irc, msg): if msg.command == 'PRIVMSG': - if self.filtercommand is not None: + s = msg.args[1] + for filtercommand in self.filtercommands: myIrc = MyFunProxy() - self.filtercommand(myIrc, msg, [msg.args[1]]) - msg = ircmsgs.IrcMsg(msg=msg, args=(msg.args[0], myIrc.s)) + 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'] + 'scramble', 'morse', 'reverse', 'urlquote', 'md5','sha'] def outfilter(self, irc, msg, args): """[] @@ -155,12 +157,12 @@ class Fun(callbacks.Privmsg): if command: command = callbacks.canonicalName(command) if command in self._filterCommands: - self.filtercommand = getattr(self, command) + self.filtercommands.append(getattr(self, command)) irc.reply(msg, conf.replySuccess) else: irc.error(msg, 'That\'s not a valid filter command.') else: - self.filtercommand = None + self.filtercommands = [] irc.reply(msg, conf.replySuccess) outfilter = privmsgs.checkCapability(outfilter, 'admin') diff --git a/test/test_Fun.py b/test/test_Fun.py index b2dad1082..33d97ccb5 100644 --- a/test/test_Fun.py +++ b/test/test_Fun.py @@ -94,6 +94,8 @@ class FunTest(PluginTestCase, PluginDocumentation): def testoutfilter(self): self.assertNotError('outfilter rot13') self.assertResponse('rot13 foobar', 'foobar') + self.assertNotError('outfilter rot13') + self.assertResponse('rot13 foobar', 'sbbone') self.assertNotError('outfilter') self.assertResponse('rot13 foobar', 'sbbone') self.assertNotError('outfilter ROT13')