Skip to content

Commit

Permalink
feat: 添加"使用者为管理员立即退群,为普通群员仅拒绝回复"后端逻辑 (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
baiyu-yu authored Jan 8, 2025
1 parent 6f25fd8 commit 9a59cdd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions api/ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func banConfigSet(c echo.Context) error {
config.BanList.BanBehaviorQuitLastPlace = v.BanBehaviorQuitLastPlace
config.BanList.BanBehaviorQuitPlaceImmediately = v.BanBehaviorQuitPlaceImmediately
config.BanList.BanBehaviorQuitIfAdmin = v.BanBehaviorQuitIfAdmin
config.BanList.BanBehaviorQuitIfAdminSilentIfNotAdmin = v.BanBehaviorQuitIfAdminSilentIfNotAdmin
config.BanList.ScoreReducePerMinute = v.ScoreReducePerMinute
config.BanList.ThresholdWarn = v.ThresholdWarn
config.BanList.ThresholdBan = v.ThresholdBan
Expand Down
21 changes: 11 additions & 10 deletions dice/dice_ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ func (i *BanListInfoItem) toText(_ *Dice) string {
}

type BanListInfo struct {
Parent *Dice `yaml:"-" json:"-"`
Map *SyncMap[string, *BanListInfoItem] `yaml:"-" json:"-"`
BanBehaviorRefuseReply bool `yaml:"banBehaviorRefuseReply" json:"banBehaviorRefuseReply"` // 拉黑行为: 拒绝回复
BanBehaviorRefuseInvite bool `yaml:"banBehaviorRefuseInvite" json:"banBehaviorRefuseInvite"` // 拉黑行为: 拒绝邀请
BanBehaviorQuitLastPlace bool `yaml:"banBehaviorQuitLastPlace" json:"banBehaviorQuitLastPlace"` // 拉黑行为: 退出事发群
BanBehaviorQuitPlaceImmediately bool `yaml:"banBehaviorQuitPlaceImmediately" json:"banBehaviorQuitPlaceImmediately"` // 拉黑行为: 使用时立即退出群
BanBehaviorQuitIfAdmin bool `yaml:"banBehaviorQuitIfAdmin" json:"banBehaviorQuitIfAdmin"` // 拉黑行为: 邀请者以上权限使用时立即退群,否则发出警告信息
ThresholdWarn int64 `yaml:"thresholdWarn" json:"thresholdWarn"` // 警告阈值
ThresholdBan int64 `yaml:"thresholdBan" json:"thresholdBan"` // 错误阈值
AutoBanMinutes int64 `yaml:"autoBanMinutes" json:"autoBanMinutes"` // 自动禁止时长
Parent *Dice `yaml:"-" json:"-"`
Map *SyncMap[string, *BanListInfoItem] `yaml:"-" json:"-"`
BanBehaviorRefuseReply bool `yaml:"banBehaviorRefuseReply" json:"banBehaviorRefuseReply"` // 拉黑行为: 拒绝回复
BanBehaviorRefuseInvite bool `yaml:"banBehaviorRefuseInvite" json:"banBehaviorRefuseInvite"` // 拉黑行为: 拒绝邀请
BanBehaviorQuitLastPlace bool `yaml:"banBehaviorQuitLastPlace" json:"banBehaviorQuitLastPlace"` // 拉黑行为: 退出事发群
BanBehaviorQuitPlaceImmediately bool `yaml:"banBehaviorQuitPlaceImmediately" json:"banBehaviorQuitPlaceImmediately"` // 拉黑行为: 使用时立即退出群
BanBehaviorQuitIfAdmin bool `yaml:"banBehaviorQuitIfAdmin" json:"banBehaviorQuitIfAdmin"` // 拉黑行为: 邀请者以上权限使用时立即退群,否则发出警告信息
BanBehaviorQuitIfAdminSilentIfNotAdmin bool `yaml:"banBehaviorQuitIfAdminSilentIfNotAdmin" json:"banBehaviorQuitIfAdminSilentIfNotAdmin"` // 拉黑行为: 邀请者以上权限使用时立即退群,否则仅拒绝回复
ThresholdWarn int64 `yaml:"thresholdWarn" json:"thresholdWarn"` // 警告阈值
ThresholdBan int64 `yaml:"thresholdBan" json:"thresholdBan"` // 错误阈值
AutoBanMinutes int64 `yaml:"autoBanMinutes" json:"autoBanMinutes"` // 自动禁止时长

ScoreReducePerMinute int64 `yaml:"scoreReducePerMinute" json:"scoreReducePerMinute"` // 每分钟下降
ScoreGroupMuted int64 `yaml:"scoreGroupMuted" json:"scoreGroupMuted"` // 群组禁言
Expand Down
17 changes: 11 additions & 6 deletions dice/im_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ func checkBan(ctx *MsgContext, msg *Message) (notReply bool) {

if ctx.PrivilegeLevel == -30 {
groupLevel := ctx.GroupRoleLevel
if d.Config.BanList.BanBehaviorQuitIfAdmin && msg.MessageType == "group" {
if (d.Config.BanList.BanBehaviorQuitIfAdmin || d.Config.BanList.BanBehaviorQuitIfAdminSilentIfNotAdmin) && msg.MessageType == "group" {
// 黑名单用户 - 立即退出所在群
banListInfoItem, _ := ctx.Dice.Config.BanList.GetByID(msg.Sender.UserID)
reasontext := FormatBlacklistReasons(banListInfoItem)
Expand All @@ -1576,13 +1576,18 @@ func checkBan(ctx *MsgContext, msg *Message) (notReply bool) {
log.Infof("收到群(%s)内普通群员黑名单用户<%s>(%s)的消息,但在信任群所以不做其他操作", groupID, msg.Sender.Nickname, msg.Sender.UserID)
} else {
notReply = true
noticeMsg := fmt.Sprintf("检测到群(%s)内黑名单用户<%s>(%s),因是普通群员,进行群内通告\n%s", groupID, msg.Sender.Nickname, msg.Sender.UserID, reasontext)
log.Info(noticeMsg)
if d.Config.BanList.BanBehaviorQuitIfAdmin {
noticeMsg := fmt.Sprintf("检测到群(%s)内黑名单用户<%s>(%s),因是普通群员,进行群内通告\n%s", groupID, msg.Sender.Nickname, msg.Sender.UserID, reasontext)
log.Info(noticeMsg)

text := fmt.Sprintf("警告: <%s>(%s)是黑名单用户,将对骰主进行通知。", msg.Sender.Nickname, msg.Sender.UserID)
ReplyGroupRaw(ctx, &Message{GroupID: groupID}, text, "")
text := fmt.Sprintf("警告: <%s>(%s)是黑名单用户,将对骰主进行通知。", msg.Sender.Nickname, msg.Sender.UserID)
ReplyGroupRaw(ctx, &Message{GroupID: groupID}, text, "")

ctx.Notice(noticeMsg)
ctx.Notice(noticeMsg)
} else {
noticeMsg := fmt.Sprintf("检测到群(%s)内黑名单用户<%s>(%s),因是普通群员,忽略黑名单用户信息,不做其他操作\n%s", groupID, msg.Sender.Nickname, msg.Sender.UserID, reasontext)
log.Info(noticeMsg)
}
}
}
} else if d.Config.BanList.BanBehaviorQuitPlaceImmediately && msg.MessageType == "group" {
Expand Down

0 comments on commit 9a59cdd

Please sign in to comment.