Bantracker: add separate configs so comment request, and review requests,

can be configured independently.
This commit is contained in:
Elián Hanisch 2011-05-29 19:22:34 -03:00
parent 46d07b8095
commit 223c3f9229
3 changed files with 57 additions and 31 deletions

View File

@ -185,7 +185,7 @@ conf.registerChannelValue(Bantracker.request, 'type',
"List of events for which the bot should request a comment.")) "List of events for which the bot should request a comment."))
conf.registerChannelValue(Bantracker.request, 'ignore', conf.registerChannelValue(Bantracker.request, 'ignore',
registry.SpaceSeparatedListOfStrings(['FloodBot?', 'FloodBotK?', 'ChanServ'], registry.SpaceSeparatedListOfStrings(['FloodBot?', 'FloodBotK?', 'ChanServ'],
"List of nicks for which the bot won't request to comment or review."\ "List of nicks for which the bot won't request a comment."\
" Is case insensible and wildcards * ? are accepted.")) " Is case insensible and wildcards * ? are accepted."))
conf.registerChannelValue(Bantracker.request, 'forward', conf.registerChannelValue(Bantracker.request, 'forward',
registry.SpaceSeparatedListOfStrings([], registry.SpaceSeparatedListOfStrings([],
@ -194,10 +194,26 @@ conf.registerChannelValue(Bantracker.request, 'forward',
" Is case insensible and wildcards * ? are accepted.")) " Is case insensible and wildcards * ? are accepted."))
conf.registerChannelValue(Bantracker.request.forward, 'channels', conf.registerChannelValue(Bantracker.request.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 comment request if the op is in the forward list."))
conf.registerGlobalValue(Bantracker.request, 'review',
conf.registerChannelValue(Bantracker, 'review',
registry.Boolean(True,
"Enable/disable reviews per channel."))
conf.registerGlobalValue(Bantracker.review, 'when',
registry.Float(7, registry.Float(7,
"Days after which the bot will request for review a ban. Can be an integer or decimal" "Days after which the bot will request for review a ban. Can be an integer or decimal"
" value. Zero disables reviews.")) " value. Zero disables reviews globally."))
conf.registerChannelValue(Bantracker.review, 'ignore',
registry.SpaceSeparatedListOfStrings(['FloodBot?', 'FloodBotK?', 'ChanServ'],
"List of nicks for which the bot won't request a review."\
" Is case insensible and wildcards * ? are accepted."))
conf.registerChannelValue(Bantracker.review, 'forward',
registry.SpaceSeparatedListOfStrings([],
"List of nicks for which the bot will forward the reviews to"\
" the channels/nicks defined in forwards.channels option."\
" Is case insensible and wildcards * ? are accepted."))
conf.registerChannelValue(Bantracker.review.forward, 'channels',
registry.SpaceSeparatedListOfStrings([],
"List of channels/nicks to forward the request if the op is in the forward list."))

View File

@ -442,7 +442,7 @@ class Bantracker(callbacks.Plugin):
if nickMatch(nick, self.registryValue('request.forward', channel)): if nickMatch(nick, self.registryValue('request.forward', channel)):
s = "Please somebody comment on the %s of %s in %s done by %s, use:"\ s = "Please somebody comment on the %s of %s in %s done by %s, use:"\
" %scomment %s <comment>" %(type, mask, channel, nick, prefix, ban.id) " %scomment %s <comment>" %(type, mask, channel, nick, prefix, ban.id)
self._sendForward(irc, s, channel) self._sendForward(irc, s, 'request', channel)
else: else:
# send to op # send to op
s = "Please comment on the %s of %s in %s, use: %scomment %s <comment>" \ s = "Please comment on the %s of %s in %s, use: %scomment %s <comment>" \
@ -450,7 +450,7 @@ class Bantracker(callbacks.Plugin):
irc.reply(s, to=nick, private=True) irc.reply(s, to=nick, private=True)
def reviewBans(self, irc=None): def reviewBans(self, irc=None):
reviewTime = int(self.registryValue('request.review') * 86400) reviewTime = int(self.registryValue('review.when') * 86400)
if not reviewTime: if not reviewTime:
# time is zero, do nothing # time is zero, do nothing
return return
@ -463,12 +463,13 @@ class Bantracker(callbacks.Plugin):
for channel, bans in self.bans.iteritems(): for channel, bans in self.bans.iteritems():
if not self.registryValue('enabled', channel) \ if not self.registryValue('enabled', channel) \
or not self.registryValue('request', channel): or not self.registryValue('review', channel):
continue continue
for ban in bans: for ban in bans:
if guessBanType(ban.mask) in ('quiet', 'removal'): type = guessBanType(ban.mask)
# skip mutes and kicks if type == 'removal':
# skip kicks
continue continue
banAge = now - ban.when banAge = now - ban.when
reviewWindow = lastreview - ban.when reviewWindow = lastreview - ban.when
@ -489,20 +490,29 @@ class Bantracker(callbacks.Plugin):
# probably a ban restored by IRC server in a netsplit # probably a ban restored by IRC server in a netsplit
# XXX see if something can be done about this # XXX see if something can be done about this
continue continue
if nickMatch(nick, self.registryValue('request.ignore', channel)): if nickMatch(nick, self.registryValue('review.ignore', channel)):
# in the ignore list # in the ignore list
continue continue
if not ban.id: if not ban.id:
ban.id = self.get_banId(ban.mask, channel) ban.id = self.get_banId(ban.mask, channel)
if nickMatch(nick, self.registryValue('request.forward', channel)): if nickMatch(nick, self.registryValue('review.forward', channel)):
s = "Hi, please somebody review the ban '%s' set by %s on %s in"\ s = "Hi, please somebody review the %s '%s' set by %s on %s in"\
" %s, link: %s/bans.cgi?log=%s" %(ban.mask, nick, ban.ascwhen, channel, " %s, link: %s/bans.cgi?log=%s" % (type,
self.registryValue('bansite'), ban.id) ban.mask,
self._sendForward(irc, s, channel) nick,
ban.ascwhen,
channel,
self.registryValue('bansite'),
ban.id)
self._sendForward(irc, s, 'review', channel)
else: else:
s = "Hi, please review the ban '%s' that you set on %s in %s, link:"\ s = "Hi, please review the %s '%s' that you set on %s in %s, link:"\
" %s/bans.cgi?log=%s" %(ban.mask, ban.ascwhen, channel, " %s/bans.cgi?log=%s" % (type,
self.registryValue('bansite'), ban.id) ban.mask,
ban.ascwhen,
channel,
self.registryValue('bansite'),
ban.id)
msg = ircmsgs.privmsg(nick, s) msg = ircmsgs.privmsg(nick, s)
if host in self.pendingReviews \ if host in self.pendingReviews \
and (nick, msg) not in self.pendingReviews[host]: and (nick, msg) not in self.pendingReviews[host]:
@ -513,10 +523,10 @@ class Bantracker(callbacks.Plugin):
# since we made sure bans are sorted by time, the bans left are more recent # since we made sure bans are sorted by time, the bans left are more recent
break break
def _sendForward(self, irc, s, channel=None): def _sendForward(self, irc, s, setting, channel=None):
if not irc: if not irc:
return return
for chan in self.registryValue('request.forward.channels', channel=channel): for chan in self.registryValue('%s.forward.channels' % setting, channel=channel):
msg = ircmsgs.notice(chan, s) msg = ircmsgs.notice(chan, s)
irc.queueMsg(msg) irc.queueMsg(msg)

View File

@ -41,7 +41,10 @@ class BantrackerTestCase(ChannelPluginTestCase):
pluginConf.request.setValue(False) # disable comments pluginConf.request.setValue(False) # disable comments
pluginConf.request.ignore.set('') pluginConf.request.ignore.set('')
pluginConf.request.forward.set('') pluginConf.request.forward.set('')
pluginConf.request.review.setValue(1.0/86400) # one second pluginConf.review.setValue(False) # disable reviews
pluginConf.review.when.setValue(1.0/86400) # one second
pluginConf.review.ignore.set('')
pluginConf.review.forward.set('')
# Bantracker for some reason doesn't use Supybot's own methods for check capabilities, # Bantracker for some reason doesn't use Supybot's own methods for check capabilities,
# so it doesn't have a clue about testing and screws my tests by default. # so it doesn't have a clue about testing and screws my tests by default.
# This would fix it until I bring myself to take a look # This would fix it until I bring myself to take a look
@ -183,10 +186,9 @@ class BantrackerTestCase(ChannelPluginTestCase):
" use: @comment 2 <comment>") " use: @comment 2 <comment>")
def testReview(self): def testReview(self):
pluginConf.request.setValue(True) pluginConf.review.setValue(True)
cb = self.getCallback() cb = self.getCallback()
self.feedBan('asd!*@*') self.feedBan('asd!*@*')
self.irc.takeMsg() # ignore comment request comment
cb.reviewBans() cb.reviewBans()
self.assertFalse(cb.pendingReviews) self.assertFalse(cb.pendingReviews)
print 'waiting 4 secs..' print 'waiting 4 secs..'
@ -231,12 +233,11 @@ class BantrackerTestCase(ChannelPluginTestCase):
"%s/bans.cgi?log=2" %(cb.bans['#test'][1].ascwhen, pluginConf.bansite())) "%s/bans.cgi?log=2" %(cb.bans['#test'][1].ascwhen, pluginConf.bansite()))
def testReviewForward(self): def testReviewForward(self):
pluginConf.request.setValue(True) pluginConf.review.setValue(True)
pluginConf.request.forward.set('bot') pluginConf.review.forward.set('bot')
pluginConf.request.forward.channels.set('#channel') pluginConf.review.forward.channels.set('#channel')
cb = self.getCallback() cb = self.getCallback()
self.feedBan('asd!*@*', prefix='bot!user@host.net') self.feedBan('asd!*@*', prefix='bot!user@host.net')
self.irc.takeMsg() # ignore comment request comment
cb.reviewBans(self.irc) cb.reviewBans(self.irc)
self.assertFalse(cb.pendingReviews) self.assertFalse(cb.pendingReviews)
print 'waiting 2 secs..' print 'waiting 2 secs..'
@ -250,8 +251,8 @@ class BantrackerTestCase(ChannelPluginTestCase):
"%s/bans.cgi?log=1" %(cb.bans['#test'][0].ascwhen, pluginConf.bansite())) "%s/bans.cgi?log=1" %(cb.bans['#test'][0].ascwhen, pluginConf.bansite()))
def testReviewIgnore(self): def testReviewIgnore(self):
pluginConf.request.setValue(True) pluginConf.review.setValue(True)
pluginConf.request.ignore.set('FloodBot? FloodBotK?') pluginConf.review.ignore.set('FloodBot? FloodBotK?')
cb = self.getCallback() cb = self.getCallback()
self.feedBan('asd!*@*', prefix='floodbotk1!bot@botpit.com') self.feedBan('asd!*@*', prefix='floodbotk1!bot@botpit.com')
cb.reviewBans(self.irc) cb.reviewBans(self.irc)
@ -265,10 +266,9 @@ class BantrackerTestCase(ChannelPluginTestCase):
def testReviewNickFallback(self): def testReviewNickFallback(self):
"""If for some reason we don't have ops full hostmask, revert to nick match. This may be """If for some reason we don't have ops full hostmask, revert to nick match. This may be
needed in the future as hostmasks aren't stored in the db.""" needed in the future as hostmasks aren't stored in the db."""
pluginConf.request.setValue(True) pluginConf.review.setValue(True)
cb = self.getCallback() cb = self.getCallback()
self.feedBan('asd!*@*') self.feedBan('asd!*@*')
self.irc.takeMsg() # ignore comment request comment
cb.bans['#test'][0].who = 'op' # replace hostmask by nick cb.bans['#test'][0].who = 'op' # replace hostmask by nick
print 'waiting 2 secs..' print 'waiting 2 secs..'
time.sleep(2) time.sleep(2)