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 14 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
3 changes: 2 additions & 1 deletion .gitignore
ColinLeDev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ cmd/shardorchestrator/shardorchestrator
cmd/shardorchestrator/capturepanics
__debug_bin*
app.env
.scannerwork
.scannerwork
yagpdb_docker/docker-compose.yml
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" "Append original warn reason when removing" .ModConfig.DelwarnIncludeWarnReason}}
<hr />
</div>
<div class="col-sm">
<div class="form-group">
Expand Down
34 changes: 29 additions & 5 deletions moderation/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,24 +1015,48 @@ var ModerationCommands = []*commands.YAGCommand{
return nil, err
}

_, err = MBaseCmdSecond(parsed, "", true, discordgo.PermissionManageMessages, config.WarnCmdRoles, config.WarnCommandsEnabled, true)
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()
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
}
if numDeleted == 0 {
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, warning deleted", 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, warning deleted", 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: c.DelwarnSendToModlog,
DelwarnIncludeWarnReason: 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,
DelwarnIncludeWarnReason: model.DelwarnIncludeWarnReason,
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