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)