Made outfilters stackable, added md5 and sha as outfilters.

This commit is contained in:
Jeremy Fincher 2003-10-22 05:15:41 +00:00
parent e50243262d
commit 13c10c899e
2 changed files with 11 additions and 7 deletions

View File

@ -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):
"""[<command>]
@ -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')

View File

@ -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')