Skip to content

Commit

Permalink
Add Reaction() to emojis (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
cane authored Apr 25, 2023
1 parent 38bc148 commit 57b63ff
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions discord/emoji.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package discord

import (
"fmt"
"time"

"github.com/disgoorg/snowflake/v2"
Expand All @@ -21,6 +22,14 @@ type Emoji struct {
Available bool `json:"available,omitempty"`
}

// Reaction returns a string used for manipulating with reactions. May be empty if the Name is empty
func (e Emoji) Reaction() string {
if e.Name == "" {
return ""
}
return reaction(e.Name, e.ID)
}

// Mention returns the string used to send the Emoji
func (e Emoji) Mention() string {
if e.Animated {
Expand Down Expand Up @@ -61,3 +70,18 @@ type PartialEmoji struct {
Name *string `json:"name"`
Animated bool `json:"animated"`
}

// Reaction returns a string used for manipulating with reactions. May be empty if the Name is nil
func (e PartialEmoji) Reaction() string {
if e.Name == nil {
return ""
}
if e.ID == nil {
return *e.Name
}
return reaction(*e.Name, *e.ID)
}

func reaction(name string, id snowflake.ID) string {
return fmt.Sprintf("%s:%s", name, id)
}

0 comments on commit 57b63ff

Please sign in to comment.