Skip to content

Commit

Permalink
fix /rep by accounting for discord embed limits
Browse files Browse the repository at this point in the history
  • Loading branch information
coool9 authored and Southclaws committed Feb 8, 2024
1 parent 532393d commit 81f649e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bot/commands/cmd_rep.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/Southclaws/cj/types"
)

// limit of discord embed fields is 25
// I have put 23 to account for the 'filling' embed field (look below)
const DISCORD_EMBED_FIELDS_LIMIT = 23

func (cm *CommandManager) commandRep(
interaction *discordgo.InteractionCreate,
args map[string]*discordgo.ApplicationCommandInteractionDataOption,
Expand Down Expand Up @@ -67,6 +71,9 @@ func FormatUserReactions(reactions *[]storage.ReactionCounter, author *discordgo

for _, reaction := range *reactions {
if validateEmoji(reaction.Reaction, serverEmoji) {
if len(embed.Fields) == DISCORD_EMBED_FIELDS_LIMIT {
break
}
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
Name: fmt.Sprintf("%s​", reaction.Reaction),
Value: fmt.Sprintf("%dx", reaction.Counter),
Expand Down

0 comments on commit 81f649e

Please sign in to comment.