From 2908cb3ce26929fb3d01367665bb8e71077ff47b Mon Sep 17 00:00:00 2001 From: StarHeartHunt Date: Fri, 9 Jul 2021 16:02:54 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20tweak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nonebot/adapters/feishu/message.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/nonebot-adapter-feishu/nonebot/adapters/feishu/message.py b/packages/nonebot-adapter-feishu/nonebot/adapters/feishu/message.py index e1c748db..f79c60bf 100644 --- a/packages/nonebot-adapter-feishu/nonebot/adapters/feishu/message.py +++ b/packages/nonebot-adapter-feishu/nonebot/adapters/feishu/message.py @@ -218,11 +218,11 @@ class MessageDeserializer: def deserialize(self) -> Message: dict_mention = {} - if self.type == "post": - if self.mentions: - for mention in self.mentions: - dict_mention[mention["key"]] = mention + if self.mentions: + for mention in self.mentions: + dict_mention[mention["key"]] = mention + if self.type == "post": msg = Message() if self.data["title"] != "": msg += MessageSegment("text", {'text': self.data["title"]}) @@ -237,6 +237,12 @@ class MessageDeserializer: msg += MessageSegment(tag if tag != "img" else "image", seg) return msg._merge() + elif self.type == "text": + for key, mention in dict_mention.items(): + self.data["text"] = self.data["text"].replace(key, f"@{mention['name']}") + self.data["mentions"] = dict_mention + + return Message(MessageSegment(self.type, self.data)) else: return Message(MessageSegment(self.type, self.data))