From 0a65ac5e6e9aed8b027c5dc731e167b79dcf698b Mon Sep 17 00:00:00 2001 From: EP Date: Sun, 1 Dec 2024 14:25:31 +0100 Subject: [PATCH] Support attached images when issuing warnings to user The purpose is to allow moderators to add an attached image when issuing a warning to a user. Usecase would be a screenshot of the offense like DM advertisement /warnings will show attached image as part of the warning "reason". --- moderation/commands.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/moderation/commands.go b/moderation/commands.go index edc9a84b1b..568f69ff99 100644 --- a/moderation/commands.go +++ b/moderation/commands.go @@ -886,13 +886,23 @@ var ModerationCommands = []*commands.YAGCommand{ if parsed.TraditionalTriggerData != nil { msg = parsed.TraditionalTriggerData.Message } - err = WarnUser(config, parsed.GuildData.GS.ID, parsed.GuildData.CS, msg, parsed.Author, target, parsed.Args[1].Str(), parsed.Context().Value(commands.CtxKeyExecutedByCommandTemplate) == true) - if err != nil { - return nil, err - } - - return GenericCmdResp(MAWarned, target, 0, false, true), nil - }, + // Check for attachments in the message + attachmentURLs := make([]string, 0) + for _, att := range msg.Attachments { + attachmentURLs = append(attachmentURLs, att.URL) + } + // Add attachment URLs to the reason + reason := parsed.Args[1].Str() + if len(attachmentURLs) > 0 { + reason = fmt.Sprintf("%s\n\nAttachments: %s", reason, strings.Join(attachmentURLs, ", ")) + } + + err = WarnUser(config, parsed.GuildData.GS.ID, parsed.GuildData.CS, msg, parsed.Author, target, reason) + if err != nil { + return nil, err + } + return GenericCmdResp(MAWarned, target, 0, false, true), nil + }, }, { CustomEnabled: true,