Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持GroupNameChangeNoticeEvent事件 #109

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
))
}
}
Loading