mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-05 23:50:08 +08:00
Prefer using group code
This commit is contained in:
parent
8694c16f05
commit
cb3d4362ba
@ -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? {
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user