RateLimit: Add optional error message.
parent
80253dab8f
commit
711c9e506f
|
@ -51,6 +51,9 @@ RateLimit = conf.registerPlugin('RateLimit')
|
|||
# This is where your configuration variables (if any) should go. For example:
|
||||
# conf.registerGlobalValue(RateLimit, 'someConfigVariableName',
|
||||
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
||||
conf.registerChannelValue(RateLimit, 'error',
|
||||
registry.Boolean(False, _("""Determines whether an error message will
|
||||
be sent if a user reaches the rate limit.""")))
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
|
|
@ -138,6 +138,10 @@ class RateLimit(callbacks.Plugin):
|
|||
if len(list_) >= record.count:
|
||||
self.log.info('Throttling command %r call (rate limited).',
|
||||
command)
|
||||
if self.registryValue('error', msg.args[0]):
|
||||
irc.error(_('This command has been called more than {0} '
|
||||
'times in the last {1} seconds.').format(
|
||||
record.count, record.interval))
|
||||
return True
|
||||
list_.append((user, time.time()))
|
||||
self._history[command] = list_
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
###
|
||||
|
||||
from supybot.test import *
|
||||
import supybot.conf as conf
|
||||
|
||||
class RateLimitTestCase(PluginTestCase):
|
||||
plugins = ('RateLimit', 'User', 'Utilities')
|
||||
|
@ -52,6 +53,9 @@ class RateLimitTestCase(PluginTestCase):
|
|||
self.assertResponse('echo spam', 'spam', frm='foo!a@a')
|
||||
self.assertNoResponse('echo spam', frm='foo!a@a')
|
||||
self.assertResponse('echo spam', 'spam', frm='bar!a@a')
|
||||
with conf.supybot.plugins.RateLimit.Error.context(True):
|
||||
self.assertRegexp('echo spam', 'called more than 3 times',
|
||||
frm='foo!a@a')
|
||||
|
||||
time.sleep(1.1)
|
||||
|
||||
|
|
Loading…
Reference in New Issue