From eb123bb3a951031b3a66dfecd79eb2de6eda313c Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 23 Apr 2020 14:46:30 +0800 Subject: [PATCH] Fix #242 --- .../mirai/qqandroid/contact/MemberImpl.kt | 3 ++ .../protocol/data/proto/msgType0x210.kt | 2 +- .../protocol/packet/chat/TroopManagement.kt | 7 +++- .../packet/chat/receive/OnlinePush.kt | 35 +++++++++++++++++++ .../net.mamoe.mirai/event/events/BotEvents.kt | 3 +- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt index 4fc9335f4..9e95341f9 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt @@ -142,6 +142,9 @@ internal class MemberImpl constructor( @JvmSynthetic override suspend fun mute(durationSeconds: Int) { + check(this.id != bot.id) { + "A bot can't mute itself." + } checkBotPermissionHigherThanThis() bot.network.run { TroopManagement.Mute( diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/msgType0x210.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/msgType0x210.kt index bc8c5c1cf..d19d4f6f6 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/msgType0x210.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/msgType0x210.kt @@ -769,7 +769,7 @@ internal class Submsgtype0x27 { @Serializable internal class GroupMemberProfileInfo( @ProtoId(1) @JvmField val field: Int = 0, - @ProtoId(2) @JvmField val value: ByteArray = EMPTY_BYTE_ARRAY + @ProtoId(2) @JvmField val value: String = "" ) : ProtoBuf @Serializable diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/TroopManagement.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/TroopManagement.kt index 502b39f97..0f3fc8474 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/TroopManagement.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/TroopManagement.kt @@ -383,9 +383,14 @@ internal class TroopManagement { internal object EditGroupNametag : OutgoingPacketFactory("friendlist.ModifyGroupCardReq") { - object Response : Packet + object Response : Packet { + override fun toString(): String { + return "TroopManagement.EditGroupNametag.Response" + } + } override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): EditGroupNametag.Response { + this.close() return Response } diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt index f94ab84c5..28b9842be 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt @@ -529,12 +529,47 @@ internal class OnlinePush { } ?: emptySequence() } + fun Submsgtype0x27.SubMsgType0x27.ModGroupMemberProfile.transform(bot: QQAndroidBot): Sequence { + return this.msgGroupMemberProfileInfos?.asSequence()?.mapNotNull { info -> + when (info.field) { + 1 -> { // name card + val new = info.value + val group = bot.getGroupOrNull(this.groupCode) ?: return@mapNotNull null + group.checkIsGroupImpl() + val member = group.getOrNull(this.uin) ?: return@mapNotNull null + member.checkIsMemberImpl() + + val old = member.nameCard + + if (new == old) return@mapNotNull null + + return@mapNotNull MemberCardChangeEvent(old, new, member, null) + } + 2 -> { + if (info.value.singleOrNull()?.toInt() != 0) { + bot.logger.debug { + "Unknown Transformers528 0x27L ModGroupMemberProfile, field=${info.field}, value=${info.value}" + } + } + return@mapNotNull null + } + else -> { + bot.logger.debug { + "Unknown Transformers528 0x27L ModGroupMemberProfile, field=${info.field}, value=${info.value}" + } + return@mapNotNull null + } + } + } ?: emptySequence() + } + return@lambda528 vProtobuf.loadAs(Submsgtype0x27.SubMsgType0x27.MsgBody.serializer()).msgModInfos.asSequence() .flatMap { when { it.msgModFriendRemark != null -> it.msgModFriendRemark.transform(bot) it.msgDelFriend != null -> it.msgDelFriend.transform(bot) it.msgModGroupProfile != null -> it.msgModGroupProfile.transform(bot) + it.msgModGroupMemberProfile != null -> it.msgModGroupMemberProfile.transform(bot) else -> { bot.network.logger.debug { "Transformers528 0x27L: new data: ${it._miraiContentToString()}" diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt index ec3d50824..d9e1b5ef6 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt @@ -469,7 +469,8 @@ data class MemberCardChangeEvent( @PlannedRemoval("1.0.0") @Deprecated("operator is always unknown", level = DeprecationLevel.ERROR) override val operator: Member? -) : GroupMemberEvent, @Deprecated("operator is always unknown", level = DeprecationLevel.ERROR) GroupOperableEvent +) : GroupMemberEvent, Packet, + @Deprecated("operator is always unknown", level = DeprecationLevel.ERROR) GroupOperableEvent /** * 群头衔改动. 一定为群主操作