Merge remote-tracking branch 'origin/master'

This commit is contained in:
Him188 2020-02-03 01:30:06 +08:00
commit 06e6819d25
3 changed files with 32 additions and 16 deletions

View File

@ -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.

View File

@ -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<Member>): ContactList<Member> {
suspend fun getTroopMemberList(group: GroupImpl, list: ContactList<Member>, owner: Long): ContactList<Member> {
bot.logger.info("开始获取群[${group.groupCode}]成员列表")
var size = 0
var nextUin = 0L
@ -203,13 +209,26 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
nextUin
).sendAndExpect<FriendList.GetTroopMemberList.Response>(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

View File

@ -52,7 +52,7 @@ internal class FriendList {
GetTroopMemberListReq.serializer(),
GetTroopMemberListReq(
uin = client.uin,
groupCode = targetGroupId,
groupCode = targetGroupCode,
groupUin = targetGroupId,
nextUin = nextUin,
reqType = 0,