mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 15:44:06 +01:00
Made outfilter channel-specific.
This commit is contained in:
parent
5ae13a9422
commit
3538f2c7b4
@ -132,39 +132,43 @@ class MyFunProxy(object):
|
|||||||
|
|
||||||
class Fun(callbacks.Privmsg):
|
class Fun(callbacks.Privmsg):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.filtercommands = []
|
self.outFilters = ircutils.IrcDict()
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
|
|
||||||
def outFilter(self, irc, msg):
|
def outFilter(self, irc, msg):
|
||||||
if msg.command == 'PRIVMSG':
|
if msg.command == 'PRIVMSG':
|
||||||
s = msg.args[1]
|
if msg.args[0] in self.outFilters:
|
||||||
for filtercommand in self.filtercommands:
|
s = msg.args[1]
|
||||||
myIrc = MyFunProxy()
|
methods = self.outFilters[msg.args[0]]
|
||||||
filtercommand(myIrc, msg, [s])
|
for filtercommand in methods:
|
||||||
s = myIrc.s
|
myIrc = MyFunProxy()
|
||||||
msg = ircmsgs.IrcMsg(msg=msg, args=(msg.args[0], s))
|
filtercommand(myIrc, msg, [s])
|
||||||
|
s = myIrc.s
|
||||||
|
msg = ircmsgs.IrcMsg(msg=msg, args=(msg.args[0], s))
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
_filterCommands = ['jeffk', 'leet', 'rot13', 'hexlify', 'binary', 'lithp',
|
_filterCommands = ['jeffk', 'leet', 'rot13', 'hexlify', 'binary', 'lithp',
|
||||||
'scramble', 'morse', 'reverse', 'urlquote', 'md5','sha']
|
'scramble', 'morse', 'reverse', 'urlquote', 'md5','sha']
|
||||||
def outfilter(self, irc, msg, args):
|
def outfilter(self, irc, msg, args, channel):
|
||||||
"""[<command>]
|
"""[<channel>] [<command>]
|
||||||
|
|
||||||
Sets the outFilter of this plugin to be <command>. If no command is
|
Sets the outFilter of this plugin to be <command>. If no command is
|
||||||
given, unsets the outFilter.
|
given, unsets the outFilter. <channel> is only necessary if the
|
||||||
|
message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
command = privmsgs.getArgs(args, needed=0, optional=1)
|
command = privmsgs.getArgs(args, needed=0, optional=1)
|
||||||
if command:
|
if command:
|
||||||
command = callbacks.canonicalName(command)
|
command = callbacks.canonicalName(command)
|
||||||
if command in self._filterCommands:
|
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)
|
irc.reply(msg, conf.replySuccess)
|
||||||
else:
|
else:
|
||||||
irc.error(msg, 'That\'s not a valid filter command.')
|
irc.error(msg, 'That\'s not a valid filter command.')
|
||||||
else:
|
else:
|
||||||
self.filtercommands = []
|
self.outFilters[channel] = []
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
outfilter = privmsgs.checkCapability(outfilter, 'admin')
|
outfilter = privmsgs.checkChannelCapability(outfilter, 'op')
|
||||||
|
|
||||||
def hexip(self, irc, msg, args):
|
def hexip(self, irc, msg, args):
|
||||||
"""<ip>
|
"""<ip>
|
||||||
|
@ -35,7 +35,7 @@ import re
|
|||||||
|
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
class FunTest(PluginTestCase, PluginDocumentation):
|
class FunTest(ChannelPluginTestCase, PluginDocumentation):
|
||||||
plugins = ('Fun',)
|
plugins = ('Fun',)
|
||||||
def testNoErrors(self):
|
def testNoErrors(self):
|
||||||
self.assertNotError('leet foobar')
|
self.assertNotError('leet foobar')
|
||||||
@ -98,14 +98,15 @@ class FunTest(PluginTestCase, PluginDocumentation):
|
|||||||
self.assertNotRegexp('scramble %s' % s, s)
|
self.assertNotRegexp('scramble %s' % s, s)
|
||||||
|
|
||||||
def testoutfilter(self):
|
def testoutfilter(self):
|
||||||
|
s = self.nick.encode('rot13')
|
||||||
self.assertNotError('outfilter rot13')
|
self.assertNotError('outfilter rot13')
|
||||||
self.assertResponse('rot13 foobar', 'foobar')
|
self.assertResponse('rot13 foobar', '%s: foobar' % s)
|
||||||
self.assertNotError('outfilter rot13')
|
self.assertNotError('outfilter rot13')
|
||||||
self.assertResponse('rot13 foobar', 'sbbone')
|
self.assertResponse('rot13 foobar', 'sbbone')
|
||||||
self.assertNotError('outfilter')
|
self.assertNotError('outfilter')
|
||||||
self.assertResponse('rot13 foobar', 'sbbone')
|
self.assertResponse('rot13 foobar', 'sbbone')
|
||||||
self.assertNotError('outfilter ROT13')
|
self.assertNotError('outfilter ROT13')
|
||||||
self.assertResponse('rot13 foobar', 'foobar')
|
self.assertResponse('rot13 foobar', '%s: foobar' % s)
|
||||||
self.assertNotError('outfilter')
|
self.assertNotError('outfilter')
|
||||||
self.assertResponse('rot13 foobar', 'sbbone')
|
self.assertResponse('rot13 foobar', 'sbbone')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user