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:
parent
157f1bf361
commit
7b4b86dc0d
|
@ -54,7 +54,7 @@ class Markov(Module):
|
||||||
# set up regexes, for replying to specific stuff
|
# set up regexes, for replying to specific stuff
|
||||||
trainpattern = '^!markov\s+train\s+(.*)$'
|
trainpattern = '^!markov\s+train\s+(.*)$'
|
||||||
learnpattern = '^!markov\s+learn\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.trainre = re.compile(trainpattern)
|
||||||
self.learnre = re.compile(learnpattern)
|
self.learnre = re.compile(learnpattern)
|
||||||
|
@ -148,11 +148,19 @@ class Markov(Module):
|
||||||
|
|
||||||
match = self.replyre.search(what)
|
match = self.replyre.search(what)
|
||||||
if match:
|
if match:
|
||||||
|
min_size = 15
|
||||||
|
max_size = 100
|
||||||
|
|
||||||
if match.group(2):
|
if match.group(2):
|
||||||
line = match.group(2)
|
min_size = int(match.group(2))
|
||||||
return self._reply_to_line(line)
|
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:
|
else:
|
||||||
return self._reply()
|
return self._reply(min_size=min_size, max_size=max_size)
|
||||||
|
|
||||||
def _learn_line(self, line):
|
def _learn_line(self, line):
|
||||||
"""Create Markov chains from the provided line."""
|
"""Create Markov chains from the provided line."""
|
||||||
|
|
Loading…
Reference in New Issue