From 8f6063135ef09e4190dcde5ddde8a59b1b889c3e Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Thu, 9 May 2013 09:40:55 +0200 Subject: [PATCH] Add supybot.abuse.flood.interval. --- plugins/Ctcp/plugin.py | 6 +++++- plugins/Misc/plugin.py | 10 ++++++++-- plugins/Owner/plugin.py | 8 ++++++-- src/conf.py | 3 +++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/plugins/Ctcp/plugin.py b/plugins/Ctcp/plugin.py index ebcedbce4..0512480d5 100644 --- a/plugins/Ctcp/plugin.py +++ b/plugins/Ctcp/plugin.py @@ -47,7 +47,11 @@ class Ctcp(callbacks.PluginRegexp): self.__parent = super(Ctcp, self) self.__parent.__init__(irc) self.ignores = ircutils.IrcDict() - self.floods = ircutils.FloodQueue(60) + self.floods = ircutils.FloodQueue(conf.supybot.abuse.flood.interval()) + conf.supybot.abuse.flood.interval.addCallback(self.setFloodQueueTimeout) + + def setFloodQueueTimeout(self, *args, **kwargs): + self.floods.timeout = conf.supybot.abuse.flood.interval() def callCommand(self, command, irc, msg, *args, **kwargs): if conf.supybot.abuse.flood.ctcp(): diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index 54e91b818..99186ff25 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -75,7 +75,12 @@ class Misc(callbacks.Plugin): def __init__(self, irc): self.__parent = super(Misc, self) self.__parent.__init__(irc) - self.invalidCommands = ircutils.FloodQueue(60) + self.invalidCommands = \ + ircutils.FloodQueue(conf.supybot.abuse.flood.interval()) + conf.supybot.abuse.flood.interval.addCallback(self.setFloodQueueTimeout) + + def setFloodQueueTimeout(self, *args, **kwargs): + self.invalidCommands.timeout = conf.supybot.abuse.flood.interval() def callPrecedence(self, irc): return ([cb for cb in irc.callbacks if cb is not self], []) @@ -103,8 +108,9 @@ class Misc(callbacks.Plugin): ircdb.ignores.add(banmask, time.time() + punishment) if conf.supybot.abuse.flood.command.invalid.notify(): irc.reply(_('You\'ve given me %s invalid commands within the last ' - 'minute; I\'m now ignoring you for %s.') % + '%i seconds; I\'m now ignoring you for %s.') % (maximum, + conf.supybot.abuse.flood.interval(), utils.timeElapsed(punishment, seconds=False))) return # Now, for normal handling. diff --git a/plugins/Owner/plugin.py b/plugins/Owner/plugin.py index 72ac6c274..6fa6e3d60 100644 --- a/plugins/Owner/plugin.py +++ b/plugins/Owner/plugin.py @@ -112,7 +112,8 @@ class Owner(callbacks.Plugin): self.__parent = super(Owner, self) self.__parent.__init__(irc) # Setup command flood detection. - self.commands = ircutils.FloodQueue(60) + self.commands = ircutils.FloodQueue(conf.supybot.abuse.flood.interval()) + conf.supybot.abuse.flood.interval.addCallback(self.setFloodQueueTimeout) # Setup plugins and default plugins for commands. # # This needs to be done before we connect to any networks so that the @@ -235,6 +236,8 @@ class Owner(callbacks.Plugin): irc.queueMsg(conf.supybot.networks.get(irc.network).channels.joins()) do422 = do377 = do376 + def setFloodQueueTimeout(self, *args, **kwargs): + self.commands.timeout = conf.supybot.abuse.flood.interval() def doPrivmsg(self, irc, msg): assert self is irc.callbacks[0], \ 'Owner isn\'t first callback: %r' % irc.callbacks @@ -257,8 +260,9 @@ class Owner(callbacks.Plugin): 'command flood.', banmask, punishment) ircdb.ignores.add(banmask, time.time() + punishment) irc.reply('You\'ve given me %s commands within the last ' - 'minute; I\'m now ignoring you for %s.' % + '%i seconds; I\'m now ignoring you for %s.' % (maximum, + conf.supybot.abuse.flood.interval(), utils.timeElapsed(punishment, seconds=False))) return try: diff --git a/src/conf.py b/src/conf.py index ac8ba332e..96a713d6b 100644 --- a/src/conf.py +++ b/src/conf.py @@ -690,6 +690,9 @@ registerGlobalValue(supybot.commands.defaultPlugins, 'importantPlugins', ### registerGroup(supybot, 'abuse') registerGroup(supybot.abuse, 'flood') +registerGlobalValue(supybot.abuse.flood, 'interval', + registry.PositiveInteger(60, _("""Determines the interval used for + the history storage."""))) registerGlobalValue(supybot.abuse.flood, 'command', registry.Boolean(True, _("""Determines whether the bot will defend itself against command-flooding.""")))