Channel: Add pattern matching to @ban list.

This commit is contained in:
Valentin Lorentz 2014-11-24 18:26:25 +01:00
parent 283cdb3b1d
commit 8de804be7d
2 changed files with 28 additions and 9 deletions

View File

@ -29,6 +29,7 @@
### ###
import sys import sys
import fnmatch
import supybot.conf as conf import supybot.conf as conf
import supybot.ircdb as ircdb import supybot.ircdb as ircdb
@ -597,27 +598,32 @@ class Channel(callbacks.Plugin):
remove = wrap(remove, ['op', 'hostmask']) remove = wrap(remove, ['op', 'hostmask'])
@internationalizeDocstring @internationalizeDocstring
def list(self, irc, msg, args, channel): def list(self, irc, msg, args, channel, mask):
"""[<channel>] """[<channel>] [<mask>]
If you have the #channel,op capability, this will show you the If you have the #channel,op capability, this will show you the
current persistent bans on the <channel>. current persistent bans on the <channel>.
""" """
c = ircdb.channels.getChannel(channel) all_bans = ircdb.channels.getChannel(channel).bans
if c.bans: if mask:
mask = mask.replace(r'\*', '[*]')
filtered_bans = fnmatch.filter(all_bans, mask)
else:
filtered_bans = all_bans
if filtered_bans:
bans = [] bans = []
for ban in c.bans: for ban in filtered_bans:
if c.bans[ban]: if all_bans[ban]:
bans.append(format(_('%q (expires %t)'), bans.append(format(_('%q (expires %t)'),
ban, c.bans[ban])) ban, all_bans[ban]))
else: else:
bans.append(format(_('%q (never expires)'), bans.append(format(_('%q (never expires)'),
ban, c.bans[ban])) ban, all_bans[ban]))
irc.reply(format('%L', bans)) irc.reply(format('%L', bans))
else: else:
irc.reply(format(_('There are no persistent bans on %s.'), irc.reply(format(_('There are no persistent bans on %s.'),
channel)) channel))
list = wrap(list, ['op']) list = wrap(list, ['op', optional('somethingWithoutSpaces')])
class ignore(callbacks.Commands): class ignore(callbacks.Commands):
@internationalizeDocstring @internationalizeDocstring

View File

@ -219,6 +219,19 @@ class ChannelTestCase(ChannelPluginTestCase):
self.assertNotError('ban add $a:nyuszika7h') self.assertNotError('ban add $a:nyuszika7h')
self.assertNotError('ban remove $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): def testIgnore(self):
orig = conf.supybot.protocols.irc.banmask() orig = conf.supybot.protocols.irc.banmask()
def ignore(given, expect=None): def ignore(given, expect=None):