Skip to content

Commit

Permalink
refactor: extracted SimpleEmbed into own util function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesuaheli committed Dec 28, 2024
1 parent 800642c commit 233542a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 55 deletions.
15 changes: 15 additions & 0 deletions util/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ func AuthoredEmbed[T *discordgo.User | *discordgo.Member](s *discordgo.Session,
return embed
}

// SimpleEmbed returns a new embed with the given description and color
//
// For convenience it returns a slice of one and always one embed.
func SimpleEmbed(color int, content string) []*discordgo.MessageEmbed {
return []*discordgo.MessageEmbed{{
Description: content,
Color: color,
}}
}

// SimpleEmbedf is like [SimpleEmbed] but formats according to a format specifier
func SimpleEmbedf(color int, format string, a ...any) []*discordgo.MessageEmbed {
return SimpleEmbed(color, fmt.Sprintf(format, a...))
}

// SetEmbedFooter takes a pointer to an embeds and sets the standard footer with the given name.
//
// sectionName:
Expand Down
66 changes: 11 additions & 55 deletions util/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,67 +217,39 @@ func (i *InteractionUtil) ReplyHiddenEmbedUpdate(embeds ...*discordgo.MessageEmb
// ReplySimpleEmbed is a shortcut for replying with a simple embed that only contains a single text
// and has a color.
func (i *InteractionUtil) ReplySimpleEmbed(color int, content string) {
e := &discordgo.MessageEmbed{
Description: content,
Color: color,
}
i.ReplyEmbed(e)
i.ReplyEmbed(SimpleEmbed(color, content)...)
}

// ReplySimpleEmbedf formats according to a format specifier and is a shortcut for replying with a
// simple embed that only contains a single text and has a color.
func (i *InteractionUtil) ReplySimpleEmbedf(color int, format string, a ...any) {
e := &discordgo.MessageEmbed{
Description: fmt.Sprintf(format, a...),
Color: color,
}
i.ReplyEmbed(e)
i.ReplyEmbed(SimpleEmbedf(color, format, a...)...)
}

// ReplySimpleEmbedUpdate is like ReplySimpleEmbed but make for an update for components.
func (i *InteractionUtil) ReplySimpleEmbedUpdate(color int, content string) {
e := &discordgo.MessageEmbed{
Description: content,
Color: color,
}
i.ReplyEmbedUpdate(e)
i.ReplyEmbedUpdate(SimpleEmbed(color, content)...)
}

// ReplySimpleEmbedUpdatef is like ReplySimpleEmbedf but make for an update for components.
func (i *InteractionUtil) ReplySimpleEmbedUpdatef(color int, format string, a ...any) {
e := &discordgo.MessageEmbed{
Description: fmt.Sprintf(format, a...),
Color: color,
}
i.ReplyEmbedUpdate(e)
i.ReplyEmbedUpdate(SimpleEmbedf(color, format, a...)...)
}

// ReplyHiddenSimpleEmbed is like ReplySimpleEmbed but also ephemeral.
func (i *InteractionUtil) ReplyHiddenSimpleEmbed(color int, content string) {
e := &discordgo.MessageEmbed{
Description: content,
Color: color,
}
i.ReplyHiddenEmbed(e)
i.ReplyHiddenEmbed(SimpleEmbed(color, content)...)
}

// ReplyHiddenSimpleEmbedf is like ReplySimpleEmbedf but also ephemeral.
func (i *InteractionUtil) ReplyHiddenSimpleEmbedf(color int, format string, a ...any) {
e := &discordgo.MessageEmbed{
Description: fmt.Sprintf(format, a...),
Color: color,
}
i.ReplyHiddenEmbed(e)
i.ReplyHiddenEmbed(SimpleEmbedf(color, format, a...)...)
}

// ReplyHiddenSimpleEmbedUpdate is like [InteractionUtil.ReplyHiddenSimpleEmbed] but made for an
// update for components.
func (i *InteractionUtil) ReplyHiddenSimpleEmbedUpdate(color int, content string) {
e := &discordgo.MessageEmbed{
Description: content,
Color: color,
}
i.ReplyHiddenEmbedUpdate(e)
i.ReplyHiddenEmbedUpdate(SimpleEmbed(color, content)...)
}

// ReplyHiddenSimpleEmbedUpdatef is like [InteractionUtil.ReplyHiddenSimpleEmbedf] but made for an
Expand Down Expand Up @@ -370,11 +342,7 @@ func (i *InteractionUtil) ReplyComponentsHiddenEmbedUpdate(components []discordg

// ReplyComponentsSimpleEmbed sends an embed message along with the provied message components.
func (i *InteractionUtil) ReplyComponentsSimpleEmbed(components []discordgo.MessageComponent, color int, content string) {
e := &discordgo.MessageEmbed{
Description: content,
Color: color,
}
i.ReplyComponentsEmbed(components, e)
i.ReplyComponentsEmbed(components, SimpleEmbed(color, content)...)
}

// ReplyComponentsSimpleEmbedf is like [InteractionUtil.ReplyComponentsSimpleEmbed] but formats the
Expand All @@ -385,11 +353,7 @@ func (i *InteractionUtil) ReplyComponentsSimpleEmbedf(components []discordgo.Mes

// ReplyComponentsSimpleEmbedUpdate is like [InteractionUtil.ReplyComponentsSimpleEmbed] but made for an update for components.
func (i *InteractionUtil) ReplyComponentsSimpleEmbedUpdate(components []discordgo.MessageComponent, color int, content string) {
e := &discordgo.MessageEmbed{
Description: content,
Color: color,
}
i.ReplyComponentsEmbedUpdate(components, e)
i.ReplyComponentsEmbedUpdate(components, SimpleEmbed(color, content)...)
}

// ReplyComponentsSimpleEmbedUpdatef is like [InteractionUtil.ReplyComponentsSimpleEmbedf] but made for an update for components.
Expand All @@ -400,11 +364,7 @@ func (i *InteractionUtil) ReplyComponentsSimpleEmbedUpdatef(components []discord
// ReplyComponentsHiddenSimpleEmbed is like [InteractionUtil.ReplyHiddenSimpleEmbed] but sends the
// embed message along with the provied message components.
func (i *InteractionUtil) ReplyComponentsHiddenSimpleEmbed(components []discordgo.MessageComponent, color int, content string) {
e := &discordgo.MessageEmbed{
Description: content,
Color: color,
}
i.ReplyComponentsHiddenEmbed(components, e)
i.ReplyComponentsHiddenEmbed(components, SimpleEmbed(color, content)...)
}

// ReplyComponentsHiddenSimpleEmbedf is like [InteractionUtil.ReplyHiddenSimpleEmbedf] but sends the
Expand All @@ -415,11 +375,7 @@ func (i *InteractionUtil) ReplyComponentsHiddenSimpleEmbedf(components []discord

// ReplyComponentsHiddenSimpleEmbedUpdate is like [InteractionUtil.ReplyComponentsHiddenSimpleEmbed] but made for an update for components.
func (i *InteractionUtil) ReplyComponentsHiddenSimpleEmbedUpdate(components []discordgo.MessageComponent, color int, content string) {
e := &discordgo.MessageEmbed{
Description: content,
Color: color,
}
i.ReplyComponentsHiddenEmbedUpdate(components, e)
i.ReplyComponentsHiddenEmbedUpdate(components, SimpleEmbed(color, content)...)
}

// ReplyComponentsHiddenSimpleEmbedUpdatef is like [InteractionUtil.ReplyComponentsHiddenSimpleEmbedf] but made for an update for components.
Expand Down

0 comments on commit 233542a

Please sign in to comment.