mirror of https://github.com/Mikaela/Limnoria.git
Add plugins.Markov.minChainLength and plugins.Markov.maxAttempts which
should allow for interesting Markov chains (unless you like the one-worders).
This commit is contained in:
parent
ed2488c1f8
commit
611149aadc
|
@ -78,6 +78,13 @@ conf.registerChannelValue(conf.supybot.plugins.Markov.randomSpeaking,
|
|||
conf.registerChannelValue(conf.supybot.plugins.Markov.randomSpeaking,
|
||||
'throttleTime', registry.PositiveInteger(300, """Determines the minimum
|
||||
number of seconds between the bot randomly speaking."""))
|
||||
conf.registerChannelValue(conf.supybot.plugins.Markov, 'minChainLength',
|
||||
registry.PositiveInteger(1, """Determines the length of the smallest chain
|
||||
which the markov command will generate."""))
|
||||
conf.registerChannelValue(conf.supybot.plugins.Markov, 'maxAttempts',
|
||||
registry.PositiveInteger(1, """Determines the maximum number of times the
|
||||
bot will attempt to generate a chain that meets or exceeds the size set in
|
||||
minChainLength."""))
|
||||
|
||||
class MarkovDBInterface(object):
|
||||
def close(self):
|
||||
|
@ -323,6 +330,10 @@ class Markov(callbacks.Privmsg):
|
|||
|
||||
def _markov(self, channel, irc, word1=None, word2=None, **kwargs):
|
||||
def f(db):
|
||||
minLength = self.registryValue('minChainLength', channel)
|
||||
maxTries = self.registryValue('maxAttempts', channel)
|
||||
while maxTries > 0:
|
||||
maxTries -= 1;
|
||||
if word1 and word2:
|
||||
givenArgs = True
|
||||
words = [word1, word2]
|
||||
|
@ -332,7 +343,8 @@ class Markov(callbacks.Privmsg):
|
|||
# words is of the form ['\r', word]
|
||||
words = list(db.getFirstPair(channel))
|
||||
except KeyError:
|
||||
irc.error('I don\'t have any first pairs for %s.' %channel)
|
||||
irc.error('I don\'t have any first pairs for %s.' %
|
||||
channel)
|
||||
return
|
||||
follower = words[-1]
|
||||
last = False
|
||||
|
@ -344,14 +356,24 @@ class Markov(callbacks.Privmsg):
|
|||
words[-1])
|
||||
except KeyError:
|
||||
irc.error('I found a broken link in the Markov chain. '
|
||||
'Maybe I received two bad links to start the '
|
||||
'chain.')
|
||||
' Maybe I received two bad links to start '
|
||||
'the chain.')
|
||||
return
|
||||
words.append(follower)
|
||||
if givenArgs:
|
||||
if len(words[:-1]) >= minLength:
|
||||
irc.reply(' '.join(words[:-1]), **kwargs)
|
||||
return
|
||||
else:
|
||||
continue
|
||||
else:
|
||||
if len(resp) >= minLength:
|
||||
irc.reply(' '.join(resp), **kwargs)
|
||||
return
|
||||
else:
|
||||
continue
|
||||
irc.error('I was unable to generate a Markov chain at least %s '
|
||||
'long.' % utils.nItems('word', minLength))
|
||||
return f
|
||||
|
||||
def markov(self, irc, msg, args, channel, word1, word2):
|
||||
|
|
Loading…
Reference in New Issue