diff --git a/endpoints.go b/endpoints.go index 29189af69..79cb390cf 100644 --- a/endpoints.go +++ b/endpoints.go @@ -218,6 +218,9 @@ var ( EndpointApplication = func(aID string) string { return EndpointApplications + "/" + aID } EndpointApplicationRoleConnectionMetadata = func(aID string) string { return EndpointApplication(aID) + "/role-connections/metadata" } + EndpointApplicationEmojis = func(aID string) string { return EndpointApplication(aID) + "/emojis" } + EndpointApplicationEmoji = func(aID, eID string) string { return EndpointApplication(aID) + "/emojis/" + eID } + EndpointOAuth2 = EndpointAPI + "oauth2/" EndpointOAuth2Applications = EndpointOAuth2 + "applications" EndpointOAuth2Application = func(aID string) string { return EndpointOAuth2Applications + "/" + aID } diff --git a/restapi.go b/restapi.go index ffb8e3022..4e335fa49 100644 --- a/restapi.go +++ b/restapi.go @@ -1454,6 +1454,76 @@ func (s *Session) GuildEmojiDelete(guildID, emojiID string, options ...RequestOp return } +// ApplicationEmojis returns all emojis for the given application +// appID : ID of the application +func (s *Session) ApplicationEmojis(appID string, options ...RequestOption) (emojis []*Emoji, err error) { + body, err := s.RequestWithBucketID("GET", EndpointApplicationEmojis(appID), nil, EndpointApplicationEmojis(appID), options...) + if err != nil { + return + } + + var temp struct { + Items []*Emoji `json:"items"` + } + + err = unmarshal(body, &temp) + if err != nil { + return + } + + emojis = temp.Items + return +} + +// ApplicationEmoji returns the emoji for the given application. +// appID : ID of the application +// emojiID : ID of an Emoji to retrieve +func (s *Session) ApplicationEmoji(appID, emojiID string, options ...RequestOption) (emoji *Emoji, err error) { + var body []byte + body, err = s.RequestWithBucketID("GET", EndpointApplicationEmoji(appID, emojiID), nil, EndpointApplicationEmoji(appID, emojiID), options...) + if err != nil { + return + } + + err = unmarshal(body, &emoji) + return +} + +// ApplicationEmojiCreate creates a new Emoji for the given application. +// appID : ID of the application +// data : New Emoji data +func (s *Session) ApplicationEmojiCreate(appID string, data *EmojiParams, options ...RequestOption) (emoji *Emoji, err error) { + body, err := s.RequestWithBucketID("POST", EndpointApplicationEmojis(appID), data, EndpointApplicationEmojis(appID), options...) + if err != nil { + return + } + + err = unmarshal(body, &emoji) + return +} + +// ApplicationEmojiEdit modifies and returns updated Emoji for the given application. +// appID : ID of the application +// emojiID : ID of an Emoji +// data : Updated Emoji data +func (s *Session) ApplicationEmojiEdit(appID string, emojiID string, data *EmojiParams, options ...RequestOption) (emoji *Emoji, err error) { + body, err := s.RequestWithBucketID("PATCH", EndpointApplicationEmoji(appID, emojiID), data, EndpointApplicationEmojis(appID), options...) + if err != nil { + return + } + + err = unmarshal(body, &emoji) + return +} + +// ApplicationEmojiDelete deletes an Emoji for the given application. +// appID : ID of the application +// emojiID : ID of an Emoji +func (s *Session) ApplicationEmojiDelete(appID, emojiID string, options ...RequestOption) (err error) { + _, err = s.RequestWithBucketID("DELETE", EndpointApplicationEmoji(appID, emojiID), nil, EndpointApplicationEmojis(appID), options...) + return +} + // GuildTemplate returns a GuildTemplate for the given code // templateCode: The Code of a GuildTemplate func (s *Session) GuildTemplate(templateCode string, options ...RequestOption) (st *GuildTemplate, err error) { diff --git a/structs.go b/structs.go index 148aa3c86..7d9ca5c7e 100644 --- a/structs.go +++ b/structs.go @@ -647,6 +647,7 @@ type EmojiParams struct { // NOTE: can be only set on creation. Image string `json:"image,omitempty"` // Roles for which this emoji will be available. + // NOTE: can not be used with application emoji endpoints. Roles []string `json:"roles,omitempty"` }