Files
LangBot/pkg/pipeline/resprule/rules/atbot.py
2025-09-30 21:16:27 +08:00

29 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from __future__ import annotations
from .. import rule as rule_model
from .. import entities
import langbot_plugin.api.entities.builtin.platform.message as platform_message
import langbot_plugin.api.entities.builtin.pipeline.query as pipeline_query
@rule_model.rule_class('at-bot')
class AtBotRule(rule_model.GroupRespondRule):
async def match(
self,
message_text: str,
message_chain: platform_message.MessageChain,
rule_dict: dict,
query: pipeline_query.Query,
) -> entities.RuleJudgeResult:
def remove_at(message_chain: platform_message.MessageChain):
for component in message_chain.root:
if isinstance(component, platform_message.At) and component.target == query.adapter.bot_account_id:
message_chain.remove(component)
break
remove_at(message_chain)
remove_at(message_chain) # 回复消息时会at两次检查并删除重复的
return entities.RuleJudgeResult(matching=False, replacement=message_chain)