diff --git a/mirai-core/src/commonMain/kotlin/network/notice/NewContactSupport.kt b/mirai-core/src/commonMain/kotlin/network/notice/NewContactSupport.kt index beb8f66bd..c8f86c23d 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/NewContactSupport.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/NewContactSupport.kt @@ -47,9 +47,10 @@ internal interface NewContactSupport { // can be a marker interface when context return getNewGroup(code)?.apply { groups.delegate.add(this) } } + // final suspend fun QQAndroidBot.addNewGroupByUin(groupUin: Long): GroupImpl? { if (getGroupByUin(groupUin) != null) return null - return getNewGroup(Mirai.calculateGroupCodeByGroupUin(groupUin))?.apply { groups.delegate.add(this) } + return addNewGroupByCode(Mirai.calculateGroupCodeByGroupUin(groupUin)) } suspend fun QQAndroidBot.addNewGroup(stTroopNum: StTroopNum): GroupImpl? { diff --git a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt index cdaa41037..203845cd7 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt @@ -20,6 +20,7 @@ import net.mamoe.mirai.contact.MemberPermission.* import net.mamoe.mirai.event.events.* import net.mamoe.mirai.internal.contact.addNewNormalMember import net.mamoe.mirai.internal.contact.info.MemberInfoImpl +import net.mamoe.mirai.internal.getGroupByCodeOrUin import net.mamoe.mirai.internal.getGroupByUin import net.mamoe.mirai.internal.getGroupByUinOrCode import net.mamoe.mirai.internal.message.contextualBugReportException @@ -136,14 +137,14 @@ internal class GroupOrMemberListNoticeProcessor( // 33 private suspend fun NoticePipelineContext.processGroupJoin33(data: MsgComm.Msg) = data.context { msgBody.msgContent.read { - val groupUin = Mirai.calculateGroupUinByGroupCode(readUInt().toLong()) + val groupCode = readUInt().toLong() if (remaining < 5) return discardExact(1) val joinedMemberUin = readUInt().toLong() - if (joinedMemberUin == bot.id && bot.getGroupByUin(groupUin) != null) return // duplicate + if (joinedMemberUin == bot.id && bot.getGroupByCodeOrUin(groupCode) != null) return // duplicate - val group = bot.getGroupByUin(groupUin) ?: bot.addNewGroupByUin(groupUin) ?: return + val group = bot.getGroupByCodeOrUin(groupCode) ?: bot.addNewGroupByCode(groupCode) ?: return val joinType = readByte().toInt() val invitorUin = readUInt().toLong() when (joinType) { diff --git a/mirai-core/src/commonTest/kotlin/notice/processors/BotInvitedJoinTest.kt b/mirai-core/src/commonTest/kotlin/notice/processors/BotInvitedJoinTest.kt index 867b03448..c27531cd3 100644 --- a/mirai-core/src/commonTest/kotlin/notice/processors/BotInvitedJoinTest.kt +++ b/mirai-core/src/commonTest/kotlin/notice/processors/BotInvitedJoinTest.kt @@ -106,8 +106,8 @@ internal class BotInvitedJoinTest : AbstractNoticeProcessorTest() { suspend fun runTest() = use( createContext = { bot, attributes -> object : NoticeProcessorPipelineImpl.ContextImpl(bot, attributes) { - override suspend fun QQAndroidBot.addNewGroupByUin(groupUin: Long): GroupImpl { - assertEquals(204230203, groupUin) // uin of 2230203 + override suspend fun QQAndroidBot.addNewGroupByCode(code: Long): GroupImpl { + assertEquals(2230203, code) return bot.addGroup(2230203, 1230001, name = "testtest").apply { addMember(1230003, permission = MemberPermission.MEMBER) addMember(1230001, permission = MemberPermission.OWNER) @@ -156,8 +156,8 @@ internal class BotInvitedJoinTest : AbstractNoticeProcessorTest() { suspend fun runTest() = use(createContext = { bot, attributes -> object : NoticeProcessorPipelineImpl.ContextImpl(bot, attributes) { - override suspend fun QQAndroidBot.addNewGroupByUin(groupUin: Long): GroupImpl { - assertEquals(204230203, groupUin) // uin of 2230203 + override suspend fun QQAndroidBot.addNewGroupByCode(code: Long): GroupImpl { + assertEquals(2230203, code) return bot.addGroup(2230203, 1230002, name = "testtest").apply { addMember(1230001, permission = MemberPermission.MEMBER) }