diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt index 24ba4bcd7..8426a2963 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt @@ -53,13 +53,12 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin internal class MemberImpl( qq: QQImpl, group: GroupImpl, - override val coroutineContext: CoroutineContext + override val coroutineContext: CoroutineContext, + override val permission: MemberPermission ) : ContactImpl(), Member, QQ by qq { override val group: GroupImpl by group.unsafeWeakRef() val qq: QQImpl by qq.unsafeWeakRef() - override val permission: MemberPermission - get() = TODO("not implemented") override suspend fun mute(durationSeconds: Int): Boolean { TODO("not implemented") @@ -84,9 +83,7 @@ internal class GroupImpl( override lateinit var owner: Member override fun getMember(id: Long): Member = - members.delegate.filteringGetOrAdd( - { it.id == id }, - { MemberImpl(bot.getQQ(id) as QQImpl, this, coroutineContext) }) + members.delegate.filterGetOrNull { it.id == id } ?: error("Failed to find Member${id} in group ${groupCode}") override suspend fun updateGroupInfo(): net.mamoe.mirai.data.GroupInfo { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt index 94bcded74..149fe9d43 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt @@ -12,6 +12,7 @@ import kotlinx.io.core.use import net.mamoe.mirai.contact.ContactList import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.Member +import net.mamoe.mirai.contact.MemberPermission import net.mamoe.mirai.data.MultiPacket import net.mamoe.mirai.data.Packet import net.mamoe.mirai.event.* @@ -172,13 +173,18 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler contactList ) group.owner = - MemberImpl(QQImpl(bot, EmptyCoroutineContext, it.dwGroupOwnerUin!!), group, EmptyCoroutineContext) + MemberImpl( + QQImpl(bot, EmptyCoroutineContext, it.dwGroupOwnerUin!!), + group, + EmptyCoroutineContext, + MemberPermission.OWNER + ) toGet[group] = contactList bot.groups.delegate.addLast(group) } toGet.forEach { try { - getTroopMemberList(it.key, it.value) + getTroopMemberList(it.key, it.value, it.key.owner.id) } catch (e: Exception) { bot.logger.info("群${it.key.groupCode}的列表拉取失败, 将采用动态加入") } @@ -191,7 +197,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler } - suspend fun getTroopMemberList(group: GroupImpl, list: ContactList): ContactList { + suspend fun getTroopMemberList(group: GroupImpl, list: ContactList, owner: Long): ContactList { bot.logger.info("开始获取群[${group.groupCode}]成员列表") var size = 0 var nextUin = 0L @@ -203,13 +209,26 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler nextUin ).sendAndExpect(timeoutMillis = 3000) data.members.forEach { - list.delegate.addLast( - MemberImpl( - QQImpl(bot, EmptyCoroutineContext, it.memberUin), - group, - EmptyCoroutineContext + if (it.memberUin != bot.uin) { + list.delegate.addLast( + MemberImpl( + QQImpl(bot, EmptyCoroutineContext, it.memberUin), + group, + EmptyCoroutineContext, + when { + it.memberUin == owner -> { + MemberPermission.OWNER + } + it.dwFlag == 1L -> { + MemberPermission.ADMINISTRATOR + } + else -> { + MemberPermission.MEMBER + } + } + ) ) - ) + } } size += data.members.size nextUin = data.nextUin diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/list/FriendListPacket.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/list/FriendListPacket.kt index accc02357..0e7aa84b4 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/list/FriendListPacket.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/list/FriendListPacket.kt @@ -52,7 +52,7 @@ internal class FriendList { GetTroopMemberListReq.serializer(), GetTroopMemberListReq( uin = client.uin, - groupCode = targetGroupId, + groupCode = targetGroupCode, groupUin = targetGroupId, nextUin = nextUin, reqType = 0,