Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add application emojis #373

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions rest/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ type Applications interface {
ConsumeEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) error

GetSKUs(applicationID snowflake.ID, opts ...RequestOpt) ([]discord.SKU, error)

GetApplicationEmojis(applicationID snowflake.ID, opts ...RequestOpt) ([]discord.Emoji, error)
GetApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) (*discord.Emoji, error)
CreateApplicationEmoji(applicationID snowflake.ID, emojiCreate discord.EmojiCreate, opts ...RequestOpt) (*discord.Emoji, error)
UpdateApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, emojiUpdate discord.EmojiUpdate, opts ...RequestOpt) (*discord.Emoji, error)
DeleteApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) error
}

type applicationsImpl struct {
Expand Down Expand Up @@ -219,10 +225,42 @@ func (s *applicationsImpl) GetSKUs(applicationID snowflake.ID, opts ...RequestOp
return
}

func (s *applicationsImpl) GetApplicationEmojis(applicationID snowflake.ID, opts ...RequestOpt) (emojis []discord.Emoji, err error) {
var rs emojisResponse
err = s.client.Do(GetApplicationEmojis.Compile(nil, applicationID), nil, &rs, opts...)
if err == nil {
emojis = rs.Items
}
return
}

func (s *applicationsImpl) GetApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) (emoji *discord.Emoji, err error) {
err = s.client.Do(GetApplicationEmoji.Compile(nil, applicationID, emojiID), nil, &emoji, opts...)
return
}

func (s *applicationsImpl) CreateApplicationEmoji(applicationID snowflake.ID, emojiCreate discord.EmojiCreate, opts ...RequestOpt) (emoji *discord.Emoji, err error) {
err = s.client.Do(CreateApplicationEmoji.Compile(nil, applicationID), emojiCreate, &emoji, opts...)
return
}

func (s *applicationsImpl) UpdateApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, emojiUpdate discord.EmojiUpdate, opts ...RequestOpt) (emoji *discord.Emoji, err error) {
err = s.client.Do(UpdateApplicationEmoji.Compile(nil, applicationID, emojiID), emojiUpdate, &emoji, opts...)
return
}

func (s *applicationsImpl) DeleteApplicationEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) error {
return s.client.Do(DeleteApplicationEmoji.Compile(nil, applicationID, emojiID), nil, nil, opts...)
}

func unmarshalApplicationCommandsToApplicationCommands(unmarshalCommands []discord.UnmarshalApplicationCommand) []discord.ApplicationCommand {
commands := make([]discord.ApplicationCommand, len(unmarshalCommands))
for i := range unmarshalCommands {
commands[i] = unmarshalCommands[i].ApplicationCommand
}
return commands
}

type emojisResponse struct {
Items []discord.Emoji `json:"items"`
}
6 changes: 6 additions & 0 deletions rest/rest_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ var (
ConsumeEntitlement = NewEndpoint(http.MethodPost, "/applications/{application.id}/entitlements/{entitlement.id}/consume")

GetSKUs = NewEndpoint(http.MethodGet, "/applications/{application.id}/skus")

GetApplicationEmojis = NewEndpoint(http.MethodGet, "/applications/{application.id}/emojis")
GetApplicationEmoji = NewEndpoint(http.MethodGet, "/applications/{application.id}/emojis/{emoji.id}")
CreateApplicationEmoji = NewEndpoint(http.MethodPost, "/applications/{application.id}/emojis")
UpdateApplicationEmoji = NewEndpoint(http.MethodPatch, "/applications/{application.id}/emojis/{emoji.id}")
DeleteApplicationEmoji = NewEndpoint(http.MethodDelete, "/applications/{application.id}/emojis/{emoji.id}")
)

// NewEndpoint returns a new Endpoint which requires bot auth with the given http method & route.
Expand Down
Loading