Skip to content

Instantly share code, notes, and snippets.

@Glutnix
Created March 26, 2021 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glutnix/c449138fefc0fb478d635931f10f37e9 to your computer and use it in GitHub Desktop.
Save Glutnix/c449138fefc0fb478d635931f10f37e9 to your computer and use it in GitHub Desktop.
Art Share bot script for YAGPDB
{{/*
Art Share by Juniper#9001
for yagpdb.xyz discord bot
trigger: regex: .*
Restrict to #art-share channel
Will copy any post with art or linking to art (with a link that unfurls into an embed) into another channel for posterity.
Because some links unfurl, and it takes discord a while to add the embed to that post, it tries several times before giving up looking for it
*/}}
{{$artGalleryChannel := 616118921136701440}}
{{$yagpdbUserId := 204255221017214977}}
{{$embedFound := 0}}
{{$m := .Message}}
{{if or (gt (len $m.Attachments) 0) (gt (len $m.Embeds) 0)}}
{{addReactions "⚑"}}
{{$embedFound = 1}}
{{end}}
{{$matches := reFindAllSubmatches `https://` $m.Content }}
{{if $matches}}
{{addReactions "πŸ”"}}
{{if eq $embedFound 0}}
{{sleep 1}}
{{$m = getMessage nil .Message.ID}}
{{end}}
{{if and (eq $embedFound 0) (or (gt (len $m.Attachments) 0) (gt (len $m.Embeds) 0) )}}
{{addReactions "πŸ•"}}
{{$embedFound = 1}}
{{else if eq $embedFound 0}}
{{sleep 3}}
{{$m = getMessage nil .Message.ID}}
{{end}}
{{if and (eq $embedFound 0) (or (gt (len $m.Attachments) 0) (gt (len $m.Embeds) 0) )}}
{{addReactions "πŸ•’"}}
{{$embedFound = 1}}
{{else if eq $embedFound 0}}
{{sleep 5}}
{{$m = getMessage nil .Message.ID}}
{{end}}
{{if and (eq $embedFound 0) (or (gt (len $m.Attachments) 0) (gt (len $m.Embeds) 0) )}}
{{addReactions "πŸ•”"}}
{{$embedFound = 1}}
{{else if eq $embedFound 0}}
{{sleep 10}}
{{$m = getMessage nil .Message.ID}}
{{end}}
{{if and (eq $embedFound 0) (or (gt (len $m.Attachments) 0) (gt (len $m.Embeds) 0) )}}
{{addReactions "πŸ•™"}}
{{$embedFound = 1}}
{{end}}
{{end}}
{{if eq $embedFound 1}}
{{addReactions "🎨"}}
{{ $avatar := (joinStr "" "https://cdn.discordapp.com/avatars/" (toString $m.Author.ID) "/" $m.Author ".png") }}
{{$embedRaw := sdict
"description" (joinStr "" "**[Message Link](https://discord.com/channels/" $m.GuildID "/" $m.ChannelID "/" $m.ID ") to <#" $m.ChannelID ">**\n" $m.Content)
"color" 4645612
"author" (sdict "name" $m.Author.Username "icon_url" ($m.Author.AvatarURL "64"))
"footer" (sdict "text" (joinStr "" "Art posted by <@" .Message.Author.ID "> " .Message.Author.Username))
"timestamp" $m.Timestamp
}}
{{if $m.Embeds}}
{{$embed := (index $m.Embeds 0)}}
{{if $embed.Video}}
{{$embedRaw.Set "video" (sdict "url" $embed.Video.URL) }}
{{end}}
{{if $embed.Thumbnail}}
{{$embedRaw.Set "image" (sdict "url" $embed.Thumbnail.URL) }}
{{end}}
{{if $embed.Image}}
{{$embedRaw.Set "image" (sdict "url" $embed.Image.URL) }}
{{end}}
{{end}}
{{if $m.Attachments}}
{{$embedRaw.Set "image" (sdict "url" (index $m.Attachments 0).URL) }}
{{end}}
{{ sendMessage $artGalleryChannel (cembed $embedRaw) }}
{{else}}
{{/* addReactions "πŸ€·β€β™€οΈ" */}}
{{end}}
{{deleteMessageReaction nil $m.ID $yagpdbUserId "πŸ”"}}
{{sleep 10}}
{{deleteMessageReaction nil $m.ID $yagpdbUserId "πŸ€·β€β™€οΈ" "⚑" "πŸ•" "πŸ•’" "πŸ•”" "πŸ•™"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment