diff --git a/mirai-core-api/src/commonMain/kotlin/event/Event.kt b/mirai-core-api/src/commonMain/kotlin/event/Event.kt index 46dd7dba6..528f97430 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/Event.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/Event.kt @@ -11,7 +11,6 @@ package net.mamoe.mirai.event -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.runBlocking import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock @@ -29,13 +28,13 @@ import net.mamoe.mirai.utils.MiraiExperimentalApi * ### 广播 * 广播事件的唯一方式为 [broadcast]. * - * @see subscribeAlways - * @see subscribeOnce + * @see EventChannel.subscribeAlways + * @see EventChannel.subscribeOnce * - * @see subscribeMessages + * @see EventChannel.subscribeMessages * * @see [broadcast] 广播事件 - * @see [CoroutineScope.subscribe] 监听事件 + * @see [EventChannel.subscribe] 监听事件 * * @see CancellableEvent 可被取消的事件 */ diff --git a/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt b/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt index 3629c9d7a..3ae779a7d 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/EventChannel.kt @@ -55,7 +55,7 @@ import kotlin.reflect.KClass * - [GlobalEventChannel] * - [Bot.eventChannel] * - * @see EventChannel.subscribe + * @see subscribe */ public open class EventChannel @JvmOverloads constructor( public val baseEventClass: KClass, @@ -96,7 +96,7 @@ public open class EventChannel @JvmOverloads constructor( // region transforming operations /** - * 添加一个过滤器. 过滤器将在收到任何事件之后, 传递给通过 [subscribe] 注册的监听器之前调用. + * 添加一个过滤器. 过滤器将在收到任何事件之后, 传递给通过 [EventChannel.subscribe] 注册的监听器之前调用. * * 若 [filter] 返回 `true`, 该事件将会被传给监听器. 否则将会被忽略, **监听器继续监听**. * diff --git a/mirai-core-api/src/commonMain/kotlin/event/EventChannelKotlinExtensions.kt b/mirai-core-api/src/commonMain/kotlin/event/EventChannelKotlinExtensions.kt index c813b531d..a3f5daf33 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/EventChannelKotlinExtensions.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/EventChannelKotlinExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 Mamoe Technologies and contributors. + * Copyright 2019-2021 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -27,7 +27,7 @@ import kotlin.internal.LowPriorityInOverloadResolution * * eventChannel.subscribe(GroupMessageEvent::onMessage) * ``` - * @see subscribe + * @see EventChannel.subscribe */ @JvmSynthetic @LowPriorityInOverloadResolution @@ -48,7 +48,7 @@ public inline fun EventChannel * * eventChannel.subscribe(::onMessage) * ``` - * @see subscribe + * @see EventChannel.subscribe */ @JvmSynthetic @LowPriorityInOverloadResolution @@ -70,7 +70,7 @@ public inline fun EventChannel * * eventChannel.subscribe(GroupMessageEvent::onMessage) * ``` - * @see subscribe + * @see EventChannel.subscribe */ @JvmSynthetic @LowPriorityInOverloadResolution @@ -91,7 +91,7 @@ public inline fun EventChannel * * eventChannel.subscribe(::onMessage) * ``` - * @see subscribe + * @see EventChannel.subscribe */ @JvmSynthetic @LowPriorityInOverloadResolution @@ -110,7 +110,7 @@ public inline fun EventChannel * } * eventChannel.subscribeAlways(::onMessage) * ``` - * @see subscribeAlways + * @see EventChannel.subscribeAlways */ @JvmName("subscribeAlways1") @JvmSynthetic @@ -131,7 +131,7 @@ public inline fun EventChannel * } * eventChannel.subscribeAlways(GroupMessageEvent::onMessage) * ``` - * @see subscribeAlways + * @see EventChannel.subscribeAlways */ @JvmSynthetic @LowPriorityInOverloadResolution @@ -150,7 +150,7 @@ public inline fun EventChannel * } * eventChannel.subscribeAlways(GroupMessageEvent::onMessage) * ``` - * @see subscribeAlways + * @see EventChannel.subscribeAlways */ @JvmSynthetic @LowPriorityInOverloadResolution @@ -169,7 +169,7 @@ public inline fun EventChannel * } * eventChannel.subscribeAlways(::onMessage) * ``` - * @see subscribeAlways + * @see EventChannel.subscribeAlways */ @JvmSynthetic @LowPriorityInOverloadResolution diff --git a/mirai-core-api/src/commonMain/kotlin/event/JvmMethodListeners.kt b/mirai-core-api/src/commonMain/kotlin/event/JvmMethodListeners.kt index 434b83d68..60dfd42a7 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/JvmMethodListeners.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/JvmMethodListeners.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 Mamoe Technologies and contributors. + * Copyright 2019-2021 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -26,7 +26,7 @@ import kotlin.coroutines.EmptyCoroutineContext * Kotlin 函数要求: * - 接收者 (英 receiver) 和函数参数: 所标注的 Kotlin 函数必须至少拥有一个接收者或一个函数参数, 或二者都具有. 接收者和函数参数的类型必须相同 (如果二者都存在) * 接收者或函数参数的类型都必须为 [Event] 或其子类. - * - 返回值: 为 [Unit] 或不指定返回值时将注册为 [CoroutineScope.subscribeAlways], 为 [ListeningStatus] 时将注册为 [CoroutineScope.subscribe]. + * - 返回值: 为 [Unit] 或不指定返回值时将注册为 [EventChannel.subscribeAlways], 为 [ListeningStatus] 时将注册为 [EventChannel.subscribe]. * 任何其他类型的返回值将会在注册时抛出异常. * * 所有 Kotlin 非 `suspend` 的函数都将会在 [Dispatchers.IO] 中调用 diff --git a/mirai-core-api/src/commonMain/kotlin/event/Listener.kt b/mirai-core-api/src/commonMain/kotlin/event/Listener.kt index da18efebb..03cbd8565 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/Listener.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/Listener.kt @@ -14,7 +14,6 @@ package net.mamoe.mirai.event import kotlinx.coroutines.CompletableJob -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.sync.Mutex import net.mamoe.mirai.event.Listener.EventPriority.* @@ -40,7 +39,7 @@ public enum class ListeningStatus { /** * 事件监听器. - * 由 [CoroutineScope.subscribe] 等方法返回. + * 由 [EventChannel.subscribe] 等方法返回. * * 取消监听: [complete] */ @@ -102,9 +101,9 @@ public interface Listener : CompletableJob { public val priority: EventPriority get() = NORMAL /** - * 这个方法将会调用 [CoroutineScope.subscribe] 时提供的参数 `noinline handler: suspend E.(E) -> ListeningStatus`. + * 这个方法将会调用 [EventChannel.subscribe] 时提供的参数 `noinline handler: suspend E.(E) -> ListeningStatus`. * - * 这个函数不会抛出任何异常, 详见 [CoroutineScope.subscribe] + * 这个函数不会抛出任何异常, 详见 [EventChannel.subscribe] */ public suspend fun onEvent(event: E): ListeningStatus } diff --git a/mirai-core-api/src/commonMain/kotlin/event/MessageSubscribersBuilder.kt b/mirai-core-api/src/commonMain/kotlin/event/MessageSubscribersBuilder.kt index d01091edb..15dad5ef8 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/MessageSubscribersBuilder.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/MessageSubscribersBuilder.kt @@ -40,7 +40,7 @@ public typealias MessageListener = @MessageDsl suspend T.(String) -> R * @param R 消息监听器内部的返回值 * @param Ret 每个 DSL 函数创建监听器之后的返回值 * - * @see subscribeMessages + * @see EventChannel.subscribeMessages */ @MessageDsl public open class MessageSubscribersBuilder internal constructor( diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/message.kt b/mirai-core-api/src/commonMain/kotlin/event/events/message.kt index 47bf3a26a..834702fdb 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/message.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/message.kt @@ -838,14 +838,9 @@ public abstract class AbstractMessageEvent : MessageEvent, AbstractEvent() { /** * 一个 (收到的) 消息事件. * - * 它是一个 [BotEvent], 因此可以被 [监听][Bot.subscribe] + * 它是一个 [BotEvent], 因此可以被 [监听][EventChannel.subscribe] * - * 支持的消息类型: - * - [群消息事件][GroupMessageEvent] - * - [好友消息事件][FriendMessageEvent] - * - [临时会话消息事件][TempMessageEvent] - * - * @see isContextIdenticalWith 判断语境是否相同 + * @see isContextIdenticalWith 判断语境相同 */ @Suppress("DEPRECATION") public interface MessageEvent : Event, Packet, BotEvent, MessageEventExtensions { diff --git a/mirai-core-api/src/commonMain/kotlin/event/migrationHelpers.kt b/mirai-core-api/src/commonMain/kotlin/event/migrationHelpers.kt deleted file mode 100644 index edcaf520d..000000000 --- a/mirai-core-api/src/commonMain/kotlin/event/migrationHelpers.kt +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright 2019-2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - */ - -@file:Suppress("unused", "DEPRECATION", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") -@file:JvmName("SubscriberKt") -@file:JvmMultifileClass - -package net.mamoe.mirai.event - -import kotlinx.coroutines.CoroutineScope -import net.mamoe.mirai.event.Listener.ConcurrencyKind -import net.mamoe.mirai.event.Listener.EventPriority -import kotlin.coroutines.CoroutineContext -import kotlin.coroutines.EmptyCoroutineContext -import kotlin.internal.LowPriorityInOverloadResolution -import kotlin.reflect.KClass - - -// region subscribe / subscribeAlways / subscribeOnce - -private const val COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE = """ - CoroutineScope.subscribe 已被弃用. - CoroutineScope.subscribe 设计为在指定协程作用域下创建事件监听器, 监听所有事件 E. - 但由于 Bot 也实现接口 CoroutineScope, 就可以调用 Bot.subscribe, - 直观语义上应该是监听来自 Bot 的事件, 但实际是监听来自所有 Bot 的事件. - - 请以 Bot.eventChannel 或 GlobalEventChannel 替代. 可在 EventChannel 获取更详细的帮助. -""" - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith( - "this.globalEventChannel().subscribe(coroutineContext, concurrency, priority, handler)", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -public inline fun CoroutineScope.subscribe( - coroutineContext: CoroutineContext = EmptyCoroutineContext, - concurrency: ConcurrencyKind = ConcurrencyKind.LOCKED, - priority: EventPriority = EventPriority.NORMAL, - noinline handler: suspend E.(E) -> ListeningStatus -): Listener = this.globalEventChannel().subscribe(coroutineContext, concurrency, priority, handler) - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith( - "this.globalEventChannel().subscribe(eventClass, coroutineContext, concurrency, priority, handler)", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -public fun CoroutineScope.subscribe( - eventClass: KClass, - coroutineContext: CoroutineContext = EmptyCoroutineContext, - concurrency: ConcurrencyKind = ConcurrencyKind.LOCKED, - priority: EventPriority = EventPriority.NORMAL, - handler: suspend E.(E) -> ListeningStatus -): Listener = - this.globalEventChannel().subscribe(eventClass, coroutineContext, concurrency, priority, handler) - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith( - "this.globalEventChannel().subscribeAlways(E::class, coroutineContext, concurrency, priority, handler)", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -public inline fun CoroutineScope.subscribeAlways( - coroutineContext: CoroutineContext = EmptyCoroutineContext, - concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT, - priority: EventPriority = EventPriority.NORMAL, - noinline handler: suspend E.(E) -> Unit -): Listener = - this.globalEventChannel().subscribeAlways(E::class, coroutineContext, concurrency, priority, handler) - - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith( - "this.globalEventChannel().subscribeAlways(eventClass, coroutineContext, concurrency, priority, handler)", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -public fun CoroutineScope.subscribeAlways( - eventClass: KClass, - coroutineContext: CoroutineContext = EmptyCoroutineContext, - concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT, - priority: EventPriority = EventPriority.NORMAL, - handler: suspend E.(E) -> Unit -): Listener = - this.globalEventChannel().subscribeAlways(eventClass, coroutineContext, concurrency, priority, handler) - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith( - "this.globalEventChannel().subscribeOnce(coroutineContext, priority, handler)", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -@JvmSynthetic -public inline fun CoroutineScope.subscribeOnce( - coroutineContext: CoroutineContext = EmptyCoroutineContext, - priority: EventPriority = EventPriority.NORMAL, - noinline handler: suspend E.(E) -> Unit -): Listener = this.globalEventChannel().subscribeOnce(coroutineContext, priority, handler) - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith( - "this.globalEventChannel().subscribeOnce(eventClass, coroutineContext, priority, handler)", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -public fun CoroutineScope.subscribeOnce( - eventClass: KClass, - coroutineContext: CoroutineContext = EmptyCoroutineContext, - priority: EventPriority = EventPriority.NORMAL, - handler: suspend E.(E) -> Unit -): Listener = this.globalEventChannel().subscribeOnce(eventClass, coroutineContext, priority, handler) - -// endregion - - -// region subscribe for Kotlin functional reference - - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith( - "this.globalEventChannel().subscribe(E::class, coroutineContext, concurrency, priority) { handler(this) }", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -@JvmSynthetic -@LowPriorityInOverloadResolution -@JvmName("subscribe1") -public inline fun CoroutineScope.subscribe( - crossinline handler: (E) -> ListeningStatus, - priority: EventPriority = EventPriority.NORMAL, - concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT, - coroutineContext: CoroutineContext = EmptyCoroutineContext -): Listener = - this.globalEventChannel().subscribe(E::class, coroutineContext, concurrency, priority) { handler(this) } - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith( - "this.globalEventChannel().subscribe(E::class, coroutineContext, concurrency, priority) { handler(this) }", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -@JvmSynthetic -@LowPriorityInOverloadResolution -@JvmName("subscribe2") -public inline fun CoroutineScope.subscribe( - crossinline handler: E.(E) -> ListeningStatus, - priority: EventPriority = EventPriority.NORMAL, - concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT, - coroutineContext: CoroutineContext = EmptyCoroutineContext -): Listener = - this.globalEventChannel().subscribe(E::class, coroutineContext, concurrency, priority) { handler(this) } - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith( - "this.globalEventChannel().subscribe(E::class, coroutineContext, concurrency, priority) { handler(this) }", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -@JvmSynthetic -@LowPriorityInOverloadResolution -@JvmName("subscribe1") -public inline fun CoroutineScope.subscribe( - crossinline handler: suspend (E) -> ListeningStatus, - priority: EventPriority = EventPriority.NORMAL, - concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT, - coroutineContext: CoroutineContext = EmptyCoroutineContext -): Listener = - this.globalEventChannel().subscribe(E::class, coroutineContext, concurrency, priority) { handler(this) } - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, - replaceWith = ReplaceWith( - "this.globalEventChannel().subscribe(E::class, coroutineContext, concurrency, priority) { handler(this) }", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -@JvmSynthetic -@LowPriorityInOverloadResolution -@JvmName("subscribe3") -public inline fun CoroutineScope.subscribe( - crossinline handler: suspend E.(E) -> ListeningStatus, - priority: EventPriority = EventPriority.NORMAL, - concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT, - coroutineContext: CoroutineContext = EmptyCoroutineContext -): Listener = - this.globalEventChannel().subscribe(E::class, coroutineContext, concurrency, priority) { handler(this) } - - -// endregion - - -// region subscribeAlways for Kotlin functional references - - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, replaceWith = - ReplaceWith( - "this.globalEventChannel().subscribeAlways(E::class, coroutineContext, concurrency, priority) { handler(this) }", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -@JvmSynthetic -@LowPriorityInOverloadResolution -@JvmName("subscribeAlways1") -public inline fun CoroutineScope.subscribeAlways( - crossinline handler: (E) -> Unit, - priority: EventPriority = EventPriority.NORMAL, - concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT, - coroutineContext: CoroutineContext = EmptyCoroutineContext -): Listener = this.globalEventChannel() - .subscribeAlways(E::class, coroutineContext, concurrency, priority) { handler(this) } - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, replaceWith = - ReplaceWith( - "this.globalEventChannel().subscribeAlways(E::class, coroutineContext, concurrency, priority) { handler(this) }", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -@JvmSynthetic -@LowPriorityInOverloadResolution -@JvmName("subscribeAlways1") -public inline fun CoroutineScope.subscribeAlways( - crossinline handler: E.(E) -> Unit, - priority: EventPriority = EventPriority.NORMAL, - concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT, - coroutineContext: CoroutineContext = EmptyCoroutineContext -): Listener = this.globalEventChannel() - .subscribeAlways(E::class, coroutineContext, concurrency, priority) { handler(this) } - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, replaceWith = - ReplaceWith( - "this.globalEventChannel().subscribeAlways(E::class, coroutineContext, concurrency, priority) { handler(this) }", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -@JvmSynthetic -@LowPriorityInOverloadResolution -@JvmName("subscribe4") -public inline fun CoroutineScope.subscribeAlways( - crossinline handler: suspend (E) -> Unit, - priority: EventPriority = EventPriority.NORMAL, - concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT, - coroutineContext: CoroutineContext = EmptyCoroutineContext -): Listener = this.globalEventChannel() - .subscribeAlways(E::class, coroutineContext, concurrency, priority) { handler(this) } - -@Deprecated( - COROUTINE_SCOPE_SUBSCRIBE_DEPRECATION_MESSAGE, - level = DeprecationLevel.ERROR, replaceWith = - ReplaceWith( - "this.globalEventChannel().subscribeAlways(E::class, coroutineContext, concurrency, priority) { handler(this) }", - "net.mamoe.mirai.event.Listener.ConcurrencyKind", - "net.mamoe.mirai.event.Listener.EventPriority", - "net.mamoe.mirai.event.globalEventChannel", - ) -) -@JvmSynthetic -@LowPriorityInOverloadResolution -@JvmName("subscribe1") -public inline fun CoroutineScope.subscribeAlways( - crossinline handler: suspend E.(E) -> Unit, - priority: EventPriority = EventPriority.NORMAL, - concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT, - coroutineContext: CoroutineContext = EmptyCoroutineContext -): Listener = this.globalEventChannel() - .subscribeAlways(E::class, coroutineContext, concurrency, priority) { handler(this) } - -// endregion \ No newline at end of file diff --git a/mirai-core-api/src/commonMain/kotlin/event/nextEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/nextEvent.kt index 30edfeecd..a057623b1 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/nextEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/nextEvent.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 Mamoe Technologies and contributors. + * Copyright 2019-2021 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -24,7 +24,7 @@ import kotlin.reflect.KClass * @param timeoutMillis 超时. 单位为毫秒. `-1` 为不限制. * @param filter 过滤器. 返回 `true` 时表示得到了需要的实例. 返回 `false` 时表示继续监听 * - * @see subscribe 普通地监听一个事件 + * @see EventChannel.subscribe 普通地监听一个事件 * @see syncFromEvent 挂起当前协程, 并尝试从事件中同步一个值 * * @throws TimeoutCancellationException 在超时后抛出. @@ -48,7 +48,7 @@ public suspend inline fun nextEvent( * @param timeoutMillis 超时. 单位为毫秒. * @param filter 过滤器. 返回 `true` 时表示得到了需要的实例. 返回 `false` 时表示继续监听 * - * @see subscribe 普通地监听一个事件 + * @see EventChannel.subscribe 普通地监听一个事件 * @see syncFromEvent 挂起当前协程, 并尝试从事件中同步一个值 * * @return 事件实例, 在超时后返回 `null` diff --git a/mirai-core-api/src/commonMain/kotlin/event/select.kt b/mirai-core-api/src/commonMain/kotlin/event/select.kt index d96e7b715..4bc36ab00 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/select.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/select.kt @@ -52,8 +52,8 @@ import net.mamoe.mirai.utils.MiraiExperimentalApi * * @param timeoutMillis 超时. 单位为毫秒. `-1` 为不限制 * - * @see subscribe - * @see subscribeMessages + * @see EventChannel.subscribe + * @see EventChannel.subscribeMessages * @see nextMessage 挂起协程并等待下一条消息 */ @Suppress("unused") diff --git a/mirai-core-api/src/commonMain/kotlin/event/subscribeMessages.kt b/mirai-core-api/src/commonMain/kotlin/event/subscribeMessages.kt index d4949e2bb..02d41eccf 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/subscribeMessages.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/subscribeMessages.kt @@ -82,7 +82,7 @@ public typealias GroupMessageSubscribersBuilder = MessageSubscribersBuilder EventChannel<*>.subscribeGroupMessages( @@ -100,7 +100,7 @@ public typealias FriendMessageSubscribersBuilder = MessageSubscribersBuilder EventChannel<*>.subscribeFriendMessages( @@ -118,7 +118,7 @@ public typealias TempMessageSubscribersBuilder = MessageSubscribersBuilder EventChannel<*>.subscribeTempMessages( @@ -137,7 +137,7 @@ public typealias StrangerMessageSubscribersBuilder = MessageSubscribersBuilder EventChannel<*>.subscribeStrangerMessages( @@ -157,7 +157,7 @@ public typealias OtherClientMessageSubscribersBuilder = MessageSubscribersBuilde /** * 通过 DSL 订阅来自所有 [Bot] 的所有 [OtherClient] 消息事件. DSL 语法查看 [subscribeMessages]. * - * @see subscribe 事件监听基础 + * @see EventChannel.subscribe 事件监听基础 * @see EventChannel 事件通道 */ public fun EventChannel<*>.subscribeOtherClientMessages( diff --git a/mirai-core-api/src/commonMain/kotlin/event/syncFromEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/syncFromEvent.kt index 997087a5e..88359e28b 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/syncFromEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/syncFromEvent.kt @@ -23,7 +23,7 @@ import kotlin.reflect.KClass * @param mapper 过滤转换器. 返回非 null 则代表得到了需要的值. [syncFromEvent] 会返回这个值 * * @see asyncFromEvent 本函数的异步版本 - * @see subscribe 普通地监听一个事件 + * @see EventChannel.subscribe 普通地监听一个事件 * @see nextEvent 挂起当前协程, 并获取下一个事件实例 * * @see syncFromEventOrNull 本函数的在超时后返回 `null` 的版本 @@ -59,7 +59,7 @@ public suspend inline fun syncFromEvent( * @return 超时返回 `null`, 否则返回 [mapper] 返回的第一个非 `null` 值. * * @see asyncFromEvent 本函数的异步版本 - * @see subscribe 普通地监听一个事件 + * @see EventChannel.subscribe 普通地监听一个事件 * @see nextEvent 挂起当前协程, 并获取下一个事件实例 * * @throws Throwable 当 [mapper] 抛出任何异常时, 本函数会抛出该异常 @@ -88,7 +88,7 @@ public suspend inline fun syncFromEventOrNull( * * @see syncFromEvent * @see asyncFromEvent - * @see subscribe 普通地监听一个事件 + * @see EventChannel.subscribe 普通地监听一个事件 * @see nextEvent 挂起当前协程, 并获取下一个事件实例 */ @JvmSynthetic @@ -117,7 +117,7 @@ public inline fun CoroutineScope.asyncFromEventOrNu * * @see syncFromEvent * @see asyncFromEventOrNull - * @see subscribe 普通地监听一个事件 + * @see EventChannel.subscribe 普通地监听一个事件 * @see nextEvent 挂起当前协程, 并获取下一个事件实例 */ @JvmSynthetic