From e3f6aacdf5063235c979f660c64872eb3e6afada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eli=C3=A1n=20Hanisch?= Date: Wed, 4 Jul 2012 22:12:55 -0300 Subject: [PATCH] added configuration options: * supybot.plugins.Bantracker.autoremove * supybot.plugins.Bantracker.autoremove.notify * supybot.plugins.Bantracker.autoremove.notify.channels --- Bantracker/config.py | 11 +++++++++++ Bantracker/plugin.py | 26 +++++++++++++++++++------- Bantracker/test.py | 18 +++++++++++------- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/Bantracker/config.py b/Bantracker/config.py index 78d907a..700f27c 100644 --- a/Bantracker/config.py +++ b/Bantracker/config.py @@ -225,4 +225,15 @@ conf.registerChannelValue(Bantracker.review.forward, 'channels', registry.SpaceSeparatedListOfStrings([], "List of channels/nicks to forward the request if the op is in the forward list.")) +conf.registerChannelValue(Bantracker, 'autoremove', + registry.Boolean(True, + """Enable/disable autoremoval of bans.""")) +conf.registerChannelValue(Bantracker.autoremove, 'notify', + registry.Boolean(True, + """Enable/disable notifications of removal of bans.""")) +conf.registerChannelValue(Bantracker.autoremove.notify, 'channels', + registry.SpaceSeparatedListOfStrings([], + """List of channels/nicks to notify about automatic removal of bans.""")) + + diff --git a/Bantracker/plugin.py b/Bantracker/plugin.py index b158a03..34fd292 100644 --- a/Bantracker/plugin.py +++ b/Bantracker/plugin.py @@ -775,10 +775,13 @@ class Bantracker(callbacks.Plugin): modedict = { 'quiet': '-q', 'ban': '-b' } for ban in self.managedBans.popExpired(): channel, mask, type = ban.ban.channel, ban.ban.mask, ban.ban.type + if not self.registryValue('autoremove', channel): + continue + self.log.info("%s [%s] %s in %s expired", type, - ban.ban.id, - mask, - channel) + ban.ban.id, + mask, + channel) # send unban msg unban = ircmsgs.mode(channel, (modedict[type], mask)) irc.queueMsg(unban) @@ -787,10 +790,19 @@ class Bantracker(callbacks.Plugin): for ban in self.managedBans.getExpired(600): if ban.notified: continue - id, channel, mask, type = ban.ban.id, ban.ban.channel, ban.ban.mask, ban.ban.type - notice = ircmsgs.notice('#test', "%s [%s] %s in %s will expire in a few minutes." \ - % (type, id, mask, channel)) - irc.queueMsg(notice) + + channel = ban.ban.channel + if not self.registryValue('autoremove', channel) \ + or not self.registryValue('autoremove.notify', channel): + continue + + for c in self.registryValue('autoremove.notify.channels', channel): + notice = ircmsgs.notice(c, "%s [%s] %s in %s will expire in a few minutes." \ + % (ban.ban.type, + ban.ban.id, + ban.ban.mask, + channel)) + irc.queueMsg(notice) ban.notified = True def doLog(self, irc, channel, s): diff --git a/Bantracker/test.py b/Bantracker/test.py index 7631f82..0afd3c8 100644 --- a/Bantracker/test.py +++ b/Bantracker/test.py @@ -394,13 +394,17 @@ class BantrackerTestCase(ChannelPluginTestCase): cb = self.getCallback() self.feedBan('asd!*@*') self.assertNotError('banremove 1 300') - cb.autoRemoveBans(self.irc) - msg = self.irc.takeMsg() - self.assertEqual(str(msg).strip(), - "NOTICE #test :ban [1] asd!*@* in #test will expire in a few minutes.") - # don't send the notice again. - cb.autoRemoveBans(self.irc) - self.assertFalse(self.irc.takeMsg()) + pluginConf.autoremove.notify.channels().append('#test') + try: + cb.autoRemoveBans(self.irc) + msg = self.irc.takeMsg() + self.assertEqual(str(msg).strip(), + "NOTICE #test :ban [1] asd!*@* in #test will expire in a few minutes.") + # don't send the notice again. + cb.autoRemoveBans(self.irc) + self.assertFalse(self.irc.takeMsg()) + finally: + del pluginConf.autoremove.notify.channels()[:]