Commit b7f6330e authored by Him188's avatar Him188

Cancel Member when leaved from group

parent 6e9be107
......@@ -13,9 +13,7 @@ package net.mamoe.mirai.qqandroid.contact
import kotlinx.atomicfu.AtomicInt
import kotlinx.atomicfu.atomic
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import net.mamoe.mirai.LowLevelAPI
import net.mamoe.mirai.contact.*
import net.mamoe.mirai.data.MemberInfo
......@@ -210,6 +208,7 @@ internal class MemberImpl constructor(
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
group.members.delegate.removeIf { it.id == this@MemberImpl.id }
this.cancel(CancellationException("Kicked by bot"))
MemberLeaveEvent.Kick(this@MemberImpl, null).broadcast()
}
}
......
......@@ -12,6 +12,8 @@
package net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.cancel
import kotlinx.io.core.ByteReadPacket
import kotlinx.io.core.discardExact
import kotlinx.io.core.readUByte
......@@ -116,12 +118,14 @@ internal object OnlinePushPbPushTransMsg :
0x82 -> bot.getGroupByUinOrNull(groupUin)?.let { group ->
val member = group.getOrNull(target) as? MemberImpl ?: return null
return MemberLeaveEvent.Quit(member.also {
member.cancel(CancellationException("Leaved actively"))
group.members.delegate.remove(member)
})
}
0x83 -> bot.getGroupByUin(groupUin).let { group ->
val member = group.getOrNull(target) as? MemberImpl ?: return null
return MemberLeaveEvent.Kick(member.also {
member.cancel(CancellationException("Leaved actively"))
group.members.delegate.remove(member)
}, group.members[operator])
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment