RelayNext: split antiflood into config.plugins.antiflood.messages.[nonprivmsgs]

This commit is contained in:
James Lu 2015-05-22 21:47:30 -07:00
parent 1775cf3b18
commit 9f837aa060
2 changed files with 8 additions and 5 deletions

View File

@ -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.""")))

View File

@ -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: