Compare commits
2 Commits
45413e2256
...
cf648cd555
Author | SHA1 | Date |
---|---|---|
Brian S. Stephan | cf648cd555 | |
Brian S. Stephan | c67b56ee5e |
|
@ -73,24 +73,23 @@ class Markov(Plugin):
|
|||
log.debug("not learning from %s as i've been told to ignore it", channel)
|
||||
else:
|
||||
# learn the line
|
||||
learning_what = what
|
||||
# remove our own nick and aliases from what we learn
|
||||
if connection.server_config.additional_addressed_nicks:
|
||||
all_nicks = '|'.join(connection.server_config.additional_addressed_nicks.split('\n') +
|
||||
[connection.get_nickname()])
|
||||
else:
|
||||
all_nicks = connection.get_nickname()
|
||||
learning_what = re.sub(r'^(({nicks})[:,]|@({nicks}))\s+'.format(nicks=all_nicks), '', learning_what)
|
||||
what = re.sub(r'^(({nicks})[:,]|@({nicks}))\s+'.format(nicks=all_nicks), '', what)
|
||||
|
||||
# don't learn the speaker's nick if this came over a bridge
|
||||
if channel and who == channel.discord_bridge:
|
||||
learning_what = ' '.join(learning_what.split(' ')[1:])
|
||||
what = ' '.join(what.split(' ')[1:])
|
||||
|
||||
recursing = getattr(event, 'recursing', False)
|
||||
if not recursing:
|
||||
log.debug("learning %s", learning_what)
|
||||
log.debug("learning %s", what)
|
||||
context = markovlib.get_or_create_target_context(target)
|
||||
markovlib.learn_line(learning_what, context)
|
||||
markovlib.learn_line(what, context)
|
||||
|
||||
log.debug("searching '%s' for '%s'", what, all_nicks)
|
||||
if re.search(all_nicks, what, re.IGNORECASE) is not None:
|
||||
|
|
|
@ -42,8 +42,7 @@ class MarkovTestCase(TestCase):
|
|||
mock_event.recursing = False
|
||||
|
||||
with mock.patch('markov.lib.learn_line') as mock_learn_line:
|
||||
with mock.patch('markov.lib.generate_line'):
|
||||
self.plugin.handle_chatter(self.mock_connection, mock_event)
|
||||
self.plugin.handle_chatter(self.mock_connection, mock_event)
|
||||
|
||||
self.assertEqual(mock_learn_line.call_args.args[0], 'hello this is a test message')
|
||||
|
||||
|
@ -55,8 +54,7 @@ class MarkovTestCase(TestCase):
|
|||
mock_event.recursing = False
|
||||
|
||||
with mock.patch('markov.lib.learn_line') as mock_learn_line:
|
||||
with mock.patch('markov.lib.generate_line'):
|
||||
self.plugin.handle_chatter(self.mock_connection, mock_event)
|
||||
self.plugin.handle_chatter(self.mock_connection, mock_event)
|
||||
|
||||
self.assertEqual(mock_learn_line.call_args.args[0], 'hello this is a test message')
|
||||
|
||||
|
|
Loading…
Reference in New Issue