Skip to main content

Starboard V1

note

There is a newer version of the starboard system that has all of the features of this one. We recommend that you consider switching to it / using it over this one if possible.

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

Benefits over the starboard command provided in the documentation:

  • Updates star count with more stars using a single database text entry.
  • Posts automatically removed when they fall below star threshold.
  • Ability to use "anti-star" reactions similar to an upvote/downvote system to automatically remove posts unfit for starboard.

Trigger

Type: Reaction
Additional options: Added + Removed Reactions

Configuration

  • $starEmoji
    Name of the star emoji.

  • $starLimit
    Threshold of stars needed for a message to be posted on the starboard.

  • 📌 $starboard
    Channel ID of the starboard channel.

  • $maxAge
    Maximum age of messages for stars to be considered for the starboard. Structure is (mo)nth, (w)week, (d)ay, (h)our. Example: 3d => 3 days, 1mo => 1 month.

  • $antiStarEnable
    Whether anti-star counting should be enabled. Anti-stars count towards the total number of stars but in a negative manner instead. For example, if a message had 3 stars and 1 anti-star, the adjusted number of stars would be 2.

  • $antiStarEmoji
    The name of the anti-star emoji.

  • $antiStarExtra
    The number of additional anti-star reactions needed before removing a post. For example, if this value were 0 (the default), the post would be removed if it had the same number of anti-star reactions as stars.

Code

{{/*
Allows users to react to messages with stars. If the number of reactions hits a given amount, the message is re-sent in the starboard channel.
See <https://yagpdb-cc.github.io/fun/starboardv1> for more information.

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

{{/* Configurable values */}}
{{ $starEmoji := "⭐" }}
{{ $starLimit := 4 }}
{{ $starboard := 678379546218594304 }}
{{ $maxAge := "2w" }}

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

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

{{ $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 := .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 . "") }}
{{ end }}
{{ end }}

{{if not $antiStarEnable}} {{$antiStarExtra = 0}} {{end}} {{/*if disabled reset count to zero to prevent user configured variable from interrupting desired functionality*/}}

{{ if or (lt $count $starLimit) (ge (add $antiCount $antiStarExtra) $count) }}
{{ with (dbGet 0 "starboardMessages").Value }}
{{ $idRegex := printf `\n%d:(\d+)` $thisID }}
{{ with reFindAllSubmatches $idRegex . }} {{ $starboardMessage = index . 0 1 }} {{ end }}
{{ deleteMessage $starboard $starboardMessage 0 }}
{{ dbSet 0 "starboardMessages" (reReplace $idRegex . "") }}
{{ end }}
{{ else if and $count (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 (cembed $embed) }}
{{ dbSet 0 "starboardMessages" (printf
"%s\n%d:%d"
(or (dbGet 0 "starboardMessages").Value "")
.ReactionMessage.ID $ret
) }}
{{ end }}
{{ end }}

Author

This custom command was written by @jo3-l with contributions from @dvoraknt.