diff --git a/Bantracker/config.py b/Bantracker/config.py index a5c081c..b8f183f 100644 --- a/Bantracker/config.py +++ b/Bantracker/config.py @@ -34,7 +34,9 @@ conf.registerGlobalValue(Bantracker, 'database', conf.registerGlobalValue(Bantracker, 'bansite', registry.String('', "Web site for the bantracker, without the 'bans.cgi' appended", private=True)) -conf.registerGroup(Bantracker, 'request') +conf.registerChannelValue(Bantracker, 'request', + registry.Boolean(False, + "Enable message requests from bot")) conf.registerChannelValue(Bantracker.request, 'type', SpaceSeparatedListOfTypes(['removal', 'ban', 'quiet'], "List of events for which the bot should request a comment.")) diff --git a/Bantracker/plugin.py b/Bantracker/plugin.py index d3f7a8a..f809fe8 100644 --- a/Bantracker/plugin.py +++ b/Bantracker/plugin.py @@ -408,9 +408,11 @@ class Bantracker(callbacks.Plugin): return data def requestComment(self, irc, channel, ban, type=None): + if not ban or not self.registryValue('request', channel): + return # check if we should request a comment if nickMatch(ban.who, self.registryValue('request.ignore', channel=channel)): - return + return # check the type of the action taken mask = ban.mask if not type: @@ -539,7 +541,12 @@ class Bantracker(callbacks.Plugin): # self.logs[channel] = self.logs[channel][-199:] + [s.strip()] self.logs[channel].append(s.strip()) - def doKickban(self, irc, channel, operator, target, kickmsg = None, use_time = None, extra_comment = None): + def doKickban(self, irc, channel, *args, **kwargs): + ban = self._doKickban(irc, channel, *args, **kwargs) + self.requestComment(irc, channel, ban) + return ban + + def _doKickban(self, irc, channel, operator, target, kickmsg = None, use_time = None, extra_comment = None): if not self.registryValue('enabled', channel): return n = now() @@ -559,8 +566,7 @@ class Bantracker(callbacks.Plugin): self.bans[channel] = [] ban = Ban(mask=target, who=operator, when=time.mktime(time.gmtime()), id=id) self.bans[channel].append(ban) - self.requestComment(irc, channel, ban) - return id + return ban def doUnban(self, irc, channel, nick, mask): if not self.registryValue('enabled', channel): @@ -810,7 +816,7 @@ class Bantracker(callbacks.Plugin): hostmask = self.nick_to_host(irc, target) self.doLog(irc, channel.lower(), '*** %s requested a mark for %s\n' % (msg.nick, target)) - self.doKickban(irc, channel.lower(), msg.prefix, hostmask, kickmsg) + self._doKickban(irc, channel.lower(), msg.prefix, hostmask, kickmsg) irc.replySuccess() mark = wrap(mark, [optional('channel'), 'something', additional('text')]) @@ -1030,7 +1036,7 @@ class Bantracker(callbacks.Plugin): nick = "Automated-Addition" self.log.info("Adding ban %s to %s (%s)" % (str(ban).replace('%', '%%'), chan, nick)) self.doLog(irc, channel.lower(), '*** Ban sync from channel: %s\n' % str(ban).replace('%', '%%')) - self.doKickban(irc, chan, nick, ban.mask, use_time = ban.when) + self._doKickban(irc, chan, nick, ban.mask, use_time = ban.when) return len(add_bans) if not self.check_auth(irc, msg, args, 'owner'): diff --git a/Bantracker/test.py b/Bantracker/test.py index 16e8e73..77906ac 100644 --- a/Bantracker/test.py +++ b/Bantracker/test.py @@ -21,7 +21,8 @@ class BantrackerTestCase(ChannelPluginTestCase): def setUp(self): super(BantrackerTestCase, self).setUp() self.setDb() - pluginConf.request.ignore.set('*') # disable comments + pluginConf.request.setValue(False) # disable comments + pluginConf.request.ignore.set('') pluginConf.request.forward.set('') pluginConf.request.review.setValue(1.0/86400) # one second @@ -92,7 +93,7 @@ class BantrackerTestCase(ChannelPluginTestCase): return ban def testComment(self): - pluginConf.request.ignore.set('') + pluginConf.request.setValue(True) # test bans self.feedBan('asd!*@*') msg = self.irc.takeMsg() @@ -118,7 +119,7 @@ class BantrackerTestCase(ChannelPluginTestCase): " ") def testCommentForward(self): - pluginConf.request.ignore.set('') + pluginConf.request.setValue(True) pluginConf.request.forward.set('bot') pluginConf.request.forward.channels.set('#channel') self.feedBan('qwe!*@*') @@ -133,7 +134,7 @@ class BantrackerTestCase(ChannelPluginTestCase): " use: @comment 2 ") def testReview(self): - pluginConf.request.ignore.set('') + pluginConf.request.setValue(True) cb = self.getCallback() self.feedBan('asd!*@*') self.irc.takeMsg() # ignore comment request comment @@ -180,7 +181,7 @@ class BantrackerTestCase(ChannelPluginTestCase): "%s/bans.cgi?log=2" %(cb.bans['#test'][1].ascwhen, pluginConf.bansite())) def testReviewForward(self): - pluginConf.request.ignore.set('') + pluginConf.request.setValue(True) pluginConf.request.forward.set('bot') pluginConf.request.forward.channels.set('#channel') cb = self.getCallback() @@ -201,7 +202,7 @@ 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.ignore.set('') + pluginConf.request.setValue(True) cb = self.getCallback() self.feedBan('asd!*@*') self.irc.takeMsg() # ignore comment request comment