mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Aka: Add length limit of command names in order to limit the number of database queries.
There were a lot of database queries (as much as words in the whole command) for non-aka commands.
This commit is contained in:
parent
83e1d1b91b
commit
162b9ef709
@ -51,6 +51,10 @@ Aka = conf.registerPlugin('Aka')
|
|||||||
# This is where your configuration variables (if any) should go. For example:
|
# This is where your configuration variables (if any) should go. For example:
|
||||||
# conf.registerGlobalValue(Aka, 'someConfigVariableName',
|
# conf.registerGlobalValue(Aka, 'someConfigVariableName',
|
||||||
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
||||||
|
conf.registerGlobalValue(Aka, 'maximumWordsInName',
|
||||||
|
registry.Integer(5, _("""The maximum number of words allowed in a
|
||||||
|
command name. Setting this to an high value may slow down your bot
|
||||||
|
on long commands.""")))
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
@ -276,7 +276,8 @@ class Aka(callbacks.Plugin):
|
|||||||
ret = self.getCommand(args[1:], False)
|
ret = self.getCommand(args[1:], False)
|
||||||
if ret:
|
if ret:
|
||||||
return [first] + ret
|
return [first] + ret
|
||||||
for i in xrange(1, len(args)+1):
|
max_length = self.registryValue('maximumWordsInName')
|
||||||
|
for i in xrange(1, min(len(args)+1, max_length)):
|
||||||
if self.isCommandMethod(callbacks.formatCommand(args[0:i])):
|
if self.isCommandMethod(callbacks.formatCommand(args[0:i])):
|
||||||
return args[0:i]
|
return args[0:i]
|
||||||
return []
|
return []
|
||||||
@ -365,6 +366,8 @@ class Aka(callbacks.Plugin):
|
|||||||
'this plugin.'))
|
'this plugin.'))
|
||||||
if self._db.has_aka(channel, name):
|
if self._db.has_aka(channel, name):
|
||||||
raise AkaError(_('This Aka already exists.'))
|
raise AkaError(_('This Aka already exists.'))
|
||||||
|
if len(name.split(' ')) > self.registryValue('maximumWordsInName'):
|
||||||
|
raise AkaError(_('This Aka has too many spaces in its name.'))
|
||||||
biggestDollar = findBiggestDollar(alias)
|
biggestDollar = findBiggestDollar(alias)
|
||||||
biggestAt = findBiggestAt(alias)
|
biggestAt = findBiggestAt(alias)
|
||||||
wildcard = '$*' in alias
|
wildcard = '$*' in alias
|
||||||
|
@ -178,6 +178,10 @@ class AkaChannelTestCase(ChannelPluginTestCase):
|
|||||||
class AkaTestCase(PluginTestCase):
|
class AkaTestCase(PluginTestCase):
|
||||||
plugins = ('Aka', 'Alias', 'User', 'Utilities')
|
plugins = ('Aka', 'Alias', 'User', 'Utilities')
|
||||||
|
|
||||||
|
def testMaximumLength(self):
|
||||||
|
self.assertNotError('aka add "foo bar baz qux quux" "echo test"')
|
||||||
|
self.assertError('aka add "foo bar baz qux quux corge" "echo test"')
|
||||||
|
|
||||||
def testAkaLockedHelp(self):
|
def testAkaLockedHelp(self):
|
||||||
self.assertNotError('register evil_admin foo')
|
self.assertNotError('register evil_admin foo')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user