From 583482eacb1f0dc33ee8b711cb82f825479072ca Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 06:00:10 +0000 Subject: [PATCH 01/15] Adding UnwarnSendToModlog and UnwarnIncludeWarnReason With the button on webpanel With --- moderation/assets/moderation.html | 2 ++ moderation/commands.go | 30 +++++++++++++++++++++++-- moderation/config.go | 16 ++++++++----- moderation/models/moderation_configs.go | 28 +++++++++++++++++++---- moderation/modlog.go | 1 + moderation/schema.go | 2 ++ 6 files changed, 68 insertions(+), 11 deletions(-) diff --git a/moderation/assets/moderation.html b/moderation/assets/moderation.html index 807d0ec678..2848b46a03 100644 --- a/moderation/assets/moderation.html +++ b/moderation/assets/moderation.html @@ -472,6 +472,8 @@

Delete ALL server warnings?

{{checkbox "WarnIncludeChannelLogs" "WarnIncludeChannelLogs" "Create message logs in the channel that the command was run in when a user is warned" .ModConfig.WarnIncludeChannelLogs}} {{checkbox "WarnSendToModlog" "WarnSendToModlog" "Send warnings to the modlog" .ModConfig.WarnSendToModlog}} + {{checkbox "UnwarnSendToModlog" "UnwarnSendToModlog" "Send warning removal to the modlog" .ModConfig.UnwarnSendToModlog}} + {{checkbox "UnwarnIncludeWarnReason" "UnwarnIncludeWarnReason" "Send warning reason to modlog when removing warning" .ModConfig.UnwarnIncludeWarnReason}}
diff --git a/moderation/commands.go b/moderation/commands.go index 15d2a12356..4614171900 100644 --- a/moderation/commands.go +++ b/moderation/commands.go @@ -1004,7 +1004,7 @@ var ModerationCommands = []*commands.YAGCommand{ RequiredArgs: 1, Arguments: []*dcmd.ArgDef{ {Name: "Id", Type: dcmd.Int}, - {Name: "Reason", Type: dcmd.String}, + {Name: "Reason", Type: dcmd.String, Default: ""}, }, RequiredDiscordPermsHelp: "ManageMessages or ManageGuild", SlashCommandEnabled: true, @@ -1021,10 +1021,18 @@ var ModerationCommands = []*commands.YAGCommand{ } warningID := parsed.Args[0].Int() - numDeleted, err := models.ModerationWarnings( + warning, err := models.ModerationWarnings( models.ModerationWarningWhere.ID.EQ(warningID), // don't delete warnings from other servers, even if ID is correct models.ModerationWarningWhere.GuildID.EQ(parsed.GuildData.GS.ID), + ).OneG(parsed.Context()) + if err != nil { + return fmt.Sprintf("Could not find warning with ID `%d`", warningID), nil + } + numDeleted, err := models.ModerationWarnings( + models.ModerationWarningWhere.ID.EQ(warningID), + // Recheck the server, even if it's already checked + models.ModerationWarningWhere.GuildID.EQ(parsed.GuildData.GS.ID), ).DeleteAllG(parsed.Context()) if err != nil { return "Failed deleting warning", err @@ -1033,6 +1041,24 @@ var ModerationCommands = []*commands.YAGCommand{ return fmt.Sprintf("Could not find warning with ID `%d`", warningID), nil } + if config.UnwarnSendToModlog && config.ActionChannel != 0 { + userid, err := strconv.ParseInt(warning.UserID, 10, 64) + if err != nil { + return "Failed parsing user ID", err + } + user := bot.GetUsers(parsed.GuildData.GS.ID, userid)[0] + + message := parsed.Args[1].Str() + if config.UnwarnIncludeWarnReason { + message = fmt.Sprintf("%s\n~~%s~~", message, warning.Message) + } + + err = CreateModlogEmbed(config, parsed.Author, MAUnwarned, user, message, "") + if err != nil { + return "Failed sending modlog", err + } + } + return "👌", nil }, }, diff --git a/moderation/config.go b/moderation/config.go index 11e06f66a8..f152a954b0 100644 --- a/moderation/config.go +++ b/moderation/config.go @@ -89,11 +89,13 @@ type Config struct { DefaultMuteDuration null.Int64 `valid:"0,"` // Warn - WarnCommandsEnabled bool - WarnCmdRoles types.Int64Array `valid:"role,true"` - WarnIncludeChannelLogs bool - WarnSendToModlog bool - WarnMessage string `valid:"template,5000"` + WarnCommandsEnabled bool + WarnCmdRoles types.Int64Array `valid:"role,true"` + WarnIncludeChannelLogs bool + WarnSendToModlog bool + UnwarnSendToModlog bool + UnwarnIncludeWarnReason bool + WarnMessage string `valid:"template,5000"` // Misc CleanEnabled bool @@ -153,6 +155,8 @@ func (c *Config) ToModel() *models.ModerationConfig { WarnCmdRoles: c.WarnCmdRoles, WarnIncludeChannelLogs: null.BoolFrom(c.WarnIncludeChannelLogs), WarnSendToModlog: null.BoolFrom(c.WarnSendToModlog), + UnwarnSendToModlog: null.BoolFrom(c.UnwarnSendToModlog), + UnwarnIncludeWarnReason: null.BoolFrom(c.UnwarnIncludeWarnReason), WarnMessage: null.StringFrom(c.WarnMessage), CleanEnabled: null.BoolFrom(c.CleanEnabled), @@ -218,6 +222,8 @@ func configFromModel(model *models.ModerationConfig) *Config { WarnCmdRoles: model.WarnCmdRoles, WarnIncludeChannelLogs: model.WarnIncludeChannelLogs.Bool, WarnSendToModlog: model.WarnSendToModlog.Bool, + UnwarnSendToModlog: model.UnwarnSendToModlog.Bool, + UnwarnIncludeWarnReason: model.UnwarnIncludeWarnReason.Bool, WarnMessage: model.WarnMessage.String, CleanEnabled: model.CleanEnabled.Bool, diff --git a/moderation/models/moderation_configs.go b/moderation/models/moderation_configs.go index 84032cff8f..5004d7c9cd 100644 --- a/moderation/models/moderation_configs.go +++ b/moderation/models/moderation_configs.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.17.1 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -73,6 +73,8 @@ type ModerationConfig struct { GiveRoleCmdEnabled null.Bool `boil:"give_role_cmd_enabled" json:"give_role_cmd_enabled,omitempty" toml:"give_role_cmd_enabled" yaml:"give_role_cmd_enabled,omitempty"` GiveRoleCmdModlog null.Bool `boil:"give_role_cmd_modlog" json:"give_role_cmd_modlog,omitempty" toml:"give_role_cmd_modlog" yaml:"give_role_cmd_modlog,omitempty"` GiveRoleCmdRoles types.Int64Array `boil:"give_role_cmd_roles" json:"give_role_cmd_roles,omitempty" toml:"give_role_cmd_roles" yaml:"give_role_cmd_roles,omitempty"` + UnwarnSendToModlog null.Bool `boil:"unwarn_send_to_modlog" json:"unwarn_send_to_modlog,omitempty" toml:"unwarn_send_to_modlog" yaml:"unwarn_send_to_modlog,omitempty"` + UnwarnIncludeWarnReason null.Bool `boil:"unwarn_include_warn_reason" json:"unwarn_include_warn_reason,omitempty" toml:"unwarn_include_warn_reason" yaml:"unwarn_include_warn_reason,omitempty"` R *moderationConfigR `boil:"-" json:"-" toml:"-" yaml:"-"` L moderationConfigL `boil:"-" json:"-" toml:"-" yaml:"-"` @@ -127,6 +129,8 @@ var ModerationConfigColumns = struct { GiveRoleCmdEnabled string GiveRoleCmdModlog string GiveRoleCmdRoles string + UnwarnSendToModlog string + UnwarnIncludeWarnReason string }{ GuildID: "guild_id", CreatedAt: "created_at", @@ -176,6 +180,8 @@ var ModerationConfigColumns = struct { GiveRoleCmdEnabled: "give_role_cmd_enabled", GiveRoleCmdModlog: "give_role_cmd_modlog", GiveRoleCmdRoles: "give_role_cmd_roles", + UnwarnSendToModlog: "unwarn_send_to_modlog", + UnwarnIncludeWarnReason: "unwarn_include_warn_reason", } var ModerationConfigTableColumns = struct { @@ -227,6 +233,8 @@ var ModerationConfigTableColumns = struct { GiveRoleCmdEnabled string GiveRoleCmdModlog string GiveRoleCmdRoles string + UnwarnSendToModlog string + UnwarnIncludeWarnReason string }{ GuildID: "moderation_configs.guild_id", CreatedAt: "moderation_configs.created_at", @@ -276,6 +284,8 @@ var ModerationConfigTableColumns = struct { GiveRoleCmdEnabled: "moderation_configs.give_role_cmd_enabled", GiveRoleCmdModlog: "moderation_configs.give_role_cmd_modlog", GiveRoleCmdRoles: "moderation_configs.give_role_cmd_roles", + UnwarnSendToModlog: "moderation_configs.unwarn_send_to_modlog", + UnwarnIncludeWarnReason: "moderation_configs.unwarn_include_warn_reason", } // Generated where @@ -404,6 +414,12 @@ func (w whereHelpernull_String) ILIKE(x null.String) qm.QueryMod { func (w whereHelpernull_String) NILIKE(x null.String) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelpernull_String) SIMILAR(x null.String) qm.QueryMod { + return qm.Where(w.field+" SIMILAR TO ?", x) +} +func (w whereHelpernull_String) NSIMILAR(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT SIMILAR TO ?", x) +} func (w whereHelpernull_String) IN(slice []string) qm.QueryMod { values := make([]interface{}, 0, len(slice)) for _, value := range slice { @@ -509,6 +525,8 @@ var ModerationConfigWhere = struct { GiveRoleCmdEnabled whereHelpernull_Bool GiveRoleCmdModlog whereHelpernull_Bool GiveRoleCmdRoles whereHelpertypes_Int64Array + UnwarnSendToModlog whereHelpernull_Bool + UnwarnIncludeWarnReason whereHelpernull_Bool }{ GuildID: whereHelperint64{field: "\"moderation_configs\".\"guild_id\""}, CreatedAt: whereHelpertime_Time{field: "\"moderation_configs\".\"created_at\""}, @@ -558,6 +576,8 @@ var ModerationConfigWhere = struct { GiveRoleCmdEnabled: whereHelpernull_Bool{field: "\"moderation_configs\".\"give_role_cmd_enabled\""}, GiveRoleCmdModlog: whereHelpernull_Bool{field: "\"moderation_configs\".\"give_role_cmd_modlog\""}, GiveRoleCmdRoles: whereHelpertypes_Int64Array{field: "\"moderation_configs\".\"give_role_cmd_roles\""}, + UnwarnSendToModlog: whereHelpernull_Bool{field: "\"moderation_configs\".\"unwarn_send_to_modlog\""}, + UnwarnIncludeWarnReason: whereHelpernull_Bool{field: "\"moderation_configs\".\"unwarn_include_warn_reason\""}, } // ModerationConfigRels is where relationship names are stored. @@ -577,9 +597,9 @@ func (*moderationConfigR) NewStruct() *moderationConfigR { type moderationConfigL struct{} var ( - moderationConfigAllColumns = []string{"guild_id", "created_at", "updated_at", "kick_enabled", "kick_cmd_roles", "delete_messages_on_kick", "kick_reason_optional", "kick_message", "ban_enabled", "ban_cmd_roles", "ban_reason_optional", "ban_message", "default_ban_delete_days", "timeout_enabled", "timeout_cmd_roles", "timeout_reason_optional", "timeout_remove_reason_optional", "timeout_message", "default_timeout_duration", "mute_enabled", "mute_cmd_roles", "mute_role", "mute_disallow_reaction_add", "mute_reason_optional", "unmute_reason_optional", "mute_manage_role", "mute_remove_roles", "mute_ignore_channels", "mute_message", "unmute_message", "default_mute_duration", "warn_commands_enabled", "warn_cmd_roles", "warn_include_channel_logs", "warn_send_to_modlog", "warn_message", "clean_enabled", "report_enabled", "action_channel", "report_channel", "error_channel", "log_unbans", "log_bans", "log_kicks", "log_timeouts", "give_role_cmd_enabled", "give_role_cmd_modlog", "give_role_cmd_roles"} + moderationConfigAllColumns = []string{"guild_id", "created_at", "updated_at", "kick_enabled", "kick_cmd_roles", "delete_messages_on_kick", "kick_reason_optional", "kick_message", "ban_enabled", "ban_cmd_roles", "ban_reason_optional", "ban_message", "default_ban_delete_days", "timeout_enabled", "timeout_cmd_roles", "timeout_reason_optional", "timeout_remove_reason_optional", "timeout_message", "default_timeout_duration", "mute_enabled", "mute_cmd_roles", "mute_role", "mute_disallow_reaction_add", "mute_reason_optional", "unmute_reason_optional", "mute_manage_role", "mute_remove_roles", "mute_ignore_channels", "mute_message", "unmute_message", "default_mute_duration", "warn_commands_enabled", "warn_cmd_roles", "warn_include_channel_logs", "warn_send_to_modlog", "warn_message", "clean_enabled", "report_enabled", "action_channel", "report_channel", "error_channel", "log_unbans", "log_bans", "log_kicks", "log_timeouts", "give_role_cmd_enabled", "give_role_cmd_modlog", "give_role_cmd_roles", "unwarn_send_to_modlog", "unwarn_include_warn_reason"} moderationConfigColumnsWithoutDefault = []string{"guild_id", "created_at", "updated_at"} - moderationConfigColumnsWithDefault = []string{"kick_enabled", "kick_cmd_roles", "delete_messages_on_kick", "kick_reason_optional", "kick_message", "ban_enabled", "ban_cmd_roles", "ban_reason_optional", "ban_message", "default_ban_delete_days", "timeout_enabled", "timeout_cmd_roles", "timeout_reason_optional", "timeout_remove_reason_optional", "timeout_message", "default_timeout_duration", "mute_enabled", "mute_cmd_roles", "mute_role", "mute_disallow_reaction_add", "mute_reason_optional", "unmute_reason_optional", "mute_manage_role", "mute_remove_roles", "mute_ignore_channels", "mute_message", "unmute_message", "default_mute_duration", "warn_commands_enabled", "warn_cmd_roles", "warn_include_channel_logs", "warn_send_to_modlog", "warn_message", "clean_enabled", "report_enabled", "action_channel", "report_channel", "error_channel", "log_unbans", "log_bans", "log_kicks", "log_timeouts", "give_role_cmd_enabled", "give_role_cmd_modlog", "give_role_cmd_roles"} + moderationConfigColumnsWithDefault = []string{"kick_enabled", "kick_cmd_roles", "delete_messages_on_kick", "kick_reason_optional", "kick_message", "ban_enabled", "ban_cmd_roles", "ban_reason_optional", "ban_message", "default_ban_delete_days", "timeout_enabled", "timeout_cmd_roles", "timeout_reason_optional", "timeout_remove_reason_optional", "timeout_message", "default_timeout_duration", "mute_enabled", "mute_cmd_roles", "mute_role", "mute_disallow_reaction_add", "mute_reason_optional", "unmute_reason_optional", "mute_manage_role", "mute_remove_roles", "mute_ignore_channels", "mute_message", "unmute_message", "default_mute_duration", "warn_commands_enabled", "warn_cmd_roles", "warn_include_channel_logs", "warn_send_to_modlog", "warn_message", "clean_enabled", "report_enabled", "action_channel", "report_channel", "error_channel", "log_unbans", "log_bans", "log_kicks", "log_timeouts", "give_role_cmd_enabled", "give_role_cmd_modlog", "give_role_cmd_roles", "unwarn_send_to_modlog", "unwarn_include_warn_reason"} moderationConfigPrimaryKeyColumns = []string{"guild_id"} moderationConfigGeneratedColumns = []string{} ) @@ -1182,7 +1202,7 @@ func (o ModerationConfigSlice) DeleteAll(ctx context.Context, exec boil.ContextE } sql := "DELETE FROM \"moderation_configs\" WHERE " + - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, moderationConfigPrimaryKeyColumns, len(o)) + strmangle.WhereInClause(string(dialect.LQ), string(dialect.RQ), 1, moderationConfigPrimaryKeyColumns, len(o)) if boil.IsDebug(ctx) { writer := boil.DebugWriterFrom(ctx) diff --git a/moderation/modlog.go b/moderation/modlog.go index b6612df188..637cf7a485 100644 --- a/moderation/modlog.go +++ b/moderation/modlog.go @@ -33,6 +33,7 @@ var ( MABanned = ModlogAction{Prefix: "Banned", Emoji: "🔨", Color: 0xd64848} MAUnbanned = ModlogAction{Prefix: "Unbanned", Emoji: "🔓", Color: 0x62c65f} MAWarned = ModlogAction{Prefix: "Warned", Emoji: "⚠", Color: 0xfca253} + MAUnwarned = ModlogAction{Prefix: "Warn removed", Emoji: "🧽", Color: 0xfca253} MATimeoutAdded = ModlogAction{Prefix: "Timed out", Emoji: "⏱", Color: 0x9b59b6} MATimeoutRemoved = ModlogAction{Prefix: "Timeout removed from", Emoji: "⏱", Color: 0x9b59b6} MAGiveRole = ModlogAction{Prefix: "", Emoji: "➕", Color: 0x53fcf9} diff --git a/moderation/schema.go b/moderation/schema.go index c2c9e41269..452782b21a 100644 --- a/moderation/schema.go +++ b/moderation/schema.go @@ -51,6 +51,8 @@ CREATE TABLE IF NOT EXISTS moderation_configs ( warn_include_channel_logs BOOLEAN, warn_send_to_modlog BOOLEAN, warn_message TEXT, + unwarn_send_to_modlog BOOLEAN, + unwarn_include_warn_reason BOOLEAN, clean_enabled BOOLEAN, report_enabled BOOLEAN, From 0230cdd62e70452dee4b19c5b0190a8fff7bf519 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 06:08:10 +0000 Subject: [PATCH 02/15] Optimization + Better explaination in checkbox UnwarnIncludeWarnReason --- moderation/assets/moderation.html | 2 +- moderation/commands.go | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/moderation/assets/moderation.html b/moderation/assets/moderation.html index 2848b46a03..ab47041e5a 100644 --- a/moderation/assets/moderation.html +++ b/moderation/assets/moderation.html @@ -473,7 +473,7 @@

Delete ALL server warnings?

{{checkbox "WarnIncludeChannelLogs" "WarnIncludeChannelLogs" "Create message logs in the channel that the command was run in when a user is warned" .ModConfig.WarnIncludeChannelLogs}} {{checkbox "WarnSendToModlog" "WarnSendToModlog" "Send warnings to the modlog" .ModConfig.WarnSendToModlog}} {{checkbox "UnwarnSendToModlog" "UnwarnSendToModlog" "Send warning removal to the modlog" .ModConfig.UnwarnSendToModlog}} - {{checkbox "UnwarnIncludeWarnReason" "UnwarnIncludeWarnReason" "Send warning reason to modlog when removing warning" .ModConfig.UnwarnIncludeWarnReason}} + {{checkbox "UnwarnIncludeWarnReason" "UnwarnIncludeWarnReason" "Include warning reason in the modlog" .ModConfig.UnwarnIncludeWarnReason}}
diff --git a/moderation/commands.go b/moderation/commands.go index 4614171900..6ee3b4a9f6 100644 --- a/moderation/commands.go +++ b/moderation/commands.go @@ -1021,17 +1021,23 @@ var ModerationCommands = []*commands.YAGCommand{ } warningID := parsed.Args[0].Int() - warning, err := models.ModerationWarnings( - models.ModerationWarningWhere.ID.EQ(warningID), - // don't delete warnings from other servers, even if ID is correct - models.ModerationWarningWhere.GuildID.EQ(parsed.GuildData.GS.ID), - ).OneG(parsed.Context()) - if err != nil { - return fmt.Sprintf("Could not find warning with ID `%d`", warningID), nil + + // Using that if we need to send to modlog + var warning *models.ModerationWarning + if config.UnwarnSendToModlog && config.ActionChannel != 0 { + warning, err = models.ModerationWarnings( + models.ModerationWarningWhere.ID.EQ(warningID), + // don't get warning from other servers, even if ID is correct + models.ModerationWarningWhere.GuildID.EQ(parsed.GuildData.GS.ID), + ).OneG(parsed.Context()) + if err != nil { + return fmt.Sprintf("Could not find warning with ID `%d`", warningID), nil + } } + numDeleted, err := models.ModerationWarnings( models.ModerationWarningWhere.ID.EQ(warningID), - // Recheck the server, even if it's already checked + // don't delete warnings from other servers, even if ID is correct models.ModerationWarningWhere.GuildID.EQ(parsed.GuildData.GS.ID), ).DeleteAllG(parsed.Context()) if err != nil { From 594a4bc8d250e325d552659e8070040d02c9446c Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 06:38:43 +0000 Subject: [PATCH 03/15] corrected with sqlboiler version in go.mod --- moderation/models/moderation_configs.go | 40 +++++-------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/moderation/models/moderation_configs.go b/moderation/models/moderation_configs.go index 5004d7c9cd..9a52444b70 100644 --- a/moderation/models/moderation_configs.go +++ b/moderation/models/moderation_configs.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.17.1 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.14.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -402,24 +402,6 @@ func (w whereHelpernull_String) GT(x null.String) qm.QueryMod { func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } -func (w whereHelpernull_String) LIKE(x null.String) qm.QueryMod { - return qm.Where(w.field+" LIKE ?", x) -} -func (w whereHelpernull_String) NLIKE(x null.String) qm.QueryMod { - return qm.Where(w.field+" NOT LIKE ?", x) -} -func (w whereHelpernull_String) ILIKE(x null.String) qm.QueryMod { - return qm.Where(w.field+" ILIKE ?", x) -} -func (w whereHelpernull_String) NILIKE(x null.String) qm.QueryMod { - return qm.Where(w.field+" NOT ILIKE ?", x) -} -func (w whereHelpernull_String) SIMILAR(x null.String) qm.QueryMod { - return qm.Where(w.field+" SIMILAR TO ?", x) -} -func (w whereHelpernull_String) NSIMILAR(x null.String) qm.QueryMod { - return qm.Where(w.field+" NOT SIMILAR TO ?", x) -} func (w whereHelpernull_String) IN(slice []string) qm.QueryMod { values := make([]interface{}, 0, len(slice)) for _, value := range slice { @@ -995,13 +977,13 @@ func (o ModerationConfigSlice) UpdateAll(ctx context.Context, exec boil.ContextE } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ModerationConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) +func (o *ModerationConfig) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *ModerationConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { +func (o *ModerationConfig) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { if o == nil { return errors.New("models: no moderation_configs provided for upsert") } @@ -1051,7 +1033,7 @@ func (o *ModerationConfig) Upsert(ctx context.Context, exec boil.ContextExecutor var err error if !cached { - insert, _ := insertColumns.InsertColumnSet( + insert, ret := insertColumns.InsertColumnSet( moderationConfigAllColumns, moderationConfigColumnsWithDefault, moderationConfigColumnsWithoutDefault, @@ -1067,18 +1049,12 @@ func (o *ModerationConfig) Upsert(ctx context.Context, exec boil.ContextExecutor return errors.New("models: unable to upsert moderation_configs, could not build update column list") } - ret := strmangle.SetComplement(moderationConfigAllColumns, strmangle.SetIntersect(insert, update)) - conflict := conflictColumns - if len(conflict) == 0 && updateOnConflict && len(update) != 0 { - if len(moderationConfigPrimaryKeyColumns) == 0 { - return errors.New("models: unable to upsert moderation_configs, could not build conflict column list") - } - + if len(conflict) == 0 { conflict = make([]string, len(moderationConfigPrimaryKeyColumns)) copy(conflict, moderationConfigPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"moderation_configs\"", updateOnConflict, ret, update, conflict, insert, opts...) + cache.query = buildUpsertQueryPostgres(dialect, "\"moderation_configs\"", updateOnConflict, ret, update, conflict, insert) cache.valueMapping, err = queries.BindMapping(moderationConfigType, moderationConfigMapping, insert) if err != nil { @@ -1202,7 +1178,7 @@ func (o ModerationConfigSlice) DeleteAll(ctx context.Context, exec boil.ContextE } sql := "DELETE FROM \"moderation_configs\" WHERE " + - strmangle.WhereInClause(string(dialect.LQ), string(dialect.RQ), 1, moderationConfigPrimaryKeyColumns, len(o)) + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, moderationConfigPrimaryKeyColumns, len(o)) if boil.IsDebug(ctx) { writer := boil.DebugWriterFrom(ctx) From 94c6e7cd9d65ebe386ab668433ddc4c435eb7ff5 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 07:19:18 +0000 Subject: [PATCH 04/15] Warning removed --- moderation/modlog.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moderation/modlog.go b/moderation/modlog.go index 637cf7a485..ae08c97f50 100644 --- a/moderation/modlog.go +++ b/moderation/modlog.go @@ -33,7 +33,7 @@ var ( MABanned = ModlogAction{Prefix: "Banned", Emoji: "🔨", Color: 0xd64848} MAUnbanned = ModlogAction{Prefix: "Unbanned", Emoji: "🔓", Color: 0x62c65f} MAWarned = ModlogAction{Prefix: "Warned", Emoji: "⚠", Color: 0xfca253} - MAUnwarned = ModlogAction{Prefix: "Warn removed", Emoji: "🧽", Color: 0xfca253} + MAUnwarned = ModlogAction{Prefix: "Warning removed", Emoji: "🧽", Color: 0xfca253} MATimeoutAdded = ModlogAction{Prefix: "Timed out", Emoji: "⏱", Color: 0x9b59b6} MATimeoutRemoved = ModlogAction{Prefix: "Timeout removed from", Emoji: "⏱", Color: 0x9b59b6} MAGiveRole = ModlogAction{Prefix: "", Emoji: "➕", Color: 0x53fcf9} From 9c57f1b91a8609244b7fdd2a436068671b594e77 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 18:39:42 +0000 Subject: [PATCH 05/15] https://github.com/botlabs-gg/yagpdb/pull/1795#discussion_r1884262446 Removed because unused https://github.com/botlabs-gg/yagpdb/pull/1795#discussion_r1884271314 Maybe change also the text ? https://github.com/botlabs-gg/yagpdb/pull/1795#discussion_r1884288576 Altered table --- moderation/assets/moderation.html | 4 +- moderation/commands.go | 10 ++-- moderation/config.go | 12 ++--- moderation/models/moderation_configs.go | 40 ++++++++------- moderation/models/moderation_warnings.go | 36 ++++++-------- moderation/models/muted_users.go | 18 +++---- moderation/models/psql_upsert.go | 63 ++++++------------------ moderation/modlog.go | 2 +- moderation/schema.go | 5 +- 9 files changed, 74 insertions(+), 116 deletions(-) diff --git a/moderation/assets/moderation.html b/moderation/assets/moderation.html index ab47041e5a..4cf9ca230f 100644 --- a/moderation/assets/moderation.html +++ b/moderation/assets/moderation.html @@ -472,8 +472,8 @@

Delete ALL server warnings?

{{checkbox "WarnIncludeChannelLogs" "WarnIncludeChannelLogs" "Create message logs in the channel that the command was run in when a user is warned" .ModConfig.WarnIncludeChannelLogs}} {{checkbox "WarnSendToModlog" "WarnSendToModlog" "Send warnings to the modlog" .ModConfig.WarnSendToModlog}} - {{checkbox "UnwarnSendToModlog" "UnwarnSendToModlog" "Send warning removal to the modlog" .ModConfig.UnwarnSendToModlog}} - {{checkbox "UnwarnIncludeWarnReason" "UnwarnIncludeWarnReason" "Include warning reason in the modlog" .ModConfig.UnwarnIncludeWarnReason}} + {{checkbox "DelwarnSendToModlog" "DelwarnSendToModlog" "Send warning removal to the modlog" .ModConfig.DelwarnSendToModlog}} + {{checkbox "DelwarnIncludeWarnReason" "DelwarnIncludeWarnReason" "Include warning reason in the modlog" .ModConfig.DelwarnIncludeWarnReason}}
diff --git a/moderation/commands.go b/moderation/commands.go index 6ee3b4a9f6..850e90c709 100644 --- a/moderation/commands.go +++ b/moderation/commands.go @@ -1004,7 +1004,7 @@ var ModerationCommands = []*commands.YAGCommand{ RequiredArgs: 1, Arguments: []*dcmd.ArgDef{ {Name: "Id", Type: dcmd.Int}, - {Name: "Reason", Type: dcmd.String, Default: ""}, + {Name: "Reason", Type: dcmd.String}, }, RequiredDiscordPermsHelp: "ManageMessages or ManageGuild", SlashCommandEnabled: true, @@ -1024,7 +1024,7 @@ var ModerationCommands = []*commands.YAGCommand{ // Using that if we need to send to modlog var warning *models.ModerationWarning - if config.UnwarnSendToModlog && config.ActionChannel != 0 { + if config.DelwarnSendToModlog && config.ActionChannel != 0 { warning, err = models.ModerationWarnings( models.ModerationWarningWhere.ID.EQ(warningID), // don't get warning from other servers, even if ID is correct @@ -1047,7 +1047,7 @@ var ModerationCommands = []*commands.YAGCommand{ return fmt.Sprintf("Could not find warning with ID `%d`", warningID), nil } - if config.UnwarnSendToModlog && config.ActionChannel != 0 { + if config.DelwarnSendToModlog && config.ActionChannel != 0 { userid, err := strconv.ParseInt(warning.UserID, 10, 64) if err != nil { return "Failed parsing user ID", err @@ -1055,11 +1055,11 @@ var ModerationCommands = []*commands.YAGCommand{ user := bot.GetUsers(parsed.GuildData.GS.ID, userid)[0] message := parsed.Args[1].Str() - if config.UnwarnIncludeWarnReason { + if config.DelwarnIncludeWarnReason { message = fmt.Sprintf("%s\n~~%s~~", message, warning.Message) } - err = CreateModlogEmbed(config, parsed.Author, MAUnwarned, user, message, "") + err = CreateModlogEmbed(config, parsed.Author, MADelwarn, user, message, "") if err != nil { return "Failed sending modlog", err } diff --git a/moderation/config.go b/moderation/config.go index f152a954b0..6b7322d8e4 100644 --- a/moderation/config.go +++ b/moderation/config.go @@ -93,8 +93,8 @@ type Config struct { WarnCmdRoles types.Int64Array `valid:"role,true"` WarnIncludeChannelLogs bool WarnSendToModlog bool - UnwarnSendToModlog bool - UnwarnIncludeWarnReason bool + DelwarnSendToModlog bool + DelwarnIncludeWarnReason bool WarnMessage string `valid:"template,5000"` // Misc @@ -155,8 +155,8 @@ func (c *Config) ToModel() *models.ModerationConfig { WarnCmdRoles: c.WarnCmdRoles, WarnIncludeChannelLogs: null.BoolFrom(c.WarnIncludeChannelLogs), WarnSendToModlog: null.BoolFrom(c.WarnSendToModlog), - UnwarnSendToModlog: null.BoolFrom(c.UnwarnSendToModlog), - UnwarnIncludeWarnReason: null.BoolFrom(c.UnwarnIncludeWarnReason), + DelwarnSendToModlog: null.BoolFrom(c.DelwarnSendToModlog), + DelwarnIncludeWarnReason: null.BoolFrom(c.DelwarnIncludeWarnReason), WarnMessage: null.StringFrom(c.WarnMessage), CleanEnabled: null.BoolFrom(c.CleanEnabled), @@ -222,8 +222,8 @@ func configFromModel(model *models.ModerationConfig) *Config { WarnCmdRoles: model.WarnCmdRoles, WarnIncludeChannelLogs: model.WarnIncludeChannelLogs.Bool, WarnSendToModlog: model.WarnSendToModlog.Bool, - UnwarnSendToModlog: model.UnwarnSendToModlog.Bool, - UnwarnIncludeWarnReason: model.UnwarnIncludeWarnReason.Bool, + DelwarnSendToModlog: model.DelwarnSendToModlog.Bool, + DelwarnIncludeWarnReason: model.DelwarnIncludeWarnReason.Bool, WarnMessage: model.WarnMessage.String, CleanEnabled: model.CleanEnabled.Bool, diff --git a/moderation/models/moderation_configs.go b/moderation/models/moderation_configs.go index 9a52444b70..33b23cb98a 100644 --- a/moderation/models/moderation_configs.go +++ b/moderation/models/moderation_configs.go @@ -1,4 +1,4 @@ -// Code generated by SQLBoiler 4.14.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. // This file is meant to be re-generated in place and/or deleted at any time. package models @@ -73,8 +73,8 @@ type ModerationConfig struct { GiveRoleCmdEnabled null.Bool `boil:"give_role_cmd_enabled" json:"give_role_cmd_enabled,omitempty" toml:"give_role_cmd_enabled" yaml:"give_role_cmd_enabled,omitempty"` GiveRoleCmdModlog null.Bool `boil:"give_role_cmd_modlog" json:"give_role_cmd_modlog,omitempty" toml:"give_role_cmd_modlog" yaml:"give_role_cmd_modlog,omitempty"` GiveRoleCmdRoles types.Int64Array `boil:"give_role_cmd_roles" json:"give_role_cmd_roles,omitempty" toml:"give_role_cmd_roles" yaml:"give_role_cmd_roles,omitempty"` - UnwarnSendToModlog null.Bool `boil:"unwarn_send_to_modlog" json:"unwarn_send_to_modlog,omitempty" toml:"unwarn_send_to_modlog" yaml:"unwarn_send_to_modlog,omitempty"` - UnwarnIncludeWarnReason null.Bool `boil:"unwarn_include_warn_reason" json:"unwarn_include_warn_reason,omitempty" toml:"unwarn_include_warn_reason" yaml:"unwarn_include_warn_reason,omitempty"` + DelwarnSendToModlog null.Bool `boil:"delwarn_send_to_modlog" json:"delwarn_send_to_modlog,omitempty" toml:"delwarn_send_to_modlog" yaml:"delwarn_send_to_modlog,omitempty"` + DelwarnIncludeWarnReason null.Bool `boil:"delwarn_include_warn_reason" json:"delwarn_include_warn_reason,omitempty" toml:"delwarn_include_warn_reason" yaml:"delwarn_include_warn_reason,omitempty"` R *moderationConfigR `boil:"-" json:"-" toml:"-" yaml:"-"` L moderationConfigL `boil:"-" json:"-" toml:"-" yaml:"-"` @@ -129,8 +129,8 @@ var ModerationConfigColumns = struct { GiveRoleCmdEnabled string GiveRoleCmdModlog string GiveRoleCmdRoles string - UnwarnSendToModlog string - UnwarnIncludeWarnReason string + DelwarnSendToModlog string + DelwarnIncludeWarnReason string }{ GuildID: "guild_id", CreatedAt: "created_at", @@ -180,8 +180,8 @@ var ModerationConfigColumns = struct { GiveRoleCmdEnabled: "give_role_cmd_enabled", GiveRoleCmdModlog: "give_role_cmd_modlog", GiveRoleCmdRoles: "give_role_cmd_roles", - UnwarnSendToModlog: "unwarn_send_to_modlog", - UnwarnIncludeWarnReason: "unwarn_include_warn_reason", + DelwarnSendToModlog: "delwarn_send_to_modlog", + DelwarnIncludeWarnReason: "delwarn_include_warn_reason", } var ModerationConfigTableColumns = struct { @@ -233,8 +233,8 @@ var ModerationConfigTableColumns = struct { GiveRoleCmdEnabled string GiveRoleCmdModlog string GiveRoleCmdRoles string - UnwarnSendToModlog string - UnwarnIncludeWarnReason string + DelwarnSendToModlog string + DelwarnIncludeWarnReason string }{ GuildID: "moderation_configs.guild_id", CreatedAt: "moderation_configs.created_at", @@ -284,8 +284,8 @@ var ModerationConfigTableColumns = struct { GiveRoleCmdEnabled: "moderation_configs.give_role_cmd_enabled", GiveRoleCmdModlog: "moderation_configs.give_role_cmd_modlog", GiveRoleCmdRoles: "moderation_configs.give_role_cmd_roles", - UnwarnSendToModlog: "moderation_configs.unwarn_send_to_modlog", - UnwarnIncludeWarnReason: "moderation_configs.unwarn_include_warn_reason", + DelwarnSendToModlog: "moderation_configs.delwarn_send_to_modlog", + DelwarnIncludeWarnReason: "moderation_configs.delwarn_include_warn_reason", } // Generated where @@ -402,6 +402,12 @@ func (w whereHelpernull_String) GT(x null.String) qm.QueryMod { func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelpernull_String) LIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" LIKE ?", x) +} +func (w whereHelpernull_String) NLIKE(x null.String) qm.QueryMod { + return qm.Where(w.field+" NOT LIKE ?", x) +} func (w whereHelpernull_String) IN(slice []string) qm.QueryMod { values := make([]interface{}, 0, len(slice)) for _, value := range slice { @@ -507,8 +513,8 @@ var ModerationConfigWhere = struct { GiveRoleCmdEnabled whereHelpernull_Bool GiveRoleCmdModlog whereHelpernull_Bool GiveRoleCmdRoles whereHelpertypes_Int64Array - UnwarnSendToModlog whereHelpernull_Bool - UnwarnIncludeWarnReason whereHelpernull_Bool + DelwarnSendToModlog whereHelpernull_Bool + DelwarnIncludeWarnReason whereHelpernull_Bool }{ GuildID: whereHelperint64{field: "\"moderation_configs\".\"guild_id\""}, CreatedAt: whereHelpertime_Time{field: "\"moderation_configs\".\"created_at\""}, @@ -558,8 +564,8 @@ var ModerationConfigWhere = struct { GiveRoleCmdEnabled: whereHelpernull_Bool{field: "\"moderation_configs\".\"give_role_cmd_enabled\""}, GiveRoleCmdModlog: whereHelpernull_Bool{field: "\"moderation_configs\".\"give_role_cmd_modlog\""}, GiveRoleCmdRoles: whereHelpertypes_Int64Array{field: "\"moderation_configs\".\"give_role_cmd_roles\""}, - UnwarnSendToModlog: whereHelpernull_Bool{field: "\"moderation_configs\".\"unwarn_send_to_modlog\""}, - UnwarnIncludeWarnReason: whereHelpernull_Bool{field: "\"moderation_configs\".\"unwarn_include_warn_reason\""}, + DelwarnSendToModlog: whereHelpernull_Bool{field: "\"moderation_configs\".\"delwarn_send_to_modlog\""}, + DelwarnIncludeWarnReason: whereHelpernull_Bool{field: "\"moderation_configs\".\"delwarn_include_warn_reason\""}, } // ModerationConfigRels is where relationship names are stored. @@ -579,9 +585,9 @@ func (*moderationConfigR) NewStruct() *moderationConfigR { type moderationConfigL struct{} var ( - moderationConfigAllColumns = []string{"guild_id", "created_at", "updated_at", "kick_enabled", "kick_cmd_roles", "delete_messages_on_kick", "kick_reason_optional", "kick_message", "ban_enabled", "ban_cmd_roles", "ban_reason_optional", "ban_message", "default_ban_delete_days", "timeout_enabled", "timeout_cmd_roles", "timeout_reason_optional", "timeout_remove_reason_optional", "timeout_message", "default_timeout_duration", "mute_enabled", "mute_cmd_roles", "mute_role", "mute_disallow_reaction_add", "mute_reason_optional", "unmute_reason_optional", "mute_manage_role", "mute_remove_roles", "mute_ignore_channels", "mute_message", "unmute_message", "default_mute_duration", "warn_commands_enabled", "warn_cmd_roles", "warn_include_channel_logs", "warn_send_to_modlog", "warn_message", "clean_enabled", "report_enabled", "action_channel", "report_channel", "error_channel", "log_unbans", "log_bans", "log_kicks", "log_timeouts", "give_role_cmd_enabled", "give_role_cmd_modlog", "give_role_cmd_roles", "unwarn_send_to_modlog", "unwarn_include_warn_reason"} + moderationConfigAllColumns = []string{"guild_id", "created_at", "updated_at", "kick_enabled", "kick_cmd_roles", "delete_messages_on_kick", "kick_reason_optional", "kick_message", "ban_enabled", "ban_cmd_roles", "ban_reason_optional", "ban_message", "default_ban_delete_days", "timeout_enabled", "timeout_cmd_roles", "timeout_reason_optional", "timeout_remove_reason_optional", "timeout_message", "default_timeout_duration", "mute_enabled", "mute_cmd_roles", "mute_role", "mute_disallow_reaction_add", "mute_reason_optional", "unmute_reason_optional", "mute_manage_role", "mute_remove_roles", "mute_ignore_channels", "mute_message", "unmute_message", "default_mute_duration", "warn_commands_enabled", "warn_cmd_roles", "warn_include_channel_logs", "warn_send_to_modlog", "warn_message", "clean_enabled", "report_enabled", "action_channel", "report_channel", "error_channel", "log_unbans", "log_bans", "log_kicks", "log_timeouts", "give_role_cmd_enabled", "give_role_cmd_modlog", "give_role_cmd_roles", "delwarn_send_to_modlog", "delwarn_include_warn_reason"} moderationConfigColumnsWithoutDefault = []string{"guild_id", "created_at", "updated_at"} - moderationConfigColumnsWithDefault = []string{"kick_enabled", "kick_cmd_roles", "delete_messages_on_kick", "kick_reason_optional", "kick_message", "ban_enabled", "ban_cmd_roles", "ban_reason_optional", "ban_message", "default_ban_delete_days", "timeout_enabled", "timeout_cmd_roles", "timeout_reason_optional", "timeout_remove_reason_optional", "timeout_message", "default_timeout_duration", "mute_enabled", "mute_cmd_roles", "mute_role", "mute_disallow_reaction_add", "mute_reason_optional", "unmute_reason_optional", "mute_manage_role", "mute_remove_roles", "mute_ignore_channels", "mute_message", "unmute_message", "default_mute_duration", "warn_commands_enabled", "warn_cmd_roles", "warn_include_channel_logs", "warn_send_to_modlog", "warn_message", "clean_enabled", "report_enabled", "action_channel", "report_channel", "error_channel", "log_unbans", "log_bans", "log_kicks", "log_timeouts", "give_role_cmd_enabled", "give_role_cmd_modlog", "give_role_cmd_roles", "unwarn_send_to_modlog", "unwarn_include_warn_reason"} + moderationConfigColumnsWithDefault = []string{"kick_enabled", "kick_cmd_roles", "delete_messages_on_kick", "kick_reason_optional", "kick_message", "ban_enabled", "ban_cmd_roles", "ban_reason_optional", "ban_message", "default_ban_delete_days", "timeout_enabled", "timeout_cmd_roles", "timeout_reason_optional", "timeout_remove_reason_optional", "timeout_message", "default_timeout_duration", "mute_enabled", "mute_cmd_roles", "mute_role", "mute_disallow_reaction_add", "mute_reason_optional", "unmute_reason_optional", "mute_manage_role", "mute_remove_roles", "mute_ignore_channels", "mute_message", "unmute_message", "default_mute_duration", "warn_commands_enabled", "warn_cmd_roles", "warn_include_channel_logs", "warn_send_to_modlog", "warn_message", "clean_enabled", "report_enabled", "action_channel", "report_channel", "error_channel", "log_unbans", "log_bans", "log_kicks", "log_timeouts", "give_role_cmd_enabled", "give_role_cmd_modlog", "give_role_cmd_roles", "delwarn_send_to_modlog", "delwarn_include_warn_reason"} moderationConfigPrimaryKeyColumns = []string{"guild_id"} moderationConfigGeneratedColumns = []string{} ) diff --git a/moderation/models/moderation_warnings.go b/moderation/models/moderation_warnings.go index bb433062cc..96e2934f2c 100644 --- a/moderation/models/moderation_warnings.go +++ b/moderation/models/moderation_warnings.go @@ -109,16 +109,14 @@ func (w whereHelperint) NIN(slice []int) qm.QueryMod { type whereHelperstring struct{ field string } -func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } -func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } -func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } -func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) } -func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) } +func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } +func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) } +func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) } func (w whereHelperstring) IN(slice []string) qm.QueryMod { values := make([]interface{}, 0, len(slice)) for _, value := range slice { @@ -571,13 +569,13 @@ func (o ModerationWarningSlice) UpdateAll(ctx context.Context, exec boil.Context } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *ModerationWarning) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) +func (o *ModerationWarning) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *ModerationWarning) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { +func (o *ModerationWarning) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { if o == nil { return errors.New("models: no moderation_warnings provided for upsert") } @@ -627,7 +625,7 @@ func (o *ModerationWarning) Upsert(ctx context.Context, exec boil.ContextExecuto var err error if !cached { - insert, _ := insertColumns.InsertColumnSet( + insert, ret := insertColumns.InsertColumnSet( moderationWarningAllColumns, moderationWarningColumnsWithDefault, moderationWarningColumnsWithoutDefault, @@ -643,18 +641,12 @@ func (o *ModerationWarning) Upsert(ctx context.Context, exec boil.ContextExecuto return errors.New("models: unable to upsert moderation_warnings, could not build update column list") } - ret := strmangle.SetComplement(moderationWarningAllColumns, strmangle.SetIntersect(insert, update)) - conflict := conflictColumns - if len(conflict) == 0 && updateOnConflict && len(update) != 0 { - if len(moderationWarningPrimaryKeyColumns) == 0 { - return errors.New("models: unable to upsert moderation_warnings, could not build conflict column list") - } - + if len(conflict) == 0 { conflict = make([]string, len(moderationWarningPrimaryKeyColumns)) copy(conflict, moderationWarningPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"moderation_warnings\"", updateOnConflict, ret, update, conflict, insert, opts...) + cache.query = buildUpsertQueryPostgres(dialect, "\"moderation_warnings\"", updateOnConflict, ret, update, conflict, insert) cache.valueMapping, err = queries.BindMapping(moderationWarningType, moderationWarningMapping, insert) if err != nil { diff --git a/moderation/models/muted_users.go b/moderation/models/muted_users.go index f69f7bf1b2..bf380c7c85 100644 --- a/moderation/models/muted_users.go +++ b/moderation/models/muted_users.go @@ -546,13 +546,13 @@ func (o MutedUserSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor } // UpsertG attempts an insert, and does an update or ignore on conflict. -func (o *MutedUser) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { - return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns, opts...) +func (o *MutedUser) UpsertG(ctx context.Context, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { + return o.Upsert(ctx, boil.GetContextDB(), updateOnConflict, conflictColumns, updateColumns, insertColumns) } // Upsert attempts an insert using an executor, and does an update or ignore on conflict. // See boil.Columns documentation for how to properly use updateColumns and insertColumns. -func (o *MutedUser) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { +func (o *MutedUser) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error { if o == nil { return errors.New("models: no muted_users provided for upsert") } @@ -602,7 +602,7 @@ func (o *MutedUser) Upsert(ctx context.Context, exec boil.ContextExecutor, updat var err error if !cached { - insert, _ := insertColumns.InsertColumnSet( + insert, ret := insertColumns.InsertColumnSet( mutedUserAllColumns, mutedUserColumnsWithDefault, mutedUserColumnsWithoutDefault, @@ -618,18 +618,12 @@ func (o *MutedUser) Upsert(ctx context.Context, exec boil.ContextExecutor, updat return errors.New("models: unable to upsert muted_users, could not build update column list") } - ret := strmangle.SetComplement(mutedUserAllColumns, strmangle.SetIntersect(insert, update)) - conflict := conflictColumns - if len(conflict) == 0 && updateOnConflict && len(update) != 0 { - if len(mutedUserPrimaryKeyColumns) == 0 { - return errors.New("models: unable to upsert muted_users, could not build conflict column list") - } - + if len(conflict) == 0 { conflict = make([]string, len(mutedUserPrimaryKeyColumns)) copy(conflict, mutedUserPrimaryKeyColumns) } - cache.query = buildUpsertQueryPostgres(dialect, "\"muted_users\"", updateOnConflict, ret, update, conflict, insert, opts...) + cache.query = buildUpsertQueryPostgres(dialect, "\"muted_users\"", updateOnConflict, ret, update, conflict, insert) cache.valueMapping, err = queries.BindMapping(mutedUserType, mutedUserMapping, insert) if err != nil { diff --git a/moderation/models/psql_upsert.go b/moderation/models/psql_upsert.go index 07602da9c5..824e36ebaf 100644 --- a/moderation/models/psql_upsert.go +++ b/moderation/models/psql_upsert.go @@ -11,36 +11,12 @@ import ( "github.com/volatiletech/strmangle" ) -type UpsertOptions struct { - conflictTarget string - updateSet string -} - -type UpsertOptionFunc func(o *UpsertOptions) - -func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc { - return func(o *UpsertOptions) { - o.conflictTarget = conflictTarget - } -} - -func UpsertUpdateSet(updateSet string) UpsertOptionFunc { - return func(o *UpsertOptions) { - o.updateSet = updateSet - } -} - // buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided. -func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string { +func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret) - upsertOpts := &UpsertOptions{} - for _, o := range opts { - o(upsertOpts) - } - buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) @@ -58,35 +34,24 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon columns, ) - if upsertOpts.conflictTarget != "" { - buf.WriteString(upsertOpts.conflictTarget) - } else if len(conflict) != 0 { - buf.WriteByte('(') - buf.WriteString(strings.Join(conflict, ", ")) - buf.WriteByte(')') - } - buf.WriteByte(' ') - if !updateOnConflict || len(update) == 0 { buf.WriteString("DO NOTHING") } else { - buf.WriteString("DO UPDATE SET ") + buf.WriteByte('(') + buf.WriteString(strings.Join(conflict, ", ")) + buf.WriteString(") DO UPDATE SET ") - if upsertOpts.updateSet != "" { - buf.WriteString(upsertOpts.updateSet) - } else { - for i, v := range update { - if len(v) == 0 { - continue - } - if i != 0 { - buf.WriteByte(',') - } - quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) - buf.WriteString(quoted) - buf.WriteString(" = EXCLUDED.") - buf.WriteString(quoted) + for i, v := range update { + if len(v) == 0 { + continue + } + if i != 0 { + buf.WriteByte(',') } + quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v) + buf.WriteString(quoted) + buf.WriteString(" = EXCLUDED.") + buf.WriteString(quoted) } } diff --git a/moderation/modlog.go b/moderation/modlog.go index ae08c97f50..94f02012dc 100644 --- a/moderation/modlog.go +++ b/moderation/modlog.go @@ -33,7 +33,7 @@ var ( MABanned = ModlogAction{Prefix: "Banned", Emoji: "🔨", Color: 0xd64848} MAUnbanned = ModlogAction{Prefix: "Unbanned", Emoji: "🔓", Color: 0x62c65f} MAWarned = ModlogAction{Prefix: "Warned", Emoji: "⚠", Color: 0xfca253} - MAUnwarned = ModlogAction{Prefix: "Warning removed", Emoji: "🧽", Color: 0xfca253} + MADelwarn = ModlogAction{Prefix: "Warning removed from", Emoji: "🧽", Color: 0xfca253} MATimeoutAdded = ModlogAction{Prefix: "Timed out", Emoji: "⏱", Color: 0x9b59b6} MATimeoutRemoved = ModlogAction{Prefix: "Timeout removed from", Emoji: "⏱", Color: 0x9b59b6} MAGiveRole = ModlogAction{Prefix: "", Emoji: "➕", Color: 0x53fcf9} diff --git a/moderation/schema.go b/moderation/schema.go index 452782b21a..f2bd3f8759 100644 --- a/moderation/schema.go +++ b/moderation/schema.go @@ -51,8 +51,6 @@ CREATE TABLE IF NOT EXISTS moderation_configs ( warn_include_channel_logs BOOLEAN, warn_send_to_modlog BOOLEAN, warn_message TEXT, - unwarn_send_to_modlog BOOLEAN, - unwarn_include_warn_reason BOOLEAN, clean_enabled BOOLEAN, report_enabled BOOLEAN, @@ -77,6 +75,9 @@ ALTER TABLE moderation_configs ALTER COLUMN created_at SET NOT NULL; `, ` ALTER TABLE moderation_configs ALTER COLUMN updated_at SET NOT NULL; `, ` +ALTER TABLE moderation_configs ADD COLUMN IF NOT EXISTS delwarn_send_to_modlog BOOLEAN NOT NULL DEFAULT false; +ALTER TABLE moderation_configs ADD COLUMN IF NOT EXISTS delwarn_include_warn_reason BOOLEAN NOT NULL DEFAULT false; +`, ` CREATE TABLE IF NOT EXISTS moderation_warnings ( id SERIAL PRIMARY KEY, From ce1e45b477f43e76f7149aa1f600ef59a96f469f Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 19:01:30 +0000 Subject: [PATCH 06/15] https://github.com/botlabs-gg/yagpdb/pull/1795#discussion_r1884261503 --- moderation/commands.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/moderation/commands.go b/moderation/commands.go index 850e90c709..3083307253 100644 --- a/moderation/commands.go +++ b/moderation/commands.go @@ -1015,7 +1015,8 @@ var ModerationCommands = []*commands.YAGCommand{ return nil, err } - _, err = MBaseCmdSecond(parsed, "", true, discordgo.PermissionManageMessages, config.WarnCmdRoles, config.WarnCommandsEnabled, true) + reason := SafeArgString(parsed, 1) + reason, err = MBaseCmdSecond(parsed, reason, true, discordgo.PermissionManageMessages, config.WarnCmdRoles, config.WarnCommandsEnabled, true) if err != nil { return nil, err } @@ -1054,12 +1055,11 @@ var ModerationCommands = []*commands.YAGCommand{ } user := bot.GetUsers(parsed.GuildData.GS.ID, userid)[0] - message := parsed.Args[1].Str() if config.DelwarnIncludeWarnReason { - message = fmt.Sprintf("%s\n~~%s~~", message, warning.Message) + reason = fmt.Sprintf("%s\n~~%s~~", reason, warning.Message) } - err = CreateModlogEmbed(config, parsed.Author, MADelwarn, user, message, "") + err = CreateModlogEmbed(config, parsed.Author, MADelwarn, user, reason, "") if err != nil { return "Failed sending modlog", err } From 1d0e26f59e08c62180b1562fca0d367a9821276a Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 19:06:56 +0000 Subject: [PATCH 07/15] hr https://github.com/botlabs-gg/yagpdb/pull/1795#discussion_r1884272176 --- moderation/assets/moderation.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/moderation/assets/moderation.html b/moderation/assets/moderation.html index 4cf9ca230f..d6ff0beb9e 100644 --- a/moderation/assets/moderation.html +++ b/moderation/assets/moderation.html @@ -469,9 +469,10 @@

Delete ALL server warnings?


- + {{checkbox "WarnIncludeChannelLogs" "WarnIncludeChannelLogs" "Create message logs in the channel that the command was run in when a user is warned" .ModConfig.WarnIncludeChannelLogs}} {{checkbox "WarnSendToModlog" "WarnSendToModlog" "Send warnings to the modlog" .ModConfig.WarnSendToModlog}} +
{{checkbox "DelwarnSendToModlog" "DelwarnSendToModlog" "Send warning removal to the modlog" .ModConfig.DelwarnSendToModlog}} {{checkbox "DelwarnIncludeWarnReason" "DelwarnIncludeWarnReason" "Include warning reason in the modlog" .ModConfig.DelwarnIncludeWarnReason}}
From 092a571cf9c6ebfde27c4b34300888d67facad8d Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 19:40:47 +0000 Subject: [PATCH 08/15] Changed it in my db - NON NULL --- moderation/models/moderation_configs.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/moderation/models/moderation_configs.go b/moderation/models/moderation_configs.go index 33b23cb98a..7f7cbe1333 100644 --- a/moderation/models/moderation_configs.go +++ b/moderation/models/moderation_configs.go @@ -73,8 +73,8 @@ type ModerationConfig struct { GiveRoleCmdEnabled null.Bool `boil:"give_role_cmd_enabled" json:"give_role_cmd_enabled,omitempty" toml:"give_role_cmd_enabled" yaml:"give_role_cmd_enabled,omitempty"` GiveRoleCmdModlog null.Bool `boil:"give_role_cmd_modlog" json:"give_role_cmd_modlog,omitempty" toml:"give_role_cmd_modlog" yaml:"give_role_cmd_modlog,omitempty"` GiveRoleCmdRoles types.Int64Array `boil:"give_role_cmd_roles" json:"give_role_cmd_roles,omitempty" toml:"give_role_cmd_roles" yaml:"give_role_cmd_roles,omitempty"` - DelwarnSendToModlog null.Bool `boil:"delwarn_send_to_modlog" json:"delwarn_send_to_modlog,omitempty" toml:"delwarn_send_to_modlog" yaml:"delwarn_send_to_modlog,omitempty"` - DelwarnIncludeWarnReason null.Bool `boil:"delwarn_include_warn_reason" json:"delwarn_include_warn_reason,omitempty" toml:"delwarn_include_warn_reason" yaml:"delwarn_include_warn_reason,omitempty"` + DelwarnSendToModlog bool `boil:"delwarn_send_to_modlog" json:"delwarn_send_to_modlog" toml:"delwarn_send_to_modlog" yaml:"delwarn_send_to_modlog"` + DelwarnIncludeWarnReason bool `boil:"delwarn_include_warn_reason" json:"delwarn_include_warn_reason" toml:"delwarn_include_warn_reason" yaml:"delwarn_include_warn_reason"` R *moderationConfigR `boil:"-" json:"-" toml:"-" yaml:"-"` L moderationConfigL `boil:"-" json:"-" toml:"-" yaml:"-"` @@ -464,6 +464,15 @@ func (w whereHelpernull_Int64) NIN(slice []int64) qm.QueryMod { func (w whereHelpernull_Int64) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) } func (w whereHelpernull_Int64) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) } +type whereHelperbool struct{ field string } + +func (w whereHelperbool) EQ(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } +func (w whereHelperbool) NEQ(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } +func (w whereHelperbool) LT(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } +func (w whereHelperbool) LTE(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } +func (w whereHelperbool) GT(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } +func (w whereHelperbool) GTE(x bool) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } + var ModerationConfigWhere = struct { GuildID whereHelperint64 CreatedAt whereHelpertime_Time @@ -513,8 +522,8 @@ var ModerationConfigWhere = struct { GiveRoleCmdEnabled whereHelpernull_Bool GiveRoleCmdModlog whereHelpernull_Bool GiveRoleCmdRoles whereHelpertypes_Int64Array - DelwarnSendToModlog whereHelpernull_Bool - DelwarnIncludeWarnReason whereHelpernull_Bool + DelwarnSendToModlog whereHelperbool + DelwarnIncludeWarnReason whereHelperbool }{ GuildID: whereHelperint64{field: "\"moderation_configs\".\"guild_id\""}, CreatedAt: whereHelpertime_Time{field: "\"moderation_configs\".\"created_at\""}, @@ -564,8 +573,8 @@ var ModerationConfigWhere = struct { GiveRoleCmdEnabled: whereHelpernull_Bool{field: "\"moderation_configs\".\"give_role_cmd_enabled\""}, GiveRoleCmdModlog: whereHelpernull_Bool{field: "\"moderation_configs\".\"give_role_cmd_modlog\""}, GiveRoleCmdRoles: whereHelpertypes_Int64Array{field: "\"moderation_configs\".\"give_role_cmd_roles\""}, - DelwarnSendToModlog: whereHelpernull_Bool{field: "\"moderation_configs\".\"delwarn_send_to_modlog\""}, - DelwarnIncludeWarnReason: whereHelpernull_Bool{field: "\"moderation_configs\".\"delwarn_include_warn_reason\""}, + DelwarnSendToModlog: whereHelperbool{field: "\"moderation_configs\".\"delwarn_send_to_modlog\""}, + DelwarnIncludeWarnReason: whereHelperbool{field: "\"moderation_configs\".\"delwarn_include_warn_reason\""}, } // ModerationConfigRels is where relationship names are stored. From 5f1a88ccee1fe98fb51eee00fe4caa13ee2bb33d Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 19:43:07 +0000 Subject: [PATCH 09/15] Config match the sqlboilder --- moderation/config.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/moderation/config.go b/moderation/config.go index 6b7322d8e4..c37147e35e 100644 --- a/moderation/config.go +++ b/moderation/config.go @@ -155,8 +155,8 @@ func (c *Config) ToModel() *models.ModerationConfig { WarnCmdRoles: c.WarnCmdRoles, WarnIncludeChannelLogs: null.BoolFrom(c.WarnIncludeChannelLogs), WarnSendToModlog: null.BoolFrom(c.WarnSendToModlog), - DelwarnSendToModlog: null.BoolFrom(c.DelwarnSendToModlog), - DelwarnIncludeWarnReason: null.BoolFrom(c.DelwarnIncludeWarnReason), + DelwarnSendToModlog: c.DelwarnSendToModlog, + DelwarnIncludeWarnReason: c.DelwarnIncludeWarnReason, WarnMessage: null.StringFrom(c.WarnMessage), CleanEnabled: null.BoolFrom(c.CleanEnabled), @@ -222,8 +222,8 @@ func configFromModel(model *models.ModerationConfig) *Config { WarnCmdRoles: model.WarnCmdRoles, WarnIncludeChannelLogs: model.WarnIncludeChannelLogs.Bool, WarnSendToModlog: model.WarnSendToModlog.Bool, - DelwarnSendToModlog: model.DelwarnSendToModlog.Bool, - DelwarnIncludeWarnReason: model.DelwarnIncludeWarnReason.Bool, + DelwarnSendToModlog: model.DelwarnSendToModlog, + DelwarnIncludeWarnReason: model.DelwarnIncludeWarnReason, WarnMessage: model.WarnMessage.String, CleanEnabled: model.CleanEnabled.Bool, From bb97d198265bbc6bf28ab80742b3633fb5c1386f Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 19:46:13 +0000 Subject: [PATCH 10/15] .gitignore my docker ccompose --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 403eb16170..8e5ab8af62 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ cmd/shardorchestrator/shardorchestrator cmd/shardorchestrator/capturepanics __debug_bin* app.env -.scannerwork \ No newline at end of file +.scannerwork +yagpdb_docker/docker-compose.yml From 29633f6ab7b9b12c2f06ccf2e0b4c01ab4d13b38 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 19:50:10 +0000 Subject: [PATCH 11/15] missing the `, ` --- moderation/schema.go | 1 + 1 file changed, 1 insertion(+) diff --git a/moderation/schema.go b/moderation/schema.go index f2bd3f8759..9b5dcd834b 100644 --- a/moderation/schema.go +++ b/moderation/schema.go @@ -76,6 +76,7 @@ ALTER TABLE moderation_configs ALTER COLUMN created_at SET NOT NULL; ALTER TABLE moderation_configs ALTER COLUMN updated_at SET NOT NULL; `, ` ALTER TABLE moderation_configs ADD COLUMN IF NOT EXISTS delwarn_send_to_modlog BOOLEAN NOT NULL DEFAULT false; +`, ` ALTER TABLE moderation_configs ADD COLUMN IF NOT EXISTS delwarn_include_warn_reason BOOLEAN NOT NULL DEFAULT false; `, ` From 136379758711c1227bc6bbb2484e41c87dd6aa7e Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 19:50:34 +0000 Subject: [PATCH 12/15] Changed text to "Append original warn reason when removing" --- moderation/assets/moderation.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moderation/assets/moderation.html b/moderation/assets/moderation.html index d6ff0beb9e..3554347bf6 100644 --- a/moderation/assets/moderation.html +++ b/moderation/assets/moderation.html @@ -474,7 +474,7 @@

Delete ALL server warnings?

{{checkbox "WarnSendToModlog" "WarnSendToModlog" "Send warnings to the modlog" .ModConfig.WarnSendToModlog}}
{{checkbox "DelwarnSendToModlog" "DelwarnSendToModlog" "Send warning removal to the modlog" .ModConfig.DelwarnSendToModlog}} - {{checkbox "DelwarnIncludeWarnReason" "DelwarnIncludeWarnReason" "Include warning reason in the modlog" .ModConfig.DelwarnIncludeWarnReason}} + {{checkbox "DelwarnIncludeWarnReason" "DelwarnIncludeWarnReason" "Append original warn reason when removing" .ModConfig.DelwarnIncludeWarnReason}}
From 53581c1054c46d3e278b87ac3e9d00ea433065ea Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 20:05:25 +0000 Subject: [PATCH 13/15] https://github.com/botlabs-gg/yagpdb/pull/1795#discussion_r1884401951 + adding that warning has been deleted in the error messages --- moderation/commands.go | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/moderation/commands.go b/moderation/commands.go index 3083307253..8ecac0cc10 100644 --- a/moderation/commands.go +++ b/moderation/commands.go @@ -1015,32 +1015,24 @@ var ModerationCommands = []*commands.YAGCommand{ return nil, err } + warningID := parsed.Args[0].Int() + reason := SafeArgString(parsed, 1) reason, err = MBaseCmdSecond(parsed, reason, true, discordgo.PermissionManageMessages, config.WarnCmdRoles, config.WarnCommandsEnabled, true) if err != nil { return nil, err } - warningID := parsed.Args[0].Int() - - // Using that if we need to send to modlog - var warning *models.ModerationWarning - if config.DelwarnSendToModlog && config.ActionChannel != 0 { - warning, err = models.ModerationWarnings( - models.ModerationWarningWhere.ID.EQ(warningID), - // don't get warning from other servers, even if ID is correct - models.ModerationWarningWhere.GuildID.EQ(parsed.GuildData.GS.ID), - ).OneG(parsed.Context()) - if err != nil { - return fmt.Sprintf("Could not find warning with ID `%d`", warningID), nil - } - } - - numDeleted, err := models.ModerationWarnings( + warning, err := models.ModerationWarnings( models.ModerationWarningWhere.ID.EQ(warningID), - // don't delete warnings from other servers, even if ID is correct + // don't get warning from other servers, even if ID is correct models.ModerationWarningWhere.GuildID.EQ(parsed.GuildData.GS.ID), - ).DeleteAllG(parsed.Context()) + ).OneG(parsed.Context()) + if err != nil { + return fmt.Sprintf("Could not find warning with ID `%d`", warningID), nil + } + + numDeleted, err := warning.DeleteG(parsed.Context()) if err != nil { return "Failed deleting warning", err } From 272ee31e0827e0fe6469365a35965fee980581f5 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 13 Dec 2024 20:05:56 +0000 Subject: [PATCH 14/15] Adding "warning deleted" to error messages when appropried --- moderation/commands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moderation/commands.go b/moderation/commands.go index 8ecac0cc10..4265781961 100644 --- a/moderation/commands.go +++ b/moderation/commands.go @@ -1043,7 +1043,7 @@ var ModerationCommands = []*commands.YAGCommand{ if config.DelwarnSendToModlog && config.ActionChannel != 0 { userid, err := strconv.ParseInt(warning.UserID, 10, 64) if err != nil { - return "Failed parsing user ID", err + return "Failed parsing user ID, warning deleted", err } user := bot.GetUsers(parsed.GuildData.GS.ID, userid)[0] @@ -1053,7 +1053,7 @@ var ModerationCommands = []*commands.YAGCommand{ err = CreateModlogEmbed(config, parsed.Author, MADelwarn, user, reason, "") if err != nil { - return "Failed sending modlog", err + return "Failed sending modlog, warning deleted", err } } From 866df7b731bd4551c303557e9fe29736683e49d0 Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 18 Dec 2024 17:11:28 +0000 Subject: [PATCH 15/15] Reverted gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8e5ab8af62..7b302296d5 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,3 @@ cmd/shardorchestrator/capturepanics __debug_bin* app.env .scannerwork -yagpdb_docker/docker-compose.yml