Skip to content

Commit

Permalink
Add supybot.abuse.flood.interval.
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed May 9, 2013
1 parent c0c479a commit 8f60631
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 5 additions & 1 deletion plugins/Ctcp/plugin.py
Expand Up @@ -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():
Expand Down
10 changes: 8 additions & 2 deletions plugins/Misc/plugin.py
Expand Up @@ -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], [])
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions plugins/Owner/plugin.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/conf.py
Expand Up @@ -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.""")))
Expand Down

0 comments on commit 8f60631

Please sign in to comment.