diff --git a/ircbot/bot.py b/ircbot/bot.py index 67ec77f..5df7258 100644 --- a/ircbot/bot.py +++ b/ircbot/bot.py @@ -170,7 +170,7 @@ class DrReactor(irc.client.Reactor): [connection.get_nickname()]) else: all_nicks = connection.get_nickname() - addressed_pattern = r'^(({nicks})[:,]|@({nicks}))\s+(?P.*)'.format(nicks=all_nicks) + addressed_pattern = r'^(({nicks})[:,]|@({nicks})[:,]?)\s+(?P.*)'.format(nicks=all_nicks) # ignore the first word, a nick, if the speaker is the bridge try: diff --git a/markov/ircplugin.py b/markov/ircplugin.py index 4abb58c..f226bb3 100644 --- a/markov/ircplugin.py +++ b/markov/ircplugin.py @@ -86,7 +86,7 @@ class Markov(Plugin): [connection.get_nickname()]) else: all_nicks = connection.get_nickname() - learning_what = re.sub(r'^(({nicks})[:,]|@({nicks}))\s+'.format(nicks=all_nicks), '', learning_what) + learning_what = re.sub(r'^(({nicks})[:,]|@({nicks})[:,]?)\s+'.format(nicks=all_nicks), '', learning_what) recursing = getattr(event, 'recursing', False) if not recursing: @@ -98,7 +98,7 @@ class Markov(Plugin): if re.search(all_nicks, what, re.IGNORECASE) is not None: context = self.get_or_create_target_context(target) - addressed_pattern = r'^(({nicks})[:,]|@({nicks}))\s+(?P.*)'.format(nicks=all_nicks) + addressed_pattern = r'^(({nicks})[:,]|@({nicks})[:,]?)\s+(?P.*)'.format(nicks=all_nicks) match = re.match(addressed_pattern, what, re.IGNORECASE) if match: # i was addressed directly, so respond, addressing diff --git a/tests/test_ircbot_bot.py b/tests/test_ircbot_bot.py index 2d4c27c..d029028 100644 --- a/tests/test_ircbot_bot.py +++ b/tests/test_ircbot_bot.py @@ -72,6 +72,17 @@ class DrReactorTestCase(TestCase): self.assertTrue(mock_event.addressed) + def test_handle_event_bridge_addressed_alternate_with_colon(self): + """Test that the core identifies being addressed in the alternate style through a discord bridge.""" + mock_event = mock.MagicMock() + mock_event.arguments = [' @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() diff --git a/tests/test_markov_ircplugin.py b/tests/test_markov_ircplugin.py index 63994f6..933271c 100644 --- a/tests/test_markov_ircplugin.py +++ b/tests/test_markov_ircplugin.py @@ -118,6 +118,20 @@ class MarkovTestCase(TestCase): self.assertEqual(mock_learn_line.call_args.args[0], 'hello this is a test message') + def test_learn_bridge_and_variant_with_colon_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 + mock_event.source = 'bridge!bridge@localhost' + + 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.assertEqual(mock_learn_line.call_args.args[0], 'hello this is a test message') + def test_autocreate_ircchannel(self): """Test that we create the necessary config objects when seeing a target for the first time.""" self.assertEqual(IrcChannel.objects.filter(name='#fakechannel').count(), 0)