Snipe Message
Retrieves the most recently deleted message in the past hour (non-premium) / 12 hours (premium).
Trigger
Type: Command
Trigger: snipe
Usage
-snipe
- Retrieves the most recently deleted message in the past hour (non-premium) / 12 hours (premium).
Configuration
$REDACT_INVITES
Whether or not to remove invites from messages when displaying deleted message.
Code
{{/*
Retrieves the most recent deleted message in the past hour (non-premium) / 12 hours (premium).
See <https://yagpdb-cc.github.io/utilities/snipe-message> for more information.
Author: zen | ゼン#0008 <https://github.com/z3nn13/>
Co-Author: H1nr1 <https://github.com/H1nr1>
*/}}
{{ $REDACT_INVITES := false }}
{{ $re := `<t:(\d+):R>\) \*{2}[\w.]+\*{2} \(ID (\d{17,})\): (.*)` }}
{{ $undelete := execAdmin "ud -a" }}
{{ $data := reFindAllSubmatches $re $undelete 1 }}
{{ if not $data }}
Nothing to snipe here
{{ return }}
{{ end }}
{{ $data = index $data 0 }}
{{ $col := 0 }}
{{ $pos := 0 }}
{{ range .Guild.Roles }}
{{- if not (and (in $.Member.Roles .ID) .Color (lt $pos .Position)) }} {{- continue }} {{- end }}
{{- $pos = .Position }}
{{- $col = .Color -}}
{{ end }}
{{ $time := index $data 1 | timestampToTime }}
{{ $member := index $data 2 | getMember }}
{{ $msg := index $data 3 }}
{{ if $REDACT_INVITES }}
{{ $msg = reReplace `(?:https?://)?(?:www\.|ptb\.|canary\.)?(?i:discord(?:app)?|dsc|invite|disboard)\.(?i:gg|com|io|me|li|id|org)/\S+` $msg "<*redacted invite link*>" }}
{{ end }}
{{ $send := sdict "reply" .Message.ID }}
{{ $embed := sdict
"author" (sdict
"icon_url" ($member.User.AvatarURL "256")
"name" (printf "%s (ID %d)" $member.User.Username $member.User.ID)
)
"footer" (sdict "icon_url" (.Guild.IconURL "256"))
"timestamp" $time
"color" $col
}}
{{ $embed.Set "description" (printf "Message from <t:%d:R>" $time.Unix) }}
{{ if not $msg }}
{{ $embed.Set "description" (printf "%s\n⚠️ An attachment/embed was deleted" $embed.description) }}
{{ else if gt (len $msg) 1950 }}
{{ $embed.Set "description" (printf "%s\n⚠️ Message exceeded 2k characters. Contents sent as file instead" $embed.description) }}
{{ $send.Set "file" $msg }}
{{ else }}
{{ $embed.Set "description" (printf "%s\n%s" $embed.description $msg) }}
{{ end }}
{{ $imgRe := `\.(?i:jpe?g|png|gif|tif|webp)`}}
{{ if and ($imgURL := reFind .LinkRegex $msg) (reFind $imgRe $imgURL) }}
{{ $embed.footer.Set "text" "⚠️ An image link was detected" }}
{{ $embed.Set "image" (sdict "url" $imgURL) }}
{{ end }}
{{ $send.Set "embed" $embed }}
{{ sendMessage nil (complexMessage $send) }}
Author
This custom command was written by zen | ゼン.