Skip to main content

Main CC

This command allows users to react to messages with stars. If the number of stars reaches a given amount, it will be sent in the starboard channel.

For more information about the starboard system, see this page.

Trigger

Type: Reaction
Additional options: Added + Removed Reactions

note

This command should be set to ignore your starboard channel in the channel restrictions.

Configuration

See the starboard system overview for more information regarding how to configure this command.

Code

{{/*
Allows users to react to messages with stars. If it reaches a given amount, it will be sent in the starboard channel.
See <https://yagpdb-cc.github.io/fun/starboard/main-cc> for more information.

Author: dvoraknt <https://github.com/dvoraknt>
*/}}

{{/* Configurable values */}}
{{$starEmoji := "⭐"}}
{{$starEmFull := "⭐"}}
{{$starLimit := 4}}
{{$starboard := 712681639410663516}}
{{$maxAge := "2w"}}
{{$selfStarEnable := false}}
{{$warnMessages := false}}

{{$antiStarEnable := false}}
{{$antiStarEmoji := "❌"}}
{{$antiStarEmFull := "❌"}}
{{$antiStarExtra := 0}}
{{/* End of configurable values */}}

{{$linkRegex := `https?:\/\/(?:\w+\.)?[\w-]+\.[\w]{2,3}(?:\/[\w-_.]+)+\.(?:png|jpg|jpeg|gif|webp)`}}

{{$thisID := .ReactionMessage.ID}}{{$skip := true}}
{{$data := ""}}{{$starboardData := ""}}{{$sboardPost := print $thisID}}{{$cid := .Reaction.ChannelID}}{{$mid := .Reaction.MessageID}}
{{if and (or (eq .Reaction.Emoji.Name $starEmoji) (eq .Reaction.Emoji.Name $antiStarEmoji)) (not .User.Bot)}}
{{if not (dbGet 0 "starboardReactions")}}{{dbSet 0 "starboardReactions" (sdict $sboardPost (sdict "ID" $sboardPost "listID" "" "listAnti" ""))}}{{end}}
{{with (dbGet 0 "starboardReactions").Value}}{{$data = sdict .}}{{end}}
{{$starboardData = $data.Get $sboardPost}}

{{if and .ReactionAdded (not $selfStarEnable) (eq .User.ID (.Message.Author).ID)}}
{{deleteMessageReaction $cid $mid .User.ID $starEmFull $antiStarEmFull}}
{{if $warnMessages}}{{$ret := sendMessageRetID nil (print .User.Mention " You can't influence your own post!")}}
{{deleteMessage $cid $ret 3}}{{end}}
{{else if $starboardData}}
{{$starboardData = sdict $starboardData}}

{{if and .ReactionAdded (eq .Reaction.Emoji.Name $starEmoji)}}
{{if reFind (print "SB" .User.ID ",") $starboardData.listID}}
{{deleteMessageReaction $cid $mid .User.ID $starEmFull}}
{{if $warnMessages}}{{$ret := sendMessageRetID nil (print .User.Mention " You already reacted on starboard!")}}
{{deleteMessage $cid $ret 3}}{{end}}
{{else if reFind (print .User.ID ",") $starboardData.listAnti}}
{{deleteMessageReaction $cid $mid .User.ID $starEmFull}}
{{if $warnMessages}}{{$ret := sendMessageRetID nil (print .User.Mention " You can't star and anti-star the same message!")}}
{{deleteMessage $cid $ret 3}}{{end}}
{{else}}
{{$IDregex:= print "PO" .User.ID ","}}
{{$starboardData.Set "listID" (print $starboardData.listID $IDregex)}}
{{$skip = false}}
{{end}}

{{else if eq .Reaction.Emoji.Name $starEmoji}}
{{$IDregex := print "PO" .User.ID ","}}
{{if reFind $IDregex $starboardData.listID}}
{{$starboardData.Set "listID" (reReplace $IDregex $starboardData.listID "")}}
{{end}}
{{$skip = false}}
{{end}}

{{if and $antiStarEnable .ReactionAdded (eq .Reaction.Emoji.Name $antiStarEmoji)}}
{{if reFind (print "SB" .User.ID ",") $starboardData.listAnti}}
{{deleteMessageReaction $cid $mid .User.ID $antiStarEmFull}}
{{if $warnMessages}}{{$ret := sendMessageRetID nil (print .User.Mention " You already reacted on starboard!")}}
{{deleteMessage $cid $ret 3}}{{end}}
{{else if reFind (print .User.ID ",") $starboardData.listID}}
{{deleteMessageReaction $cid $mid .User.ID $antiStarEmFull}}
{{if $warnMessages}}{{$ret := sendMessageRetID nil (print .User.Mention " You can't star and anti-star the same message!")}}
{{deleteMessage $cid $ret 3}}{{end}}
{{else}}
{{$IDregex:= print "PO" .User.ID ","}}
{{$starboardData.Set "listAnti" (print $starboardData.listAnti $IDregex)}}
{{$skip = false}}
{{end}}

{{else if and $antiStarEnable (eq .Reaction.Emoji.Name $antiStarEmoji)}}
{{$IDregex := print "PO" .User.ID ","}}
{{if reFind $IDregex $starboardData.listAnti}}
{{$starboardData.Set "listAnti" (reReplace $IDregex $starboardData.listAnti "")}}
{{end}}
{{$skip = false}}
{{end}}

{{$data.Set $sboardPost $starboardData}}
{{dbSet 0 "starboardReactions" $data}}

{{else}}
{{$data.Set $sboardPost (sdict "ID" $sboardPost "listID" (print "PO" .User.ID ",") "listAnti" "")}}
{{dbSet 0 "starboardReactions" $data}}
{{$skip = false}}
{{end}}
{{end}}

