Add supybot.abuse.flood.interval.

This commit is contained in:
Valentin Lorentz 2013-05-09 09:40:55 +02:00
parent c0c479a77c
commit 8f6063135e
4 changed files with 22 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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