From c283e6b924950837b288498285c2a8599440f885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eli=C3=A1n=20Hanisch?= Date: Fri, 13 Jul 2012 13:45:37 -0300 Subject: [PATCH] add a simple @baninfo command for check when a ban expires. --- Bantracker/plugin.py | 35 +++++++++++++++++++++++++++++++++++ Bantracker/test.py | 6 ++++++ 2 files changed, 41 insertions(+) diff --git a/Bantracker/plugin.py b/Bantracker/plugin.py index 8974aca..cf3ef11 100644 --- a/Bantracker/plugin.py +++ b/Bantracker/plugin.py @@ -1490,6 +1490,41 @@ class Bantracker(callbacks.Plugin): banremove = wrap(banremove, ['id', 'text']) + def baninfo(self, irc, msg, args, id): + """ + + Show ban information. + """ + 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] + type = guessBanType(mask) + if type == 'quiet': + mask = mask[1:] + for br in self.managedBans: + if br.ban.id == id: + break + else: + br = None + + if br: + irc.reply("[%s] %s - %s - %s - expires in %s" \ + % (id, type, mask, channel, + (br.ban.when + br.expires) - nowSeconds())) + else: + if type in ('quiet', 'ban'): + irc.reply("[%s] %s - %s - %s - never expires" \ + % (id, type, mask, channel)) + else: + irc.reply("[%s] %s - %s - %s" % (id, type, mask, channel)) + + + baninfo = wrap(baninfo, ['id']) + def banlink(self, irc, msg, args, id, highlight): """ [] diff --git a/Bantracker/test.py b/Bantracker/test.py index 0382642..73fee7f 100644 --- a/Bantracker/test.py +++ b/Bantracker/test.py @@ -447,5 +447,11 @@ class BantrackerTestCase(ChannelPluginTestCase): self.assertEqual(L[i].ban.mask, n) self.assertEqual(L[0].ban.channel, '#test') + def testBaninfo(self): + cb = self.getCallback() + self.feedBan('asd!*@*') + self.assertResponse('baninfo 1', '[1] ban - asd!*@* - #test - never expires') + self.assertNotError('banremove 1 10') + self.assertResponse('baninfo 1', '[1] ban - asd!*@* - #test - expires in 10.0')