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

Added support for the icon and unicode_emoji role struct fields #1334

Merged
merged 3 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
23 changes: 23 additions & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1239,13 +1239,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 users's banner image.
//
// 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
FedorLap2006 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down