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

Bug: bot.editMessage 无法支持某些 message elements #1342

Open
tzwm opened this issue Jan 22, 2024 · 2 comments
Open

Bug: bot.editMessage 无法支持某些 message elements #1342

tzwm opened this issue Jan 22, 2024 · 2 comments

Comments

@tzwm
Copy link

tzwm commented Jan 22, 2024

Describe the bug

同样一个 message elements,直接 session.send 发送能正常渲染,但是 editMessage 无法正确渲染。
image

this.ctx.command('test <prompt:string>')
  .action(async (argv: Argv, prompt: string) => {
    const msgStr = '"city 4" - <at id="4444" />';
    const msg = h.parse(msgStr);
    await this.ctx.bots[0].editMessage(
      '4444',
      '4444',
      msg,
    );
    await argv.session.send(msgStr);
  });

Steps to reproduce

见上述代码。

Expected behavior

预期和 session.send 有一致的渲染表现。

Screenshots

No response

Versions

  • OS: macOS
  • Platform: Discord
  • Node version: v.20.5.1
  • Koishi version: v4.16.6

Additional context

No response

@tzwm tzwm added the bug BUG label Jan 22, 2024
@CyanChanges
Copy link

CyanChanges commented Jan 29, 2024

主要问题就是在 Discord 的 editMessage 不会将 Satori 的 Fragment 转换为对应平台的格式
然后直接发送出去了, 然后平台 (Discord) 不认 Satori Elements, 就直接显示了

正常 session.send 的流程:

session.send 调用 bot.sendMessage L150

async send(fragment: Fragment, options: Universal.SendOptions = {}) {
if (!fragment) return
options.session = this
return this.bot.sendMessage(this.channelId, fragment, this.guildId, options).catch<string[]>((error) => {
logger.warn(error)
return []
})
}

然后看这边, 调用了 bot.createMessage L167
https://github.com/satorijs/satori/blob/5c0b8d6d715df11908ec3be8efbfe9bf31868bc3/packages/core/src/bot.ts#L167

然后用了 MessageEncoder 进行转换 - 将 Satori Elements 转换成对应平台的东西, L163
https://github.com/satorijs/satori/blob/5c0b8d6d715df11908ec3be8efbfe9bf31868bc3/packages/core/src/message.ts#L26

image
然后 MessageEncoder DiscordMessageEncoder 的 .flush()
再调用 Discord 内部的 API 发送出去
https://github.com/satorijs/satori/blob/5c0b8d6d715df11908ec3be8efbfe9bf31868bc3/packages/core/src/bot.ts#L163

session.bot.editMessage 的流程

拿到 session, 直接调用 bot.editMessage
https://github.com/satorijs/satori/blob/5c0b8d6d715df11908ec3be8efbfe9bf31868bc3/adapters/discord/src/bot.ts#L71-L81
这边用 h.normalize 确保了是 Satori Elements... L72
然后直接 toString 了??? L63
这边可以看到没有做任何对应平台的转换
image
https://github.com/satorijs/satori/blob/5c0b8d6d715df11908ec3be8efbfe9bf31868bc3/adapters/discord/src/bot.ts#L72-L73
然后调用了内部的 editMessage 方法, 向 Discord 的 Bot API 发送请求来 edit
https://github.com/satorijs/satori/blob/5c0b8d6d715df11908ec3be8efbfe9bf31868bc3/adapters/discord/src/bot.ts#L78
然而 Discord 肯定是不认 Satori Elements 的, 然后就直接显示出来了
image

@shigma
Copy link
Member

shigma commented Jan 29, 2024

这是 bug,会修。

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

No branches or pull requests

3 participants