diff --git a/mirai-core-api/src/commonMain/kotlin/data/MemberInfo.kt b/mirai-core-api/src/commonMain/kotlin/data/MemberInfo.kt index 59b72d2a4..6f36c121f 100644 --- a/mirai-core-api/src/commonMain/kotlin/data/MemberInfo.kt +++ b/mirai-core-api/src/commonMain/kotlin/data/MemberInfo.kt @@ -21,4 +21,6 @@ public interface MemberInfo : FriendInfo { public val specialTitle: String public val muteTimestamp: Int + + public val anonymousId: String? get() = null } \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt index f9b2f1c30..e18564be9 100644 --- a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt @@ -230,6 +230,12 @@ internal class GroupImpl( } override fun newMember(memberInfo: MemberInfo): Member { + memberInfo.anonymousId?.let { anId -> + return AnonymousMemberImpl( + this, this.coroutineContext, + memberInfo, anId + ) + } return MemberImpl( Mirai._lowLevelNewFriend(bot, memberInfo) as FriendImpl, this, @@ -238,7 +244,7 @@ internal class GroupImpl( ) } - internal fun newAnonymous(name: String): Member = newMember( + internal fun newAnonymous(name: String, id: String): Member = newMember( object : MemberInfo { override val nameCard = name override val permission = MemberPermission.MEMBER @@ -247,6 +253,7 @@ internal class GroupImpl( override val uin = 80000000L override val nick = name override val remark: String = "匿名" + override val anonymousId: String get() = id } ) diff --git a/mirai-core/src/commonMain/kotlin/message/incomingSourceImpl.kt b/mirai-core/src/commonMain/kotlin/message/incomingSourceImpl.kt index d5bc1a881..1274fdf20 100644 --- a/mirai-core/src/commonMain/kotlin/message/incomingSourceImpl.kt +++ b/mirai-core/src/commonMain/kotlin/message/incomingSourceImpl.kt @@ -20,6 +20,7 @@ import net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm import net.mamoe.mirai.internal.network.protocol.data.proto.SourceMsg import net.mamoe.mirai.internal.network.protocol.packet.EMPTY_BYTE_ARRAY import net.mamoe.mirai.internal.utils._miraiContentToString +import net.mamoe.mirai.internal.utils.encodeToBase64 import net.mamoe.mirai.internal.utils.encodeToString import net.mamoe.mirai.internal.utils.io.serialization.toByteArray import net.mamoe.mirai.message.data.Message @@ -154,7 +155,7 @@ internal data class MessageSourceFromGroupImpl( ) as GroupImpl).run { get(msg.msgHead.fromUin) ?: msg.msgBody.richText.elems.firstOrNull { it.anonGroupMsg != null }?.run { - newAnonymous(anonGroupMsg!!.anonNick.encodeToString()) + newAnonymous(anonGroupMsg!!.anonNick.encodeToString(), anonGroupMsg.anonId.encodeToBase64()) } ?: error("cannot find member for MessageSourceFromGroupImpl. msg=${msg._miraiContentToString()}") } diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.PbPushGroupMsg.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.PbPushGroupMsg.kt index f7e8c5603..cc52c585d 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.PbPushGroupMsg.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.PbPushGroupMsg.kt @@ -29,6 +29,7 @@ import net.mamoe.mirai.internal.network.protocol.data.proto.MsgOnlinePush import net.mamoe.mirai.internal.network.protocol.data.proto.Oidb0x8fc import net.mamoe.mirai.internal.network.protocol.packet.IncomingPacketFactory import net.mamoe.mirai.internal.utils._miraiContentToString +import net.mamoe.mirai.internal.utils.encodeToBase64 import net.mamoe.mirai.internal.utils.encodeToString import net.mamoe.mirai.internal.utils.io.serialization.loadAs import net.mamoe.mirai.internal.utils.io.serialization.readProtoBuf @@ -74,10 +75,10 @@ internal object OnlinePushPbPushGroupMsg : IncomingPacketFactory("Onlin val group = bot.getGroup(pbPushMsg.msg.msgHead.groupInfo!!.groupCode) as GroupImpl? ?: return null // 机器人还正在进群 val sender = if (anonymous != null) { - group.newAnonymous(anonymous.anonNick.encodeToString()) + group.newAnonymous(anonymous.anonNick.encodeToString(), anonymous.anonId.encodeToBase64()) } else { - group[pbPushMsg.msg.msgHead.fromUin] - } as MemberImpl + group[pbPushMsg.msg.msgHead.fromUin] as MemberImpl + } val name = if (anonymous != null) { sender.nameCard @@ -99,7 +100,7 @@ internal object OnlinePushPbPushGroupMsg : IncomingPacketFactory("Onlin val flags = extraInfo?.flags ?: 0 return GroupMessageEvent( senderName = name.also { - if (it != sender.nameCard) { + if (sender is MemberImpl && it != sender.nameCard) { val origin = sender._nameCard sender._nameCard = name MemberCardChangeEvent(origin, name, sender).broadcast()