Skip to content

Commit 1d30887

Browse files
authored
Merge pull request #2089 from sopel-irc/ignore-tagged-bots
coretasks: activate `message-tags` and use it to ignore other bots' tagged messages
2 parents eb6dd0b + 7547fb4 commit 1d30887

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

sopel/coretasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ def receive_cap_ls_reply(bot, trigger):
904904
'cap-notify',
905905
'server-time',
906906
'userhost-in-names',
907+
'message-tags',
907908
]
908909
for cap in core_caps:
909910
if cap not in bot._cap_reqs:

sopel/plugins/rules.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,13 @@ def match_preconditions(self, bot, pretrigger):
959959
event = pretrigger.event
960960
intent = pretrigger.tags.get('intent')
961961
nick = pretrigger.nick
962+
is_bot_message = (
963+
(
964+
'draft/bot' in pretrigger.tags or # can be removed...someday
965+
'bot' in pretrigger.tags
966+
) and
967+
event in ["PRIVMSG", "NOTICE"]
968+
)
962969
is_echo_message = (
963970
nick.lower() == bot.nick.lower() and
964971
event in ["PRIVMSG", "NOTICE"]
@@ -967,6 +974,7 @@ def match_preconditions(self, bot, pretrigger):
967974
return (
968975
self.match_event(event) and
969976
self.match_intent(intent) and
977+
(not is_bot_message or (is_echo_message and self.allow_echo())) and
970978
(not is_echo_message or self.allow_echo())
971979
)
972980

test/plugins/test_plugins_rules.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,23 @@ def test_rule_match_privmsg_action(mockbot):
654654
assert not list(rule.match(mockbot, pretrigger))
655655

656656

657+
def test_rule_match_privmsg_bot_tag(mockbot):
658+
regex = re.compile(r'.*')
659+
rule = rules.Rule([regex])
660+
661+
line = '@draft/bot :[email protected] PRIVMSG #sopel :Hi!'
662+
pretrigger = trigger.PreTrigger(mockbot.nick, line)
663+
assert not list(rule.match(mockbot, pretrigger)), (
664+
'Line with `draft/bot` tag must be ignored'
665+
)
666+
667+
line = '@bot :[email protected] PRIVMSG #sopel :Hi!'
668+
pretrigger = trigger.PreTrigger(mockbot.nick, line)
669+
assert not list(rule.match(mockbot, pretrigger)), (
670+
'Line with final/ratified `bot` tag must be ignored'
671+
)
672+
673+
657674
def test_rule_match_privmsg_echo(mockbot):
658675
line = ':[email protected] PRIVMSG #sopel :Hi!'
659676
pretrigger = trigger.PreTrigger(mockbot.nick, line)

0 commit comments

Comments
 (0)