From 8de804be7dfc614529080f3a26ea23af5079cb90 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 24 Nov 2014 18:26:25 +0100 Subject: [PATCH] Channel: Add pattern matching to @ban list. --- plugins/Channel/plugin.py | 24 +++++++++++++++--------- plugins/Channel/test.py | 13 +++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/plugins/Channel/plugin.py b/plugins/Channel/plugin.py index 55df35216..9eb4ab23d 100644 --- a/plugins/Channel/plugin.py +++ b/plugins/Channel/plugin.py @@ -29,6 +29,7 @@ ### import sys +import fnmatch import supybot.conf as conf import supybot.ircdb as ircdb @@ -597,27 +598,32 @@ class Channel(callbacks.Plugin): remove = wrap(remove, ['op', 'hostmask']) @internationalizeDocstring - def list(self, irc, msg, args, channel): - """[] + def list(self, irc, msg, args, channel, mask): + """[] [] If you have the #channel,op capability, this will show you the current persistent bans on the . """ - c = ircdb.channels.getChannel(channel) - if c.bans: + all_bans = ircdb.channels.getChannel(channel).bans + if mask: + mask = mask.replace(r'\*', '[*]') + filtered_bans = fnmatch.filter(all_bans, mask) + else: + filtered_bans = all_bans + if filtered_bans: bans = [] - for ban in c.bans: - if c.bans[ban]: + for ban in filtered_bans: + if all_bans[ban]: bans.append(format(_('%q (expires %t)'), - ban, c.bans[ban])) + ban, all_bans[ban])) else: bans.append(format(_('%q (never expires)'), - ban, c.bans[ban])) + ban, all_bans[ban])) irc.reply(format('%L', bans)) else: irc.reply(format(_('There are no persistent bans on %s.'), channel)) - list = wrap(list, ['op']) + list = wrap(list, ['op', optional('somethingWithoutSpaces')]) class ignore(callbacks.Commands): @internationalizeDocstring diff --git a/plugins/Channel/test.py b/plugins/Channel/test.py index 33d4b2367..6a8e4568e 100644 --- a/plugins/Channel/test.py +++ b/plugins/Channel/test.py @@ -219,6 +219,19 @@ class ChannelTestCase(ChannelPluginTestCase): self.assertNotError('ban add $a:nyuszika7h') self.assertNotError('ban remove $a:nyuszika7h') + def testBanList(self): + self.assertNotError('ban add foo!bar@baz') + self.assertNotError('ban add foobar!*@baz') + self.assertNotError('ban add foobar!qux@baz') + self.assertRegexp('ban list', r'.*foo!bar@baz.*') + self.assertRegexp('ban list', r'.*foobar!\*@baz.*') + self.assertRegexp('ban list', r'.*foobar!qux@baz.*') + self.assertNotRegexp('ban list foobar!*@baz', r'.*foo!bar@baz.*') + self.assertRegexp('ban list foobar!*@baz', r'.*foobar!\*@baz.*') + self.assertRegexp('ban list foobar!*@baz', r'.*foobar!qux@baz.*') + self.assertResponse('ban list foobar!\*@baz', + '"foobar!*@baz" (never expires)') + def testIgnore(self): orig = conf.supybot.protocols.irc.banmask() def ignore(given, expect=None):