From 6a294c0cb72a089acb0ec2dd837041c2c03c9d7c Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 28 Nov 2019 23:11:52 +0800 Subject: [PATCH] Make all the KnownEventParserAndHandlers internal --- .../packet/event/AndroidOnlineStatusChange.kt | 2 +- .../packet/event/ConnectionOccupiedEvent.kt | 2 +- .../tim/packet/event/EventPacketFactory.kt | 3 +- .../event/FriendAddRequestEventPacket.kt | 2 +- .../event/FriendConversationIniliaze.kt | 2 +- .../tim/packet/event/GroupFileUpload.kt | 2 +- .../protocol/tim/packet/event/MemberJoin.kt | 35 ++++++++++++++++++- .../tim/packet/event/MemberKickEvent.kt | 2 +- .../tim/packet/event/MemberPermission.kt | 2 +- .../protocol/tim/packet/event/Message.kt | 4 +-- 10 files changed, 45 insertions(+), 11 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/AndroidOnlineStatusChange.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/AndroidOnlineStatusChange.kt index 2337058b5..69bb9cd2d 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/AndroidOnlineStatusChange.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/AndroidOnlineStatusChange.kt @@ -22,7 +22,7 @@ data class AndroidDeviceStatusChangePacket(val kind: Kind) : Packet { * Android 客户端在线状态改变 */ @PacketVersion(date = "2019.10.31", timVersion = "2.3.2 (21173)") -object AndroidDeviceOnlineStatusChangedEventFactory : KnownEventParserAndHandler(0x00C4u) { +internal object AndroidDeviceOnlineStatusChangedEventFactory : KnownEventParserAndHandler(0x00C4u) { override suspend fun ByteReadPacket.parse(bot: Bot, identity: EventPacketIdentity): AndroidDeviceStatusChangePacket { discardExact(13) return AndroidDeviceStatusChangePacket( diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/ConnectionOccupiedEvent.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/ConnectionOccupiedEvent.kt index 552f792ee..53b74d6df 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/ConnectionOccupiedEvent.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/ConnectionOccupiedEvent.kt @@ -15,7 +15,7 @@ inline class ConnectionOccupiedEvent(val message: String) : EventPacket { override fun toString(): String = "ConnectionOccupiedEvent(${message.replace("\n", "")})" } -internal object ConnectionOccupiedPacketFactory : KnownEventParserAndHandler(0x0030u) { +internal object ConnectionOccupiedPacketHandler : KnownEventParserAndHandler(0x0030u) { override suspend fun ByteReadPacket.parse(bot: Bot, identity: EventPacketIdentity): ConnectionOccupiedEvent { discardExact(6) return ConnectionOccupiedEvent(readBytes((remaining - 8).toInt()).encodeToString()) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/EventPacketFactory.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/EventPacketFactory.kt index 40377ee4b..be59baf1a 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/EventPacketFactory.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/EventPacketFactory.kt @@ -96,6 +96,7 @@ abstract class KnownEventParserAndHandler(override val id: USh FriendMessageEventParserAndHandler, FriendAddRequestEventPacket, MemberGoneEventPacketHandler, - ConnectionOccupiedPacketFactory + ConnectionOccupiedPacketHandler, + MemberJoinPacketHandler ) } \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/FriendAddRequestEventPacket.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/FriendAddRequestEventPacket.kt index 0f7014e74..110cbed09 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/FriendAddRequestEventPacket.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/FriendAddRequestEventPacket.kt @@ -37,7 +37,7 @@ data class ReceiveFriendAddRequestEvent( } @PacketVersion(date = "2019.11.20", timVersion = "2.3.2 (21173)") -object FriendAddRequestEventPacket : KnownEventParserAndHandler(0x02DFu) { +internal object FriendAddRequestEventPacket : KnownEventParserAndHandler(0x02DFu) { override suspend fun ByteReadPacket.parse(bot: Bot, identity: EventPacketIdentity): ReceiveFriendAddRequestEvent = bot.withSession { // 00 00 00 08 00 0A 00 04 01 00 // 00 00 00 01 diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/FriendConversationIniliaze.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/FriendConversationIniliaze.kt index 6335f51d0..b55c8fd05 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/FriendConversationIniliaze.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/FriendConversationIniliaze.kt @@ -14,7 +14,7 @@ data class FriendConversationInitialize( ) : EventPacket @PacketVersion(date = "2019.11.2", timVersion = "2.3.2 (21173)") -object FriendConversationInitializedEventParserAndHandler : KnownEventParserAndHandler(0x0079u) { +internal object FriendConversationInitializedEventParserAndHandler : KnownEventParserAndHandler(0x0079u) { override suspend fun ByteReadPacket.parse(bot: Bot, identity: EventPacketIdentity): FriendConversationInitialize { discardExact(4)// 00 00 00 00 return FriendConversationInitialize(readUInt()) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/GroupFileUpload.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/GroupFileUpload.kt index 1e2ebb9f3..e1fc929cc 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/GroupFileUpload.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/GroupFileUpload.kt @@ -11,7 +11,7 @@ import net.mamoe.mirai.utils.io.debugPrint data class GroupFileUploadPacket(inline val xmlMessage: String) : EventPacket @PacketVersion(date = "2019.7.1", timVersion = "2.3.2 (21173)") -object GroupFileUploadEventFactory : KnownEventParserAndHandler(0x002Du) { +internal object GroupFileUploadEventFactory : KnownEventParserAndHandler(0x002Du) { override suspend fun ByteReadPacket.parse(bot: Bot, identity: EventPacketIdentity): GroupFileUploadPacket { this.debugPrint("GroupFileUploadPacket") return GroupFileUploadPacket("") diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberJoin.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberJoin.kt index ebc0afe6b..c62f81cff 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberJoin.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberJoin.kt @@ -1,7 +1,40 @@ +@file:Suppress("EXPERIMENTAL_UNSIGNED_LITERALS") + package net.mamoe.mirai.network.protocol.tim.packet.event +import kotlinx.io.core.ByteReadPacket +import net.mamoe.mirai.Bot +import net.mamoe.mirai.contact.Member +import net.mamoe.mirai.event.events.BotEvent +import net.mamoe.mirai.network.BotNetworkHandler +import net.mamoe.mirai.network.protocol.tim.packet.Packet +import net.mamoe.mirai.utils.MiraiInternalAPI + //群有新成员加入 //事件 id 00 21 // -//00 00 00 08 00 0A 00 04 01 00 00 00 32 DC FC C8 01 2D 5C 53 A6 03 3E 03 3F A2 06 B4 B4 BD A8 D5 DF 00 30 42 34 37 31 30 36 43 30 44 44 34 41 34 44 30 35 30 39 44 45 31 32 30 42 43 35 45 34 44 38 45 42 37 30 36 39 31 45 36 44 45 36 44 39 46 37 36 30 \ No newline at end of file +//00 00 00 08 00 0A 00 04 01 00 00 00 32 DC FC C8 01 2D 5C 53 A6 03 3E 03 3F A2 06 B4 B4 BD A8 D5 DF 00 30 42 34 37 31 30 36 43 30 44 44 34 41 34 44 30 35 30 39 44 45 31 32 30 42 43 35 45 34 44 38 45 42 37 30 36 39 31 45 36 44 45 36 44 39 46 37 36 30 + +/** + * 新成员加入. 此时这个人还没被添加到群列表 + */ +internal class MemberJoinEventPacket( + val member: Member +) : Packet + +class MemberJoinEvent : BotEvent() { + +} + +@UseExperimental(MiraiInternalAPI::class) +internal object MemberJoinPacketHandler : KnownEventParserAndHandler(0x0021u) { + override suspend fun ByteReadPacket.parse(bot: Bot, identity: EventPacketIdentity): MemberJoinEventPacket { + + TODO() + } + + override suspend fun BotNetworkHandler<*>.handlePacket(packet: MemberJoinEventPacket) { + + } +} \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberKickEvent.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberKickEvent.kt index ca23712f4..ce977799d 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberKickEvent.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberKickEvent.kt @@ -48,7 +48,7 @@ data class BeingKickEvent(val group: Group, val operator: Member) : MemberListCh /** * 成员退出. 可能是被踢出也可能是主动退出 */ -object MemberGoneEventPacketHandler : KnownEventParserAndHandler(0x0022u) { +internal object MemberGoneEventPacketHandler : KnownEventParserAndHandler(0x0022u) { override suspend fun ByteReadPacket.parse(bot: Bot, identity: EventPacketIdentity): MemberListChangedEvent { discardExact(11) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberPermission.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberPermission.kt index c537701fd..755dd26b2 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberPermission.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MemberPermission.kt @@ -28,7 +28,7 @@ data class MemberPermissionChangePacket( } @PacketVersion(date = "2019.11.1", timVersion = "2.3.2 (21173)") -object GroupMemberPermissionChangedEventFactory : KnownEventParserAndHandler(0x002Cu) { +internal object GroupMemberPermissionChangedEventFactory : KnownEventParserAndHandler(0x002Cu) { override suspend fun ByteReadPacket.parse(bot: Bot, identity: EventPacketIdentity): MemberPermissionChangePacket { // 群里一个人变成管理员: // 00 00 00 08 00 0A 00 04 01 00 00 00 22 96 29 7B 01 01 76 E4 B8 DD 01 diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/Message.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/Message.kt index a8d6e8f4d..b0c273625 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/Message.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/Message.kt @@ -113,7 +113,7 @@ data class GroupMessage( } @PacketVersion(date = "2019.11.2", timVersion = "2.3.2 (21173)") -object GroupMessageEventParserAndHandler : KnownEventParserAndHandler(0x0052u) { +internal object GroupMessageEventParserAndHandler : KnownEventParserAndHandler(0x0052u) { override suspend fun ByteReadPacket.parse(bot: Bot, identity: EventPacketIdentity): GroupMessage { discardExact(31) val groupNumber = readUInt() @@ -183,7 +183,7 @@ data class FriendMessage( @Suppress("unused") @PacketVersion(date = "2019.11.2", timVersion = "2.3.2 (21173)") -object FriendMessageEventParserAndHandler : KnownEventParserAndHandler(0x00A6u) { +internal object FriendMessageEventParserAndHandler : KnownEventParserAndHandler(0x00A6u) { override suspend fun ByteReadPacket.parse(bot: Bot, identity: EventPacketIdentity): FriendMessage { discardExact(2) val l1 = readShort()