RateLimit: Add @unset.
parent
a9b34d1497
commit
6929fc1e8e
|
@ -69,6 +69,17 @@ class RateLimitDB(dbi.DB):
|
|||
self.add(record)
|
||||
else:
|
||||
self.set(previous_record.id, record)
|
||||
def unset_user_limit(self, channel, user, command):
|
||||
try:
|
||||
record = list(filter(
|
||||
lambda x:x.user == user and
|
||||
x.command == command and
|
||||
x.channel == channel,
|
||||
self))[0]
|
||||
except IndexError:
|
||||
raise
|
||||
else:
|
||||
self.remove(record.id)
|
||||
|
||||
def get_limits(self, command):
|
||||
return filter(lambda x:x.command == command, self)
|
||||
|
@ -148,6 +159,26 @@ class RateLimit(callbacks.Plugin):
|
|||
self.db.set_user_limit(None, user, count, interval, command)
|
||||
irc.replySuccess()
|
||||
|
||||
@wrap([optional(first('otherUser', ('literal', '*'))),
|
||||
'commandName', 'admin'])
|
||||
def unset(self, irc, msg, args, user, command):
|
||||
"""[<user>] <command>
|
||||
|
||||
Unsets the rate limit of the <command> for the <user>.
|
||||
If <user> is not given, the rate limit will be enforced globally,
|
||||
and if * is given as the <user>, the rate limit will be enforced
|
||||
for everyone."""
|
||||
if user is None:
|
||||
user = 'global'
|
||||
elif user != '*':
|
||||
user = user.id
|
||||
try:
|
||||
self.db.unset_user_limit(None, user, command)
|
||||
except IndexError:
|
||||
irc.error(_('This rate limit did not exist.'))
|
||||
else:
|
||||
irc.replySuccess()
|
||||
|
||||
@wrap(['commandName'])
|
||||
def get(self, irc, msg, args, command):
|
||||
"""<command>
|
||||
|
|
|
@ -53,6 +53,19 @@ class RateLimitTestCase(PluginTestCase):
|
|||
self.assertNoResponse('echo spam', frm='foo!a@a')
|
||||
self.assertResponse('echo spam', 'spam', frm='bar!a@a')
|
||||
|
||||
time.sleep(1.1)
|
||||
|
||||
self.assertNotError('ratelimit unset foo echo')
|
||||
self.assertResponse('ratelimit get echo',
|
||||
'global: none, *: none')
|
||||
self.assertResponse('echo spam', 'spam', frm='foo!a@a')
|
||||
self.assertResponse('echo spam', 'spam', frm='foo!a@a')
|
||||
self.assertResponse('echo spam', 'spam', frm='foo!a@a')
|
||||
self.assertResponse('echo spam', 'spam', frm='foo!a@a')
|
||||
|
||||
self.assertRegexp('ratelimit unset foo echo',
|
||||
'Error:.*did not exist')
|
||||
|
||||
def testStar(self):
|
||||
self.assertResponse('ratelimit get echo',
|
||||
'global: none, *: none')
|
||||
|
|
Loading…
Reference in New Issue