From 876da07144e834c81b4bee46d4022c0af6c95233 Mon Sep 17 00:00:00 2001 From: ryoii Date: Sat, 22 Feb 2020 00:40:40 +0800 Subject: [PATCH 1/2] tool man fixes bugs which he doesnt know at all --- .../network/QQAndroidBotNetworkHandler.kt | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) 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 4746a5fff..57782c6f5 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 @@ -374,12 +374,12 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler // with generic type, less mistakes private suspend fun

generifiedParsePacket(input: Input) { KnownPacketFactories.parseIncomingPacket(bot, input) { packetFactory: PacketFactory

, packet: P, commandName: String, sequenceId: Int -> - handlePacket(packetFactory, packet, commandName, sequenceId) if (packet is MultiPacket<*>) { packet.forEach { handlePacket(null, it, commandName, sequenceId) } } + handlePacket(packetFactory, packet, commandName, sequenceId) } } @@ -388,29 +388,6 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler */ suspend fun

handlePacket(packetFactory: PacketFactory

?, packet: P, commandName: String, sequenceId: Int) { // highest priority: pass to listeners (attached by sendAndExpect). - packetListeners.forEach { listener -> - if (listener.filter(commandName, sequenceId) && packetListeners.remove(listener)) { - listener.complete(packet) - } - } - - // check top-level cancelling - if (packet != null && PacketReceivedEvent(packet).broadcast().isCancelled) { - return - } - - - // broadcast - if (packet is Event) { - if (packet is BroadcastControllable) { - if (packet.shouldBroadcast) packet.broadcast() - } else { - packet.broadcast() - } - - if (packet is CancellableEvent && packet.isCancelled) return - } - if (packet != null && (bot.logger.isEnabled || logger.isEnabled)) { val logMessage = "Received: ${packet.toString().replace("\n", """\n""").replace("\r", "")}" @@ -419,12 +396,32 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler } else logger.verbose(logMessage) } + packetListeners.forEach { listener -> + if (listener.filter(commandName, sequenceId) && packetListeners.remove(listener)) { + listener.complete(packet) + } + } + packetFactory?.run { when (this) { is OutgoingPacketFactory

-> bot.handle(packet) is IncomingPacketFactory

-> bot.handle(packet, sequenceId)?.sendWithoutExpect() } } + + if (packet != null && PacketReceivedEvent(packet).broadcast().isCancelled) { + return + } + + if (packet is Event) { + if (packet is BroadcastControllable) { + if (packet.shouldBroadcast) packet.broadcast() + } else { + packet.broadcast() + } + + if (packet is CancellableEvent && packet.isCancelled) return + } } /** From 24eab8f76c459f86261cbcbacf4c18a6d1c6948c Mon Sep 17 00:00:00 2001 From: ryoii Date: Sat, 22 Feb 2020 00:46:40 +0800 Subject: [PATCH 2/2] rename EventType_CN.md to EventType_CH.md --- mirai-api-http/{EventType_CN.md => EventType_CH.md} | 0 mirai-api-http/README_CH.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename mirai-api-http/{EventType_CN.md => EventType_CH.md} (100%) diff --git a/mirai-api-http/EventType_CN.md b/mirai-api-http/EventType_CH.md similarity index 100% rename from mirai-api-http/EventType_CN.md rename to mirai-api-http/EventType_CH.md diff --git a/mirai-api-http/README_CH.md b/mirai-api-http/README_CH.md index 8af771a53..a102a1b90 100644 --- a/mirai-api-http/README_CH.md +++ b/mirai-api-http/README_CH.md @@ -408,7 +408,7 @@ Content-Type:multipart/form-data ### 事件类型一览 -[事件类型一览](./EventType_CN.md) +[事件类型一览](EventType_CH.md) > 事件为Bot被动接收的信息,无法主动构建