From 33da0a534d930c634215057dd93f5e52b27e7503 Mon Sep 17 00:00:00 2001 From: EvolvedGhost <727511070@qq.com> Date: Mon, 18 Nov 2024 16:50:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81GroupNameChangeNoticeEvent?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- onebot/src/main/kotlin/sdk/event/EventMap.kt | 1 + .../group/GroupNameChangeNoticeEvent.kt | 23 +++++++++++++++++++ .../overflow/internal/listener/group.kt | 18 ++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 onebot/src/main/kotlin/sdk/event/notice/group/GroupNameChangeNoticeEvent.kt diff --git a/onebot/src/main/kotlin/sdk/event/EventMap.kt b/onebot/src/main/kotlin/sdk/event/EventMap.kt index 1bbb0bf..24946b8 100644 --- a/onebot/src/main/kotlin/sdk/event/EventMap.kt +++ b/onebot/src/main/kotlin/sdk/event/EventMap.kt @@ -33,6 +33,7 @@ object EventMap { "group_increase" to GroupIncreaseNoticeEvent::class, "group_ban" to GroupBanNoticeEvent::class, "group_recall" to GroupMsgDeleteNoticeEvent::class, + "group_name_change" to GroupNameChangeNoticeEvent::class, "notify" to NotifyNoticeEvent::class, "lucky_king" to GroupLuckyKingNoticeEvent::class, "honor" to GroupHonorChangeNoticeEvent::class, diff --git a/onebot/src/main/kotlin/sdk/event/notice/group/GroupNameChangeNoticeEvent.kt b/onebot/src/main/kotlin/sdk/event/notice/group/GroupNameChangeNoticeEvent.kt new file mode 100644 index 0000000..d4edc93 --- /dev/null +++ b/onebot/src/main/kotlin/sdk/event/notice/group/GroupNameChangeNoticeEvent.kt @@ -0,0 +1,23 @@ +package cn.evolvefield.onebot.sdk.event.notice.group + +import cn.evolvefield.onebot.sdk.event.notice.NoticeEvent +import com.google.gson.annotations.SerializedName +import lombok.AllArgsConstructor +import lombok.Data +import lombok.EqualsAndHashCode +import lombok.NoArgsConstructor +import lombok.experimental.SuperBuilder + +@Data +@NoArgsConstructor +@AllArgsConstructor +@SuperBuilder(toBuilder = true) +@EqualsAndHashCode(callSuper = true) +class GroupNameChangeNoticeEvent : NoticeEvent() { + @SerializedName("name") + var name = "" + @SerializedName("group_id") + var groupId = 0L + @SerializedName("operator_id") + var operatorId = 0L +} diff --git a/overflow-core/src/main/kotlin/top/mrxiaom/overflow/internal/listener/group.kt b/overflow-core/src/main/kotlin/top/mrxiaom/overflow/internal/listener/group.kt index 2484a8e..25595be 100644 --- a/overflow-core/src/main/kotlin/top/mrxiaom/overflow/internal/listener/group.kt +++ b/overflow-core/src/main/kotlin/top/mrxiaom/overflow/internal/listener/group.kt @@ -32,7 +32,7 @@ internal fun addGroupListeners() { GroupAdminNoticeListener(), GroupEssenceNoticeListener(), GroupCardChangeNoticeListener(), - + GroupNameChangeListener() ).forEach(EventBus::addListener) } @@ -369,3 +369,19 @@ internal class GroupCardChangeNoticeListener : EventListener { + override suspend fun onMessage(e: GroupNameChangeNoticeEvent) { + val bot = e.bot ?: return + if (bot.checkId(e.groupId) { + "%onebot 返回了异常的数值 group_id=%value" + }) return + val group = bot.group(e.groupId) + val origin = group.name + val new = e.name + group.impl.groupName = new + val operator = if (e.operatorId <= 0) null else group.queryMember(e.operatorId) + bot.eventDispatcher.broadcastAsync(GroupNameChangeEvent( + origin, new, group, operator + )) + } +}