Skip to content

Instantly share code, notes, and snippets.

@mesmere
Last active July 7, 2023 12:35
Show Gist options
  • Select an option

  • Save mesmere/65a6d2fcb2f2672af43af2cc212a3e24 to your computer and use it in GitHub Desktop.

Select an option

Save mesmere/65a6d2fcb2f2672af43af2cc212a3e24 to your computer and use it in GitHub Desktop.
YAGPDB CC system for auto-sanitizing messages. tiktok to vxtiktok, twitter to nitter, removes tracking url parameters
{{/* Trigger on NONE */}}
{{/* Find the user's dominant role color for the accent bar on the notice message. */}}
{{ $color := 0 }}
{{ $pos := 0 }}
{{ range .Member.Roles }}
{{- with $.Guild.GetRole . -}}
{{- if and .Color (lt $pos .Position) -}}
{{- $color = .Color -}}
{{- $pos = .Position -}}
{{- end -}}
{{- end -}}
{{ end }}
{{/* Send notice message and resend the original dirty message with the sanitized link. */}}
{{ $embed := cembed
"description" "Rewrote a URL to keep members safe."
"footer" (sdict "text" (print "Triggered by " .User.String) "icon_url" (.Member.AvatarURL "256"))
"color" $color
}}
{{ $noticeMsgId := 0 }}
{{ if .Message.MessageReference }}
{{ if eq .Message.MessageReference.ChannelID .Message.ChannelID }}
{{ $noticeMsgId = sendMessageRetID nil (complexMessage "embed" $embed "reply" .Message.MessageReference.MessageID) }}
{{ end }}
{{ end }}
{{ if eq $noticeMsgId 0 }}
{{ $noticeMsgId = sendMessageRetID nil $embed }}
{{ end }}
{{ $sanitizedMsgId := sendMessageRetID nil (reReplace .ExecData.regex .Message.Content .ExecData.replace) }}
{{/* Store the ID of the sanitized message so that we can delete it later if the user clicks the X reaction. */}}
{{ $record := sdict
"sanitizedMsgId" (str $sanitizedMsgId)
"userId" (str .User.ID)
}}
{{ dbSetExpire 0 (str $noticeMsgId) $record (toInt64 (toDuration "1w").Seconds) }}
{{ addMessageReactions nil $noticeMsgId "❌" }}
{{/* Delete the user's original dirty message. */}}
{{ deleteMessage nil .Message.ID 0 }}
{{/* DISABLED! see 108.go.tmpl for twitter->nitter rewriting */
{{/* Trigger on regex: (?P<keep>https?://twitter\.com/[^/\s]+?/status/\d+)/?\?[^|>\s]+ */}}
{{/* Note that the 15 here refers to the CC coincidentally numbered #15 above. }}
{{ execCC 15 nil 0 (sdict "regex" .CCTrigger "replace" "${keep}") }}
{{/* Trigger on reaction added. */}}
{{ $dbRecord := dbGet 0 (str .Message.ID) }}
{{ if $dbRecord }}
{{ $dbUserId := toInt ($dbRecord.Value.Get "userId") }}
{{ $dbSanitizedMsgId := toInt ($dbRecord.Value.Get "sanitizedMsgId") }}
{{ if and (eq $dbUserId .User.ID) (eq .Reaction.Emoji.Name "❌") }}
{{ deleteMessage nil .Message.ID 0 }}
{{ deleteMessage nil $dbSanitizedMsgId 0 }}
{{ else }}
{{ deleteMessageReaction nil .Message.ID .User.ID .Reaction.Emoji.APIName }}
{{ end }}
{{ end }}
{{/* Trigger on regex: (?P<keep>https?://(?:www\.)?instagram\.com/[^?|>\s]+?)\?[^|>\s]+ */}}
{{ execCC 15 nil 0 (sdict "regex" .CCTrigger "replace" "${keep}") }}
{{/* Trigger on regex: https?://(www\.)?tiktok\.com/(?P<keep>@[^/?|>\s]+?/video/\d+/?)(\?[^|>\s]+)? */}}
{{ execCC 15 nil 0 (sdict "regex" .CCTrigger "replace" (print "https://vxtiktok.com/" "${keep}")) }}
{{/* Trigger on regex: https?://(?P<subdomain>\w{1,3})\.tiktok\.com/(?P<id>[a-zA-Z0-9]{4,30}/?)(\?[^|>\s]+)? */}}
{{ execCC 15 nil 0 (sdict "regex" .CCTrigger "replace" "https://${subdomain}.vxtiktok.com/${id}") }}
{{/* Trigger on regex: https?://(www\.)?tiktok\.com/t/(?P<id>[a-zA-Z0-9]+)/?(\?[^|>\s]+) */}}
{{ execCC 15 nil 0 (sdict "regex" .CCTrigger "replace" "https://vxtiktok.com/t/${id}") }}
{{/* Trigger on regex: https?://twitter\.com(?P<keep>[^?|>\s]*?)(?:\?[^|>\s]*)?(?P<after>[|>\s]|$) */}}
{{ execCC 15 nil 0 (sdict "regex" .CCTrigger "replace" "https://untwit.rileyann.workers.dev${keep}") }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment