Skip to main content

Ghost-Ping Detector v2

Version two of the ghost ping detector. Has all the features of the original in addition to the ability to send logs when a ghost ping is detected.

Ghost pings

A ghost ping is when you mention a user and then delete the message, leaving a ping that cannot be found: hence the term "ghost ping".

note

This command only works if the ghost ping was deleted within 5 seconds of being sent (or 10 seconds if $CHECK is enabled).

Trigger

Type: Regex
Trigger: <@!?\d{17,19}> or \A.

Configuration

  • $CHECK
    Whether to schedule two execCC checks. The way this command works is that it checks after 5 seconds whether the message was deleted. This does mean that if you delete the message more than 5 seconds after message creation, this CC won't catch it by default.

    By enabling this option, the command will check twice instead of once, meaning that messages deleted between 5 and 10 seconds of being sent will be caught as well.

  • $LOG
    Whether message logs should be sent in the channel when ghost pings are detected.

Code

{{/*
Ghost-ping detector v2.
See <https://yagpdb-cc.github.io/utilities/ghost-ping-v2> for more information.

Author: Devonte <https://github.com/devnote-dev>
*/}}

{{/* Configurable values */}}
{{ $CHECK := false }}
{{ $LOG := false }}
{{/* End of configurable values */}}

{{ if .ExecData }}
{{ $mentions := "" }} {{ $ping := false }}
{{ if ($m := getMessage nil .ExecData.message) }}
{{ if not $m.Mentions }}
{{ $ping = true }}
{{ end }}
{{ else }}
{{ $ping = true }}
{{ end }}

{{ if $ping }}
{{ if gt (len .ExecData.mentions) 1 }}
{{ range .ExecData.mentions }}
{{- $mentions = joinStr ">, <@" $mentions . -}}
{{ end }}
{{ else }}
{{ $mentions = index .ExecData.mentions 0 }}
{{ end }}

{{ $col := 16777215 }} {{ $p := 0 }} {{ $r := .Member.Roles }}
{{ range .Guild.Roles }}
{{- if and (in $r .ID) (.Color) (lt $p .Position) -}}
{{- $p = .Position -}}
{{- $col = .Color -}}
{{- end -}}
{{ end }}

{{ $log := "" }}
{{ if $LOG }}
{{ $log = print "\n**Logs:** [Message Logs](" (exec "logs") ")" }}
{{ end }}

{{/* Embed Construct */}}
{{ $embed := cembed
"description" (print "**Channel:** <#" .Channel.ID ">\n**Message:**\n" .ExecData.content "\n\n**Mentioned Users:** <@" $mentions ">" $log)
"color" $col
"footer" (sdict "text" "Detector triggered")
"timestamp" currentTime }}

{{/* Content Format */}}
{{ $msgContent := print "Ghost ping detected by <@" .ExecData.author ">!" }}

{{ sendMessage nil (complexMessage "content" $msgContent "embed" $embed) }}
{{ else }}
{{ if and $CHECK (not .ExecData.break) }}
{{ $ids := cslice }}

{{ range .Message.Mentions }}
{{- $ids = $ids.Append (str .ID) -}}
{{ end }}

{{ execCC .CCID nil 5 (sdict "message" .Message.ID "author" .Message.Author.ID "mentions" $ids "content" .Message.Content "break" true) }}
{{ end }}
{{ end }}
{{ else }}
{{ if .Message.Mentions }}
{{ $ids := cslice }}
{{ range .Message.Mentions }}
{{ $ids = $ids.Append (str .ID) }}
{{ end }}

{{ execCC .CCID nil 5 (sdict "message" .Message.ID "author" .Message.Author.ID "mentions" $ids "content" .Message.Content "break" false) }}
{{ end }}
{{ end }}

Author

This custom command was written by @devnote-dev.