From ec5ade90a12c86d28a3a8e5cae75cd30ddeea848 Mon Sep 17 00:00:00 2001 From: rf_tar_railt <3165388245@qq.com> Date: Tue, 16 Apr 2024 14:18:46 +0800 Subject: [PATCH] feat(onebot.v11) impl pull Message resolve #161 --- .mina/onebot-v11.toml | 2 +- avilla/onebot/v11/perform/action/message.py | 44 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/.mina/onebot-v11.toml b/.mina/onebot-v11.toml index 026b3bc9..b0810186 100644 --- a/.mina/onebot-v11.toml +++ b/.mina/onebot-v11.toml @@ -7,7 +7,7 @@ raw-dependencies = [ [project] name = "avilla-onebot-v11" -version = "1.0.0a26" # WIP for release. +version = "1.0.0a27" # WIP for release. authors = [ {name = "GreyElaina", email = "GreyElaina@outlook.com"}, ] diff --git a/avilla/onebot/v11/perform/action/message.py b/avilla/onebot/v11/perform/action/message.py index 2eab728d..9ca0d9c3 100644 --- a/avilla/onebot/v11/perform/action/message.py +++ b/avilla/onebot/v11/perform/action/message.py @@ -204,3 +204,47 @@ async def send_friend_forward_msg(self, target: Selector, forward: Forward) -> S return ( Selector().land(self.account.route["land"]).friend(target.pattern["friend"]).message(result["message_id"]) ) + + @m.pull("land.group.message", Message) + async def get_group_message(self, message: Selector, route: ...) -> Message: + result = await self.account.connection.call( + "get_msg", + { + "message_id": int(message.pattern["message"]), + }, + ) + if result is None: + raise RuntimeError(f"Failed to get message from {message.pattern['group']}: {message}") + if not result["group"]: + raise RuntimeError(f"Failed to get message from {message.pattern['group']}: {message}") + group = Selector().land(self.account.route["land"]).group(str(result["group_id"])) + content = await OneBot11Capability(self.account.staff).deserialize_chain(result["message"]) + return Message( + str(result["message_id"]), + group, + group.member(result["sender"]["user_id"]), + content, + datetime.fromtimestamp(result["time"]), + ) + + @m.pull("land.friend.message", Message) + async def get_friend_message(self, message: Selector, route: ...) -> Message: + result = await self.account.connection.call( + "get_msg", + { + "message_id": int(message.pattern["message"]), + }, + ) + if result is None: + raise RuntimeError(f"Failed to get message from {message.pattern['friend']}: {message}") + if result["group"]: + raise RuntimeError(f"Failed to get message from {message.pattern['friend']}: {message}") + friend = Selector().land(self.account.route["land"]).friend(str(result["user_id"])) + content = await OneBot11Capability(self.account.staff).deserialize_chain(result["message"]) + return Message( + str(result["message_id"]), + friend, + friend, + content, + datetime.fromtimestamp(result["time"]), + )