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 + )) + } +}