Skip to content

Commit 176d3b6

Browse files
authored
Merge pull request #916 from simple-robot/message-from-id
feat(api): 为 `Bot` 增加用于根据ID获取源消息的API
2 parents d672221 + a2a6108 commit 176d3b6

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

simbot-api/api/simbot-api.api

Lines changed: 5 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 messageFromId (Llove/forte/simbot/common/id/ID;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
370+
public static synthetic fun messageFromId$suspendImpl (Llove/forte/simbot/bot/Bot;Llove/forte/simbot/common/id/ID;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
371+
public fun messageFromIdAsync (Llove/forte/simbot/common/id/ID;)Ljava/util/concurrent/CompletableFuture;
372+
public fun messageFromIdBlocking (Llove/forte/simbot/common/id/ID;)Llove/forte/simbot/message/MessageContent;
373+
public fun messageFromIdReserve (Llove/forte/simbot/common/id/ID;)Llove/forte/simbot/suspendrunner/reserve/SuspendReserve;
369374
public synthetic fun messageFromReference (Llove/forte/simbot/message/MessageReference;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
370375
public static synthetic fun messageFromReference$suspendImpl (Llove/forte/simbot/bot/Bot;Llove/forte/simbot/message/MessageReference;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
371376
public fun messageFromReferenceAsync (Llove/forte/simbot/message/MessageReference;)Ljava/util/concurrent/CompletableFuture;

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ package love.forte.simbot.bot
2727

2828
import kotlinx.coroutines.CoroutineScope
2929
import kotlinx.coroutines.Job
30+
import kotlinx.coroutines.NonCancellable.join
3031
import kotlinx.coroutines.cancel
3132
import kotlinx.coroutines.launch
3233
import love.forte.simbot.ability.CompletionAware
@@ -65,6 +66,9 @@ public interface Bot : IDContainer, LifecycleAware, CompletionAware, CoroutineSc
6566
* (比如向平台申请并下发的某种 `bot_id` 或者 `token` )。
6667
*
6768
* 通常情况下,它会是注册bot时候使用的某种唯一标识。
69+
* 它只能作为 simbot application 中的唯一表示,
70+
* 无法确保其代表某种 _用户ID_ 。
71+
* 对于不同的平台可能会视情况提供额外的属性来获取其用户ID。
6872
*
6973
*/
7074
public override val id: ID
@@ -127,19 +131,47 @@ public interface Bot : IDContainer, LifecycleAware, CompletionAware, CoroutineSc
127131
* (如果是此原因,则实现者应当提供另外可供使用的专属API。)
128132
* - 否则,将根据具体地引用信息查询并得到其对应地 [MessageContent]。
129133
*
134+
* 如果一个消息引用等同于一个消息的ID,那么 [messageFromReference] 的效果等同于 [messageFromId]。
135+
*
130136
* @throws UnsupportedOperationException 可能因为:
131-
* - 实现者尚未实现此API
137+
* - 实现者尚未实现此API
132138
* - 如果存在引用的概念、但对应平台明确由于各种原因无法查询引用源消息时
133-
* - 或者如果存在引用的概念、但消息引用无法使用 [MessageReference] 进行表达时
134-
* 如果是后者,则实现者应当提供另外可供使用的专属API
139+
* - 或者如果存在引用的概念、但消息引用无法使用 [MessageReference] 进。行表达时。
140+
* 此时则实现者应当提供另外可供使用的专属API
135141
* @throws RuntimeException 可能在获取引用的过程中产生的异常 (比如API请求失败,或查不到对应结果)。
136142
* 这通常来自进行挂起查询的过程(如果有的话)。
137143
* @since 4.6.0
144+
*
145+
* @see messageFromId
138146
*/
139147
@ST
140148
public suspend fun messageFromReference(reference: MessageReference): MessageContent =
141149
throw UnsupportedOperationException()
142150

151+
/**
152+
* 根据一个 [消息ID][ID] 获取它对应地源消息。
153+
*
154+
* - 如果实现者尚未实现此功能则会抛出 [UnsupportedOperationException]。
155+
* - 如果存在消息ID、但对应平台明确由于各种原因无法根据ID查询源消息时会抛出 [UnsupportedOperationException]。
156+
* - 如果存在消息ID、但无法仅通过一个 [ID] 来进行查询时 (例如需要其他附加的复合信息查询)
157+
* 会抛出 [UnsupportedOperationException]。此时实现者应当提供另外可供使用的专属API。
158+
* - 否则,将根据 [ID] 查询并得到其对应地 [MessageContent]。
159+
*
160+
* @throws UnsupportedOperationException 可能因为:
161+
* - 实现者尚未实现此API。
162+
* - 如果存在消息ID、但对应平台明确由于各种原因无法根据ID查询源消息时。
163+
* - 或者如果存在消息ID、但无法仅通过一个 [ID] 来进行查询时 (例如需要其他附加的复合信息查询)。
164+
* 此时实现者应当提供另外可供使用的专属API。
165+
* @throws RuntimeException 可能在获取引用的过程中产生的异常 (比如API请求失败,或查不到对应结果)。
166+
* 这通常来自进行挂起查询的过程(如果有的话)。
167+
* @since 4.6.0
168+
*
169+
* @see messageFromReference
170+
*/
171+
@ST
172+
public suspend fun messageFromId(id: ID): MessageContent =
173+
throw UnsupportedOperationException()
174+
143175
// join & cancel
144176

145177
/**

0 commit comments

Comments
 (0)