Last active
May 1, 2020 23:11
-
-
Save loopyd/22bd1fe779d599d218f205f9701fd9b3 to your computer and use it in GitHub Desktop.
[Yagscript/yag-cc/dialogHelper] Template to make the complex process of creating embed and abiding by Discord rate limit much easier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{- define "embedBuilder" }} | |
{{/* Important stuff */}} | |
{{ $thisdot := . }} | |
{{ $embedFlag := false }} {{ $reactionFlag := false }} {{ $msg := "" }} | |
{{ if not .MessageID }} {{ .Set "MessageID" 0 }} {{ end }} | |
{{ if not .ChannelID }} {{ .Set "ChannelID" .Parent.Channel.ID }} {{ end }} | |
{{ if not .UserID }} {{ .Set "UserID" .Parent.User.ID }} {{ end }} | |
{{/* Construct base/derived embed object */}} | |
{{ $gI := printf "https://cdn.discordapp.com/icons/%d/%s.png" .Parent.Guild.ID .Parent.Guild.Icon }} | |
{{- $e := (sdict "title" nil "description" nil "color" 0xFF0000 "footer" (sdict "icon_url" $gI "text" (printf "%s | Goscript by HeavyPaws\nRequested by: %s (%d)" .Parent.Guild.Name .Parent.User.Username .Parent.User.ID) ) "author" (sdict "name" .Parent.Guild.Name "icon_url" $gI ) "fields" nil ) }} | |
{{- range $k1, $v1 := .Input -}} {{- range $k2, $v2 := $e }} | |
{{- if (eq $k2 $k1) -}} {{- $e.Set $k2 $v1 }} | |
{{- end }} {{- end }} {{- end }} | |
{{/* Check for changes needed for embed. */}} | |
{{ $msg = getMessage .ChannelID .MessageID }} | |
{{- if $msg }} {{- $embeds := $msg.Embeds }} {{ if $embeds }} | |
{{- $embed := index $msg.Embeds 0 }} | |
{{- range $k1, $v1 := sdict $embed }} {{- range $k2, $v2 := sdict $e }} | |
{{- if and (eq $k2 $k1) (ne $v2 $v1) }} {{- $embedFlag := true }} {{- end }} | |
{{- end }} {{- end }} | |
{{- end }} {{- end }} | |
{{/* Handle add/update of embed */}} | |
{{- if eq $embedFlag false }} | |
{{- $id := sendMessageRetID .ChannelID (complexMessage "embed" (cembed $e)) }} | |
{{- .Set "MessageID" $id }} | |
{{ $msg = getMessage .ChannelID .MessageID }} | |
{{- else if eq $embedFlag true }} | |
{{- editMessage .ChannelID .MessageID (complexMessageEdit "embed" (cembed $e)) }} | |
{{- end }} | |
{{- if .Pagination }} | |
{{- .Set "Reactions" (cslice | |
"◀️" "▶️" "🏠" "🚀" "♻️" "❌") }} | |
{{- else if .YesNo }} | |
{{- .Set "Reactions" (cslice | |
"✅" "❌") }} | |
{{- else if .SimpleModal }} | |
{{- .Set "Reactions" (cslice | |
"🆗") }} | |
{{- end }} | |
{{ if $msg.Reactions }} | |
{{- range $i1, $v1 := cslice .Reactions }} {{- range $i2, $v2 := cslice $msg.Reactions }} | |
{{- if or (not $v1) (not $v2) }} | |
{{- $reactionFlag = true }} | |
{{- else if and (not $v1) (not $v2) }} | |
{{/* Dummy/Trap condition for both null */}} | |
{{- else }} | |
{{- if ne $v1 $v2 }} {{ $reactionFlag = true }} {{ end }} | |
{{- end }} | |
{{- end }} {{- end }} | |
{{- else }} | |
{{ if .Reactions }} {{ $reactionFlag = true }} {{ end }} | |
{{- end }} | |
{{/* Handle add/update of reactions */}} | |
{{- if eq $reactionFlag true }} | |
{{- deleteAllMessageReactions (.Get "ChannelID") (.Get "MessageID") }} | |
{{- range $i, $re := .Reactions }} | |
{{- addMessageReactions ($thisdot.Get "ChannelID") ($thisdot.Get "MessageID") | |
$re }} | |
{{- end }} | |
{{- end }} | |
{{- .Set "Input" $e }} | |
{{- end }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment