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."))
conf.registerChannelValue(Bantracker.request, 'ignore',
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."))
conf.registerChannelValue(Bantracker.request, 'forward',
registry.SpaceSeparatedListOfStrings([],
@ -194,10 +194,26 @@ conf.registerChannelValue(Bantracker.request, 'forward',
" Is case insensible and wildcards * ? are accepted."))
conf.registerChannelValue(Bantracker.request.forward, 'channels',
registry.SpaceSeparatedListOfStrings([],
"List of channels/nicks to forward the request if the op is in the forward list."))
conf.registerGlobalValue(Bantracker.request, 'review',
"List of channels/nicks to forward the comment request if the op is in the forward list."))
conf.registerChannelValue(Bantracker, 'review',
registry.Boolean(True,
"Enable/disable reviews per channel."))
conf.registerGlobalValue(Bantracker.review, 'when',
registry.Float(7,
"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)):
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)
self._sendForward(irc, s, channel)
self._sendForward(irc, s, 'request', channel)
else:
# send to op
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)
def reviewBans(self, irc=None):
reviewTime = int(self.registryValue('request.review') * 86400)
reviewTime = int(self.registryValue('review.when') * 86400)
if not reviewTime:
# time is zero, do nothing
return
@ -463,12 +463,13 @@ class Bantracker(callbacks.Plugin):
for channel, bans in self.bans.iteritems():
if not self.registryValue('enabled', channel) \
or not self.registryValue('request', channel):
or not self.registryValue('review', channel):
continue
for ban in bans:
if guessBanType(ban.mask) in ('quiet', 'removal'):
# skip mutes and kicks
type = guessBanType(ban.mask)
if type == 'removal':
# skip kicks
continue
banAge = now - ban.when
reviewWindow = lastreview - ban.when
@ -489,20 +490,29 @@ class Bantracker(callbacks.Plugin):
# probably a ban restored by IRC server in a netsplit
# XXX see if something can be done about this
continue
if nickMatch(nick, self.registryValue('request.ignore', channel)):
if nickMatch(nick, self.registryValue('review.ignore', channel)):
# in the ignore list
continue
if not ban.id:
ban.id = self.get_banId(ban.mask, channel)
if nickMatch(nick, self.registryValue('request.forward', channel)):
s = "Hi, please somebody review the ban '%s' set by %s on %s in"\
" %s, link: %s/bans.cgi?log=%s" %(ban.mask, nick, ban.ascwhen, channel,
self.registryValue('bansite'), ban.id)
self._sendForward(irc, s, channel)
if nickMatch(nick, self.registryValue('review.forward', channel)):
s = "Hi, please somebody review the %s '%s' set by %s on %s in"\
" %s, link: %s/bans.cgi?log=%s" % (type,
ban.mask,
nick,
ban.ascwhen,
channel,
self.registryValue('bansite'),
ban.id)
self._sendForward(irc, s, 'review', channel)
else:
s = "Hi, please review the ban '%s' that you set on %s in %s, link:"\
" %s/bans.cgi?log=%s" %(ban.mask, ban.ascwhen, channel,
self.registryValue('bansite'), ban.id)
s = "Hi, please review the %s '%s' that you set on %s in %s, link:"\
" %s/bans.cgi?log=%s" % (type,
ban.mask,
ban.ascwhen,
channel,
self.registryValue('bansite'),
ban.id)
msg = ircmsgs.privmsg(nick, s)
if host in self.pendingReviews \
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
break
def _sendForward(self, irc, s, channel=None):
def _sendForward(self, irc, s, setting, channel=None):
if not irc:
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)
irc.queueMsg(msg)

View File

@ -41,7 +41,10 @@ class BantrackerTestCase(ChannelPluginTestCase):
pluginConf.request.setValue(False) # disable comments
pluginConf.request.ignore.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,
# 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
@ -183,10 +186,9 @@ class BantrackerTestCase(ChannelPluginTestCase):
" use: @comment 2 <comment>")
def testReview(self):
pluginConf.request.setValue(True)
pluginConf.review.setValue(True)
cb = self.getCallback()
self.feedBan('asd!*@*')
self.irc.takeMsg() # ignore comment request comment
cb.reviewBans()
self.assertFalse(cb.pendingReviews)
print 'waiting 4 secs..'
@ -231,12 +233,11 @@ class BantrackerTestCase(ChannelPluginTestCase):
"%s/bans.cgi?log=2" %(cb.bans['#test'][1].ascwhen, pluginConf.bansite()))
def testReviewForward(self):
pluginConf.request.setValue(True)
pluginConf.request.forward.set('bot')
pluginConf.request.forward.channels.set('#channel')
pluginConf.review.setValue(True)
pluginConf.review.forward.set('bot')
pluginConf.review.forward.channels.set('#channel')
cb = self.getCallback()
self.feedBan('asd!*@*', prefix='bot!user@host.net')
self.irc.takeMsg() # ignore comment request comment
cb.reviewBans(self.irc)
self.assertFalse(cb.pendingReviews)
print 'waiting 2 secs..'
@ -250,8 +251,8 @@ class BantrackerTestCase(ChannelPluginTestCase):
"%s/bans.cgi?log=1" %(cb.bans['#test'][0].ascwhen, pluginConf.bansite()))
def testReviewIgnore(self):
pluginConf.request.setValue(True)
pluginConf.request.ignore.set('FloodBot? FloodBotK?')
pluginConf.review.setValue(True)
pluginConf.review.ignore.set('FloodBot? FloodBotK?')
cb = self.getCallback()
self.feedBan('asd!*@*', prefix='floodbotk1!bot@botpit.com')
cb.reviewBans(self.irc)
@ -265,10 +266,9 @@ class BantrackerTestCase(ChannelPluginTestCase):
def testReviewNickFallback(self):
"""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."""
pluginConf.request.setValue(True)
pluginConf.review.setValue(True)
cb = self.getCallback()
self.feedBan('asd!*@*')
self.irc.takeMsg() # ignore comment request comment
cb.bans['#test'][0].who = 'op' # replace hostmask by nick
print 'waiting 2 secs..'
time.sleep(2)