Skip to content

Commit 124d06c

Browse files
合并拉取请求 #339
删除 `@Filter` 的 `and`、`or` 参数
2 parents 4ffd44f + 0298573 commit 124d06c

File tree

6 files changed

+324
-456
lines changed

6 files changed

+324
-456
lines changed

apis/simbot-api/src/main/kotlin/love/forte/simbot/event/EventFilter.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import love.forte.simbot.Api4J
2121
import love.forte.simbot.BlockingFilter
2222
import love.forte.simbot.Filter
2323
import love.forte.simbot.PriorityConstant
24+
import love.forte.simbot.utils.runWithInterruptible
2425

2526
/**
2627
* 事件过滤器。
@@ -34,6 +35,8 @@ import love.forte.simbot.PriorityConstant
3435
*
3536
* 过滤器存在 [优先级][priority], 默认情况下的优先级为 [PriorityConstant.NORMAL].
3637
*
38+
* 对于不支持挂起函数的实现者,可参考 [BlockingEventFilter]。
39+
*
3740
* @author ForteScarlet
3841
*/
3942
public interface EventFilter : Filter<EventListenerProcessingContext> {
@@ -73,6 +76,6 @@ public interface BlockingEventFilter : EventFilter, BlockingFilter<EventListener
7376
*/
7477
@JvmSynthetic
7578
@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")
76-
override suspend fun test(context: EventListenerProcessingContext): Boolean = testBlocking()
79+
override suspend fun test(context: EventListenerProcessingContext): Boolean = runWithInterruptible { testBlocking() }
7780

7881
}

boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/AnnotationEventFilter.kt

-133
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package love.forte.simboot.annotation
2+
3+
import love.forte.simbot.Api4J
4+
import love.forte.simbot.MutableAttributeMap
5+
import love.forte.simbot.event.*
6+
7+
/**
8+
* 应用于 [@Filter][love.forte.simboot.annotation.Filter] 注解上的
9+
* [Filter.by][love.forte.simboot.annotation.Filter.by] 参数,用于
10+
* 通过参数构建一个当前 `Filter` 对应的过滤器实例。
11+
*
12+
* ```kotlin
13+
* @Filter(by = FooAnnotationEventFilterFactory::class)
14+
* suspend fun Event.onEvent() { ... }
15+
* ```
16+
*
17+
* @author ForteScarlet
18+
*/
19+
public interface AnnotationEventFilterFactory {
20+
21+
22+
/**
23+
* 通过提供的监听函数和过滤器注解参数来解析并得到一个 [EventFilter] 实例。
24+
*
25+
* 如果需要跳过本次解析,可以直接返回一个 null。
26+
*
27+
* @see Filter.by
28+
*
29+
*/
30+
public fun resolveFilter(
31+
listener: EventListener,
32+
listenerAttributes: MutableAttributeMap,
33+
filter: Filter,
34+
filters: Filters,
35+
): EventFilter?
36+
37+
}
38+
39+
40+
/**
41+
* 应用于 [love.forte.simboot.annotation.Filter] 注解上用来直接处理对应注解的函数。
42+
*
43+
* 非挂起的阻塞实现参考 [BlockingAnnotationEventFilter].
44+
*
45+
* @see BlockingAnnotationEventFilter
46+
* @author ForteScarlet
47+
*/
48+
@Deprecated("Unused")
49+
@Suppress("KDocUnresolvedReference")
50+
public interface AnnotationEventFilter : EventFilter {
51+
52+
public fun init(listener: EventListener, filter: Filter, filters: Filters)
53+
54+
55+
@Deprecated("Unused")
56+
public enum class InitType {
57+
INDEPENDENT,
58+
UNITED
59+
}
60+
61+
62+
override suspend fun test(context: EventListenerProcessingContext): Boolean
63+
64+
}
65+
66+
67+
/**
68+
* 应用于 [love.forte.simboot.annotation.Filter] 注解上用来直接处理对应注解的函数。
69+
*
70+
* 是阻塞的 [AnnotationEventFilter] 类型实现,主要用于为不支持挂起函数的实现方使用。
71+
*
72+
* @see AnnotationEventFilter
73+
*
74+
*/
75+
@Suppress("DEPRECATION")
76+
@Deprecated("Unused")
77+
@Api4J
78+
public interface BlockingAnnotationEventFilter : AnnotationEventFilter, BlockingEventFilter {
79+
80+
/**
81+
* 过滤器的检测函数。通过 [EventProcessingContext] 来验证是否需要处理当前事件。
82+
*/
83+
@Api4J
84+
override fun testBlocking(): Boolean
85+
86+
87+
/**
88+
* 过滤器的检测函数。通过 [EventProcessingContext] 来验证是否需要处理当前事件。
89+
*/
90+
@JvmSynthetic
91+
override suspend fun test(context: EventListenerProcessingContext): Boolean = testBlocking()
92+
93+
94+
}

0 commit comments

Comments
 (0)