diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/api/simbot-component-onebot-v11-core.api b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/api/simbot-component-onebot-v11-core.api index 1c055a2..c3bc070 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/api/simbot-component-onebot-v11-core.api +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/api/simbot-component-onebot-v11-core.api @@ -1810,6 +1810,8 @@ public abstract interface class love/forte/simbot/component/onebot/v11/core/bot/ public abstract fun getName ()Ljava/lang/String; public abstract fun getUserId ()Llove/forte/simbot/common/id/ID; public abstract fun isMe (Llove/forte/simbot/common/id/ID;)Z + public synthetic fun messageFromIdBlocking (Llove/forte/simbot/common/id/ID;)Llove/forte/simbot/message/MessageContent; + public synthetic fun messageFromReferenceBlocking (Llove/forte/simbot/message/MessageReference;)Llove/forte/simbot/message/MessageContent; public abstract fun push (Ljava/lang/String;)Lkotlinx/coroutines/flow/Flow; public fun pushAndLaunch (Ljava/lang/String;)Lkotlinx/coroutines/Job; public abstract synthetic fun queryLoginInfo (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBot.kt b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBot.kt index 1b23bc6..d35901e 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBot.kt +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBot.kt @@ -18,7 +18,6 @@ package love.forte.simbot.component.onebot.v11.core.bot import io.ktor.client.* -import io.ktor.client.statement.* import io.ktor.http.* import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow @@ -42,6 +41,7 @@ import love.forte.simbot.component.onebot.v11.core.actor.OneBotStranger import love.forte.simbot.component.onebot.v11.core.api.* import love.forte.simbot.component.onebot.v11.message.OneBotMessageContent import love.forte.simbot.event.EventResult +import love.forte.simbot.message.MessageReference import love.forte.simbot.suspendrunner.ST import kotlin.coroutines.CoroutineContext import kotlin.jvm.JvmSynthetic @@ -241,13 +241,50 @@ public interface OneBotBot : Bot, OneBotApiExecutable { * 注意:此API是实验性的,未来可能会随时被变更或删除。 * * @see GetMsgApi - * @throws Throwable 任何API请求过程中可能产生的异常, - * 例如消息不存在 + * @throws RuntimeException 任何API请求过程中可能产生的异常, + * 例如消息不存在或反序列化错误。 */ @ST @ExperimentalOneBotAPI public suspend fun getMessageContent(messageId: ID): OneBotMessageContent + /** + * 根据 [id] 使用 [GetMsgApi] 查询消息内容, + * 并得到对应的 [OneBotMessageContent]。 + * + * 注意:此API是实验性的,未来可能会随时被变更或删除, + * 同 [getMessageContent]。 + * + * @see GetMsgApi + * @see getMessageContent + * @throws RuntimeException 任何API请求过程中可能产生的异常, + * 例如消息不存在或反序列化错误。 + * + * @since 1.3.0 + */ + @ST + @ExperimentalOneBotAPI + override suspend fun messageFromId(id: ID): OneBotMessageContent = getMessageContent(id) + + /** + * 根据消息引用的id使用 [GetMsgApi] 查询消息内容, + * 并得到对应的 [OneBotMessageContent]。 + * + * 注意:此API是实验性的,未来可能会随时被变更或删除, + * 同 [getMessageContent]。 + * + * @see getMessageContent + * + * @see GetMsgApi + * @throws RuntimeException 任何API请求过程中可能产生的异常, + * 例如消息不存在或反序列化错误。 + * + * @since 1.3.0 + */ + @ST + @ExperimentalOneBotAPI + override suspend fun messageFromReference(reference: MessageReference): OneBotMessageContent = + getMessageContent(id) } diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/internal/message/OneBotMessageContentImpl.kt b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/internal/message/OneBotMessageContentImpl.kt index 95b6a4c..24bd962 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/internal/message/OneBotMessageContentImpl.kt +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/internal/message/OneBotMessageContentImpl.kt @@ -21,10 +21,12 @@ import love.forte.simbot.ability.DeleteOption import love.forte.simbot.ability.StandardDeleteOption import love.forte.simbot.common.id.ID import love.forte.simbot.component.onebot.v11.core.api.DeleteMsgApi +import love.forte.simbot.component.onebot.v11.core.api.GetMsgApi import love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl import love.forte.simbot.component.onebot.v11.message.OneBotMessageContent import love.forte.simbot.component.onebot.v11.message.resolveToMessageElement import love.forte.simbot.component.onebot.v11.message.segment.OneBotMessageSegment +import love.forte.simbot.component.onebot.v11.message.segment.OneBotReply import love.forte.simbot.component.onebot.v11.message.segment.OneBotText import love.forte.simbot.message.Messages import love.forte.simbot.message.toMessages @@ -56,6 +58,13 @@ internal class OneBotMessageContentImpl( sb?.toString() } + override suspend fun referenceMessage(): OneBotMessageContent? { + val ref = messages.firstNotNullOfOrNull { it as? OneBotReply } + ?: return null + + return bot.getMessageContent(ref.id) + } + override suspend fun delete(vararg options: DeleteOption) { runCatching { bot.executeData(DeleteMsgApi.create(id)) diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-message/api/simbot-component-onebot-v11-message.api b/simbot-component-onebot-v11/simbot-component-onebot-v11-message/api/simbot-component-onebot-v11-message.api index 97df05e..704bc76 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-message/api/simbot-component-onebot-v11-message.api +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-message/api/simbot-component-onebot-v11-message.api @@ -1,11 +1,20 @@ public abstract interface class love/forte/simbot/component/onebot/v11/message/OneBotMessageContent : love/forte/simbot/message/MessageContent { - public abstract fun delete ([Llove/forte/simbot/ability/DeleteOption;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract synthetic fun delete ([Llove/forte/simbot/ability/DeleteOption;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun getId ()Llove/forte/simbot/common/id/ID; public abstract fun getMessages ()Llove/forte/simbot/message/Messages; public abstract fun getPlainText ()Ljava/lang/String; + public fun getReference ()Llove/forte/simbot/component/onebot/v11/message/segment/OneBotReply; + public synthetic fun getReference ()Llove/forte/simbot/message/MessageReference; + public fun getReferenceAsync ()Ljava/util/concurrent/CompletableFuture; + public fun getReferenceMessage ()Llove/forte/simbot/component/onebot/v11/message/OneBotMessageContent; + public synthetic fun getReferenceMessage ()Llove/forte/simbot/message/MessageContent; + public fun getReferenceMessageAsync ()Ljava/util/concurrent/CompletableFuture; + public fun getReferenceMessageReserve ()Llove/forte/simbot/suspendrunner/reserve/SuspendReserve; + public fun getReferenceReserve ()Llove/forte/simbot/suspendrunner/reserve/SuspendReserve; public abstract fun getSourceSegments ()Ljava/util/List; - public fun reference (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public synthetic fun reference (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun reference$suspendImpl (Llove/forte/simbot/component/onebot/v11/message/OneBotMessageContent;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract synthetic fun referenceMessage (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } public abstract interface class love/forte/simbot/component/onebot/v11/message/OneBotMessageElement : love/forte/simbot/message/Message$Element { diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-message/build.gradle.kts b/simbot-component-onebot-v11/simbot-component-onebot-v11-message/build.gradle.kts index 1098676..ac4be45 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-message/build.gradle.kts +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-message/build.gradle.kts @@ -28,8 +28,7 @@ plugins { kotlin("multiplatform") kotlin("plugin.serialization") `simbot-onebot-dokka-partial-configure` - // 没用到 - // `simbot-onebot-suspend-transform-configure` + `simbot-onebot-suspend-transform-configure` alias(libs.plugins.ksp) } diff --git a/simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/message/OneBotMessageContent.kt b/simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/message/OneBotMessageContent.kt index 1fa34e2..be5a51d 100644 --- a/simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/message/OneBotMessageContent.kt +++ b/simbot-component-onebot-v11/simbot-component-onebot-v11-message/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/message/OneBotMessageContent.kt @@ -28,6 +28,7 @@ import love.forte.simbot.message.MessageContent import love.forte.simbot.message.Messages import love.forte.simbot.message.PlainText import love.forte.simbot.suspendrunner.STP +import kotlin.jvm.JvmSynthetic /** @@ -70,6 +71,16 @@ public interface OneBotMessageContent : MessageContent { override suspend fun reference(): OneBotReply? = messages.firstNotNullOfOrNull { it as? OneBotReply } + /** + * 根据 [消息引用][reference] 信息通过API查询对应引用的消息内容。 + * + * @throws RuntimeException 任何可能在请求API过程中产生的异常 + * + * @since 1.3.0 + */ + @STP + override suspend fun referenceMessage(): OneBotMessageContent? + /** * 消息中所有的 [文本消息][PlainText] * (或者说 [sourceSegments] 中所有的 [OneBotText]) @@ -88,6 +99,7 @@ public interface OneBotMessageContent : MessageContent { * @throws Exception 任何请求API过程中可能会产生的异常, * 例如因权限不足或消息不存在得到的请求错误 */ + @JvmSynthetic override suspend fun delete(vararg options: DeleteOption) }