add 'banremove' command for set expire time of bans.
This commit is contained in:
@ -863,7 +863,7 @@ class Bantracker(callbacks.Plugin):
|
||||
comment = self.getHostFromBan(irc, msg, mask)
|
||||
ban = self.doKickban(irc, channel, msg.prefix, mask + realname,
|
||||
extra_comment=comment)
|
||||
if True:
|
||||
if False:
|
||||
# FIXME ban autoremove should be set with a command, but I'm
|
||||
# lazy.
|
||||
self.managedBans.add(BanRemoval(ban, 1))
|
||||
@ -1284,6 +1284,30 @@ class Bantracker(callbacks.Plugin):
|
||||
irc.error("No comments recorded for ban %i" % id)
|
||||
comment = wrap(comment, ['id', optional('text')])
|
||||
|
||||
def banremove(self, irc, msg, args, id, timespec):
|
||||
"""<id> <time>
|
||||
|
||||
Sets expiration time.
|
||||
"""
|
||||
L = self.db_run("SELECT mask, channel 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 = L[0]
|
||||
for ban in self.bans[channel]:
|
||||
if mask == ban.mask:
|
||||
break
|
||||
else:
|
||||
# no active ban it seems
|
||||
irc.reply("Ban '%s' isn't active in %s." % (mask, channel))
|
||||
return
|
||||
|
||||
self.managedBans.add(BanRemoval(ban, timespec))
|
||||
irc.replySuccess()
|
||||
banremove = wrap(banremove, ['id', 'int'])
|
||||
|
||||
def banlink(self, irc, msg, args, id, highlight):
|
||||
"""<id> [<highlight>]
|
||||
|
||||
|
@ -347,11 +347,12 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||
fetch = self.query("SELECT id,channel,mask,operator FROM bans")
|
||||
self.assertEqual((1, '#test', 'troll', 'op'), fetch[0])
|
||||
|
||||
def testBanAutoRemove(self):
|
||||
def testBanremove(self):
|
||||
cb = self.getCallback()
|
||||
self.feedBan('asd!*@*')
|
||||
self.assertTrue(cb.managedBans) # ban in list
|
||||
cb.autoRemoveBans(self.irc)
|
||||
self.assertFalse(cb.managedBans)
|
||||
self.assertNotError('banremove 1 1')
|
||||
self.assertTrue(cb.managedBans) # ban in list
|
||||
print 'waiting 2 secs ...'
|
||||
time.sleep(2)
|
||||
@ -360,6 +361,16 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||
msg = self.irc.takeMsg() # unban msg
|
||||
self.assertEqual(str(msg).strip(), "MODE #test -b :asd!*@*")
|
||||
|
||||
def testBanremoveBadId(self):
|
||||
self.assertResponse('banremove 1 0', "I don't know any ban with that id.")
|
||||
|
||||
def testBanremoveInactiveBan(self):
|
||||
self.feedBan('asd!*@*')
|
||||
self.irc.feedMsg(ircmsgs.unban(self.channel, 'asd!*@*',
|
||||
'op!user@host.net'))
|
||||
self.assertResponse('banremove 1 0',
|
||||
"Ban 'asd!*@*' isn't active in #test.")
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user