mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
Channel: Add pattern matching to @ban list.
This commit is contained in:
parent
283cdb3b1d
commit
8de804be7d
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user