From 9f837aa060c28f11113baa6e3cfb1bd74b50f1dc Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 22 May 2015 21:47:30 -0700 Subject: [PATCH] RelayNext: split antiflood into config.plugins.antiflood.messages.[nonprivmsgs] --- RelayNext/config.py | 3 +++ RelayNext/plugin.py | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/RelayNext/config.py b/RelayNext/config.py index e5a572b..70089b0 100644 --- a/RelayNext/config.py +++ b/RelayNext/config.py @@ -71,6 +71,9 @@ conf.registerChannelValue(RelayNext.antiflood, 'seconds', conf.registerChannelValue(RelayNext.antiflood, 'maximum', registry.PositiveInteger(15, _("""Determines the maximum amount of incoming messages the bot will allow from a relay channel before flood protection is triggered."""))) +conf.registerChannelValue(RelayNext.antiflood.maximum, 'nonPrivmsgs', + registry.PositiveInteger(10, _("""Determines the maximum amount of incoming non-PRIVMSG events + the bot will allow from a relay channel before flood protection is triggered."""))) conf.registerChannelValue(RelayNext.antiflood, 'timeout', registry.PositiveInteger(60, _("""Determines the amount of time in seconds the bot should block messages if flood protection is triggered."""))) diff --git a/RelayNext/plugin.py b/RelayNext/plugin.py index 77984a4..5efbb41 100644 --- a/RelayNext/plugin.py +++ b/RelayNext/plugin.py @@ -199,10 +199,6 @@ class RelayNext(callbacks.Plugin): s = s.replace("- -", "-", 1) return s - def checkFlood(self, channel, source, command): - maximum = self.registryValue("antiflood.maximum", channel) - return len(self.msgcounters[(source, command)]) > maximum - def keepstate(self): for irc in world.ircs: self.ircstates[irc.network] = deepcopy(irc.state.channels) @@ -233,7 +229,11 @@ class RelayNext(callbacks.Plugin): self.msgcounters[(source, msg.command)].enqueue(msg.prefix) except KeyError: self.msgcounters[(source, msg.command)] = TimeoutQueue(seconds) - if self.checkFlood(channel, source, msg.command): + if msg.command == "PRIVMSG": + maximum = self.registryValue("antiflood.maximum", channel) + else: + maximum = self.registryValue("antiflood.maximum.nonPrivmsgs", channel) + if len(self.msgcounters[(source, msg.command)]) > maximum: self.log.debug("RelayNext (%s): message from %s blocked by " "flood protection.", irc.network, channel) if self.floodTriggered: