Skip to content

Commit

Permalink
支持GroupNameChangeNoticeEvent事件 (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolvedGhost authored Nov 18, 2024
1 parent ce542f0 commit 54e53f3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions onebot/src/main/kotlin/sdk/event/EventMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal fun addGroupListeners() {
GroupAdminNoticeListener(),
GroupEssenceNoticeListener(),
GroupCardChangeNoticeListener(),

GroupNameChangeListener()
).forEach(EventBus::addListener)
}

Expand Down Expand Up @@ -369,3 +369,19 @@ internal class GroupCardChangeNoticeListener : EventListener<GroupCardChangeNoti
))
}
}
internal class GroupNameChangeListener : EventListener<GroupNameChangeNoticeEvent> {
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
))
}
}

0 comments on commit 54e53f3

Please sign in to comment.