simple-robot / simpler-robot

Simple Robot,一个bot风格的Kotlin多平台事件调度框架,异步高效、Java友好!/ A Bot-style Kotlin Multiplatform event scheduling framework, asynchronous and high-performance, java-friendly! 🐱😼😻😸
https://simbot.forte.love
GNU Lesser General Public License v3.0
520 stars 43 forks source link

Kook无法解析特定CardMessage消息 #706

Closed axiangcoding closed 1 year ago

axiangcoding commented 1 year ago

版本号

v3.1.0

附加版本

simbot-component-kook-core:3.0.0.0-alpha.6

涉及的编程语言

Java

项目构建工具

Gradle

涉及的组件库

KOOK

问题描述

解析一些格式的CardMessage失败

复现方式

将下文消息发送到一个监听的频道中,即可稳定复现

监听代码如下,springboot项目中注册bean:

@Component
@Slf4j
public class MyListener {
    @Listener
    @Filter(targets = @Filter.Targets(atBot = true))
    public void onEvent(ChannelMessageEvent event) {
        log.info("监听到了 {}", event.getMessageContent().getPlainText());
        event.replyAsync("你好,我是机器人");
        event.replyAsync("再发一条");
    }
}

相关日志

2023-06-27T21:10:11.484+08:00  WARN 57732 --- [         task-9] l.f.s.c.k.m.ReceiveMessageContent        : [: ] Cannot decode card message content to CardMessage, as text.

kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 78: Expected beginning of the string, but got { at path: $[0].modules[0].text
JSON input: .....les":[{"type":"header","text":{"type":"plain-text","emoji":t.....
    at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:24) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:32) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.json.internal.AbstractJsonLexer.fail(AbstractJsonLexer.kt:584) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$default(AbstractJsonLexer.kt:582) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.json.internal.AbstractJsonLexer.consumeStringLenient(AbstractJsonLexer.kt:453) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.json.internal.AbstractJsonLexer.consumeStringLenientNotNull(AbstractJsonLexer.kt:425) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeString(StreamingJsonDecoder.kt:343) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.encoding.AbstractDecoder.decodeStringElement(AbstractDecoder.kt:58) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at love.forte.simbot.kook.objects.CardModule$Header$$serializer.deserialize(Card.kt:490) ~[simbot-component-kook-api-3.0.0.0-alpha.6.jar:?]
    at love.forte.simbot.kook.objects.CardModule$Header$$serializer.deserialize(Card.kt:490) ~[simbot-component-kook-api-3.0.0.0-alpha.6.jar:?]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:86) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableElement(StreamingJsonDecoder.kt:165) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.encoding.CompositeDecoder$DefaultImpls.decodeSerializableElement$default(Decoding.kt:533) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.internal.CollectionLikeSerializer.readElement(CollectionSerializers.kt:80) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.internal.AbstractCollectionSerializer.readElement$default(CollectionSerializers.kt:51) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:36) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.internal.AbstractCollectionSerializer.deserialize(CollectionSerializers.kt:43) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:70) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableElement(StreamingJsonDecoder.kt:165) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at love.forte.simbot.kook.objects.Card$$serializer.deserialize(Card.kt:245) ~[simbot-component-kook-api-3.0.0.0-alpha.6.jar:?]
    at love.forte.simbot.kook.objects.Card$$serializer.deserialize(Card.kt:245) ~[simbot-component-kook-api-3.0.0.0-alpha.6.jar:?]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:70) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableElement(StreamingJsonDecoder.kt:165) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.encoding.CompositeDecoder$DefaultImpls.decodeSerializableElement$default(Decoding.kt:533) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.internal.CollectionLikeSerializer.readElement(CollectionSerializers.kt:80) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.internal.AbstractCollectionSerializer.readElement$default(CollectionSerializers.kt:51) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:36) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.internal.AbstractCollectionSerializer.deserialize(CollectionSerializers.kt:43) ~[kotlinx-serialization-core-jvm-1.5.1.jar:1.5.1]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:70) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at love.forte.simbot.kook.objects.CardMessageSerializer.deserialize(Card.kt:144) ~[simbot-component-kook-api-3.0.0.0-alpha.6.jar:?]
    at love.forte.simbot.kook.objects.CardMessageSerializer.deserialize(Card.kt:141) ~[simbot-component-kook-api-3.0.0.0-alpha.6.jar:?]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:70) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at kotlinx.serialization.json.Json.decodeFromString(Json.kt:107) ~[kotlinx-serialization-json-jvm-1.5.1.jar:?]
    at love.forte.simbot.kook.objects.CardMessage$Companion.decode(Card.kt:129) ~[simbot-component-kook-api-3.0.0.0-alpha.6.jar:?]
    at love.forte.simbot.kook.objects.CardMessage$Companion.decode$default(Card.kt:126) ~[simbot-component-kook-api-3.0.0.0-alpha.6.jar:?]
    at love.forte.simbot.component.kook.message.KookReceiveMessageContentKt.tryDecodeCardContent(KookReceiveMessageContent.kt:197) [simbot-component-kook-core-3.0.0.0-alpha.6.jar:?]
    at love.forte.simbot.component.kook.message.KookReceiveMessageContentKt.toMessages(KookReceiveMessageContent.kt:172) [simbot-component-kook-core-3.0.0.0-alpha.6.jar:?]
    at love.forte.simbot.component.kook.message.KookReceiveMessageContent$messages$2.invoke(KookReceiveMessageContent.kt:117) [simbot-component-kook-core-3.0.0.0-alpha.6.jar:?]
    at love.forte.simbot.component.kook.message.KookReceiveMessageContent$messages$2.invoke(KookReceiveMessageContent.kt:117) [simbot-component-kook-core-3.0.0.0-alpha.6.jar:?]
    at kotlin.SafePublicationLazyImpl.getValue(LazyJVM.kt:107) [kotlin-stdlib-1.8.22.jar:1.8.22-release-407(1.8.22)]
    at love.forte.simbot.component.kook.message.KookReceiveMessageContent.getMessages(KookReceiveMessageContent.kt:117) [simbot-component-kook-core-3.0.0.0-alpha.6.jar:?]
    at love.forte.simbot.message.MessageContent$plainText$2.invoke(MessageContent.kt:42) [simbot-api-3.1.0.jar:?]
    at love.forte.simbot.message.MessageContent$plainText$2.invoke(MessageContent.kt:41) [simbot-api-3.1.0.jar:?]
    at kotlin.SafePublicationLazyImpl.getValue(LazyJVM.kt:107) [kotlin-stdlib-1.8.22.jar:1.8.22-release-407(1.8.22)]
    at love.forte.simbot.message.MessageContent.getPlainText(MessageContent.kt:41) [simbot-api-3.1.0.jar:?]
    at love.forte.simbot.core.event.CoreEventListenerProcessingContext.<init>(SimpleEventListenerManagerImpl.kt:516) [simbot-core-3.1.0.jar:?]
    at love.forte.simbot.core.event.SimpleEventListenerManagerImplKt.withListener(SimpleEventListenerManagerImpl.kt:507) [simbot-core-3.1.0.jar:?]
    at love.forte.simbot.core.event.SimpleEventListenerManagerImplKt.access$withListener(SimpleEventListenerManagerImpl.kt:1) [simbot-core-3.1.0.jar:?]
    at love.forte.simbot.core.event.SimpleEventListenerManagerImpl$doInvoke$2$1$1.invokeSuspend(SimpleEventListenerManagerImpl.kt:309) [simbot-core-3.1.0.jar:?]
    at love.forte.simbot.core.event.SimpleEventListenerManagerImpl$doInvoke$2$1$1.invoke(SimpleEventListenerManagerImpl.kt) [simbot-core-3.1.0.jar:?]
    at love.forte.simbot.core.event.SimpleEventListenerManagerImpl$doInvoke$2$1$1.invoke(SimpleEventListenerManagerImpl.kt) [simbot-core-3.1.0.jar:?]
    at love.forte.simbot.core.event.EventProcessingDirectInterceptEntrance.doIntercept(EventInterceptEntrance.kt:116) [simbot-core-3.1.0.jar:?]
    at love.forte.simbot.core.event.SimpleEventListenerManagerImpl$doInvoke$2.invokeSuspend(SimpleEventListenerManagerImpl.kt:306) [simbot-core-3.1.0.jar:?]
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) [kotlin-stdlib-1.8.22.jar:1.8.22-release-407(1.8.22)]
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) [kotlinx-coroutines-core-jvm-1.6.4.jar:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
    at java.lang.Thread.run(Thread.java:833) [?:?]

其他补充

对应的CardMessage的json如下:

[
  {
    "theme": "success",
    "color": "",
    "size": "lg",
    "modules": [
      {
        "type": "header",
        "text": {
          "type": "plain-text",
          "emoji": true,
          "content": "你好,我是AXBot",
          "elements": []
        },
        "elements": []
      },
      {
        "type": "divider",
        "elements": []
      },
      {
        "type": "section",
        "mode": "left",
        "accessory": null,
        "text": {
          "type": "kmarkdown",
          "content": "现在是北京时间: 2023-06-27T21:10:10.387599529",
          "elements": []
        },
        "elements": []
      },
      {
        "type": "section",
        "mode": "left",
        "accessory": null,
        "text": {
          "type": "kmarkdown",
          "content": "你似乎输入了一个错误的命令:你好",
          "elements": []
        },
        "elements": []
      },
      {
        "type": "section",
        "mode": "left",
        "accessory": null,
        "text": {
          "type": "kmarkdown",
          "content": "需要我做些什么呢?如果不知道怎么开始,可以输入 axbot 帮助 开始探索",
          "elements": []
        },
        "elements": []
      },
      {
        "type": "divider",
        "elements": []
      },
      {
        "type": "section",
        "mode": "right",
        "accessory": {
          "type": "button",
          "theme": "primary",
          "value": "https://www.kookapp.cn/app/oauth2/authorize?id=15253&permissions=924672&client_id=eXJ0-Ntgqw-q33Oe&redirect_uri=&scope=bot",
          "click": "link",
          "text": {
            "type": "kmarkdown",
            "content": "邀请AXBot",
            "elements": []
          },
          "external": false,
          "elements": []
        },
        "text": {
          "type": "kmarkdown",
          "content": "邀请机器人加入你的服务器!",
          "elements": []
        },
        "elements": []
      },
      {
        "type": "divider",
        "elements": []
      },
      {
        "type": "section",
        "mode": "right",
        "accessory": {
          "type": "button",
          "theme": "info",
          "value": "https://github.com/axiangcoding/AXBot",
          "click": "link",
          "text": {
            "type": "kmarkdown",
            "content": "GitHub",
            "elements": []
          },
          "external": true,
          "elements": []
        },
        "text": {
          "type": "kmarkdown",
          "content": "Powered By AXBot.",
          "elements": []
        },
        "elements": []
      }
    ],
    "type": "card"
  }
]
ForteScarlet commented 1 year ago

尝试开启 love.forte.simbot.component.kook.botTRACE 级别日志并尝试提供在接收事件时的原始 JSON 字符串, 这个日志的文本部分内容可能是这个样子的:

On signal: { ... }

On signal: 开头。

axiangcoding commented 1 year ago

尝试开启 love.forte.simbot.component.kook.botTRACE 级别日志并尝试提供在接收事件时的原始 JSON 字符串, 这个日志的文本部分内容可能是这个样子的:

On signal: { ... }

On signal: 开头。

找到一条相关的

2023-06-27T23:49:42.186+08:00 DEBUG 65988 --- [         task-2] l.f.s.c.k.m.ReceiveMessageContent        : [: ] Cannot decode card message content [[{"theme":"success","color":"","size":"lg","modules":[{"type":"header","text":{"type":"plain-text","emoji":true,"content":"你好,我是AXBot","elements":[]},"elements":[]},{"type":"divider","elements":[]},{"type":"section","mode":"left","accessory":null,"text":{"type":"kmarkdown","content":"现在是北京时间: *2023-06-27T23:49:41.634649792*","elements":[]},"elements":[]},{"type":"section","mode":"left","accessory":null,"text":{"type":"kmarkdown","content":"你似乎输入了一个错误的命令:`你好`","elements":[]},"elements":[]},{"type":"section","mode":"left","accessory":null,"text":{"type":"kmarkdown","content":"需要我做些什么呢?如果不知道怎么开始,可以输入 `axbot 帮助` 开始探索","elements":[]},"elements":[]},{"type":"divider","elements":[]},{"type":"section","mode":"right","accessory":{"type":"button","theme":"primary","value":"https:\/\/www.kookapp.cn\/app\/oauth2\/authorize?id=15253&permissions=924672&client_id=eXJ0-Ntgqw-q33Oe&redirect_uri=&scope=bot","click":"link","text":{"type":"kmarkdown","content":"邀请AXBot","elements":[]},"external":false,"elements":[]},"text":{"type":"kmarkdown","content":"邀请机器人加入你的服务器!","elements":[]},"elements":[]},{"type":"divider","elements":[]},{"type":"section","mode":"right","accessory":{"type":"button","theme":"info","value":"https:\/\/github.com\/axiangcoding\/AXBot","click":"link","text":{"type":"kmarkdown","content":"GitHub","elements":[]},"external":true,"elements":[]},"text":{"type":"kmarkdown","content":"Powered By AXBot.","elements":[]},"elements":[]}],"type":"card"}]] to CardMessage, as text.
axiangcoding commented 1 year ago

看起来是

[
  [
    {
      "theme": "success",
      "color": "",
      "size": "lg",
      "modules": [
        {
          "type": "header",
          "text": {            # 这里识别为 字符串了,而实际上是个对象
            "type": "plain-text",
            "emoji": true,
            "content": "你好,我是AXBot",
            "elements": []
          },
          "elements": []
        },
        { "type": "divider", "elements": [] },
        {
ForteScarlet commented 1 year ago

使用快照时注意添加快照仓库地址

repositories {
    mavenCentral()
    // 快照仓库
    maven {
        url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
        mavenContent {
            snapshotsOnly()
        }
    }
}