satorijs / satori

The Universal Messenger Protocol
MIT License
151 stars 43 forks source link

Bug: QQ 适配器未实现部分事件 #183

Closed tuanzisama closed 9 months ago

tuanzisama commented 10 months ago

我正在使用 koishi-thirdeye 注册事件,但无法在方法中正确使用装饰器进行获取对应变量。

  @UseEvent('qq/guild-member-add')
  // onGuildUserJoin(@PutSession() session: QQ.MemberWithGuild, @PutBot() bot: Bot) {
  // onGuildUserJoin(@PutSession() session: QQ.GatewayEvents['GUILD_MEMBER_ADD'], @PutBot() bot: Bot) {
  onGuildUserJoin(session: any, @PutBot() bot: Bot) {
    console.info(session); // original data from adapter-qq (offical qq-guild) 
    console.info(session.bot); // undefined
  }

koishi-thirdeye 使用了下述代码进行处理

export const PutBot = koishiRegistrar.decorateCommandPut(
  (data) => data.argv.session.bot,
);

事件在正确注册后,其装饰器始终为undefined,在查阅调用堆栈后,发现@satori/core有一处判断,删掉了内部事件传递出的Session实例。 我不能确认是设计如此,还是bug,亦或是有其他解决方案能获取适配器内部抛出的Session实例。还请指教,谢谢。

https://github.com/satorijs/satori/blob/1d830da79fc9fe73a4888d975e6155ba19740ea1/packages/core/src/bot.ts#L154C1-L157C6

shigma commented 10 months ago

这是预期的,内部事件不触发会话,而是直接提供平台原生数据包。已经拿到原生数据的情况下确实不需要会话对象。

tuanzisama commented 10 months ago

目前我有一些疑问,在上文举例中的注册新成员加入群组事件,应当使用koishi提供的guild-member-added还是适配器提供的qq/guild-member-add

如若选择后者,在拿到原生数据包后,再调用类似发送消息等API,以何种方式获得koishi的Bot实例呢?还是说仍然使用适配器提供的API?🤔

shigma commented 10 months ago

首先我并不知道有一个 qq/guild-member-add 事件。QQ 官方的 API 似乎没有提供此能力。

如果你说的是更一般的情况,那么其实也分两类:

tuanzisama commented 10 months ago

QQ官方确有此 事件

在实际注册事件中,使用 Koishi 文档中标注的 guild-member-added 事件并不能被触发,相反内部事件可以。遂查看了源代码,实属无奈才去使用的qq/guild-member-add

image

另在刚刚的回复中提到的“直接调用 Bot API”,我不解的是在没有 Session 对象时,如何获取这个Bot实例。

tuanzisama commented 10 months ago

再一次的翻阅了 @koishijs/plugin-adapter-qq 的源码,发现是其内部 utils.ts#adaptSession 没有针对部分QQ官方事件做处理(包括但不限于 GUILD_MEMBER_ADD)。

刚刚在 node_modules/@satorijs/adapter-qq/lib/index.js 中增加了一个if判断 (虽然不应该这样干) , 但 Koishi 的标准化事件(guild-member-added) 被正确触发了。

看起来是漏掉了此类事件了。

shigma commented 10 months ago

是的,我们会把这个事件加上,感谢您的提醒!

tuanzisama commented 10 months ago

感谢您的回复和所有团队成员的贡献。😆

在发现问题所在后,仿佛一切都那么的明朗。🤣

shigma commented 9 months ago

已经实现了,忘了说了 🤣

更新一下即可