mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-05 07:30:09 +08:00
Fix references
This commit is contained in:
parent
4bbdd588d5
commit
54794a6e49
@ -11,6 +11,7 @@
|
||||
|
||||
package net.mamoe.mirai.event
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import net.mamoe.mirai.event.internal.broadcastInternal
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
@ -31,7 +32,7 @@ import kotlin.jvm.Volatile
|
||||
* @see subscribeMessages
|
||||
*
|
||||
* @see [broadcast] 广播事件
|
||||
* @see [subscribe] 监听事件
|
||||
* @see [CoroutineScope.subscribe] 监听事件
|
||||
*/
|
||||
interface Event {
|
||||
/**
|
||||
|
@ -68,7 +68,7 @@ abstract class AbstractCancellableEvent : AbstractEvent(), CancellableEvent
|
||||
fun <R> Bot.subscribeMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
listeners: MessagePacketSubscribersBuilder.() -> R
|
||||
): R {
|
||||
contract {
|
||||
@ -94,7 +94,7 @@ fun <R> Bot.subscribeMessages(
|
||||
fun <R> Bot.subscribeGroupMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
listeners: GroupMessageSubscribersBuilder.() -> R
|
||||
): R {
|
||||
contract {
|
||||
@ -120,7 +120,7 @@ fun <R> Bot.subscribeGroupMessages(
|
||||
fun <R> Bot.subscribeFriendMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
listeners: FriendMessageSubscribersBuilder.() -> R
|
||||
): R {
|
||||
contract {
|
||||
@ -147,7 +147,7 @@ fun <R> Bot.subscribeFriendMessages(
|
||||
fun <R> Bot.subscribeTempMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
listeners: TempMessageSubscribersBuilder.() -> R
|
||||
): R {
|
||||
contract {
|
||||
@ -172,7 +172,7 @@ fun <R> Bot.subscribeTempMessages(
|
||||
inline fun <reified E : BotEvent> Bot.incoming(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
capacity: Int = Channel.UNLIMITED
|
||||
): ReceiveChannel<E> {
|
||||
return Channel<E>(capacity).apply {
|
||||
@ -192,7 +192,7 @@ fun <R> CoroutineScope.subscribeMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
listeners: MessagePacketSubscribersBuilder.() -> R
|
||||
): R = this.subscribeMessages(coroutineContext, concurrencyKind, Listener.EventPriority.MONITOR, listeners)
|
||||
): R = this.subscribeMessages(coroutineContext, concurrencyKind, EventPriority.MONITOR, listeners)
|
||||
|
||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
@ -201,7 +201,7 @@ fun <R> CoroutineScope.subscribeGroupMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
listeners: GroupMessageSubscribersBuilder.() -> R
|
||||
): R = this.subscribeGroupMessages(coroutineContext, concurrencyKind, Listener.EventPriority.MONITOR, listeners)
|
||||
): R = this.subscribeGroupMessages(coroutineContext, concurrencyKind, EventPriority.MONITOR, listeners)
|
||||
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@ -210,7 +210,7 @@ fun <R> CoroutineScope.subscribeFriendMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
listeners: FriendMessageSubscribersBuilder.() -> R
|
||||
): R = this.subscribeFriendMessages(coroutineContext, concurrencyKind, Listener.EventPriority.MONITOR, listeners)
|
||||
): R = this.subscribeFriendMessages(coroutineContext, concurrencyKind, EventPriority.MONITOR, listeners)
|
||||
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@ -219,7 +219,7 @@ fun <R> CoroutineScope.subscribeTempMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
listeners: TempMessageSubscribersBuilder.() -> R
|
||||
): R = this.subscribeTempMessages(coroutineContext, concurrencyKind, Listener.EventPriority.MONITOR, listeners)
|
||||
): R = this.subscribeTempMessages(coroutineContext, concurrencyKind, EventPriority.MONITOR, listeners)
|
||||
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@ -228,7 +228,7 @@ fun <R> Bot.subscribeMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
listeners: MessagePacketSubscribersBuilder.() -> R
|
||||
): R = this.subscribeMessages(coroutineContext, concurrencyKind, Listener.EventPriority.MONITOR, listeners)
|
||||
): R = this.subscribeMessages(coroutineContext, concurrencyKind, EventPriority.MONITOR, listeners)
|
||||
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@ -237,7 +237,7 @@ fun <R> Bot.subscribeGroupMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
listeners: GroupMessageSubscribersBuilder.() -> R
|
||||
): R = this.subscribeGroupMessages(coroutineContext, concurrencyKind, Listener.EventPriority.MONITOR, listeners)
|
||||
): R = this.subscribeGroupMessages(coroutineContext, concurrencyKind, EventPriority.MONITOR, listeners)
|
||||
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@ -246,7 +246,7 @@ fun <R> Bot.subscribeFriendMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
listeners: FriendMessageSubscribersBuilder.() -> R
|
||||
): R = this.subscribeFriendMessages(coroutineContext, concurrencyKind, Listener.EventPriority.MONITOR, listeners)
|
||||
): R = this.subscribeFriendMessages(coroutineContext, concurrencyKind, EventPriority.MONITOR, listeners)
|
||||
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@ -255,4 +255,4 @@ fun <R> Bot.subscribeTempMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
listeners: TempMessageSubscribersBuilder.() -> R
|
||||
): R = this.subscribeTempMessages(coroutineContext, concurrencyKind, Listener.EventPriority.MONITOR, listeners)
|
||||
): R = this.subscribeTempMessages(coroutineContext, concurrencyKind, EventPriority.MONITOR, listeners)
|
@ -47,7 +47,7 @@ internal fun <E : Event> CoroutineScope.Handler(
|
||||
): Handler<E> {
|
||||
@OptIn(ExperimentalCoroutinesApi::class) // don't remove
|
||||
val context = this.newCoroutineContext(coroutineContext)
|
||||
return Handler(context[Job], context, handler, concurrencyKind, Listener.EventPriority.NORMAL)
|
||||
return Handler(context[Job], context, handler, concurrencyKind, EventPriority.NORMAL)
|
||||
}
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ internal fun <E : Event> CoroutineScope.Handler(
|
||||
internal fun <E : Event> CoroutineScope.Handler(
|
||||
coroutineContext: CoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.NORMAL,
|
||||
priority: Listener.EventPriority = EventPriority.NORMAL,
|
||||
handler: suspend (E) -> ListeningStatus
|
||||
): Handler<E> {
|
||||
@OptIn(ExperimentalCoroutinesApi::class) // don't remove
|
||||
@ -163,7 +163,7 @@ internal suspend fun <E : AbstractEvent> callAndRemoveIfRequired(
|
||||
}
|
||||
}
|
||||
coroutineScope {
|
||||
GlobalEventListeners[Listener.EventPriority.MONITOR].forEachNode { eventNode ->
|
||||
GlobalEventListeners[EventPriority.MONITOR].forEachNode { eventNode ->
|
||||
if (event.isIntercepted) {
|
||||
return@coroutineScope
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ import kotlin.reflect.KClass
|
||||
@JvmSynthetic
|
||||
suspend inline fun <reified E : Event, R : Any> syncFromEvent(
|
||||
timeoutMillis: Long = -1,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
crossinline mapper: suspend E.(E) -> R?
|
||||
): R {
|
||||
require(timeoutMillis == -1L || timeoutMillis > 0) { "timeoutMillis must be -1 or > 0" }
|
||||
@ -68,7 +68,7 @@ suspend inline fun <reified E : Event, R : Any> syncFromEvent(
|
||||
@JvmSynthetic
|
||||
suspend inline fun <reified E : Event, R : Any> syncFromEventOrNull(
|
||||
timeoutMillis: Long,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
crossinline mapper: suspend E.(E) -> R?
|
||||
): R? {
|
||||
require(timeoutMillis > 0) { "timeoutMillis must be > 0" }
|
||||
@ -97,7 +97,7 @@ suspend inline fun <reified E : Event, R : Any> syncFromEventOrNull(
|
||||
inline fun <reified E : Event, R : Any> CoroutineScope.asyncFromEventOrNull(
|
||||
timeoutMillis: Long,
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
crossinline mapper: suspend E.(E) -> R?
|
||||
): Deferred<R?> {
|
||||
require(timeoutMillis == -1L || timeoutMillis > 0) { "timeoutMillis must be -1 or > 0" }
|
||||
@ -126,7 +126,7 @@ inline fun <reified E : Event, R : Any> CoroutineScope.asyncFromEventOrNull(
|
||||
inline fun <reified E : Event, R : Any> CoroutineScope.asyncFromEvent(
|
||||
timeoutMillis: Long = -1,
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
crossinline mapper: suspend E.(E) -> R?
|
||||
): Deferred<R> {
|
||||
require(timeoutMillis == -1L || timeoutMillis > 0) { "timeoutMillis must be -1 or > 0" }
|
||||
|
@ -33,7 +33,7 @@ import kotlin.reflect.KClass
|
||||
@JvmSynthetic
|
||||
suspend inline fun <reified E : Event> nextEvent(
|
||||
timeoutMillis: Long = -1,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR
|
||||
): E {
|
||||
require(timeoutMillis == -1L || timeoutMillis > 0) { "timeoutMillis must be -1 or > 0" }
|
||||
return withTimeoutOrCoroutineScope(timeoutMillis) {
|
||||
@ -55,7 +55,7 @@ suspend inline fun <reified E : Event> nextEvent(
|
||||
@JvmSynthetic
|
||||
suspend inline fun <reified E : Event> nextEventOrNull(
|
||||
timeoutMillis: Long,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR
|
||||
): E? {
|
||||
return withTimeoutOrNull(timeoutMillis) {
|
||||
nextEventImpl(E::class, this, priority)
|
||||
@ -79,7 +79,7 @@ suspend inline fun <reified E : Event> nextEventOrNull(
|
||||
@JvmSynthetic
|
||||
suspend inline fun <reified E : BotEvent> Bot.nextEvent(
|
||||
timeoutMillis: Long = -1,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR
|
||||
): E {
|
||||
require(timeoutMillis == -1L || timeoutMillis > 0) { "timeoutMillis must be -1 or > 0" }
|
||||
return withTimeoutOrCoroutineScope(timeoutMillis) {
|
||||
|
@ -28,7 +28,7 @@ import kotlin.jvm.JvmSynthetic
|
||||
*
|
||||
* 创建的所有事件监听器都会判断发送人信息 ([isContextIdenticalWith]), 监听之后的所有消息.
|
||||
*
|
||||
* [selectBuilder] DSL 类似于 [subscribeMessages] 的 DSL, 屏蔽了一些 `reply` DSL 以确保类型安全
|
||||
* [selectBuilder] DSL 类似于 [CoroutineScope.subscribeMessages] 的 DSL, 屏蔽了一些 `reply` DSL 以确保类型安全
|
||||
*
|
||||
* ```kotlin
|
||||
* reply("开启复读模式")
|
||||
@ -62,7 +62,7 @@ import kotlin.jvm.JvmSynthetic
|
||||
suspend inline fun <reified T : MessageEvent> T.whileSelectMessages(
|
||||
timeoutMillis: Long = -1,
|
||||
filterContext: Boolean = true,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
crossinline selectBuilder: @MessageDsl MessageSelectBuilder<T, Boolean>.() -> Unit
|
||||
) = whileSelectMessagesImpl(timeoutMillis, filterContext, priority, selectBuilder)
|
||||
|
||||
@ -75,7 +75,7 @@ suspend inline fun <reified T : MessageEvent> T.whileSelectMessages(
|
||||
suspend inline fun <reified T : MessageEvent> T.selectMessagesUnit(
|
||||
timeoutMillis: Long = -1,
|
||||
filterContext: Boolean = true,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
crossinline selectBuilder: @MessageDsl MessageSelectBuilderUnit<T, Unit>.() -> Unit
|
||||
) = selectMessagesImpl(timeoutMillis, true, filterContext, priority, selectBuilder)
|
||||
|
||||
@ -85,7 +85,7 @@ suspend inline fun <reified T : MessageEvent> T.selectMessagesUnit(
|
||||
*
|
||||
* 创建的所有事件监听器都会判断发送人信息 ([isContextIdenticalWith]), 监听之后的所有消息.
|
||||
*
|
||||
* [selectBuilder] DSL 类似于 [subscribeMessages] 的 DSL, 屏蔽了一些 `reply` DSL 以确保类型安全
|
||||
* [selectBuilder] DSL 类似于 [CoroutineScope.subscribeMessages] 的 DSL, 屏蔽了一些 `reply` DSL 以确保类型安全
|
||||
*
|
||||
* ```kotlin
|
||||
* val value: String = selectMessages {
|
||||
@ -105,7 +105,7 @@ suspend inline fun <reified T : MessageEvent> T.selectMessagesUnit(
|
||||
suspend inline fun <reified T : MessageEvent, R> T.selectMessages(
|
||||
timeoutMillis: Long = -1,
|
||||
filterContext: Boolean = true,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
// @BuilderInference
|
||||
crossinline selectBuilder: @MessageDsl MessageSelectBuilder<T, R>.() -> Unit
|
||||
): R =
|
||||
@ -117,7 +117,7 @@ suspend inline fun <reified T : MessageEvent, R> T.selectMessages(
|
||||
/**
|
||||
* [selectMessages] 时的 DSL 构建器.
|
||||
*
|
||||
* 它是特殊化的消息监听 ([subscribeMessages]) DSL, 屏蔽了一些 `reply` DSL 以确保作用域安全性
|
||||
* 它是特殊化的消息监听 ([CoroutineScope.subscribeMessages]) DSL, 屏蔽了一些 `reply` DSL 以确保作用域安全性
|
||||
*
|
||||
* @see MessageSelectBuilderUnit 查看上层 API
|
||||
*/
|
||||
@ -232,7 +232,7 @@ abstract class MessageSelectBuilder<M : MessageEvent, R> @PublishedApi internal
|
||||
/**
|
||||
* [selectMessagesUnit] 或 [selectMessages] 时的 DSL 构建器.
|
||||
*
|
||||
* 它是特殊化的消息监听 ([subscribeMessages]) DSL
|
||||
* 它是特殊化的消息监听 ([CoroutineScope.subscribeMessages]) DSL
|
||||
*
|
||||
* @see MessageSubscribersBuilder 查看上层 API
|
||||
*/
|
||||
|
@ -43,7 +43,7 @@ typealias MessagePacketSubscribersBuilder = MessageSubscribersBuilder<MessageEve
|
||||
fun <R> CoroutineScope.subscribeMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
listeners: MessagePacketSubscribersBuilder.() -> R
|
||||
): R {
|
||||
// contract 可帮助 IDE 进行类型推断. 无实际代码作用.
|
||||
@ -77,7 +77,7 @@ typealias GroupMessageSubscribersBuilder = MessageSubscribersBuilder<GroupMessag
|
||||
fun <R> CoroutineScope.subscribeGroupMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
listeners: GroupMessageSubscribersBuilder.() -> R
|
||||
): R {
|
||||
contract {
|
||||
@ -105,7 +105,7 @@ typealias FriendMessageSubscribersBuilder = MessageSubscribersBuilder<FriendMess
|
||||
fun <R> CoroutineScope.subscribeFriendMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
listeners: FriendMessageSubscribersBuilder.() -> R
|
||||
): R {
|
||||
contract {
|
||||
@ -133,7 +133,7 @@ typealias TempMessageSubscribersBuilder = MessageSubscribersBuilder<TempMessageE
|
||||
fun <R> CoroutineScope.subscribeTempMessages(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
listeners: TempMessageSubscribersBuilder.() -> R
|
||||
): R {
|
||||
contract {
|
||||
@ -166,7 +166,7 @@ fun <R> CoroutineScope.subscribeTempMessages(
|
||||
inline fun <reified E : Event> CoroutineScope.incoming(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
capacity: Int = Channel.UNLIMITED
|
||||
): ReceiveChannel<E> {
|
||||
return Channel<E>(capacity).apply {
|
||||
|
@ -62,7 +62,7 @@ enum class ListeningStatus {
|
||||
|
||||
/**
|
||||
* 事件监听器.
|
||||
* 由 [subscribe] 等方法返回.
|
||||
* 由 [CoroutineScope.subscribe] 等方法返回.
|
||||
*
|
||||
* 取消监听: [complete]
|
||||
*/
|
||||
@ -123,9 +123,9 @@ interface Listener<in E : Event> : CompletableJob {
|
||||
val priority: EventPriority get() = NORMAL
|
||||
|
||||
/**
|
||||
* 这个方法将会调用 [subscribe] 时提供的参数 `noinline handler: suspend E.(E) -> ListeningStatus`.
|
||||
* 这个方法将会调用 [CoroutineScope.subscribe] 时提供的参数 `noinline handler: suspend E.(E) -> ListeningStatus`.
|
||||
*
|
||||
* 这个函数不会抛出任何异常, 详见 [subscribe]
|
||||
* 这个函数不会抛出任何异常, 详见 [CoroutineScope.subscribe]
|
||||
*/
|
||||
suspend fun onEvent(event: E): ListeningStatus
|
||||
}
|
||||
@ -220,7 +220,7 @@ inline fun <reified E : Event> CoroutineScope.subscribe(
|
||||
): Listener<E> = subscribe(E::class, coroutineContext, concurrency, priority, handler)
|
||||
|
||||
/**
|
||||
* 与 [subscribe] 的区别是接受 [eventClass] 参数, 而不使用 `reified` 泛型
|
||||
* 与 [CoroutineScope.subscribe] 的区别是接受 [eventClass] 参数, 而不使用 `reified` 泛型
|
||||
*
|
||||
* @see CoroutineScope.subscribe
|
||||
*
|
||||
@ -281,7 +281,7 @@ fun <E : Event> CoroutineScope.subscribeAlways(
|
||||
* @param coroutineContext 给事件监听协程的额外的 [CoroutineContext]
|
||||
* @param priority 处理优先级, 优先级高的先执行
|
||||
*
|
||||
* @see subscribe 获取更多说明
|
||||
* @see CoroutineScope.subscribe 获取更多说明
|
||||
*/
|
||||
@JvmSynthetic
|
||||
inline fun <reified E : Event> CoroutineScope.subscribeOnce(
|
||||
|
@ -48,7 +48,7 @@ fun MessageEvent.isContextIdenticalWith(another: MessageEvent): Boolean {
|
||||
@JvmSynthetic
|
||||
suspend inline fun <reified P : MessageEvent> P.nextMessage(
|
||||
timeoutMillis: Long = -1,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
noinline filter: suspend P.(P) -> Boolean = { true }
|
||||
): MessageChain {
|
||||
return syncFromEvent<P, P>(timeoutMillis, priority) {
|
||||
@ -70,7 +70,7 @@ suspend inline fun <reified P : MessageEvent> P.nextMessage(
|
||||
@JvmSynthetic
|
||||
suspend inline fun <reified P : MessageEvent> P.nextMessageOrNull(
|
||||
timeoutMillis: Long,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
noinline filter: suspend P.(P) -> Boolean = { true }
|
||||
): MessageChain? {
|
||||
require(timeoutMillis > 0) { "timeoutMillis must be > 0" }
|
||||
@ -86,7 +86,7 @@ suspend inline fun <reified P : MessageEvent> P.nextMessageOrNull(
|
||||
inline fun <reified P : MessageEvent> P.nextMessageAsync(
|
||||
timeoutMillis: Long = -1,
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
noinline filter: suspend P.(P) -> Boolean = { true }
|
||||
): Deferred<MessageChain> {
|
||||
return this.bot.async(coroutineContext) {
|
||||
@ -103,7 +103,7 @@ inline fun <reified P : MessageEvent> P.nextMessageAsync(
|
||||
inline fun <reified P : MessageEvent> P.nextMessageOrNullAsync(
|
||||
timeoutMillis: Long,
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
priority: Listener.EventPriority = Listener.EventPriority.MONITOR,
|
||||
priority: Listener.EventPriority = EventPriority.MONITOR,
|
||||
noinline filter: suspend P.(P) -> Boolean = { true }
|
||||
): Deferred<MessageChain?> {
|
||||
require(timeoutMillis > 0) { "timeoutMillis must be > 0" }
|
||||
|
@ -71,7 +71,7 @@ annotation class EventHandler(
|
||||
* @see Listener.EventPriority
|
||||
* @see Event.intercept
|
||||
*/
|
||||
val priority: Listener.EventPriority = Listener.EventPriority.NORMAL,
|
||||
val priority: Listener.EventPriority = EventPriority.NORMAL,
|
||||
/**
|
||||
* 是否自动忽略被 [取消][CancellableEvent.isCancelled]
|
||||
* @see CancellableEvent
|
||||
|
@ -97,7 +97,7 @@ internal class JvmMethodEventsTest {
|
||||
called.getAndIncrement()
|
||||
}
|
||||
|
||||
@EventHandler(Listener.EventPriority.MONITOR)
|
||||
@EventHandler(EventPriority.MONITOR)
|
||||
private fun TestEvent.`receiver param LS`(event: TestEvent): ListeningStatus {
|
||||
called.getAndIncrement()
|
||||
return ListeningStatus.STOPPED
|
||||
|
Loading…
Reference in New Issue
Block a user