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

Implement support for Application emojis #1566

Merged
merged 3 commits into from
Oct 6, 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
3 changes: 3 additions & 0 deletions endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
70 changes: 70 additions & 0 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Big-Iron-Cheems marked this conversation as resolved.
Show resolved Hide resolved
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) {
Expand Down
1 change: 1 addition & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,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"`
}

Expand Down
Loading