mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-21 12:59:13 +08:00
Cancel Member when leaved from group
This commit is contained in:
parent
6e9be107ef
commit
b7f6330ed9
@ -13,9 +13,7 @@ package net.mamoe.mirai.qqandroid.contact
|
|||||||
|
|
||||||
import kotlinx.atomicfu.AtomicInt
|
import kotlinx.atomicfu.AtomicInt
|
||||||
import kotlinx.atomicfu.atomic
|
import kotlinx.atomicfu.atomic
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.SupervisorJob
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import net.mamoe.mirai.LowLevelAPI
|
import net.mamoe.mirai.LowLevelAPI
|
||||||
import net.mamoe.mirai.contact.*
|
import net.mamoe.mirai.contact.*
|
||||||
import net.mamoe.mirai.data.MemberInfo
|
import net.mamoe.mirai.data.MemberInfo
|
||||||
@ -210,6 +208,7 @@ internal class MemberImpl constructor(
|
|||||||
|
|
||||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
group.members.delegate.removeIf { it.id == this@MemberImpl.id }
|
group.members.delegate.removeIf { it.id == this@MemberImpl.id }
|
||||||
|
this.cancel(CancellationException("Kicked by bot"))
|
||||||
MemberLeaveEvent.Kick(this@MemberImpl, null).broadcast()
|
MemberLeaveEvent.Kick(this@MemberImpl, null).broadcast()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive
|
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.ByteReadPacket
|
||||||
import kotlinx.io.core.discardExact
|
import kotlinx.io.core.discardExact
|
||||||
import kotlinx.io.core.readUByte
|
import kotlinx.io.core.readUByte
|
||||||
@ -116,12 +118,14 @@ internal object OnlinePushPbPushTransMsg :
|
|||||||
0x82 -> bot.getGroupByUinOrNull(groupUin)?.let { group ->
|
0x82 -> bot.getGroupByUinOrNull(groupUin)?.let { group ->
|
||||||
val member = group.getOrNull(target) as? MemberImpl ?: return null
|
val member = group.getOrNull(target) as? MemberImpl ?: return null
|
||||||
return MemberLeaveEvent.Quit(member.also {
|
return MemberLeaveEvent.Quit(member.also {
|
||||||
|
member.cancel(CancellationException("Leaved actively"))
|
||||||
group.members.delegate.remove(member)
|
group.members.delegate.remove(member)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
0x83 -> bot.getGroupByUin(groupUin).let { group ->
|
0x83 -> bot.getGroupByUin(groupUin).let { group ->
|
||||||
val member = group.getOrNull(target) as? MemberImpl ?: return null
|
val member = group.getOrNull(target) as? MemberImpl ?: return null
|
||||||
return MemberLeaveEvent.Kick(member.also {
|
return MemberLeaveEvent.Kick(member.also {
|
||||||
|
member.cancel(CancellationException("Leaved actively"))
|
||||||
group.members.delegate.remove(member)
|
group.members.delegate.remove(member)
|
||||||
}, group.members[operator])
|
}, group.members[operator])
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user