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

`MessageContent` 的被引用消息指向的是消息本身而不是被引用的消息 #174

Closed NoMathExpectation closed 2 weeks ago

NoMathExpectation commented 2 weeks 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.4.0")
    implementation("love.forte.simbot.component:simbot-component-kook-core:4.0.1")

涉及的编程语言

Kotlin

项目构建工具

Gradle

内容描述

自己手搓了一个获取被引用的消息的指令,并打印到日志里。

suspend fun LiteralSelectionCommandNode<AnyExecuteContext>.commandRef() =
    literal("ref")
        .requiresPermission("command.experimental.ref")
        .executes {
            logger.info { it.originalMessage?.referenceMessage?.messages?.toReadableString() }
        }

在kook上执行时,打印的却是消息本身: image

image

ForteScarlet commented 2 weeks ago

logger.info { it.originalMessage?.referenceMessage?.messages?.toReadableString() }

这里的 it.originalMessage 的类型就是对应的 MessageContent 是吗

NoMathExpectation commented 2 weeks ago

logger.info { it.originalMessage?.referenceMessage?.messages?.toReadableString() }

这里的 it.originalMessage 的类型就是对应的 MessageContent 是吗

是的,因为这个指令系统是分析转换为字符串后的消息,所以需要绑定一个对应原始消息方便指令处理

ForteScarlet commented 2 weeks ago

好的。 题外话顺带一提:Kotlin 里按理说应该使用挂起函数 content.referenceMessage() 而不是阻塞属性 content.rferenceMessage,如果在Kotlin里使用非挂起的属性或函数应当会有警告才对,这些阻塞API都是为了Java而设计的

NoMathExpectation commented 2 weeks ago

好的。 题外话顺带一提:Kotlin 里按理说应该使用挂起函数 content.referenceMessage() 而不是阻塞属性 content.rferenceMessage,如果在Kotlin里使用非挂起的属性或函数应当会有警告才对,这些阻塞API都是为了Java而设计的

即使用这个属性idea也完全没有警告的说...

ForteScarlet commented 2 weeks ago

image 没有类似这种的提示吗?

NoMathExpectation commented 2 weeks ago

image 没有类似这种的提示吗?

image

ForteScarlet commented 2 weeks ago

怪事,也没有直接通过idea快速修复加上的 @Opt(Api4J::class)

NoMathExpectation commented 2 weeks ago

怪事,也没有直接通过idea快速修复加上的 @Opt(Api4J::class)

没有,完全没有任何OptIn

ForteScarlet commented 2 weeks ago

好吧,这个问题有空我再看看有没有办法改善吧。不过至少现在你知道了( 可以把这类阻塞属性或阻塞函数都换成对应的挂起API