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

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions moderation/assets/moderation.html
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ <h4>Delete ALL server warnings?</h4>

{{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}}
ColinLeDev marked this conversation as resolved.
Show resolved Hide resolved
{{checkbox "UnwarnIncludeWarnReason" "UnwarnIncludeWarnReason" "Include warning reason in the modlog" .ModConfig.UnwarnIncludeWarnReason}}
ashishjh-bst marked this conversation as resolved.
Show resolved Hide resolved
<hr />
</div>
<div class="col-sm">
Expand Down
34 changes: 33 additions & 1 deletion moderation/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""},
ColinLeDev marked this conversation as resolved.
Show resolved Hide resolved
},
RequiredDiscordPermsHelp: "ManageMessages or ManageGuild",
SlashCommandEnabled: true,
Expand All @@ -1021,6 +1021,20 @@ var ModerationCommands = []*commands.YAGCommand{
}

warningID := parsed.Args[0].Int()

// 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),
// don't delete warnings from other servers, even if ID is correct
Expand All @@ -1033,6 +1047,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()
ColinLeDev marked this conversation as resolved.
Show resolved Hide resolved
if config.UnwarnIncludeWarnReason {
message = fmt.Sprintf("%s\n~~%s~~", message, warning.Message)
ColinLeDev marked this conversation as resolved.
Show resolved Hide resolved
}

err = CreateModlogEmbed(config, parsed.Author, MAUnwarned, user, message, "")
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
UnwarnSendToModlog bool
UnwarnIncludeWarnReason 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),
UnwarnSendToModlog: null.BoolFrom(c.UnwarnSendToModlog),
UnwarnIncludeWarnReason: null.BoolFrom(c.UnwarnIncludeWarnReason),
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,
UnwarnSendToModlog: model.UnwarnSendToModlog.Bool,
UnwarnIncludeWarnReason: model.UnwarnIncludeWarnReason.Bool,
WarnMessage: model.WarnMessage.String,

CleanEnabled: model.CleanEnabled.Bool,
Expand Down
50 changes: 23 additions & 27 deletions moderation/models/moderation_configs.go

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

1 change: 1 addition & 0 deletions moderation/modlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "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}
Expand Down
2 changes: 2 additions & 0 deletions moderation/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
ColinLeDev marked this conversation as resolved.
Show resolved Hide resolved
unwarn_include_warn_reason BOOLEAN,
clean_enabled BOOLEAN,
report_enabled BOOLEAN,
Expand Down