Support group disband kind decoding (#1525)

* Support group disband kind decoding

* Update mirai-core-api/src/commonMain/kotlin/event/events/group.kt

* Add useless comment for triggering build

Co-authored-by: Him188 <Him188@mamoe.net>
This commit is contained in:
sandtechnology 2021-09-11 14:29:39 +08:00 committed by GitHub
parent b451dfaf96
commit 394012ec3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -57,6 +57,18 @@ public sealed class BotLeaveEvent : BotEvent, Packet, AbstractEvent(), GroupMemb
public override fun toString(): String = "BotLeaveEvent.Kick(group=${group.id},operator=${operator.id})" public override fun toString(): String = "BotLeaveEvent.Kick(group=${group.id},operator=${operator.id})"
} }
/**
* 机器人因群主解散群而退出群. 操作人一定是群主
* @since 2.8
*/
@MiraiExperimentalApi("BotLeaveEvent 的子类可能在将来改动. 使用 BotLeaveEvent 以保证兼容性.")
public data class Disband @MiraiInternalApi constructor(
public override val group: Group
) : BotLeaveEvent(), GroupOperableEvent {
public override val operator: NormalMember = group.owner
public override fun toString(): String = "BotLeaveEvent.Disband(group=${group.id})"
}
public override val bot: Bot get() = group.bot public override val bot: Bot get() = group.bot
} }

View File

@ -361,6 +361,12 @@ internal class GroupOrMemberListNoticeProcessor(
groupUin: Long, groupUin: Long,
) { ) {
when (kind) { when (kind) {
// 01 为bot为群主时解散群
1, 0x81 -> bot.getGroupByUinOrCode(groupUin)?.let { group ->
collect(BotLeaveEvent.Disband(group))
bot.groups.delegate.remove(group)
group.cancel(CancellationException("Being Disband"))
}
2, 0x82 -> bot.getGroupByUinOrCode(groupUin)?.let { group -> 2, 0x82 -> bot.getGroupByUinOrCode(groupUin)?.let { group ->
if (target == bot.id) { if (target == bot.id) {
collect(BotLeaveEvent.Active(group)) collect(BotLeaveEvent.Active(group))
@ -531,4 +537,4 @@ internal class GroupOrMemberListNoticeProcessor(
} else return } else return
} }
*/ */
} }