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

Add unwarn modlog (with option on dashbord) #1795

Merged
merged 16 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 8 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
5 changes: 4 additions & 1 deletion moderation/assets/moderation.html
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,13 @@ <h4>Delete ALL server warnings?</h4>
</select>
</div>
<hr />

{{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}}
<hr />
{{checkbox "DelwarnSendToModlog" "DelwarnSendToModlog" "Send warning removal to the modlog" .ModConfig.DelwarnSendToModlog}}
{{checkbox "DelwarnIncludeWarnReason" "DelwarnIncludeWarnReason" "Include warning reason in the modlog" .ModConfig.DelwarnIncludeWarnReason}}
<hr />
</div>
<div class="col-sm">
<div class="form-group">
Expand Down
34 changes: 33 additions & 1 deletion moderation/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,12 +1015,27 @@ 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
}

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(
models.ModerationWarningWhere.ID.EQ(warningID),
ColinLeDev marked this conversation as resolved.
Show resolved Hide resolved
// don't delete warnings from other servers, even if ID is correct
Expand All @@ -1033,6 +1048,23 @@ var ModerationCommands = []*commands.YAGCommand{
return fmt.Sprintf("Could not find warning with ID `%d`", warningID), nil
}

if config.DelwarnSendToModlog && 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]

if config.DelwarnIncludeWarnReason {
reason = fmt.Sprintf("%s\n~~%s~~", reason, warning.Message)
}

err = CreateModlogEmbed(config, parsed.Author, MADelwarn, user, reason, "")
if err != nil {
return "Failed sending modlog", err
}
}

return "👌", nil
},
},
Expand Down
16 changes: 11 additions & 5 deletions moderation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
DelwarnSendToModlog bool
DelwarnIncludeWarnReason bool
WarnMessage string `valid:"template,5000"`

// Misc
CleanEnabled bool
Expand Down Expand Up @@ -153,6 +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),
WarnMessage: null.StringFrom(c.WarnMessage),

CleanEnabled: null.BoolFrom(c.CleanEnabled),
Expand Down Expand Up @@ -218,6 +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,
ColinLeDev marked this conversation as resolved.
Show resolved Hide resolved
WarnMessage: model.WarnMessage.String,

CleanEnabled: model.CleanEnabled.Bool,
Expand Down
51 changes: 31 additions & 20 deletions moderation/models/moderation_configs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading