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"]), + )