Explorar o código

Cancel Member when leaved from group

Him188 %!s(int64=5) %!d(string=hai) anos
pai
achega
b7f6330ed9

+ 2 - 3
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt

@@ -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 == [email protected] }
+            this.cancel(CancellationException("Kicked by bot"))
             MemberLeaveEvent.Kick(this@MemberImpl, null).broadcast()
         }
     }

+ 4 - 0
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt

@@ -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])
                         }