Bot: Corrected arguments.Emoji's ID field

This commit is contained in:
diamondburned (Forefront) 2020-04-08 21:33:46 -07:00
parent 3ee307b788
commit fb1b028ad7
1 changed files with 16 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import (
"regexp"
"github.com/diamondburned/arikawa/api/rate"
"github.com/diamondburned/arikawa/discord"
)
var (
@ -14,30 +15,30 @@ var (
)
type Emoji struct {
ID string
ID discord.Snowflake
Name string
Custom bool
Name string
Animated bool
}
func (e Emoji) APIString() string {
if !e.Custom {
return e.ID
return e.Name
}
return e.Name + ":" + e.ID
return e.Name + ":" + e.ID.String()
}
func (e Emoji) String() string {
if !e.Custom {
return e.ID
return e.Name
}
if e.Animated {
return "<a:" + e.Name + ":" + e.ID + ">"
return "<a:" + e.Name + ":" + e.ID.String() + ">"
} else {
return "<:" + e.Name + ":" + e.ID + ">"
return "<:" + e.Name + ":" + e.ID.String() + ">"
}
}
@ -46,7 +47,7 @@ func (e Emoji) URL() string {
return ""
}
base := "https://cdn.discordapp.com/emojis/" + e.ID
base := "https://cdn.discordapp.com/emojis/" + e.ID.String()
if e.Animated {
return base + ".gif"
@ -62,7 +63,7 @@ func (e *Emoji) Usage() string {
func (e *Emoji) Parse(arg string) error {
// Check if Unicode emoji
if rate.StringIsEmojiOnly(arg) {
e.ID = arg
e.Name = arg
e.Custom = false
return nil
@ -74,10 +75,15 @@ func (e *Emoji) Parse(arg string) error {
return ErrInvalidEmoji
}
id, err := discord.ParseSnowflake(matches[3])
if err != nil {
return err
}
e.Custom = true
e.Animated = matches[1] == "a"
e.Name = matches[2]
e.ID = matches[3]
e.ID = id
return nil
}