-
Notifications
You must be signed in to change notification settings - Fork 0
/
starboard.go.tmpl
81 lines (68 loc) · 3.14 KB
/
starboard.go.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{{/* Trigger: Reaction */}}
{{/* Configuration variables */}}
{{$reactionEmoji := "⭐"}}
{{$minReactions := 3}} {{/* Number of reactions needed */}}
{{$reactorRoleIDs := cslice 0}} {{/* Instant star roles. Replace the 0 with a list of space separated role IDs. */}}
{{$repostChannelID := 0}} {{/* Replace 0 with the channel ID where starred posts should go. */}}
{{$author := .ReactionMessage.Author}}
{{$authorAvatar := $author.AvatarURL "256"}}
{{$originalMessage := .ReactionMessage.Content}}
{{$messageURL := (joinStr "/" "https://discord.com/channels" .Guild.ID .Channel.ID .ReactionMessage.ID)}}
{{$media := ""}}
{{$channelName := .Channel.Name}}
{{$reactMember := getMember .User.ID}}
{{$hasRole := "0"}}
{{range $reactorRoleIDs}}
{{$roleID := toInt64 .}}
{{if in $reactMember.Roles $roleID}}
{{$hasRole = "1"}}
{{end}}
{{end}}
{{$starCount := 0}}
{{range .ReactionMessage.Reactions}}
{{if eq .Emoji.Name $reactionEmoji}}
{{$starCount = .Count}}
{{end}}
{{end}}
{{if and (eq .Reaction.Emoji.Name $reactionEmoji) (or (ge $starCount $minReactions) (not (eq $hasRole "0")))}}
{{range .ReactionMessage.Attachments}} {{/* My behavior simply grabs the first */}}
{{if and (ne .Width 0) (not $media)}}
{{$media = .ProxyURL}}
{{end}}
{{end}}
{{$posted := dbGet .ReactionMessage.ID "posted"}}
{{$transformed := $posted.Value}}
{{if (not $transformed)}}
{{$transformed = "0"}}
{{end}}
{{if (eq $transformed "1")}}
{{$repostMessageID := dbGet .ReactionMessage.ID "repost"}}
{{$postToEdit := getMessage $repostChannelID $repostMessageID.Value}}
{{if (getMessage $repostChannelID $repostMessageID.Value)}}
{{editMessage $repostChannelID $repostMessageID.Value (complexMessageEdit "content" (joinStr "" "⭐**" $starCount "** | " .Channel.Mention) "silent" true "embed" (cembed
"author" (sdict "name" (joinStr "" $author.String) "icon_url" $authorAvatar)
"title" (joinStr "" "Original message") "url" $messageURL
"description" $originalMessage
"image" (sdict "url" $media)
))}}
{{else}}
{{$sentMessage := sendMessageRetID $repostChannelID (complexMessage "content" (joinStr "" "⭐**" $starCount "** | " .Channel.Mention) "silent" true "embed" (cembed
"author" (sdict "name" (joinStr "" $author.String) "icon_url" $authorAvatar)
"title" (joinStr "" "Original message") "url" $messageURL
"description" $originalMessage
"image" (sdict "url" $media)
))}}
{{dbSet .ReactionMessage.ID "repost" (joinStr "" $sentMessage)}}
{{dbSet .ReactionMessage.ID "posted" "1"}}
{{end}}
{{else}}
{{$sentMessage := sendMessageRetID $repostChannelID (complexMessage "content" (joinStr "" "⭐**" $starCount "** | " .Channel.Mention) "silent" true "embed" (cembed
"author" (sdict "name" (joinStr "" $author.String) "icon_url" $authorAvatar)
"title" (joinStr "" "Original message") "url" $messageURL
"description" $originalMessage
"image" (sdict "url" $media)
))}}
{{dbSet .ReactionMessage.ID "repost" (joinStr "" $sentMessage)}}
{{dbSet .ReactionMessage.ID "posted" "1"}}
{{end}}
{{end}}