Skip to content

Commit 57013f5

Browse files
committed
Add FuzzyEventTypeImplementation opt-in annotation for event type clarity
1 parent d39e8b8 commit 57013f5

13 files changed

+168
-12
lines changed

simbot-api/api/simbot-api.api

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,9 @@ public final class love/forte/simbot/event/EventResult_jvmKt {
14521452
public static final fun collectCollectableReactively (Llove/forte/simbot/event/StandardEventResult$CollectableReactivelyResult;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
14531453
}
14541454

1455+
public abstract interface annotation class love/forte/simbot/event/FuzzyEventTypeImplementation : java/lang/annotation/Annotation {
1456+
}
1457+
14551458
public abstract interface class love/forte/simbot/event/GroupMemberChangeEvent : love/forte/simbot/event/ChangeEvent, love/forte/simbot/event/ChatGroupMemberEvent {
14561459
public abstract synthetic fun content (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
14571460
public synthetic fun getContent ()Ljava/lang/Object;
@@ -1848,7 +1851,7 @@ public abstract interface class love/forte/simbot/event/OrganizationEvent : love
18481851
public fun getContentReserve ()Llove/forte/simbot/suspendrunner/reserve/SuspendReserve;
18491852
}
18501853

1851-
public abstract interface class love/forte/simbot/event/OrganizationJoinRequestEvent : love/forte/simbot/event/OrganizationEvent {
1854+
public abstract interface class love/forte/simbot/event/OrganizationJoinRequestEvent : love/forte/simbot/event/OrganizationRequestEvent {
18521855
public fun getRequester ()Llove/forte/simbot/definition/User;
18531856
public fun getRequesterAsync ()Ljava/util/concurrent/CompletableFuture;
18541857
public abstract fun getRequesterId ()Llove/forte/simbot/common/id/ID;

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
* Copyright (c) 2024. ForteScarlet.
2+
* Copyright (c) 2024-2025. ForteScarlet.
33
*
44
* Project https://github.com/simple-robot/simpler-robot
55
66
*
7-
* This file is part of the Simple Robot Library.
7+
* This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
88
*
99
* This program is free software: you can redistribute it and/or modify
1010
* it under the terms of the GNU Lesser General Public License as published by
@@ -33,6 +33,7 @@ import love.forte.simbot.suspendrunner.STP
3333
* @author ForteScarlet
3434
*/
3535
@STP
36+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
3637
public interface ActorEvent : BotEvent, ContentEvent {
3738
/**
3839
* 被作为事件中心的 [Actor]。
@@ -46,6 +47,7 @@ public interface ActorEvent : BotEvent, ContentEvent {
4647
* @author ForteScarlet
4748
*/
4849
@STP
50+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
4951
public interface ContactEvent : ActorEvent {
5052
/**
5153
* 被作为事件中心的 [Contact]。
@@ -59,6 +61,7 @@ public interface ContactEvent : ActorEvent {
5961
* @author ForteScarlet
6062
*/
6163
@STP
64+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
6265
public interface OrganizationEvent : ActorEvent {
6366
/**
6467
* 被作为事件中心的 [Organization]。
@@ -72,6 +75,7 @@ public interface OrganizationEvent : ActorEvent {
7275
* @author ForteScarlet
7376
*/
7477
@STP
78+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
7579
public interface ChatRoomEvent : ActorEvent {
7680
/**
7781
* 被作为事件中心的 [ChatRoom]。
@@ -86,6 +90,7 @@ public interface ChatRoomEvent : ActorEvent {
8690
* @author ForteScarlet
8791
*/
8892
@STP
93+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
8994
public interface ChatGroupEvent : ChatRoomEvent, OrganizationEvent {
9095
/**
9196
* 被作为事件中心的 [ChatGroup]。
@@ -99,6 +104,7 @@ public interface ChatGroupEvent : ChatRoomEvent, OrganizationEvent {
99104
* @author ForteScarlet
100105
*/
101106
@STP
107+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
102108
public interface GuildEvent : OrganizationEvent {
103109
/**
104110
* 被作为事件中心的 [Guild]。
@@ -111,6 +117,7 @@ public interface GuildEvent : OrganizationEvent {
111117
* 此类型由一些存在组织信息、但组织信息不是主要信息的事件类型实现。
112118
*/
113119
@STP
120+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
114121
public interface OrganizationSourceEvent : BotEvent, SourceEvent {
115122
/**
116123
* 事件中的 [Organization].
@@ -124,6 +131,7 @@ public interface OrganizationSourceEvent : BotEvent, SourceEvent {
124131
* @author ForteScarlet
125132
*/
126133
@STP
134+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
127135
public interface ChannelEvent : ActorEvent, OrganizationSourceEvent {
128136
/**
129137
* 事件中的 [channel][content] 所属的 [Guild]。
@@ -143,6 +151,7 @@ public interface ChannelEvent : ActorEvent, OrganizationSourceEvent {
143151
* @author ForteScarlet
144152
*/
145153
@STP
154+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
146155
public interface ChatChannelEvent : ChannelEvent, ChatRoomEvent {
147156
/**
148157
* 被作为事件中心的 [ChatChannel]。
@@ -156,6 +165,7 @@ public interface ChatChannelEvent : ChannelEvent, ChatRoomEvent {
156165
* @author ForteScarlet
157166
*/
158167
@STP
168+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
159169
public interface MemberEvent : ActorEvent, OrganizationSourceEvent {
160170
/**
161171
* 事件中 [member][content] 所属的 [Organization]。
@@ -175,6 +185,7 @@ public interface MemberEvent : ActorEvent, OrganizationSourceEvent {
175185
* @author ForteScarlet
176186
*/
177187
@STP
188+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
178189
public interface ChatGroupMemberEvent : MemberEvent {
179190
/**
180191
* 事件中 [member][content] 所属的 [ChatGroup]。
@@ -193,6 +204,7 @@ public interface ChatGroupMemberEvent : MemberEvent {
193204
* @author ForteScarlet
194205
*/
195206
@STP
207+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
196208
public interface GuildMemberEvent : MemberEvent {
197209
/**
198210
* 事件中 [member][content] 所属的 [Guild]。

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import love.forte.simbot.bot.BotManager
3333
*
3434
* @author ForteScarlet
3535
*/
36+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
3637
public interface BotStageEvent : InternalNotificationEvent, BotEvent {
3738
/**
3839
* 相关的 bot.
@@ -45,11 +46,13 @@ public interface BotStageEvent : InternalNotificationEvent, BotEvent {
4546
*
4647
* @author ForteScarlet
4748
*/
49+
@OptIn(FuzzyEventTypeImplementation::class)
4850
public interface BotRegisteredEvent : BotStageEvent
4951

5052
/**
5153
* 当一个 Bot **首次** 启动成功后的事件。
5254
*
5355
* @author ForteScarlet
5456
*/
57+
@OptIn(FuzzyEventTypeImplementation::class)
5558
public interface BotStartedEvent : BotStageEvent

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
* Copyright (c) 2024. ForteScarlet.
2+
* Copyright (c) 2024-2025. ForteScarlet.
33
*
44
* Project https://github.com/simple-robot/simpler-robot
55
66
*
7-
* This file is part of the Simple Robot Library.
7+
* This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
88
*
99
* This program is free software: you can redistribute it and/or modify
1010
* it under the terms of the GNU Lesser General Public License as published by
@@ -35,6 +35,7 @@ import love.forte.simbot.suspendrunner.STP
3535
*
3636
* @author ForteScarlet
3737
*/
38+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
3839
public interface Event : IDContainer {
3940
/**
4041
* 事件的ID。
@@ -56,6 +57,7 @@ public interface Event : IDContainer {
5657
*
5758
* @author ForteScarlet
5859
*/
60+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
5961
public interface ComponentEvent : Event {
6062
/**
6163
* 所属组件
@@ -68,6 +70,7 @@ public interface ComponentEvent : Event {
6870
*
6971
* @author ForteScarlet
7072
*/
73+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
7174
public interface BotEvent : ComponentEvent {
7275
/**
7376
* 相关的 [Bot]。
@@ -88,6 +91,7 @@ public interface BotEvent : ComponentEvent {
8891
* 一个事件中可以提供的主、次要信息会优先使用 [ContentEvent] 和 [SourceEvent] 提供。
8992
*/
9093
@STP
94+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
9195
public interface ContentEvent : Event {
9296
/**
9397
* 这个事件的主要事件中心值。
@@ -101,6 +105,7 @@ public interface ContentEvent : Event {
101105
* 一个事件中可以提供的主、次要信息会优先使用 [ContentEvent] 和 [SourceEvent] 提供。
102106
*/
103107
@STP
108+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
104109
public interface SourceEvent : Event {
105110
/**
106111
* 这个事件的“源头”。
@@ -114,6 +119,7 @@ public interface SourceEvent : Event {
114119
* @author ForteScarlet
115120
*/
116121
@STP
122+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
117123
public interface ChangeEvent : ContentEvent {
118124
/**
119125
* 发生了变化的主体。
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2025. 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.event
25+
26+
/**
27+
* 通过 [SubclassOptInRequired] 标记某个事件类型为一个 “模糊的事件类型”。
28+
* 这类事件通常拥有更明确的子类型,因此也更推荐实现这些更具体的类型,
29+
* 而它们的存在主要是为了提供一个更为通用的事件类型或者仅仅提供一些额外能力(例如 `XxxAware` 之类的事件),
30+
* 以便于在事件监听或类型判断上发挥作用。
31+
*
32+
* 举个例子,[MessageEvent] 代表了一个 Bot 收到消息的事件,用户可以通过监听它来得知所有的与消息相关的事件。
33+
*
34+
* ```kotlin
35+
* eventDispatcher.process<MessageEvent> { event ->
36+
* ...
37+
* }
38+
* ```
39+
*
40+
* 但是在组件进行具体实现的时候,[MessageEvent] 所代表的含义就比较模糊:它即可能代表群消息,也可能代表私聊消息。
41+
* 因此应该根据 [ChatGroupMessageEvent] 或 [ContactMessageEvent] 这类末端更具体的类型进行实现或扩展,
42+
* 而不是直接实现 [MessageEvent]。
43+
*
44+
* ```kotlin
45+
* // 推荐实现更具体的事件类型
46+
* class MyMessageEventImpl : ChatGroupMessageEvent {
47+
* ...
48+
* }
49+
* ```
50+
*
51+
* 如果你清楚你的事件类型是一个模糊的事件类型,那么你可以使用这个注解来标记它。
52+
* 此注解主要用于警告此问题的存在,以便于开发者更好地进行事件类型的设计,但不会对代码进行任何限制。
53+
*
54+
* @since 4.11.0
55+
*
56+
* @author ForteScarlet
57+
*/
58+
@RequiresOptIn(
59+
message = "This is a fuzzy event type. It is recommended to implement a more specific event type.",
60+
level = RequiresOptIn.Level.WARNING
61+
)
62+
@Target(AnnotationTarget.CLASS, AnnotationTarget.ANNOTATION_CLASS)
63+
public annotation class FuzzyEventTypeImplementation

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ package love.forte.simbot.event
3939
* @since 4.11.0
4040
* @author ForteScarlet
4141
*/
42+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
4243
public interface InternalEvent : Event
4344

4445
/**
@@ -47,6 +48,7 @@ public interface InternalEvent : Event
4748
*
4849
* @since 4.11.0
4950
*/
51+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
5052
public interface InternalNotificationEvent : InternalEvent
5153

5254
/**
@@ -65,6 +67,7 @@ public interface InternalNotificationEvent : InternalEvent
6567
* @since 4.11.0
6668
*
6769
*/
70+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
6871
public interface InternalInterceptionEvent : InternalEvent
6972

7073
/**

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import love.forte.simbot.message.MessageReceipt
4040
*
4141
* @author ForteScarlet
4242
*/
43+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
4344
public interface InternalMessageInteractionEvent : InternalEvent {
4445
/**
4546
* 进行消息交互的实体。
@@ -62,6 +63,7 @@ public interface InternalMessageInteractionEvent : InternalEvent {
6263
*
6364
* @since 4.11.0
6465
*/
66+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
6567
public interface InternalMessagePreSendEvent :
6668
InternalInterceptionEvent,
6769
InternalMessageInteractionEvent {
@@ -97,6 +99,7 @@ public interface InternalMessagePreSendEvent :
9799
*
98100
* @since 4.11.0
99101
*/
102+
@SubclassOptInRequired(FuzzyEventTypeImplementation::class)
100103
public interface InternalMessagePostSendEvent : InternalMessageInteractionEvent {
101104
/**
102105
* 在消息发送时

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024. ForteScarlet.
2+
* Copyright (c) 2024-2025. ForteScarlet.
33
*
44
* Project https://github.com/simple-robot/simpler-robot
55
@@ -35,6 +35,7 @@ import love.forte.simbot.suspendrunner.STP
3535
* @author ForteScarlet
3636
*/
3737
@STP
38+
@OptIn(FuzzyEventTypeImplementation::class)
3839
public interface MemberChangeEvent : ChangeEvent, MemberEvent {
3940
/**
4041
* 发送了变化的 [Member]。
@@ -49,6 +50,7 @@ public interface MemberChangeEvent : ChangeEvent, MemberEvent {
4950
* @author ForteScarlet
5051
*/
5152
@STP
53+
@OptIn(FuzzyEventTypeImplementation::class)
5254
public interface GuildMemberChangeEvent : ChangeEvent, GuildMemberEvent {
5355
/**
5456
* 变化成员所在 [Guild]
@@ -68,6 +70,7 @@ public interface GuildMemberChangeEvent : ChangeEvent, GuildMemberEvent {
6870
* @author ForteScarlet
6971
*/
7072
@STP
73+
@OptIn(FuzzyEventTypeImplementation::class)
7174
public interface GroupMemberChangeEvent : ChangeEvent, ChatGroupMemberEvent {
7275
/**
7376
* 变化成员所在 [ChatGroup]

0 commit comments

Comments
 (0)