Compare commits
	
		
			No commits in common. "55d856b8fd0a3f4684a7297b2d3984bf5999f3b1" and "cfeddfdc4e99f9a1b6d1b81fc98e3a9f943359d0" have entirely different histories.
		
	
	
		
			55d856b8fd
			...
			cfeddfdc4e
		
	
		
| @ -171,18 +171,7 @@ class DrReactor(irc.client.Reactor): | ||||
|                 else: | ||||
|                     all_nicks = connection.get_nickname() | ||||
|                 addressed_pattern = r'^(({nicks})[:,]|@({nicks}))\s+(?P<addressed_msg>.*)'.format(nicks=all_nicks) | ||||
| 
 | ||||
|                 # ignore the first word, a nick, if the speaker is the bridge | ||||
|                 try: | ||||
|                     channel = IrcChannel.objects.get(name=sent_location) | ||||
|                     if sender_nick == channel.discord_bridge: | ||||
|                         short_what = ' '.join(what.split(' ')[1:]) | ||||
|                         match = re.match(addressed_pattern, short_what, re.IGNORECASE) | ||||
|                     else: | ||||
|                         match = re.match(addressed_pattern, what, re.IGNORECASE) | ||||
|                 except IrcChannel.DoesNotExist: | ||||
|                     match = re.match(addressed_pattern, what, re.IGNORECASE) | ||||
| 
 | ||||
|                 match = re.match(addressed_pattern, what, re.IGNORECASE) | ||||
|                 if match: | ||||
|                     event.addressed = True | ||||
|                     event.addressed_msg = match.group('addressed_msg') | ||||
|  | ||||
| @ -1,84 +0,0 @@ | ||||
| """Test core methods of the IRC bot.""" | ||||
| from unittest import mock | ||||
| 
 | ||||
| from django.test import TestCase | ||||
| 
 | ||||
| from ircbot.bot import DrReactor | ||||
| from ircbot.models import IrcServer | ||||
| 
 | ||||
| 
 | ||||
| class DrReactorTestCase(TestCase): | ||||
|     """Test the bot innards.""" | ||||
| 
 | ||||
|     fixtures = ['tests/fixtures/irc_server_fixture.json'] | ||||
| 
 | ||||
|     def setUp(self): | ||||
|         """Create common objects.""" | ||||
|         self.bot = DrReactor() | ||||
|         self.mock_connection = mock.MagicMock() | ||||
| 
 | ||||
|         self.mock_connection.get_nickname.return_value = 'test_bot' | ||||
|         self.mock_connection.server_config = IrcServer.objects.get(pk=1) | ||||
| 
 | ||||
|     def test_handle_event_not_addressed(self): | ||||
|         """Test that the core identifies not being addressed.""" | ||||
|         mock_event = mock.MagicMock() | ||||
|         mock_event.arguments = ['someone: hello this is a test message'] | ||||
|         mock_event.type = 'pubmsg' | ||||
|         mock_event.target = '#test' | ||||
|         self.bot._handle_event(self.mock_connection, mock_event) | ||||
| 
 | ||||
|         self.assertFalse(mock_event.addressed) | ||||
| 
 | ||||
|     def test_handle_event_addressed(self): | ||||
|         """Test that the core identifies being addressed IRC style.""" | ||||
|         mock_event = mock.MagicMock() | ||||
|         mock_event.arguments = ['test_bot: hello this is a test message'] | ||||
|         mock_event.type = 'pubmsg' | ||||
|         mock_event.target = '#test' | ||||
|         self.bot._handle_event(self.mock_connection, mock_event) | ||||
| 
 | ||||
|         self.assertTrue(mock_event.addressed) | ||||
| 
 | ||||
|     def test_handle_event_addressed_alternate(self): | ||||
|         """Test that the core identifies being addressed in the alternate (e.g. discord) style.""" | ||||
|         mock_event = mock.MagicMock() | ||||
|         mock_event.arguments = ['@test_bot hello this is a test message'] | ||||
|         mock_event.type = 'pubmsg' | ||||
|         mock_event.target = '#test' | ||||
|         self.bot._handle_event(self.mock_connection, mock_event) | ||||
| 
 | ||||
|         self.assertTrue(mock_event.addressed) | ||||
| 
 | ||||
|     def test_handle_event_bridge_addressed(self): | ||||
|         """Test that the core identifies being addressed IRC style through a discord bridge.""" | ||||
|         mock_event = mock.MagicMock() | ||||
|         mock_event.arguments = ['<someone> test_bot: hello this is a test message'] | ||||
|         mock_event.type = 'pubmsg' | ||||
|         mock_event.target = '#test' | ||||
|         mock_event.source = 'bridge!bridge@localhost' | ||||
|         self.bot._handle_event(self.mock_connection, mock_event) | ||||
| 
 | ||||
|         self.assertTrue(mock_event.addressed) | ||||
| 
 | ||||
|     def test_handle_event_bridge_addressed_alternate(self): | ||||
|         """Test that the core identifies being addressed in the alternate style through a discord bridge.""" | ||||
|         mock_event = mock.MagicMock() | ||||
|         mock_event.arguments = ['<someone> @test_bot hello this is a test message'] | ||||
|         mock_event.type = 'pubmsg' | ||||
|         mock_event.target = '#test' | ||||
|         mock_event.source = 'bridge!bridge@localhost' | ||||
|         self.bot._handle_event(self.mock_connection, mock_event) | ||||
| 
 | ||||
|         self.assertTrue(mock_event.addressed) | ||||
| 
 | ||||
|     def test_handle_event_not_addressed_not_bridge(self): | ||||
|         """Test that the core identifies not to chop the first word from a paste not from the bridge user.""" | ||||
|         mock_event = mock.MagicMock() | ||||
|         mock_event.arguments = ['<somebody> test_bot: hello this is a test message'] | ||||
|         mock_event.type = 'pubmsg' | ||||
|         mock_event.target = '#test' | ||||
|         mock_event.source = 'not-bridge!not-bridge@localhost' | ||||
|         self.bot._handle_event(self.mock_connection, mock_event) | ||||
| 
 | ||||
|         self.assertFalse(mock_event.addressed) | ||||
| @ -73,23 +73,6 @@ class MarkovTestCase(TestCase): | ||||
| 
 | ||||
|         self.assertEqual(mock_learn_line.call_args.args[0], 'hello this is a test message') | ||||
| 
 | ||||
|     def test_learn_bridge_no_edit(self): | ||||
|         """Test that if a message is from the bridge, we learn what looks like a speaker's nick. | ||||
| 
 | ||||
|         This is primarily for if someone on IRC is pasting a log --- the "<somebody> whatever" should | ||||
|         be retained in full, rather than learned as "whatever". | ||||
|         """ | ||||
|         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 = 'not-bridge!not-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], '<tester> hello this is a test message') | ||||
| 
 | ||||
|     def test_learn_bridge_and_self_edit(self): | ||||
|         """Test that we don't learn our own name when learning something addressed to us, discord style.""" | ||||
|         mock_event = mock.MagicMock() | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user