{{$count := 0}} {{$antiCount := 0}}
{{range .ReactionMessage.Reactions}}
{{- if and (eq .Emoji.Name $starEmoji) (ge .Count $starLimit)}}
{{- $count = .Count}}
{{- end -}}
{{- if and $antiStarEnable (eq .Emoji.Name $antiStarEmoji) (ge .Count $starLimit)}}
{{- $antiCount = .Count}}
{{- end -}}
{{end}}

{{$starboardMessage := 0}}{{$thisID := 0}}{{$chanID := 0}}
{{$thisID = .ReactionMessage.ID}}
{{with (dbGet 0 "starboardMessages").Value}}
{{$idRegex := printf `%d:(\d+)` $thisID}}
{{with reFindAllSubmatches $idRegex .}} {{$starboardMessage = index . 0 1}} {{end}}
{{if not (getMessage $starboard $starboardMessage)}}
{{$starboardMessage = 0}}
{{dbSet 0 "starboardMessages" (reReplace $idRegex . "")}}
{{else}}
{{range (getMessage $starboard $starboardMessage).Reactions}}
{{- if eq .Emoji.Name $starEmoji}}
{{- $count = (sub (add $count .Count) 1)}}
{{- end -}}
{{- if and $antiStarEnable (eq .Emoji.Name $antiStarEmoji)}}
{{- $antiCount = (sub (add $antiCount .Count) 1)}}
{{- end -}}
{{end}}
{{end}}
{{end}}

{{if not $antiStarEnable}} {{$antiStarExtra = 0}} {{end}} {{/*resetting count to zero to prevent user configured variable from interrupting desired functionality*/}}
{{if and (not $skip) (or (lt $count $starLimit) (ge (add $antiCount $antiStarExtra) $count))}}
{{with (dbGet 0 "starboardMessages").Value}}
{{$idRegex := printf `\n%d:(\d+):(\d+)` $thisID}}
{{with reFindAllSubmatches $idRegex .}} {{$starboardMessage = index . 0 1}} {{end}}
{{deleteMessage $starboard $starboardMessage 0}}
{{dbSet 0 "starboardMessages" (reReplace $idRegex . "")}}
{{end}}

{{if $starboardData}}
{{$nil := $starboardData.Set "listID" (reReplace `SB\d+,` $starboardData.listID "")}}
{{$nil := $starboardData.Set "listAnti" (reReplace `SB\d+,` $starboardData.listAnti "")}}
{{$data.Set $sboardPost $starboardData}}
{{dbSet 0 "starboardReactions" $data}}
{{end}}

{{else if and $count (not $skip) (or .ReactionMessage.Content .ReactionMessage.Attachments) (or (eq .Reaction.Emoji.Name $starEmoji) (eq .Reaction.Emoji.Name $antiStarEmoji)) (le (currentTime.Sub .Message.Timestamp.Parse) (toDuration $maxAge))}}
{{$emoji := "🌠"}}
{{if lt $count 5}} {{$emoji = "⭐"}}
{{else if lt $count 10}} {{$emoji = "🌟"}}
{{else if lt $count 15}} {{$emoji = "✨"}}
{{else if lt $count 20}} {{$emoji = "💫"}}
{{else if lt $count 30}} {{$emoji = "🎇"}}
{{else if lt $count 40}} {{$emoji = "🎆"}}
{{else if lt $count 50}} {{$emoji = "☄️"}}
{{end}}
{{$embed := sdict
"color" 0xFFAC33
"fields" (cslice
(sdict "name" "Author" "value" .ReactionMessage.Author.Mention "inline" true)
(sdict "name" "Channel" "value" (printf "<#%d>" .Channel.ID) "inline" true)
)
"timestamp" .ReactionMessage.Timestamp
"thumbnail" (sdict "url" (.ReactionMessage.Author.AvatarURL "1024"))
"footer" (sdict "text" (printf "%s %d | %d" $emoji $count .ReactionMessage.ID))
}}
{{with .ReactionMessage.Content}}
{{with reFind $linkRegex .}} {{$embed.Set "image" (sdict "url" .)}} {{end}}
{{$content := .}}
{{if gt (len .) 1000}} {{$content = slice . 0 1000 | printf "%s..."}} {{end}}
{{$embed.Set "fields" ($embed.fields.Append (sdict "name" "Message" "value" $content))}}
{{end}}
{{with .ReactionMessage.Attachments}}
{{$attachment := (index . 0).URL}}
{{if reFind `\.(png|jpg|jpeg|gif|webp)` $attachment}}
{{$embed.Set "image" (sdict "url" $attachment)}}
{{end}}
{{end}}
{{$embed.Set "fields" ($embed.fields.Append (sdict
"name" "Message"
"value" (printf "[Jump To](https://discordapp.com/channels/%d/%d/%d)" .Guild.ID .Channel.ID .ReactionMessage.ID)))
}}
{{with $starboardMessage}}
{{editMessage $starboard . (cembed $embed)}}
{{else}}
{{$ret := sendMessageRetID $starboard (complexMessage "embed" $embed)}}
{{if $antiStarEnable}} {{addMessageReactions $starboard $ret $starEmFull $antiStarEmFull}}
{{else}} {{addMessageReactions $starboard $ret $starEmFull}} {{end}}
{{$dbData := (printf
"%s\n%d:%d:%d"
(or (dbGet 0 "starboardMessages").Value "")
.ReactionMessage.ID $ret .Reaction.ChannelID
)}}
{{dbSet 0 "starboardMessages" $dbData}}
{{end}}
{{end}}

Author

This custom command was written by @dvoraknt.