allow : and , after @bot mentions

This commit is contained in:
Brian S. Stephan 2023-02-19 22:55:14 -06:00
parent 55d856b8fd
commit 39290fb63c
Signed by: bss
GPG Key ID: 3DE06D3180895FCB
4 changed files with 28 additions and 3 deletions

View File

@ -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<addressed_msg>.*)'.format(nicks=all_nicks)
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:

View File

@ -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<addressed_msg>.*)'.format(nicks=all_nicks)
addressed_pattern = r'^(({nicks})[:,]|@({nicks})[:,]?)\s+(?P<addressed_msg>.*)'.format(nicks=all_nicks)
match = re.match(addressed_pattern, what, re.IGNORECASE)
if match:
# i was addressed directly, so respond, addressing

View File

@ -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 = ['<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()

View File

@ -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 = ['<tester> @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)