feat: 支持开关是否忽略自身发送的消息

某些平台如 gewechat 会将自身账号在其他 APP 端发送的消息也当做消息事件下发导致给自己发消息时唤醒机器人

fixes: #890
This commit is contained in:
Soulter
2025-04-15 21:55:21 +08:00
parent 4c02857ec5
commit 589855c393
2 changed files with 17 additions and 0 deletions
+6
View File
@@ -38,6 +38,7 @@ DEFAULT_CONFIG = {
"no_permission_reply": True,
"empty_mention_waiting": True,
"friend_message_needs_wake_prefix": False,
"ignore_bot_self_message": False,
},
"provider": [],
"provider_settings": {
@@ -287,6 +288,11 @@ CONFIG_METADATA_2 = {
"type": "bool",
"hint": "启用后,私聊消息需要唤醒前缀才会被处理,同群聊一样。",
},
"ignore_bot_self_message": {
"description": "是否忽略机器人自身的消息",
"type": "bool",
"hint": "某些平台如 gewechat 会将自身账号在其他 APP 端发送的消息也当做消息事件下发导致给自己发消息时唤醒机器人",
},
"segmented_reply": {
"description": "分段回复",
"type": "object",
@@ -35,10 +35,21 @@ class WakingCheckStage(Stage):
self.friend_message_needs_wake_prefix = self.ctx.astrbot_config[
"platform_settings"
].get("friend_message_needs_wake_prefix", False)
# 是否忽略机器人自己发送的消息
self.ignore_bot_self_message = self.ctx.astrbot_config["platform_settings"].get(
"ignore_bot_self_message", False
)
async def process(
self, event: AstrMessageEvent
) -> Union[None, AsyncGenerator[None, None]]:
if (
self.ignore_bot_self_message
and event.get_self_id() == event.get_sender_id()
):
# 忽略机器人自己发送的消息
event.stop_event()
return
# 设置 sender 身份
event.message_str = event.message_str.strip()
for admin_id in self.ctx.astrbot_config["admins_id"]: