Skip to main content

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).

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/>
*/}}

{{ $re := `\n\n(<t:(\d+):f> \(<t:\d+:R>\)) \*\*[\w.#]+\*\* \(ID (\d{17,19})\)\:` }}
{{ $undelete := execAdmin "ud -a" }}
{{ $data := reFindAllSubmatches $re $undelete 1 }}
{{ if not $data }}
Nothing to snipe here
{{ return }}
{{ end }}

{{ $ex := or (and (hasPrefix "a_" .Guild.Icon) "gif") "png" }}
{{ $icon := printf "https://cdn.discordapp.com/icons/%d/%s.%s?size=1024" .Guild.ID .Guild.Icon $ex }}

{{ $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 }}

{{ $member := getMember (index $data 0 3) }}
{{ $msg := index (reSplit $re $undelete 2) 1|trimSpace }}
{{ $time := timestampToTime (index $data 0 2) }}
{{ $embed := sdict
"author" (sdict
"name" (printf "%s (ID %d)" $member.User.String $member.User.ID)
"icon_url" ($member.User.AvatarURL "256")
)
"description" (printf "Message from <t:%d:R>:\n%s" $time.Unix $msg)
"footer" (sdict
"icon_url" $icon
)
"timestamp" $time
"color" $col
}}
{{ $send := sdict "reply" .Message.ID "embed" $embed }}

{{ $imgRe := `\.(?i:jpe?g|png|gif|tif|webp)`}}
{{ if and ($imgURL := reFind .LinkRegex $msg) (reFind $imgRe $imgURL) }}
{{ $embed.footer.Set "text" (print "⚠️ An image link was detected\n" $embed.footer.text) }}
{{ $embed.Set "image" (sdict "url" $imgURL) }}
{{ end }}

{{ if not $msg }}
{{ $embed.footer.Set "text" (print "⚠️ An attachment/embed was deleted\n" $embed.footer.text) }}
{{ end }}

{{ if gt (len (printf "Message from <t:%d:R>:\n%s" $time.Unix $msg)) 2000 }}
{{ $embed.footer.Set "text" (print "⚠️ Message exceeded 2k characters. Contents sent as file instead\n" $embed.footer.text) }}
{{ $embed.Set "description" (printf "Message from <t:%d:R>") }}
{{ $send.Set "file" $msg }}
{{ end }}

{{ sendMessage nil (complexMessage $send) }}

Author

This custom command was written by zen | ゼン.