Markov: add support for requesting desired min/max size of a reply

note that since the min_size support is kind of crude at the moment,
this only partially works
This commit is contained in:
Brian S. Stephan 2011-01-25 20:25:15 -06:00
parent 157f1bf361
commit 7b4b86dc0d
1 changed files with 12 additions and 4 deletions

View File

@ -54,7 +54,7 @@ class Markov(Module):
# set up regexes, for replying to specific stuff
trainpattern = '^!markov\s+train\s+(.*)$'
learnpattern = '^!markov\s+learn\s+(.*)$'
replypattern = '^!markov\s+reply(\s+(.*)$|$)'
replypattern = '^!markov\s+reply(\s+min=(\d+))?(\s+max=(\d+))?(\s+(.*)$|$)'
self.trainre = re.compile(trainpattern)
self.learnre = re.compile(learnpattern)
@ -148,11 +148,19 @@ class Markov(Module):
match = self.replyre.search(what)
if match:
min_size = 15
max_size = 100
if match.group(2):
line = match.group(2)
return self._reply_to_line(line)
min_size = int(match.group(2))
if match.group(4):
max_size = int(match.group(4))
if match.group(5) != '':
line = match.group(6)
return self._reply_to_line(line, min_size=min_size, max_size=max_size)
else:
return self._reply()
return self._reply(min_size=min_size, max_size=max_size)
def _learn_line(self, line):
"""Create Markov chains from the provided line."""