mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-06-12 17:57:22 +02:00
Made the maximum length configurable.
This commit is contained in:
parent
f8207cf116
commit
245c77d69b
@ -53,8 +53,22 @@ import supybot.utils as utils
|
|||||||
import supybot.ircmsgs as ircmsgs
|
import supybot.ircmsgs as ircmsgs
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.privmsgs as privmsgs
|
import supybot.privmsgs as privmsgs
|
||||||
|
import supybot.registry as registry
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
|
|
||||||
|
|
||||||
|
conf.registerPlugin('Fun')
|
||||||
|
conf.registerGroup(conf.supybot.plugins.Fun, 'levenshtein')
|
||||||
|
conf.registerGlobalValue(conf.supybot.plugins.Fun.levenshtein, 'max',
|
||||||
|
registry.PositiveInteger(256, """Determines the maximum size of a string
|
||||||
|
given to the levenhstein command. The levenshtein command uses an O(n**3)
|
||||||
|
algorithm, which means that with strings of length 256, it can take 1.5
|
||||||
|
seconds to finish; with strings of length 384, though, it can take 4
|
||||||
|
seconds to finihs, and with strings of much larger lengths, it takes more
|
||||||
|
and more time. Using nested commands, strings can get quite large, hence
|
||||||
|
this variable, to limit the size of arguments passed to the levenshtein
|
||||||
|
command."""))
|
||||||
|
|
||||||
class MyFunProxy(object):
|
class MyFunProxy(object):
|
||||||
def reply(self, msg, s):
|
def reply(self, msg, s):
|
||||||
self.s = s
|
self.s = s
|
||||||
@ -290,7 +304,8 @@ class Fun(callbacks.Privmsg):
|
|||||||
between <string1> and <string2>)
|
between <string1> and <string2>)
|
||||||
"""
|
"""
|
||||||
(s1, s2) = privmsgs.getArgs(args, required=2)
|
(s1, s2) = privmsgs.getArgs(args, required=2)
|
||||||
if len(s1) > 512 or len(s2) > 512:
|
max = self.registryValue('levenshtein.max')
|
||||||
|
if len(s1) > max or len(s2) > max:
|
||||||
irc.error('Levenshtein distance is a complicated algorithm, try '
|
irc.error('Levenshtein distance is a complicated algorithm, try '
|
||||||
'it with some smaller inputs.')
|
'it with some smaller inputs.')
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user