Markov: preliminary support for the bot to conditionally shut it self up (and recover from that)
This commit is contained in:
parent
42d414a0a4
commit
14f2a027fe
@ -39,6 +39,10 @@ class Markov(Module):
|
|||||||
http://code.activestate.com/recipes/194364-the-markov-chain-algorithm/
|
http://code.activestate.com/recipes/194364-the-markov-chain-algorithm/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def timer_interval(self):
|
||||||
|
"""Do various conversation scoring and infinite reply checks."""
|
||||||
|
return 30
|
||||||
|
|
||||||
def __init__(self, irc, config, server):
|
def __init__(self, irc, config, server):
|
||||||
"""Create the Markov chainer, and learn text from a file if available."""
|
"""Create the Markov chainer, and learn text from a file if available."""
|
||||||
|
|
||||||
@ -57,6 +61,8 @@ class Markov(Module):
|
|||||||
self.learnre = re.compile(learnpattern)
|
self.learnre = re.compile(learnpattern)
|
||||||
self.replyre = re.compile(replypattern)
|
self.replyre = re.compile(replypattern)
|
||||||
|
|
||||||
|
self.shut_up = False
|
||||||
|
|
||||||
Module.__init__(self, irc, config, server)
|
Module.__init__(self, irc, config, server)
|
||||||
|
|
||||||
def db_init(self):
|
def db_init(self):
|
||||||
@ -173,19 +179,20 @@ class Markov(Module):
|
|||||||
return self.reply(connection, event, self.markov_train(connection, event, nick, userhost, what, admin_unlocked))
|
return self.reply(connection, event, self.markov_train(connection, event, nick, userhost, what, admin_unlocked))
|
||||||
elif self.learnre.search(what):
|
elif self.learnre.search(what):
|
||||||
return self.reply(connection, event, self.markov_learn(connection, event, nick, userhost, what, admin_unlocked))
|
return self.reply(connection, event, self.markov_learn(connection, event, nick, userhost, what, admin_unlocked))
|
||||||
elif self.replyre.search(what):
|
elif self.replyre.search(what) and not self.shut_up:
|
||||||
return self.reply(connection, event, self.markov_reply(connection, event, nick, userhost, what, admin_unlocked))
|
return self.reply(connection, event, self.markov_reply(connection, event, nick, userhost, what, admin_unlocked))
|
||||||
|
|
||||||
# not a command, so see if i'm being mentioned
|
if not self.shut_up:
|
||||||
if re.search(connection.get_nickname(), what, re.IGNORECASE) is not None:
|
# not a command, so see if i'm being mentioned
|
||||||
addressed_pattern = '^' + connection.get_nickname() + '[:,]\s+(.*)'
|
if re.search(connection.get_nickname(), what, re.IGNORECASE) is not None:
|
||||||
addressed_re = re.compile(addressed_pattern)
|
addressed_pattern = '^' + connection.get_nickname() + '[:,]\s+(.*)'
|
||||||
if addressed_re.match(what):
|
addressed_re = re.compile(addressed_pattern)
|
||||||
# i was addressed directly, so respond, addressing the speaker
|
if addressed_re.match(what):
|
||||||
return self.reply(connection, event, '{0:s}: {1:s}'.format(nick, self._generate_line(line=addressed_re.match(what).group(1))))
|
# i was addressed directly, so respond, addressing the speaker
|
||||||
else:
|
return self.reply(connection, event, '{0:s}: {1:s}'.format(nick, self._generate_line(line=addressed_re.match(what).group(1))))
|
||||||
# i wasn't addressed directly, so just respond
|
else:
|
||||||
return self.reply(connection, event, '{0:s}'.format(self._generate_line(line=what)))
|
# i wasn't addressed directly, so just respond
|
||||||
|
return self.reply(connection, event, '{0:s}'.format(self._generate_line(line=what)))
|
||||||
|
|
||||||
def markov_train(self, connection, event, nick, userhost, what, admin_unlocked):
|
def markov_train(self, connection, event, nick, userhost, what, admin_unlocked):
|
||||||
"""Learn lines from a file. Good for initializing a brain."""
|
"""Learn lines from a file. Good for initializing a brain."""
|
||||||
@ -233,6 +240,14 @@ class Markov(Module):
|
|||||||
else:
|
else:
|
||||||
return self._generate_line(min_size=min_size, max_size=max_size)
|
return self._generate_line(min_size=min_size, max_size=max_size)
|
||||||
|
|
||||||
|
def timer_do(self):
|
||||||
|
"""Do various things.
|
||||||
|
|
||||||
|
* Check to see if we've been talking too much, and shut up if so.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.shut_up = True
|
||||||
|
|
||||||
def _learn_line(self, line, target=None):
|
def _learn_line(self, line, target=None):
|
||||||
"""Create Markov chains from the provided line."""
|
"""Create Markov chains from the provided line."""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user