Skip to content

Commit b402102

Browse files
committed
拆分 RequestEvent 中的 accept 与 reject 操作为单独的接口,并使它们支持options风格API
1 parent 37ec0ad commit b402102

File tree

4 files changed

+168
-4
lines changed

4 files changed

+168
-4
lines changed

simbot-api/api/simbot-api.api

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
public abstract interface class love/forte/simbot/ability/AcceptOption {
2+
}
3+
4+
public abstract interface class love/forte/simbot/ability/AcceptSupport {
5+
public abstract synthetic fun accept (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
6+
public synthetic fun accept ([Llove/forte/simbot/ability/AcceptOption;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
7+
public static synthetic fun accept$suspendImpl (Llove/forte/simbot/ability/AcceptSupport;[Llove/forte/simbot/ability/AcceptOption;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
8+
public fun acceptAsync ()Ljava/util/concurrent/CompletableFuture;
9+
public fun acceptAsync ([Llove/forte/simbot/ability/AcceptOption;)Ljava/util/concurrent/CompletableFuture;
10+
public fun acceptBlocking ()V
11+
public fun acceptBlocking ([Llove/forte/simbot/ability/AcceptOption;)V
12+
public fun acceptReserve ()Llove/forte/simbot/suspendrunner/reserve/SuspendReserve;
13+
public fun acceptReserve ([Llove/forte/simbot/ability/AcceptOption;)Llove/forte/simbot/suspendrunner/reserve/SuspendReserve;
14+
}
15+
116
public abstract interface class love/forte/simbot/ability/CompletionAware {
217
public abstract fun onCompletion (Llove/forte/simbot/ability/OnCompletion;)V
318
}
@@ -47,6 +62,21 @@ public abstract interface class love/forte/simbot/ability/OnCompletion {
4762
public abstract fun invoke (Ljava/lang/Throwable;)V
4863
}
4964

65+
public abstract interface class love/forte/simbot/ability/RejectOption {
66+
}
67+
68+
public abstract interface class love/forte/simbot/ability/RejectSupport {
69+
public abstract synthetic fun reject (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
70+
public synthetic fun reject ([Llove/forte/simbot/ability/RejectOption;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
71+
public static synthetic fun reject$suspendImpl (Llove/forte/simbot/ability/RejectSupport;[Llove/forte/simbot/ability/RejectOption;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
72+
public fun rejectAsync ()Ljava/util/concurrent/CompletableFuture;
73+
public fun rejectAsync ([Llove/forte/simbot/ability/RejectOption;)Ljava/util/concurrent/CompletableFuture;
74+
public fun rejectBlocking ()V
75+
public fun rejectBlocking ([Llove/forte/simbot/ability/RejectOption;)V
76+
public fun rejectReserve ()Llove/forte/simbot/suspendrunner/reserve/SuspendReserve;
77+
public fun rejectReserve ([Llove/forte/simbot/ability/RejectOption;)Llove/forte/simbot/suspendrunner/reserve/SuspendReserve;
78+
}
79+
5080
public abstract interface class love/forte/simbot/ability/ReplySupport {
5181
public abstract synthetic fun reply (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
5282
public abstract synthetic fun reply (Llove/forte/simbot/message/Message;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@@ -1572,7 +1602,7 @@ public abstract interface class love/forte/simbot/event/OrganizationSourceEvent
15721602
public abstract synthetic fun source (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
15731603
}
15741604

1575-
public abstract interface class love/forte/simbot/event/RequestEvent : love/forte/simbot/event/BotEvent {
1605+
public abstract interface class love/forte/simbot/event/RequestEvent : love/forte/simbot/ability/AcceptSupport, love/forte/simbot/ability/RejectSupport, love/forte/simbot/event/BotEvent {
15761606
public abstract synthetic fun accept (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
15771607
public fun acceptAsync ()Ljava/util/concurrent/CompletableFuture;
15781608
public fun acceptBlocking ()V
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2024. ForteScarlet.
3+
*
4+
* Project https://github.com/simple-robot/simpler-robot
5+
6+
*
7+
* This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* Lesser GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the Lesser GNU General Public License
20+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
package love.forte.simbot.ability
25+
26+
import love.forte.simbot.event.RequestEvent
27+
import love.forte.simbot.suspendrunner.ST
28+
29+
30+
/**
31+
* 对“接受行为”的支持,由 [RequestEvent] 实现。
32+
*
33+
* @author ForteScarlet
34+
*/
35+
public interface AcceptSupport {
36+
/**
37+
* 接受此请求。
38+
*
39+
* @throws Throwable 任何可能产生的错误。
40+
*/
41+
@ST
42+
public suspend fun accept()
43+
44+
/**
45+
* 接受此请求。
46+
*
47+
* 对实现者:此函数具有默认实现以确保二进制兼容。
48+
*
49+
* @param options 用于当前接受行为的可选项。
50+
* 如果某选项实现不支持则会被忽略,支持的范围由实现者决定。
51+
* @since 4.0.0-RC3
52+
* @throws Throwable 任何可能产生的错误。
53+
*/
54+
@ST
55+
public suspend fun accept(vararg options: AcceptOption) {
56+
accept()
57+
}
58+
}
59+
60+
/**
61+
* [AcceptSupport.accept] 的可选项。
62+
* [AcceptOption] 可以自由扩展,且如果遇到不支持的实现则会将其忽略。
63+
*
64+
* @see AcceptSupport.accept
65+
*/
66+
public interface AcceptOption
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2024. ForteScarlet.
3+
*
4+
* Project https://github.com/simple-robot/simpler-robot
5+
6+
*
7+
* This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* Lesser GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the Lesser GNU General Public License
20+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
package love.forte.simbot.ability
25+
26+
import love.forte.simbot.event.RequestEvent
27+
import love.forte.simbot.suspendrunner.ST
28+
29+
30+
/**
31+
* 对“拒绝行为”的支持,由 [RequestEvent] 实现。
32+
*
33+
* @author ForteScarlet
34+
*/
35+
public interface RejectSupport {
36+
/**
37+
* 拒绝此请求。
38+
*
39+
* @throws Throwable 任何可能产生的错误。
40+
*/
41+
@ST
42+
public suspend fun reject()
43+
44+
/**
45+
* 拒绝此请求。
46+
*
47+
* 对实现者:此函数具有默认实现以确保二进制兼容。
48+
*
49+
* @param options 用于当前拒绝行为的可选项。
50+
* 如果某选项实现不支持则会被忽略,支持的范围由实现者决定。
51+
* @since 4.0.0-RC3
52+
* @throws Throwable 任何可能产生的错误。
53+
*/
54+
@ST
55+
public suspend fun reject(vararg options: RejectOption) {
56+
reject()
57+
}
58+
}
59+
60+
/**
61+
* [RejectSupport.reject] 的可选项。
62+
* [RejectOption] 可以自由扩展,且如果遇到不支持的实现则会将其忽略。
63+
*
64+
* @see RejectSupport.reject
65+
*/
66+
public interface RejectOption

simbot-api/src/commonMain/kotlin/love/forte/simbot/event/RequestEvent.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
package love.forte.simbot.event
2525

26+
import love.forte.simbot.ability.AcceptSupport
27+
import love.forte.simbot.ability.RejectSupport
2628
import love.forte.simbot.bot.Bot
2729
import love.forte.simbot.common.id.ID
2830
import love.forte.simbot.definition.ChatGroup
@@ -38,7 +40,7 @@ import love.forte.simbot.suspendrunner.STP
3840
*
3941
* @author ForteScarlet
4042
*/
41-
public interface RequestEvent : BotEvent {
43+
public interface RequestEvent : BotEvent, RejectSupport, AcceptSupport {
4244
/**
4345
* 伴随请求的附加消息。
4446
*
@@ -74,15 +76,15 @@ public interface RequestEvent : BotEvent {
7476
* @throws Exception 任何可能产生的错误。
7577
*/
7678
@ST
77-
public suspend fun reject()
79+
override suspend fun reject()
7880

7981
/**
8082
* 接受此请求。
8183
*
8284
* @throws Exception 任何可能产生的错误。
8385
*/
8486
@ST
85-
public suspend fun accept()
87+
override suspend fun accept()
8688
}
8789

8890

0 commit comments

Comments
 (0)