From 71d64fcaedcb1223d8b1679e327aeef4000f177a Mon Sep 17 00:00:00 2001 From: dgw Date: Sun, 6 Jun 2021 06:24:21 -0500 Subject: [PATCH 1/2] coretasks: request message-tags capability --- sopel/coretasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel/coretasks.py b/sopel/coretasks.py index 703874c0da..f9f236e1ee 100644 --- a/sopel/coretasks.py +++ b/sopel/coretasks.py @@ -904,6 +904,7 @@ def receive_cap_ls_reply(bot, trigger): 'cap-notify', 'server-time', 'userhost-in-names', + 'message-tags', ] for cap in core_caps: if cap not in bot._cap_reqs: From 7547fb4775d50817cee92db63dd175cd5b6e6f57 Mon Sep 17 00:00:00 2001 From: dgw Date: Sun, 6 Jun 2021 06:35:52 -0500 Subject: [PATCH 2/2] plugins.rules: ignore messages tagged as coming from a bot Only PRIVMSG and NOTICE messages from bots are filtered out, so this change doesn't affect Sopel's user tracking. JOINs, PARTs, etc. can be included later, once there exists a decorator that event handlers can use to turn this `bot` filter off. Currently supports the `draft/bot` tag AND the `bot` tag that will be used when the relevant IRCv3 extension leaves draft status. It seems like the future-proofing is of minimal risk here. --- sopel/plugins/rules.py | 8 ++++++++ test/plugins/test_plugins_rules.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/sopel/plugins/rules.py b/sopel/plugins/rules.py index 7fb3297b19..80bb7f8312 100644 --- a/sopel/plugins/rules.py +++ b/sopel/plugins/rules.py @@ -959,6 +959,13 @@ def match_preconditions(self, bot, pretrigger): event = pretrigger.event intent = pretrigger.tags.get('intent') nick = pretrigger.nick + is_bot_message = ( + ( + 'draft/bot' in pretrigger.tags or # can be removed...someday + 'bot' in pretrigger.tags + ) and + event in ["PRIVMSG", "NOTICE"] + ) is_echo_message = ( nick.lower() == bot.nick.lower() and event in ["PRIVMSG", "NOTICE"] @@ -967,6 +974,7 @@ def match_preconditions(self, bot, pretrigger): return ( self.match_event(event) and self.match_intent(intent) and + (not is_bot_message or (is_echo_message and self.allow_echo())) and (not is_echo_message or self.allow_echo()) ) diff --git a/test/plugins/test_plugins_rules.py b/test/plugins/test_plugins_rules.py index 1d1093c336..ce3653f738 100644 --- a/test/plugins/test_plugins_rules.py +++ b/test/plugins/test_plugins_rules.py @@ -654,6 +654,23 @@ def test_rule_match_privmsg_action(mockbot): assert not list(rule.match(mockbot, pretrigger)) +def test_rule_match_privmsg_bot_tag(mockbot): + regex = re.compile(r'.*') + rule = rules.Rule([regex]) + + line = '@draft/bot :TestBot!sopel@example.com PRIVMSG #sopel :Hi!' + pretrigger = trigger.PreTrigger(mockbot.nick, line) + assert not list(rule.match(mockbot, pretrigger)), ( + 'Line with `draft/bot` tag must be ignored' + ) + + line = '@bot :TestBot!sopel@example.com PRIVMSG #sopel :Hi!' + pretrigger = trigger.PreTrigger(mockbot.nick, line) + assert not list(rule.match(mockbot, pretrigger)), ( + 'Line with final/ratified `bot` tag must be ignored' + ) + + def test_rule_match_privmsg_echo(mockbot): line = ':TestBot!sopel@example.com PRIVMSG #sopel :Hi!' pretrigger = trigger.PreTrigger(mockbot.nick, line)