Skip to content

Commit d672221

Browse files
authored
Merge pull request #915 from simple-robot/reference-for-source-message
为 `MessageContent` 和 `Bot` 增加用于根据引用 `MessageReference` 获取源消息的API
2 parents 18611d8 + 9ff7e94 commit d672221

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

simbot-api/api/simbot-api.api

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ public abstract interface class love/forte/simbot/bot/Bot : kotlinx/coroutines/C
366366
public abstract synthetic fun join (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
367367
public fun joinBlocking ()V
368368
public fun joinReserve ()Llove/forte/simbot/suspendrunner/reserve/SuspendReserve;
369+
public synthetic fun messageFromReference (Llove/forte/simbot/message/MessageReference;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
370+
public static synthetic fun messageFromReference$suspendImpl (Llove/forte/simbot/bot/Bot;Llove/forte/simbot/message/MessageReference;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
371+
public fun messageFromReferenceAsync (Llove/forte/simbot/message/MessageReference;)Ljava/util/concurrent/CompletableFuture;
372+
public fun messageFromReferenceBlocking (Llove/forte/simbot/message/MessageReference;)Llove/forte/simbot/message/MessageContent;
373+
public fun messageFromReferenceReserve (Llove/forte/simbot/message/MessageReference;)Llove/forte/simbot/suspendrunner/reserve/SuspendReserve;
369374
public abstract synthetic fun start (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
370375
public fun startAsync ()Ljava/util/concurrent/CompletableFuture;
371376
public fun startBlocking ()V
@@ -1964,9 +1969,14 @@ public abstract interface class love/forte/simbot/message/MessageContent : love/
19641969
public abstract fun getPlainText ()Ljava/lang/String;
19651970
public fun getReference ()Llove/forte/simbot/message/MessageReference;
19661971
public fun getReferenceAsync ()Ljava/util/concurrent/CompletableFuture;
1972+
public fun getReferenceMessage ()Llove/forte/simbot/message/MessageContent;
1973+
public fun getReferenceMessageAsync ()Ljava/util/concurrent/CompletableFuture;
1974+
public fun getReferenceMessageReserve ()Llove/forte/simbot/suspendrunner/reserve/SuspendReserve;
19671975
public fun getReferenceReserve ()Llove/forte/simbot/suspendrunner/reserve/SuspendReserve;
19681976
public synthetic fun reference (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
19691977
public static synthetic fun reference$suspendImpl (Llove/forte/simbot/message/MessageContent;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1978+
public synthetic fun referenceMessage (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1979+
public static synthetic fun referenceMessage$suspendImpl (Llove/forte/simbot/message/MessageContent;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
19701980
}
19711981

19721982
public final class love/forte/simbot/message/MessageContentKt {

simbot-api/src/commonMain/kotlin/love/forte/simbot/bot/Bot.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import love.forte.simbot.definition.Channel
3939
import love.forte.simbot.definition.ChatGroup
4040
import love.forte.simbot.definition.Contact
4141
import love.forte.simbot.definition.Guild
42+
import love.forte.simbot.message.MessageContent
43+
import love.forte.simbot.message.MessageReference
4244
import love.forte.simbot.suspendrunner.ST
4345
import love.forte.simbot.suspendrunner.STP
4446
import kotlin.jvm.JvmName
@@ -112,6 +114,32 @@ public interface Bot : IDContainer, LifecycleAware, CompletionAware, CoroutineSc
112114
*/
113115
public val isStarted: Boolean
114116

117+
// abilities
118+
119+
/**
120+
* 根据一个 [消息引用][reference] 查询或获取它对应地源消息。
121+
*
122+
* - 如果实现者尚未实现此功能则会抛出 [UnsupportedOperationException]。
123+
* - 如果实现的对应平台明确存在**引用**的概念、但由于各种原因无法查询引用源消息时,
124+
* 将会抛出 [UnsupportedOperationException]。
125+
* - 如果实现的对应平台明确存在**引用**的概念、但消息引用无法使用 [MessageReference] 进行表达时,
126+
* 将会抛出 [UnsupportedOperationException]。
127+
* (如果是此原因,则实现者应当提供另外可供使用的专属API。)
128+
* - 否则,将根据具体地引用信息查询并得到其对应地 [MessageContent]。
129+
*
130+
* @throws UnsupportedOperationException 可能因为:
131+
* - 实现者尚未实现此API
132+
* - 如果存在引用的概念、但对应平台明确由于各种原因无法查询引用源消息时
133+
* - 或者如果存在引用的概念、但消息引用无法使用 [MessageReference] 进行表达时
134+
* 如果是后者,则实现者应当提供另外可供使用的专属API。
135+
* @throws RuntimeException 可能在获取引用的过程中产生的异常 (比如API请求失败,或查不到对应结果)。
136+
* 这通常来自进行挂起查询的过程(如果有的话)。
137+
* @since 4.6.0
138+
*/
139+
@ST
140+
public suspend fun messageFromReference(reference: MessageReference): MessageContent =
141+
throw UnsupportedOperationException()
142+
115143
// join & cancel
116144

117145
/**

simbot-api/src/commonMain/kotlin/love/forte/simbot/message/MessageContent.kt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ package love.forte.simbot.message
2626
import love.forte.simbot.ability.DeleteFailureException
2727
import love.forte.simbot.ability.DeleteOption
2828
import love.forte.simbot.ability.DeleteSupport
29+
import love.forte.simbot.bot.Bot
2930
import love.forte.simbot.common.id.ID
3031
import love.forte.simbot.suspendrunner.STP
3132
import kotlin.jvm.JvmSynthetic
@@ -107,14 +108,37 @@ public interface MessageContent : DeleteSupport {
107108
* 则使用 [reference] 时应当抛出信息明确的 [UnsupportedOperationException] 异常。
108109
*
109110
* @throws UnsupportedOperationException 如果实现者的所属平台有明确的 _消息引用_ 概念,
110-
* 但是无法通过 [MessageReference] 这个类型进行表述
111-
*
111+
* 但是无法通过 [MessageReference] 这个类型进行表述
112+
* @throws RuntimeException 可能在获取引用的过程中产生的异常。这通常来自进行挂起查询的过程(如果有的话)。
112113
* @since 4.5.0
113114
*/
114115
@STP
115116
public suspend fun reference(): MessageReference? =
116117
messages.firstOrNull { it is MessageReference } as? MessageReference?
117118

119+
/**
120+
* 根据 [消息引用][reference] (或具体实现内部的某种真实引用),
121+
* 查询此引用的源消息。
122+
*
123+
* - 如果实现者尚未实现此功能,或 [reference] 返回 `null`,
124+
* 则 [referenceMessage] 的结果为 `null`。
125+
* - 如果实现的对应平台明确存在**引用**的概念、但由于各种原因无法查询引用源消息时,
126+
* [referenceMessage] 将会抛出 [UnsupportedOperationException]。
127+
* - 否则,将根据具体地引用信息查询并得到其对应地 [MessageContent]。
128+
* 与 [reference] 不同,[referenceMessage] 大概率会产生网络请求和挂起行为,
129+
* 但具体行为还是以具体实现为准。
130+
*
131+
*
132+
* @throws UnsupportedOperationException 如果存在引用的概念、
133+
* 但对应平台明确由于各种原因无法查询引用源消息时。
134+
* @throws RuntimeException 可能在获取引用的过程中产生的异常。这通常来自进行挂起查询的过程(如果有的话)。
135+
*
136+
* @since 4.6.0
137+
*
138+
* @see Bot.messageFromReference
139+
*/
140+
@STP
141+
public suspend fun referenceMessage(): MessageContent? = null
118142
}
119143

120144
/**

0 commit comments

Comments
 (0)