Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否提供一个将序列化消息转为 Message 的方式? #61

Open
MeetWq opened this issue Mar 21, 2024 · 1 comment
Open

能否提供一个将序列化消息转为 Message 的方式? #61

MeetWq opened this issue Mar 21, 2024 · 1 comment

Comments

@MeetWq
Copy link

MeetWq commented Mar 21, 2024

目前的需求是获取引用消息的内容,获取消息详情的 api message/view 的返回值是 ChannelMessage,该怎么将它转为 nonebot 中的 Message 呢?

适配器中有 MessageDeserializer 来反序列化,但它似乎是处理消息事件中的字段,和消息详情的返回值有些区别,例如:
Image 是这么反序列化的,

@classmethod
@override
def _deserialize(cls, raw_data: dict) -> Self:
return cls.create(raw_data["attachments"]["url"])

但一个 Image 消息 message/view 的结果中并没有 “attachments”

id_='90625bd9-d961-4dac-b43b-0c004b5f367b'
type=2
content='https://img.kookapp.cn/assets/2024-03/Yxv60BzCYN0hl0u0.gif'
embeds=[]
attachments=None

和这个类似的需求是 chatrecorder 插件,为了记录机器人发出的消息,需要将序列化后的消息反序列化回去,目前 chatrecorder 中是这么写的:
https://github.com/noneplugin/nonebot-plugin-chatrecorder/blob/5f390660e3c0567d1ed41134968261623cdd2f54/nonebot_plugin_chatrecorder/adapters/kaiheila.py#L78-L96

@Tian-que
Copy link
Owner

Tian-que commented Apr 29, 2024

明白你的意图,api和返回值和实际的消息event是有出入,这里如果已经存储了被引用的消息,是否可以通过msg_id来查询

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants