allow setting multiple bans with one command.
This commit is contained in:
parent
909d56d704
commit
3c7eff0f70
|
@ -1491,8 +1491,8 @@ class Bantracker(callbacks.Plugin):
|
||||||
irc.error("No comments recorded for ban %i" % id)
|
irc.error("No comments recorded for ban %i" % id)
|
||||||
comment = wrap(comment, ['id', optional('text')])
|
comment = wrap(comment, ['id', optional('text')])
|
||||||
|
|
||||||
def banremove(self, irc, msg, args, id, timespec):
|
def banremove(self, irc, msg, args, ids, timespec):
|
||||||
"""<id> <time>
|
"""<id>[,<id> ...] <time>
|
||||||
|
|
||||||
Sets expiration time.
|
Sets expiration time.
|
||||||
"""
|
"""
|
||||||
|
@ -1502,44 +1502,53 @@ class Bantracker(callbacks.Plugin):
|
||||||
irc.error("bad time format.")
|
irc.error("bad time format.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# lets check if is already managed first
|
ids = [ int(i) for i in ids.split(',') if i.isdigit() and int(i) > 0 ]
|
||||||
for idx, remove in enumerate(self.managedBans):
|
|
||||||
if id == remove.ban.id:
|
|
||||||
ban = remove.ban
|
|
||||||
del self.managedBans.shelf[idx]
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
L = self.db_run("SELECT mask, channel, removal FROM bans WHERE id = %s",
|
|
||||||
id, expect_result=True)
|
|
||||||
if not L:
|
|
||||||
irc.reply("I don't know any ban with that id.")
|
|
||||||
return
|
|
||||||
|
|
||||||
mask, channel, removal = L[0]
|
for id in ids:
|
||||||
type = guessBanType(mask)
|
# lets check if is already managed first
|
||||||
if type not in ('ban', 'quiet'):
|
for idx, remove in enumerate(self.managedBans):
|
||||||
irc.reply("Id %s is a %s, only bans or quiets can be autoremoved." % (id, type))
|
if id == remove.ban.id:
|
||||||
return
|
ban = remove.ban
|
||||||
|
del self.managedBans.shelf[idx]
|
||||||
if removal:
|
|
||||||
irc.reply("Ban '%s' was already removed in %s." % (mask, channel))
|
|
||||||
return
|
|
||||||
|
|
||||||
for ban in self.bans[channel]:
|
|
||||||
if mask == ban.mask:
|
|
||||||
if ban.id is None:
|
|
||||||
ban.id = id
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# ban not in sync it seems, shouldn't happen normally.
|
L = self.db_run("SELECT mask, channel, removal FROM bans WHERE id = %s",
|
||||||
irc.reply("Ban '%s' isn't active in %s." % (mask, channel))
|
id, expect_result=True)
|
||||||
return
|
if not L:
|
||||||
|
irc.reply("I don't know any ban with id %s." % id)
|
||||||
|
continue
|
||||||
|
|
||||||
|
mask, channel, removal = L[0]
|
||||||
|
type = guessBanType(mask)
|
||||||
|
if type not in ('ban', 'quiet'):
|
||||||
|
irc.reply("Id %s is a %s, only bans or quiets can be autoremoved." % (id, type))
|
||||||
|
continue
|
||||||
|
|
||||||
self.managedBans.add(BanRemoval(ban, seconds))
|
if removal:
|
||||||
irc.replySuccess()
|
irc.reply("Ban %s (%s) was already removed in %s." % (id, mask, channel))
|
||||||
|
continue
|
||||||
|
|
||||||
banremove = wrap(banremove, ['id', 'text'])
|
for ban in self.bans[channel]:
|
||||||
|
if mask == ban.mask:
|
||||||
|
if ban.id is None:
|
||||||
|
ban.id = id
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# ban not in sync it seems, shouldn't happen normally.
|
||||||
|
irc.reply("Ban %s (%s) isn't active in %s." % (id, mask, channel))
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.managedBans.add(BanRemoval(ban, seconds))
|
||||||
|
|
||||||
|
# check bans set
|
||||||
|
done = []
|
||||||
|
for br in self.managedBans:
|
||||||
|
if br.ban.id in ids:
|
||||||
|
done.append(str(br.ban.id))
|
||||||
|
if done:
|
||||||
|
irc.reply("Ban set for auto removal: %s" % ', '.join(done))
|
||||||
|
|
||||||
|
banremove = wrap(banremove, ['something', 'text'])
|
||||||
|
|
||||||
def baninfo(self, irc, msg, args, id):
|
def baninfo(self, irc, msg, args, id):
|
||||||
"""<id>
|
"""<id>
|
||||||
|
|
|
@ -369,12 +369,7 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||||
self.feedBan('asd!*@*', mode='q')
|
self.feedBan('asd!*@*', mode='q')
|
||||||
self.feedBan('qwe!*@*', mode='q')
|
self.feedBan('qwe!*@*', mode='q')
|
||||||
self.feedBan('zxc!*@*', mode='q')
|
self.feedBan('zxc!*@*', mode='q')
|
||||||
self.assertNotError('banremove 1 0')
|
self.assertNotError('banremove 1,2,3,4,5,6 0')
|
||||||
self.assertNotError('banremove 2 0')
|
|
||||||
self.assertNotError('banremove 3 0')
|
|
||||||
self.assertNotError('banremove 4 0')
|
|
||||||
self.assertNotError('banremove 5 0')
|
|
||||||
self.assertNotError('banremove 6 0')
|
|
||||||
print 'waiting 1 secs ...'
|
print 'waiting 1 secs ...'
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
cb.autoRemoveBans(self.irc)
|
cb.autoRemoveBans(self.irc)
|
||||||
|
@ -384,6 +379,14 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||||
msg = self.irc.takeMsg()
|
msg = self.irc.takeMsg()
|
||||||
self.assertEqual(str(msg).strip(), "MODE #test -bb qwe!*@* :asd!*@*")
|
self.assertEqual(str(msg).strip(), "MODE #test -bb qwe!*@* :asd!*@*")
|
||||||
|
|
||||||
|
def testBanremoveMultiSet(self):
|
||||||
|
self.feedBan('asd!*@*')
|
||||||
|
self.assertResponse('banremove 1,2 10',
|
||||||
|
"I don't know any ban with id 2.")
|
||||||
|
msg = self.irc.takeMsg()
|
||||||
|
self.assertEqual(msg.args[1], "test: Ban set for auto removal: 1")
|
||||||
|
|
||||||
|
|
||||||
def testBanremoveQuiet(self):
|
def testBanremoveQuiet(self):
|
||||||
cb = self.getCallback()
|
cb = self.getCallback()
|
||||||
self.feedBan('asd!*@*', mode='q')
|
self.feedBan('asd!*@*', mode='q')
|
||||||
|
@ -399,17 +402,17 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||||
self.assertResponse('banremove 1 0',
|
self.assertResponse('banremove 1 0',
|
||||||
"Id 1 is a removal, only bans or quiets can be autoremoved.")
|
"Id 1 is a removal, only bans or quiets can be autoremoved.")
|
||||||
self.feedBan('$a:nick')
|
self.feedBan('$a:nick')
|
||||||
self.assertResponse('banremove 2 0', 'The operation succeeded.')
|
self.assertResponse('banremove 2 0', 'Ban set for auto removal: 2')
|
||||||
|
|
||||||
def testBanremoveBadId(self):
|
def testBanremoveBadId(self):
|
||||||
self.assertResponse('banremove 1 0', "I don't know any ban with that id.")
|
self.assertResponse('banremove 1 0', "I don't know any ban with id 1.")
|
||||||
|
|
||||||
def testBanremoveInactiveBan(self):
|
def testBanremoveInactiveBan(self):
|
||||||
self.feedBan('asd!*@*')
|
self.feedBan('asd!*@*')
|
||||||
self.irc.feedMsg(ircmsgs.unban(self.channel, 'asd!*@*',
|
self.irc.feedMsg(ircmsgs.unban(self.channel, 'asd!*@*',
|
||||||
'op!user@host.net'))
|
'op!user@host.net'))
|
||||||
self.assertResponse('banremove 1 0',
|
self.assertResponse('banremove 1 0',
|
||||||
"Ban 'asd!*@*' was already removed in #test.")
|
"Ban 1 (asd!*@*) was already removed in #test.")
|
||||||
|
|
||||||
def testBanremoveTimeFormat(self):
|
def testBanremoveTimeFormat(self):
|
||||||
cb = self.getCallback()
|
cb = self.getCallback()
|
||||||
|
|
Loading…
Reference in New Issue