From a322ce735b878b542c184ad2f0a03eea36fd0c4e Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 11 Feb 2020 12:30:49 +0800 Subject: [PATCH] Make `CancellableEvent` an interface, introduce `AbstractCancellableEvent` --- .../mamoe/mirai/qqandroid/event/PacketReceivedEvent.kt | 4 ++-- .../qqandroid/network/QQAndroidBotNetworkHandler.kt | 9 +++------ .../kotlin/net.mamoe.mirai/message/MessagePacket.kt | 2 +- .../jvmTest/kotlin/net/mamoe/mirai/event/EventTests.kt | 1 + 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/event/PacketReceivedEvent.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/event/PacketReceivedEvent.kt index df9cbb8f2..831a1dc2b 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/event/PacketReceivedEvent.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/event/PacketReceivedEvent.kt @@ -10,10 +10,10 @@ package net.mamoe.mirai.qqandroid.event import net.mamoe.mirai.data.Packet -import net.mamoe.mirai.event.Cancellable +import net.mamoe.mirai.event.AbstractCancellableEvent import net.mamoe.mirai.event.Event /** * 接收到数据包 */ -class PacketReceivedEvent(val packet: Packet) : Event(), Cancellable \ No newline at end of file +data class PacketReceivedEvent(val packet: Packet) : Event, AbstractCancellableEvent() \ No newline at end of file diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt index abbd8c892..8b7a10104 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt @@ -23,11 +23,8 @@ import net.mamoe.mirai.contact.Member import net.mamoe.mirai.contact.MemberPermission import net.mamoe.mirai.data.MultiPacket import net.mamoe.mirai.data.Packet -import net.mamoe.mirai.event.BroadcastControllable -import net.mamoe.mirai.event.Event -import net.mamoe.mirai.event.broadcast +import net.mamoe.mirai.event.* import net.mamoe.mirai.event.events.ForceOfflineEvent -import net.mamoe.mirai.event.subscribeAlways import net.mamoe.mirai.network.BotNetworkHandler import net.mamoe.mirai.qqandroid.GroupImpl import net.mamoe.mirai.qqandroid.MemberImpl @@ -347,7 +344,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler } // check top-level cancelling - if (PacketReceivedEvent(packet).broadcast().cancelled) { + if (PacketReceivedEvent(packet).broadcast().isCancelled) { return } @@ -360,7 +357,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler packet.broadcast() } - if (packet is Cancellable && packet.cancelled) return + if (packet is CancellableEvent && packet.isCancelled) return } bot.logger.info("Received packet: ${packet.toString().replace("\n", """\n""").replace("\r", "")}") diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt index fa0d0f09a..4aeb9c04c 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt @@ -37,7 +37,7 @@ expect abstract class MessagePacket(bot: Bot) */ // Tips: 在 IntelliJ 中 (左侧边栏) 打开 `Structure`, 可查看类结构 @Suppress("NOTHING_TO_INLINE") @MiraiInternalAPI -abstract class MessagePacketBase(_bot: Bot) : EventPacket, BotEvent() { +abstract class MessagePacketBase(_bot: Bot) : EventPacket, BotEvent { /** * 接受到这条消息的 */ diff --git a/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/EventTests.kt b/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/EventTests.kt index 53d456c2d..b8b5a1ba5 100644 --- a/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/EventTests.kt +++ b/mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/EventTests.kt @@ -12,6 +12,7 @@ package net.mamoe.mirai.event import kotlinx.coroutines.CompletableJob import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.runBlocking +import net.mamoe.mirai.test.shouldBeEqualTo import kotlin.system.exitProcess import kotlin.test.Test