Make CancellableEvent an interface, introduce AbstractCancellableEvent

This commit is contained in:
Him188 2020-02-11 12:30:49 +08:00
parent 001ad975b9
commit a322ce735b
4 changed files with 7 additions and 9 deletions

View File

@ -10,10 +10,10 @@
package net.mamoe.mirai.qqandroid.event package net.mamoe.mirai.qqandroid.event
import net.mamoe.mirai.data.Packet import net.mamoe.mirai.data.Packet
import net.mamoe.mirai.event.Cancellable import net.mamoe.mirai.event.AbstractCancellableEvent
import net.mamoe.mirai.event.Event import net.mamoe.mirai.event.Event
/** /**
* 接收到数据包 * 接收到数据包
*/ */
class PacketReceivedEvent(val packet: Packet) : Event(), Cancellable data class PacketReceivedEvent(val packet: Packet) : Event, AbstractCancellableEvent()

View File

@ -23,11 +23,8 @@ import net.mamoe.mirai.contact.Member
import net.mamoe.mirai.contact.MemberPermission import net.mamoe.mirai.contact.MemberPermission
import net.mamoe.mirai.data.MultiPacket import net.mamoe.mirai.data.MultiPacket
import net.mamoe.mirai.data.Packet import net.mamoe.mirai.data.Packet
import net.mamoe.mirai.event.BroadcastControllable import net.mamoe.mirai.event.*
import net.mamoe.mirai.event.Event
import net.mamoe.mirai.event.broadcast
import net.mamoe.mirai.event.events.ForceOfflineEvent import net.mamoe.mirai.event.events.ForceOfflineEvent
import net.mamoe.mirai.event.subscribeAlways
import net.mamoe.mirai.network.BotNetworkHandler import net.mamoe.mirai.network.BotNetworkHandler
import net.mamoe.mirai.qqandroid.GroupImpl import net.mamoe.mirai.qqandroid.GroupImpl
import net.mamoe.mirai.qqandroid.MemberImpl import net.mamoe.mirai.qqandroid.MemberImpl
@ -347,7 +344,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
} }
// check top-level cancelling // check top-level cancelling
if (PacketReceivedEvent(packet).broadcast().cancelled) { if (PacketReceivedEvent(packet).broadcast().isCancelled) {
return return
} }
@ -360,7 +357,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
packet.broadcast() 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", "")}") bot.logger.info("Received packet: ${packet.toString().replace("\n", """\n""").replace("\r", "")}")

View File

@ -37,7 +37,7 @@ expect abstract class MessagePacket<TSender : QQ, TSubject : Contact>(bot: Bot)
*/ // Tips: 在 IntelliJ 中 (左侧边栏) 打开 `Structure`, 可查看类结构 */ // Tips: 在 IntelliJ 中 (左侧边栏) 打开 `Structure`, 可查看类结构
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
@MiraiInternalAPI @MiraiInternalAPI
abstract class MessagePacketBase<TSender : QQ, TSubject : Contact>(_bot: Bot) : EventPacket, BotEvent() { abstract class MessagePacketBase<TSender : QQ, TSubject : Contact>(_bot: Bot) : EventPacket, BotEvent {
/** /**
* 接受到这条消息的 * 接受到这条消息的
*/ */

View File

@ -12,6 +12,7 @@ package net.mamoe.mirai.event
import kotlinx.coroutines.CompletableJob import kotlinx.coroutines.CompletableJob
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import net.mamoe.mirai.test.shouldBeEqualTo
import kotlin.system.exitProcess import kotlin.system.exitProcess
import kotlin.test.Test import kotlin.test.Test