HydroGest / YesImBot

机械壳,人类心。
https://yesimbot.ccalliance.tech
MIT License
42 stars 5 forks source link

[bug] finalReplyId和groupId不一致时,报错 #62

Closed Touch-Night closed 2 days ago

Touch-Night commented 3 days ago

https://github.com/HydroGest/YesImBot/blob/3625be3e5ed0c594397ce6478de663fe4a321fec/src/index.ts#L499 在finalReplyTo为"private:1762918301",且groupId为"186782726"时报错如下:

RangeError: The number NaN cannot be converted to a BigInt because it is not an integer
                            at BigInt (<anonymous>)
                            at Internal.prepareArg (E:\Koishi\dev\yesimbot\node_modules\koishi-plugin-adapter-onebot\lib\index.js:142:13)
                            at _Internal.<computed> [as sendGroupMsg] (E:\Koishi\dev\yesimbot\node_modules\koishi-plugin-adapter-onebot\lib\index.js:162:52)
                            at OneBotMessageEncoder.flush (E:\Koishi\dev\yesimbot\node_modules\koishi-plugin-adapter-onebot\lib\index.js:763:354)
                            at OneBotMessageEncoder.send (E:\Koishi\dev\yesimbot\node_modules\@satorijs\core\src\message.ts:54:16)
                            at async Proxy.sendMessage (E:\Koishi\dev\yesimbot\node_modules\@satorijs\core\src\bot.ts:188:22)
                            at async <anonymous> (E:\Koishi\dev\yesimbot\external\yesimbot\src\index.ts:502:24)
                            at async next (E:\Koishi\dev\yesimbot\node_modules\@koishijs\core\src\middleware.ts:258:16)
                            at async next (E:\Koishi\dev\yesimbot\node_modules\@koishijs\core\src\middleware.ts:258:16)
                            at async next (E:\Koishi\dev\yesimbot\node_modules\@koishijs\core\src\middleware.ts:258:16)

而在finalReplyTo为"186782726",groupId为"private:1762918301"时,报错却如下:

Error: Error with request send_private_msg, args: {"user_id":6,"message":[{"type":"at","data":{"qq":"1762918301","name":"Touch Night"}},{"type":"text","data":{"text":" 本大王见识过无数挑战,这些小点子也想困住本大 王?"}}]}, retcode: 1200
                            at _Internal._get (E:\Koishi\dev\yesimbot\node_modules\koishi-plugin-adapter-onebot\lib\index.js:119:11)
                            at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
                            at async _Internal.<computed> [as sendPrivateMsg] (E:\Koishi\dev\yesimbot\node_modules\koishi-plugin-adapter-onebot\lib\index.js:162:20)
                            at async OneBotMessageEncoder.flush (E:\Koishi\dev\yesimbot\node_modules\koishi-plugin-adapter-onebot\lib\index.js:763:227)
                            at async OneBotMessageEncoder.send (E:\Koishi\dev\yesimbot\node_modules\@satorijs\core\src\message.ts:54:5)
                            at async Proxy.sendMessage (E:\Koishi\dev\yesimbot\node_modules\@satorijs\core\src\bot.ts:188:22)
                            at async <anonymous> (E:\Koishi\dev\yesimbot\external\yesimbot\src\index.ts:502:24)
                            at async next (E:\Koishi\dev\yesimbot\node_modules\@koishijs\core\src\middleware.ts:258:16)
                            at async next (E:\Koishi\dev\yesimbot\node_modules\@koishijs\core\src\middleware.ts:258:16)
                            at async next (E:\Koishi\dev\yesimbot\node_modules\@koishijs\core\src\middleware.ts:258:16)

改为finalBotMsgId = (await session.bot.sendMessage(finalReplyTo, sentence, null))[0];后恢复正常

@MiaowFISH

MiaowFISH commented 3 days ago

groupId怎么能是private:xxx呢🤔 翻koishi源码,只有两种消息类型: [Group|Channel] 和 private, 前者有 groupId 和 channelId 且相同,后者只有 channelId

Touch-Night commented 3 days ago

私聊时的channelId是private:xxx

MiaowFISH commented 2 days ago

那改回来吧,mock插件年久失修,debug到现在还没找到兼容的方法。要测试的话我手动改一下好了

MiaowFISH commented 2 days ago

另外,const groupId: string = session.guildId || session.channelId;是否有些不妥当。毕竟从字面意义上来看group明显有别于private

MiaowFISH commented 2 days ago

私聊时的channelId是private:xxx

是的,群聊是群号,私聊是private:xxx,所以一般情况下只需要传递channelId即可 至于为什么finalReplyId和groupId不一致时会报错,猜测应该是传入的session覆盖了先前的finalReplyId(koi貌似是根据channelId判断群聊或者私聊,用guildId指定从哪个群发起的群聊/私聊)导致channel和guild不匹配,错误地调用了send_private_msg

MiaowFISH commented 2 days ago

鉴于finalReplyId要么是groupId(quoteGroup也算),要么是由LLM返回的replyTo,标题建议修改为手动指定 finalReplyId 时,发送消息报错一句不一致让我多花了好多时间

Touch-Night commented 2 days ago

如果groupId和finalReplyId一致,即使finalReplyId是手动指定的,也不会报错

MiaowFISH commented 2 days ago

猜测应该是传入的session覆盖了先前的finalReplyId(koi貌似是根据channelId判断群聊或者私聊,用guildId指定从哪个群发起的群聊/私聊)导致channel和guild不匹配,错误地调用了send_private_msg

建议也去koishi那反馈下