simple-robot / simbot-component-kook

一个 Kotlin 多平台的 KOOK(开黑啦) Bot SDK 实现库,一个 Simple Robot 组件库,Java 友好、异步高效~ ❤️‍🔥❤️‍🔥😘
https://simbot.forte.love/component-kook.html
GNU Lesser General Public License v3.0
19 stars 1 forks source link

接收文件消息时报错 #169

Closed NoMathExpectation closed 3 months ago

NoMathExpectation commented 3 months ago

是否会提供贡献?

版本信息

// simbot
    val simbotVersion = "4.6.0"
    implementation("love.forte.simbot:simbot-core:$simbotVersion")
    compileOnly("love.forte.simbot.common:simbot-common-annotations:$simbotVersion")
    implementation("love.forte.simbot.component:simbot-component-onebot-v11-core:1.3.0")
    implementation("love.forte.simbot.component:simbot-component-kook-core:4.0.0")

涉及的编程语言

Kotlin

项目构建工具

Gradle

内容描述

bot在接受到文件消息时会报错:

20:57:00.418 [DefaultDispatcher-worker-3] WARN  l.f.s.c.k.m.ReceiveMessageContent - Cannot decode card message content to CardMessage, as text.
 kotlinx.serialization.MissingFieldException: Field 'cover' is required for type with serial name 'file', but it was missing at path: $[0].modules[0]
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:95) ~[kotlinx-serialization-json-jvm-1.7.1.jar:?]
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableElement(StreamingJsonDecoder.kt:168) ~[kotlinx-serialization-json-jvm-1.7.1.jar:?]
        at kotlinx.serialization.encoding.CompositeDecoder$DefaultImpls.decodeSerializableElement$default(Decoding.kt:538) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.internal.CollectionLikeSerializer.readElement(CollectionSerializers.kt:80) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.internal.AbstractCollectionSerializer.readElement$default(CollectionSerializers.kt:51) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:36) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.internal.AbstractCollectionSerializer.deserialize(CollectionSerializers.kt:43) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69) ~[kotlinx-serialization-json-jvm-1.7.1.jar:?]
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableElement(StreamingJsonDecoder.kt:168) ~[kotlinx-serialization-json-jvm-1.7.1.jar:?]
        at love.forte.simbot.kook.objects.card.Card$$serializer.deserialize(Card.kt:253) ~[simbot-component-kook-api-jvm-4.0.0.jar:?]
        at love.forte.simbot.kook.objects.card.Card$$serializer.deserialize(Card.kt:253) ~[simbot-component-kook-api-jvm-4.0.0.jar:?]
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69) ~[kotlinx-serialization-json-jvm-1.7.1.jar:?]
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableElement(StreamingJsonDecoder.kt:168) ~[kotlinx-serialization-json-jvm-1.7.1.jar:?]
        at kotlinx.serialization.encoding.CompositeDecoder$DefaultImpls.decodeSerializableElement$default(Decoding.kt:538) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.internal.CollectionLikeSerializer.readElement(CollectionSerializers.kt:80) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.internal.AbstractCollectionSerializer.readElement$default(CollectionSerializers.kt:51) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:36) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.internal.AbstractCollectionSerializer.deserialize(CollectionSerializers.kt:43) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69) ~[kotlinx-serialization-json-jvm-1.7.1.jar:?]
        at love.forte.simbot.kook.objects.card.CardMessageSerializer.deserialize(Card.kt:152) ~[simbot-component-kook-api-jvm-4.0.0.jar:?]
        at love.forte.simbot.kook.objects.card.CardMessageSerializer.deserialize(Card.kt:149) ~[simbot-component-kook-api-jvm-4.0.0.jar:?]
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69) ~[kotlinx-serialization-json-jvm-1.7.1.jar:?]
        at kotlinx.serialization.json.Json.decodeFromString(Json.kt:165) ~[kotlinx-serialization-json-jvm-1.7.1.jar:?]
        at love.forte.simbot.kook.objects.card.CardMessage$Companion.decode(Card.kt:137) ~[simbot-component-kook-api-jvm-4.0.0.jar:?]
        at love.forte.simbot.kook.objects.card.CardMessage$Companion.decode$default(Card.kt:132) ~[simbot-component-kook-api-jvm-4.0.0.jar:?]
        at love.forte.simbot.component.kook.message.KookReceiveMessageContentKt.tryDecodeCardContent(KookReceiveMessageContent.kt:442) ~[simbot-component-kook-core-jvm-4.0.0.jar:?]
        at love.forte.simbot.component.kook.message.KookReceiveMessageContentKt.toMessages(KookReceiveMessageContent.kt:418) ~[simbot-component-kook-core-jvm-4.0.0.jar:?]
        at love.forte.simbot.component.kook.message.KookReceiveMessageContent.messages_delegate$lambda$0(KookReceiveMessageContent.kt:250) ~[simbot-component-kook-core-jvm-4.0.0.jar:?]
        at kotlin.SafePublicationLazyImpl.getValue(LazyJVM.kt:107) ~[kotlin-stdlib-2.0.10.jar:2.0.10-release-540]
        at love.forte.simbot.component.kook.message.KookReceiveMessageContent.getMessages(KookReceiveMessageContent.kt:250) ~[simbot-component-kook-core-jvm-4.0.0.jar:?]
        at love.forte.simbot.component.kook.message.KookReceiveMessageContent.plainText_delegate$lambda$2(KookReceiveMessageContent.kt:253) ~[simbot-component-kook-core-jvm-4.0.0.jar:?]
        at kotlin.SafePublicationLazyImpl.getValue(LazyJVM.kt:107) [kotlin-stdlib-2.0.10.jar:2.0.10-release-540]
        at love.forte.simbot.component.kook.message.KookReceiveMessageContent.getPlainText(KookReceiveMessageContent.kt:252) [simbot-component-kook-core-jvm-4.0.0.jar:?]
        at love.forte.simbot.core.event.impl.EventListenerContextImpl.<init>(SimpleEventDispatcherImpl.kt:390) [simbot-core-jvm-4.6.0.jar:?]
        at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl.dispatchInFlow(SimpleEventDispatcherImpl.kt:368) [simbot-core-jvm-4.6.0.jar:?]
        at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl.access$dispatchInFlow(SimpleEventDispatcherImpl.kt:269) [simbot-core-jvm-4.6.0.jar:?]
        at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl$eventFlow$flow$1.invokeSuspend(SimpleEventDispatcherImpl.kt:340) [simbot-core-jvm-4.6.0.jar:?]
        at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl$eventFlow$flow$1.invoke(SimpleEventDispatcherImpl.kt) [simbot-core-jvm-4.6.0.jar:?]
        at love.forte.simbot.core.event.impl.SimpleEventDispatcherImpl$eventFlow$flow$1.invoke(SimpleEventDispatcherImpl.kt) [simbot-core-jvm-4.6.0.jar:?]
        at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:57) [kotlinx-coroutines-core-jvm-1.8.1.jar:?]
        at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:226) [kotlinx-coroutines-core-jvm-1.8.1.jar:?]
        at kotlinx.coroutines.flow.FlowKt__TransformKt$onEach$$inlined$unsafeTransform$1.collect(SafeCollector.common.kt:112) [kotlinx-coroutines-core-jvm-1.8.1.jar:?]
        at kotlinx.coroutines.flow.FlowKt__CollectKt.collect(Collect.kt:26) [kotlinx-coroutines-core-jvm-1.8.1.jar:?]
        at kotlinx.coroutines.flow.FlowKt.collect(Unknown Source) [kotlinx-coroutines-core-jvm-1.8.1.jar:?]
        at love.forte.simbot.component.kook.bot.internal.KookBotEventsKt$pushAndLaunch$1.invokeSuspend(KookBotEvents.kt:616) [simbot-component-kook-core-jvm-4.0.0.jar:?]
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) [kotlin-stdlib-2.0.10.jar:2.0.10-release-540]
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) [kotlinx-coroutines-core-jvm-1.8.1.jar:?]
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) [kotlinx-coroutines-core-jvm-1.8.1.jar:?]
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811) [kotlinx-coroutines-core-jvm-1.8.1.jar:?]
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715) [kotlinx-coroutines-core-jvm-1.8.1.jar:?]
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702) [kotlinx-coroutines-core-jvm-1.8.1.jar:?]
Caused by: kotlinx.serialization.MissingFieldException: Field 'cover' is required for type with serial name 'file', but it was missing
        at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20) ~[kotlinx-serialization-core-jvm-1.7.1.jar:1.7.1]
        at love.forte.simbot.kook.objects.card.CardModule$Files$File.<init>(Card.kt:790) ~[simbot-component-kook-api-jvm-4.0.0.jar:?]
        at love.forte.simbot.kook.objects.card.CardModule$Files$File$$serializer.deserialize(Card.kt:790) ~[simbot-component-kook-api-jvm-4.0.0.jar:?]
        at love.forte.simbot.kook.objects.card.CardModule$Files$File$$serializer.deserialize(Card.kt:790) ~[simbot-component-kook-api-jvm-4.0.0.jar:?]
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:89) ~[kotlinx-serialization-json-jvm-1.7.1.jar:?]
        ... 56 more

奇怪的是,这条日志只是警告级别,消息也还是能在日志里看到......

ForteScarlet commented 3 months ago

看起来又是一个文档里处处都有、但是实际上没有的JSON属性。

ForteScarlet commented 3 months ago

奇怪的是,这条日志只是警告级别,消息也还是能在日志里看到......

的确,当反序列化出现错误的时候,事件会被降级为 UnknownEvent (应该是叫这个)后继续推送,以便临时处理(比如自行解析JSON字符串,如果有需要的话)

NoMathExpectation commented 3 months ago

image

我觉得可能是因为这个,自己试了一下,接收mp3音乐的时候可以正常解析

ForteScarlet commented 3 months ago

的确,之后会给 cover 加个默认值。 KOOK的文档里几乎所有的属性都没有必要性的说明,从上面的示例来看估计是当时以为无效时会给 ""