diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/group.kt b/mirai-core-api/src/commonMain/kotlin/event/events/group.kt index b64e3222c..29c423656 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/group.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/group.kt @@ -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})" } + /** + * 机器人因群主解散群而退出群. 操作人一定是群主 + * @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 } diff --git a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt index 70cdf7fa6..77c4ca93a 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupOrMemberListNoticeProcessor.kt @@ -361,6 +361,12 @@ internal class GroupOrMemberListNoticeProcessor( groupUin: Long, ) { 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 -> if (target == bot.id) { collect(BotLeaveEvent.Active(group)) @@ -531,4 +537,4 @@ internal class GroupOrMemberListNoticeProcessor( } else return } */ -} \ No newline at end of file +}