added configuration options:

* supybot.plugins.Bantracker.autoremove
* supybot.plugins.Bantracker.autoremove.notify
* supybot.plugins.Bantracker.autoremove.notify.channels
This commit is contained in:
Elián Hanisch 2012-07-04 22:12:55 -03:00
parent 87f61b1654
commit e3f6aacdf5
3 changed files with 41 additions and 14 deletions

View File

@ -225,4 +225,15 @@ conf.registerChannelValue(Bantracker.review.forward, 'channels',
registry.SpaceSeparatedListOfStrings([], registry.SpaceSeparatedListOfStrings([],
"List of channels/nicks to forward the request if the op is in the forward list.")) "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."""))

View File

@ -775,10 +775,13 @@ class Bantracker(callbacks.Plugin):
modedict = { 'quiet': '-q', 'ban': '-b' } modedict = { 'quiet': '-q', 'ban': '-b' }
for ban in self.managedBans.popExpired(): for ban in self.managedBans.popExpired():
channel, mask, type = ban.ban.channel, ban.ban.mask, ban.ban.type 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, self.log.info("%s [%s] %s in %s expired", type,
ban.ban.id, ban.ban.id,
mask, mask,
channel) channel)
# send unban msg # send unban msg
unban = ircmsgs.mode(channel, (modedict[type], mask)) unban = ircmsgs.mode(channel, (modedict[type], mask))
irc.queueMsg(unban) irc.queueMsg(unban)
@ -787,10 +790,19 @@ class Bantracker(callbacks.Plugin):
for ban in self.managedBans.getExpired(600): for ban in self.managedBans.getExpired(600):
if ban.notified: if ban.notified:
continue 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." \ channel = ban.ban.channel
% (type, id, mask, channel)) if not self.registryValue('autoremove', channel) \
irc.queueMsg(notice) 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 ban.notified = True
def doLog(self, irc, channel, s): def doLog(self, irc, channel, s):

View File

@ -394,13 +394,17 @@ class BantrackerTestCase(ChannelPluginTestCase):
cb = self.getCallback() cb = self.getCallback()
self.feedBan('asd!*@*') self.feedBan('asd!*@*')
self.assertNotError('banremove 1 300') self.assertNotError('banremove 1 300')
cb.autoRemoveBans(self.irc) pluginConf.autoremove.notify.channels().append('#test')
msg = self.irc.takeMsg() try:
self.assertEqual(str(msg).strip(), cb.autoRemoveBans(self.irc)
"NOTICE #test :ban [1] asd!*@* in #test will expire in a few minutes.") msg = self.irc.takeMsg()
# don't send the notice again. self.assertEqual(str(msg).strip(),
cb.autoRemoveBans(self.irc) "NOTICE #test :ban [1] asd!*@* in #test will expire in a few minutes.")
self.assertFalse(self.irc.takeMsg()) # don't send the notice again.
cb.autoRemoveBans(self.irc)
self.assertFalse(self.irc.takeMsg())
finally:
del pluginConf.autoremove.notify.channels()[:]