Skip to main content

Cancel Report

This command handles report cancellation requests for the custom report system.

For more information about the custom report system, see this page.

Trigger

Type: Regex
Trigger: \A-c(ancel)?r(eport)?(\s+|\z)

Usage

  • -cr <id> <key> <reason> - Cancels the report with the ID provided using the user's secret key and the reason given.
tip

The values for the ID and key parameters are sent to users in DM when they run the report command.

Aliases

Instead of cr, you can also use cancelreport, cancelr, or creport.

Code

{{/*
Manages and takes care of the cancellation requests for the report system.
See <https://yagpdb-cc.github.io/moderation/report-system/cancel-report> for more information.

Author: Luca Z. <https://github.com/l-zeuch>
*/}}

{{/*ACTUAL CODE*/}}
{{$Escaped_Prefix := reQuoteMeta .ServerPrefix}}
{{if not (reFind (print `\A` $Escaped_Prefix `|<@!?204255221017214977>`) .Message.Content)}}
Did not set regex to match Server Prefix! {{deleteTrigger}}
{{else}}
{{if lt (len .CmdArgs) 3}}
```{{.Cmd}} <Message:ID> <Key:Text> <Reason:Text>```
Not enough arguments passed.
{{else}}
{{$s := sdict (dbGet .Guild.ID "reportSettings").Value}}
{{$reportLog := (toInt $s.reportLog)}}
{{$reportID := ((index .CmdArgs 0)|toInt)}}
{{$report := index (getMessage $reportLog $reportID).Embeds 0|structToSdict}}
{{range $k, $v := $report}}
{{if eq (kindOf $v true) "struct"}}
{{$report.Set $k (structToSdict $v)}}
{{end}}
{{end}}
{{$user := index (reFindAllSubmatches `\A<@!?(\d{17,19})>` $report.Description) 0 1|toInt|userArg}}
{{$userKey := (dbGet .User.ID "key").Value|str}}
{{if eq $user.ID .User.ID}}
{{if eq "used" $userKey}}
Your latest report was already cancelled!
{{else}}
{{if eq (index .CmdArgs 1) $userKey}}
{{if ge (len .CmdArgs) 3}}
{{$reason := joinStr " " (slice .CmdArgs 2)}}
{{with $report}}
{{.Set "Author" (sdict "name" (printf "%s (ID %d)" $user $user.ID) "icon_url" ($user.AvatarURL "256"))}}
{{.Footer.Set "Icon_URL" .Footer.IconURL}}
{{.Set "description" (print .Description (printf "\nCancellation of this report was requested. \n Reason: `%s`" $reason))}}
{{.Set "color" 16711935}}
{{.Set "Fields" ((cslice).AppendSlice .Fields)}}{{.Fields.Set 5 (sdict "name" "Reaction Menu Options" "value" (printf "Deny request with ❌, accept with 👌, or ask for more information with ⚠️."))}}
{{end}}
{{editMessage $reportLog $reportID (complexMessageEdit "embed" $report)}}
Cancellation requested, have a nice day!
{{dbSet .User.ID "key" "used"}}
{{end}}
{{else}}
Invalid key provided!
{{end}}
{{end}}
{{else}}
You are not the author of this report!
{{end}}{{end}}{{end}}{{deleteResponse}}

Author

This custom command was written by @l-zeuch.