From b48f972f1c3380571aef88f7384e05303c6c5529 Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 19 Dec 2019 18:12:24 +0800 Subject: [PATCH] Change upper bounds to Subscribable --- .../event/SubscribersWithBot.kt | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/SubscribersWithBot.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/SubscribersWithBot.kt index 6db2c9aa1..f9d82f017 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/SubscribersWithBot.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/SubscribersWithBot.kt @@ -3,7 +3,6 @@ package net.mamoe.mirai.event import net.mamoe.mirai.Bot -import net.mamoe.mirai.event.events.BotEvent import net.mamoe.mirai.event.internal.HandlerWithSession import net.mamoe.mirai.event.internal.Listener import net.mamoe.mirai.event.internal.subscribeInternal @@ -18,38 +17,38 @@ import kotlin.reflect.KClass // region 顶层方法 -suspend inline fun Bot.subscribe(noinline handler: suspend Bot.(E) -> ListeningStatus): Listener = +suspend inline fun Bot.subscribe(noinline handler: suspend Bot.(E) -> ListeningStatus): Listener = E::class.subscribe(this, handler) -suspend inline fun Bot.subscribeAlways(noinline listener: suspend Bot.(E) -> Unit): Listener = +suspend inline fun Bot.subscribeAlways(noinline listener: suspend Bot.(E) -> Unit): Listener = E::class.subscribeAlways(this, listener) -suspend inline fun Bot.subscribeOnce(noinline listener: suspend Bot.(E) -> Unit): Listener = +suspend inline fun Bot.subscribeOnce(noinline listener: suspend Bot.(E) -> Unit): Listener = E::class.subscribeOnce(this, listener) -suspend inline fun Bot.subscribeUntil(valueIfStop: T, noinline listener: suspend Bot.(E) -> T): Listener = +suspend inline fun Bot.subscribeUntil(valueIfStop: T, noinline listener: suspend Bot.(E) -> T): Listener = E::class.subscribeUntil(this, valueIfStop, listener) -suspend inline fun Bot.subscribeUntilFalse(noinline listener: suspend Bot.(E) -> Boolean): Listener = +suspend inline fun Bot.subscribeUntilFalse(noinline listener: suspend Bot.(E) -> Boolean): Listener = E::class.subscribeUntilFalse(this, listener) -suspend inline fun Bot.subscribeUntilTrue(noinline listener: suspend Bot.(E) -> Boolean): Listener = +suspend inline fun Bot.subscribeUntilTrue(noinline listener: suspend Bot.(E) -> Boolean): Listener = E::class.subscribeUntilTrue(this, listener) -suspend inline fun Bot.subscribeUntilNull(noinline listener: suspend Bot.(E) -> Any?): Listener = +suspend inline fun Bot.subscribeUntilNull(noinline listener: suspend Bot.(E) -> Any?): Listener = E::class.subscribeUntilNull(this, listener) -suspend inline fun Bot.subscribeWhile(valueIfContinue: T, noinline listener: suspend Bot.(E) -> T): Listener = +suspend inline fun Bot.subscribeWhile(valueIfContinue: T, noinline listener: suspend Bot.(E) -> T): Listener = E::class.subscribeWhile(this, valueIfContinue, listener) -suspend inline fun Bot.subscribeWhileFalse(noinline listener: suspend Bot.(E) -> Boolean): Listener = +suspend inline fun Bot.subscribeWhileFalse(noinline listener: suspend Bot.(E) -> Boolean): Listener = E::class.subscribeWhileFalse(this, listener) -suspend inline fun Bot.subscribeWhileTrue(noinline listener: suspend Bot.(E) -> Boolean): Listener = +suspend inline fun Bot.subscribeWhileTrue(noinline listener: suspend Bot.(E) -> Boolean): Listener = E::class.subscribeWhileTrue(this, listener) -suspend inline fun Bot.subscribeWhileNull(noinline listener: suspend Bot.(E) -> Any?): Listener = +suspend inline fun Bot.subscribeWhileNull(noinline listener: suspend Bot.(E) -> Any?): Listener = E::class.subscribeWhileNull(this, listener) // endregion @@ -57,48 +56,48 @@ suspend inline fun Bot.subscribeWhileNull(noinline listen // region KClass 的扩展方法 (仅内部使用) @PublishedApi -internal suspend fun KClass.subscribe(bot: Bot, handler: suspend Bot.(E) -> ListeningStatus) = +internal suspend fun KClass.subscribe(bot: Bot, handler: suspend Bot.(E) -> ListeningStatus) = this.subscribeInternal(HandlerWithSession(bot, handler)) @PublishedApi -internal suspend fun KClass.subscribeAlways(bot: Bot, listener: suspend Bot.(E) -> Unit) = +internal suspend fun KClass.subscribeAlways(bot: Bot, listener: suspend Bot.(E) -> Unit) = this.subscribeInternal(HandlerWithSession(bot) { listener(it); ListeningStatus.LISTENING }) @PublishedApi -internal suspend fun KClass.subscribeOnce(bot: Bot, listener: suspend Bot.(E) -> Unit) = +internal suspend fun KClass.subscribeOnce(bot: Bot, listener: suspend Bot.(E) -> Unit) = this.subscribeInternal(HandlerWithSession(bot) { listener(it); ListeningStatus.STOPPED }) @PublishedApi -internal suspend fun KClass.subscribeUntil(bot: Bot, valueIfStop: T, listener: suspend Bot.(E) -> T) = +internal suspend fun KClass.subscribeUntil(bot: Bot, valueIfStop: T, listener: suspend Bot.(E) -> T) = subscribeInternal(HandlerWithSession(bot) { if (listener(it) === valueIfStop) ListeningStatus.STOPPED else ListeningStatus.LISTENING }) @PublishedApi -internal suspend inline fun KClass.subscribeUntilFalse(bot: Bot, noinline listener: suspend Bot.(E) -> Boolean) = +internal suspend inline fun KClass.subscribeUntilFalse(bot: Bot, noinline listener: suspend Bot.(E) -> Boolean) = subscribeUntil(bot, false, listener) @PublishedApi -internal suspend inline fun KClass.subscribeUntilTrue(bot: Bot, noinline listener: suspend Bot.(E) -> Boolean) = +internal suspend inline fun KClass.subscribeUntilTrue(bot: Bot, noinline listener: suspend Bot.(E) -> Boolean) = subscribeUntil(bot, true, listener) @PublishedApi -internal suspend inline fun KClass.subscribeUntilNull(bot: Bot, noinline listener: suspend Bot.(E) -> Any?) = +internal suspend inline fun KClass.subscribeUntilNull(bot: Bot, noinline listener: suspend Bot.(E) -> Any?) = subscribeUntil(bot, null, listener) @PublishedApi -internal suspend fun KClass.subscribeWhile(bot: Bot, valueIfContinue: T, listener: suspend Bot.(E) -> T) = +internal suspend fun KClass.subscribeWhile(bot: Bot, valueIfContinue: T, listener: suspend Bot.(E) -> T) = subscribeInternal(HandlerWithSession(bot) { if (listener(it) !== valueIfContinue) ListeningStatus.STOPPED else ListeningStatus.LISTENING }) @PublishedApi -internal suspend inline fun KClass.subscribeWhileFalse(bot: Bot, noinline listener: suspend Bot.(E) -> Boolean) = +internal suspend inline fun KClass.subscribeWhileFalse(bot: Bot, noinline listener: suspend Bot.(E) -> Boolean) = subscribeWhile(bot, false, listener) @PublishedApi -internal suspend inline fun KClass.subscribeWhileTrue(bot: Bot, noinline listener: suspend Bot.(E) -> Boolean) = +internal suspend inline fun KClass.subscribeWhileTrue(bot: Bot, noinline listener: suspend Bot.(E) -> Boolean) = subscribeWhile(bot, true, listener) @PublishedApi -internal suspend inline fun KClass.subscribeWhileNull(bot: Bot, noinline listener: suspend Bot.(E) -> Any?) = +internal suspend inline fun KClass.subscribeWhileNull(bot: Bot, noinline listener: suspend Bot.(E) -> Any?) = subscribeWhile(bot, null, listener) // endregion \ No newline at end of file