Permalink
Browse files

Add supybot.abuse.flood.interval.

  • Loading branch information...
1 parent c0c479a commit 8f6063135ef09e4190dcde5ddde8a59b1b889c3e @ProgVal committed May 9, 2013
Showing with 22 additions and 5 deletions.
  1. +5 −1 plugins/Ctcp/plugin.py
  2. +8 −2 plugins/Misc/plugin.py
  3. +6 −2 plugins/Owner/plugin.py
  4. +3 −0 src/conf.py
View
@@ -47,7 +47,11 @@ def __init__(self, irc):
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():
View
@@ -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 @@ def invalidCommand(self, irc, msg, tokens):
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.
View
@@ -112,7 +112,8 @@ def __init__(self, irc=None):
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 @@ def do376(self, irc, msg):
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 @@ def doPrivmsg(self, irc, msg):
'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:
View
@@ -690,6 +690,9 @@ class ValidBrackets(registry.OnlySomeStrings):
###
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.""")))

0 comments on commit 8f60631

Please sign in to comment.