From ca07b71eb9c0f31daa9ab85310b5253f8cbc8a81 Mon Sep 17 00:00:00 2001 From: sebm253 Date: Fri, 19 Jul 2024 22:26:21 +0200 Subject: [PATCH 1/2] Add application emojis --- rest/applications.go | 38 ++++++++++++++++++++++++++++++++++++++ rest/rest_endpoints.go | 6 ++++++ 2 files changed, 44 insertions(+) diff --git a/rest/applications.go b/rest/applications.go index a73533fc..9ead4429 100644 --- a/rest/applications.go +++ b/rest/applications.go @@ -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) + + GetEmojis(applicationID snowflake.ID, opts ...RequestOpt) ([]discord.Emoji, error) + GetEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) (*discord.Emoji, error) + CreateEmoji(applicationID snowflake.ID, emojiCreate discord.EmojiCreate, opts ...RequestOpt) (*discord.Emoji, error) + UpdateEmoji(applicationID snowflake.ID, emojiID snowflake.ID, emojiUpdate discord.EmojiUpdate, opts ...RequestOpt) (*discord.Emoji, error) + DeleteEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) error } type applicationsImpl struct { @@ -219,6 +225,34 @@ func (s *applicationsImpl) GetSKUs(applicationID snowflake.ID, opts ...RequestOp return } +func (s *applicationsImpl) GetEmojis(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) GetEmoji(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) CreateEmoji(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) UpdateEmoji(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) DeleteEmoji(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 { @@ -226,3 +260,7 @@ func unmarshalApplicationCommandsToApplicationCommands(unmarshalCommands []disco } return commands } + +type emojisResponse struct { + Items []discord.Emoji `json:"items"` +} diff --git a/rest/rest_endpoints.go b/rest/rest_endpoints.go index 329bfe05..08e9c08f 100644 --- a/rest/rest_endpoints.go +++ b/rest/rest_endpoints.go @@ -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. From 57228beb09df130b358afa421ac2023dc7f2c2dc Mon Sep 17 00:00:00 2001 From: sebm253 Date: Fri, 19 Jul 2024 22:29:49 +0200 Subject: [PATCH 2/2] rename funcs --- rest/applications.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rest/applications.go b/rest/applications.go index 9ead4429..55837e53 100644 --- a/rest/applications.go +++ b/rest/applications.go @@ -44,11 +44,11 @@ type Applications interface { GetSKUs(applicationID snowflake.ID, opts ...RequestOpt) ([]discord.SKU, error) - GetEmojis(applicationID snowflake.ID, opts ...RequestOpt) ([]discord.Emoji, error) - GetEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) (*discord.Emoji, error) - CreateEmoji(applicationID snowflake.ID, emojiCreate discord.EmojiCreate, opts ...RequestOpt) (*discord.Emoji, error) - UpdateEmoji(applicationID snowflake.ID, emojiID snowflake.ID, emojiUpdate discord.EmojiUpdate, opts ...RequestOpt) (*discord.Emoji, error) - DeleteEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) 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 { @@ -225,7 +225,7 @@ func (s *applicationsImpl) GetSKUs(applicationID snowflake.ID, opts ...RequestOp return } -func (s *applicationsImpl) GetEmojis(applicationID snowflake.ID, opts ...RequestOpt) (emojis []discord.Emoji, err error) { +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 { @@ -234,22 +234,22 @@ func (s *applicationsImpl) GetEmojis(applicationID snowflake.ID, opts ...Request return } -func (s *applicationsImpl) GetEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) (emoji *discord.Emoji, err error) { +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) CreateEmoji(applicationID snowflake.ID, emojiCreate discord.EmojiCreate, opts ...RequestOpt) (emoji *discord.Emoji, err error) { +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) UpdateEmoji(applicationID snowflake.ID, emojiID snowflake.ID, emojiUpdate discord.EmojiUpdate, opts ...RequestOpt) (emoji *discord.Emoji, err error) { +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) DeleteEmoji(applicationID snowflake.ID, emojiID snowflake.ID, opts ...RequestOpt) error { +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...) }