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([],
"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' }
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):

View File

@ -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()[:]