Tian-que / nonebot-adapter-kaiheila

Kaiheila adapter for nonebot2
MIT License
27 stars 9 forks source link

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

Open MeetWq opened 6 months ago

MeetWq commented 6 months ago

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

适配器中有 MessageDeserializer 来反序列化,但它似乎是处理消息事件中的字段,和消息详情的返回值有些区别,例如: Image 是这么反序列化的, https://github.com/Tian-que/nonebot-adapter-kaiheila/blob/09efbee0f292361854ab0c8ed4a4b44504d52bec/nonebot/adapters/kaiheila/message.py#L343-L346 但一个 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 commented 5 months ago

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