Bug: 数据类型错误导致无法禁言
TTsdzb opened this issue · 2 comments
TTsdzb commented
问题
Koishi 无法正常在 Onebot 平台禁言用户。
问题原因
根据 Onebot 11 标准,禁言用户的时长(duration
参数)的类型为数字,但适配器给出的参数为字符串(参考下面日志)。这导致 Onebot 实现无法解析参数。
日志
Koishi 侧
2024-01-21 12:46:55 [W] app Error: Error with request set_group_ban, args: {"group_id":857603454,"user_id":3566233109,"duration":"600"}, retcode: 200
at Internal._get (/home/l/koishi/node_modules/.pnpm/koishi-plugin-adapter-onebot@6.4.0_koishi@4.16.4node_modules/koishi-plugin-adapter-onebot/lib/types.js:44:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Internal.<computed> [as setGroupBan] (/home/l/koishi/node_modules/.pnpm/koishi-plugin-adapter-nebot@6.4.0_koishi@4.16.4/node_modules/koishi-plugin-adapter-onebot/lib/types.js:73:26)
已经确定不是 pnpm 引发的问题。使用 npm 会出现一模一样的问题。
Onebot 侧
使用的实现为 Lagrange.OneBot Build a1530fd
warn: Lagrange.OneBot.Core.Operation.OperationService[0]
Unexpected error encountered while handling message.
System.Text.Json.JsonException: The JSON value could not be converted to System.UInt32. Path: $.duration | LineNumber: 0 | ytePositionInLine: 59.
---> System.InvalidOperationException: Cannot get the value of a token type 'String' as a number.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedNumber(JsonTokenType tokenType)
at System.Text.Json.Utf8JsonReader.TryGetUInt32(UInt32& value)
at System.Text.Json.Utf8JsonReader.GetUInt32()
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
at System.Text.Json.JsonSerializer.ReadNode[TValue](JsonNode node, JsonTypeInfo jsonTypeInfo)
at Lagrange.OneBot.Core.Operation.Group.SetGroupBanOperation.HandleOperation(BotContext context, JsonObject payload) in D:\a\Lagrange.Core\Lagrange.Core\Lagrange.OneBot\Core\Operation\Group\SetGroupBanOperation.cs:line 14
at Lagrange.OneBot.Core.Operation.OperationService.HandleOperation(MsgRecvEventArgs e) in D:\a\Lagrange.Core\Lagrange.Core\Lagrange.OneBot\Core\Operation\OperationService.cs:line 51
触发问题的插件
koishi-plugin-russian-roulette
相关版本
NodeJS: 21.5.0
koishi: 4.16.4
koishi-plugin-adapter-onebot: 6.4.0
koishi-plugin-russian-roulette: 1.0.1
TTsdzb commented
引起问题的插件 JS 文件与仓库中的 TS 文件差别较大,可能有较多更改没有更新。
正在测试实际插件中可能引发问题的原因。
TTsdzb commented
经测试该问题由插件不正确的方法调用引发。插件在调用时传递的 duration
参数为字符串而不是数字,导致该问题。