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,9 +179,10 @@ 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))
|
||||||
|
|
||||||
|
if not self.shut_up:
|
||||||
# not a command, so see if i'm being mentioned
|
# not a command, so see if i'm being mentioned
|
||||||
if re.search(connection.get_nickname(), what, re.IGNORECASE) is not None:
|
if re.search(connection.get_nickname(), what, re.IGNORECASE) is not None:
|
||||||
addressed_pattern = '^' + connection.get_nickname() + '[:,]\s+(.*)'
|
addressed_pattern = '^' + connection.get_nickname() + '[:,]\s+(.*)'
|
||||||
|
@ -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