Skip to content

Commit

Permalink
feat(roles): add support for icons and unicode emojis (#1334)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
  • Loading branch information
SamusAranX and FedorLap2006 committed Jan 2, 2024
1 parent 30b2cf2 commit 6031141
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ var (
EndpointCDNChannelIcons = EndpointCDN + "channel-icons/"
EndpointCDNBanners = EndpointCDN + "banners/"
EndpointCDNGuilds = EndpointCDN + "guilds/"
EndpointCDNRoleIcons = EndpointCDN + "role-icons/"
EndpointRoleIcon = func(rID, cID string) string {
return EndpointCDNRoleIcons + rID + "/" + cID + ".png"
}

EndpointVoice = EndpointAPI + "/voice/"
EndpointVoiceRegions = EndpointVoice + "regions"
Expand Down
29 changes: 29 additions & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1349,13 +1349,36 @@ type Role struct {
// This is a combination of bit masks; the presence of a certain permission can
// be checked by performing a bitwise AND between this int and the permission.
Permissions int64 `json:"permissions,string"`

// The hash of the role icon. Use Role.IconURL to retrieve the icon's URL.
Icon string `json:"icon"`

// The emoji assigned to this role.
UnicodeEmoji string `json:"unicode_emoji"`
}

// Mention returns a string which mentions the role
func (r *Role) Mention() string {
return fmt.Sprintf("<@&%s>", r.ID)
}

// IconURL returns the URL of the role's icon.
//
// size: The size of the desired role icon as a power of two
// Image size can be any power of two between 16 and 4096.
func (r *Role) IconURL(size string) string {
if r.Icon == "" {
return ""
}

URL := EndpointRoleIcon(r.ID, r.Icon)

if size != "" {
return URL + "?size=" + size
}
return URL
}

// RoleParams represents the parameters needed to create or update a Role
type RoleParams struct {
// The role's name
Expand All @@ -1368,6 +1391,12 @@ type RoleParams struct {
Permissions *int64 `json:"permissions,omitempty,string"`
// Whether this role is mentionable
Mentionable *bool `json:"mentionable,omitempty"`
// The role's unicode emoji.
// NOTE: can only be set if the guild has the ROLE_ICONS feature.
UnicodeEmoji *string `json:"unicode_emoji,omitempty"`
// The role's icon image encoded in base64.
// NOTE: can only be set if the guild has the ROLE_ICONS feature.
Icon *string `json:"icon,omitempty"`
}

// Roles are a collection of Role
Expand Down

0 comments on commit 6031141

Please sign in to comment.