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 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):
"""[<channel>]
def list(self, irc, msg, args, channel, mask):
"""[<channel>] [<mask>]
If you have the #channel,op capability, this will show you the
current persistent bans on the <channel>.
"""
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

View File

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