Compare commits
	
		
			2 Commits
		
	
	
		
			45413e2256
			...
			cf648cd555
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| cf648cd555 | |||
| c67b56ee5e | 
| @ -73,17 +73,23 @@ class Markov(Plugin): | |||||||
|             log.debug("not learning from %s as i've been told to ignore it", channel) |             log.debug("not learning from %s as i've been told to ignore it", channel) | ||||||
|         else: |         else: | ||||||
|             # learn the line |             # learn the line | ||||||
|  |             # remove our own nick and aliases from what we learn | ||||||
|             if connection.server_config.additional_addressed_nicks: |             if connection.server_config.additional_addressed_nicks: | ||||||
|                 all_nicks = '|'.join(connection.server_config.additional_addressed_nicks.split('\n') + |                 all_nicks = '|'.join(connection.server_config.additional_addressed_nicks.split('\n') + | ||||||
|                                      [connection.get_nickname()]) |                                      [connection.get_nickname()]) | ||||||
|             else: |             else: | ||||||
|                 all_nicks = connection.get_nickname() |                 all_nicks = connection.get_nickname() | ||||||
|             trimmed_what = re.sub(r'^(({nicks})[:,]|@({nicks}))\s+'.format(nicks=all_nicks), '', 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: | ||||||
|  |                 what = ' '.join(what.split(' ')[1:]) | ||||||
|  | 
 | ||||||
|             recursing = getattr(event, 'recursing', False) |             recursing = getattr(event, 'recursing', False) | ||||||
|             if not recursing: |             if not recursing: | ||||||
|                 log.debug("learning %s", trimmed_what) |                 log.debug("learning %s", what) | ||||||
|                 context = markovlib.get_or_create_target_context(target) |                 context = markovlib.get_or_create_target_context(target) | ||||||
|                 markovlib.learn_line(trimmed_what, context) |                 markovlib.learn_line(what, context) | ||||||
| 
 | 
 | ||||||
|         log.debug("searching '%s' for '%s'", what, all_nicks) |         log.debug("searching '%s' for '%s'", what, all_nicks) | ||||||
|         if re.search(all_nicks, what, re.IGNORECASE) is not None: |         if re.search(all_nicks, what, re.IGNORECASE) is not None: | ||||||
|  | |||||||
| @ -33,3 +33,40 @@ class MarkovTestCase(TestCase): | |||||||
|             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') |         self.assertEqual(mock_learn_line.call_args.args[0], 'hello this is a test message') | ||||||
|  | 
 | ||||||
|  |     def test_learn_self_edit(self): | ||||||
|  |         """Test that we don't learn our own name when learning something addressed to us.""" | ||||||
|  |         mock_event = mock.MagicMock() | ||||||
|  |         mock_event.arguments = ['test_bot: hello this is a test message'] | ||||||
|  |         mock_event.target = '#test' | ||||||
|  |         mock_event.recursing = False | ||||||
|  | 
 | ||||||
|  |         with mock.patch('markov.lib.learn_line') as mock_learn_line: | ||||||
|  |             self.plugin.handle_chatter(self.mock_connection, mock_event) | ||||||
|  | 
 | ||||||
|  |         self.assertEqual(mock_learn_line.call_args.args[0], 'hello this is a test message') | ||||||
|  | 
 | ||||||
|  |     def test_learn_variant_self_edit(self): | ||||||
|  |         """Test that we don't learn our own name when learning something addressed to us, discord style.""" | ||||||
|  |         mock_event = mock.MagicMock() | ||||||
|  |         mock_event.arguments = ['@test_bot hello this is a test message'] | ||||||
|  |         mock_event.target = '#test' | ||||||
|  |         mock_event.recursing = False | ||||||
|  | 
 | ||||||
|  |         with mock.patch('markov.lib.learn_line') as mock_learn_line: | ||||||
|  |             self.plugin.handle_chatter(self.mock_connection, mock_event) | ||||||
|  | 
 | ||||||
|  |         self.assertEqual(mock_learn_line.call_args.args[0], 'hello this is a test message') | ||||||
|  | 
 | ||||||
|  |     def test_learn_bridge_edit(self): | ||||||
|  |         """Test that we don't learn the speaker's nick when learning a message from the bridge.""" | ||||||
|  |         mock_event = mock.MagicMock() | ||||||
|  |         mock_event.arguments = ['<tester> hello this is a test message'] | ||||||
|  |         mock_event.target = '#test' | ||||||
|  |         mock_event.recursing = False | ||||||
|  |         mock_event.source = 'bridge!bridge@localhost' | ||||||
|  | 
 | ||||||
|  |         with mock.patch('markov.lib.learn_line') as mock_learn_line: | ||||||
|  |             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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user