Skip to content

Commit

Permalink
feat(onebot.v11) impl pull Message
Browse files Browse the repository at this point in the history
resolve #161
  • Loading branch information
RF-Tar-Railt committed Apr 16, 2024
1 parent 2c6e077 commit ec5ade9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .mina/onebot-v11.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"},
]
Expand Down
44 changes: 44 additions & 0 deletions avilla/onebot/v11/perform/action/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
)

0 comments on commit ec5ade9

Please sign in to comment.