feat(roles): add support for icons and unicode emojis (#1334)
--------- Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
This commit is contained in:
parent
30b2cf22b4
commit
603114195a
2 changed files with 33 additions and 0 deletions
|
@ -42,6 +42,10 @@ var (
|
||||||
EndpointCDNChannelIcons = EndpointCDN + "channel-icons/"
|
EndpointCDNChannelIcons = EndpointCDN + "channel-icons/"
|
||||||
EndpointCDNBanners = EndpointCDN + "banners/"
|
EndpointCDNBanners = EndpointCDN + "banners/"
|
||||||
EndpointCDNGuilds = EndpointCDN + "guilds/"
|
EndpointCDNGuilds = EndpointCDN + "guilds/"
|
||||||
|
EndpointCDNRoleIcons = EndpointCDN + "role-icons/"
|
||||||
|
EndpointRoleIcon = func(rID, cID string) string {
|
||||||
|
return EndpointCDNRoleIcons + rID + "/" + cID + ".png"
|
||||||
|
}
|
||||||
|
|
||||||
EndpointVoice = EndpointAPI + "/voice/"
|
EndpointVoice = EndpointAPI + "/voice/"
|
||||||
EndpointVoiceRegions = EndpointVoice + "regions"
|
EndpointVoiceRegions = EndpointVoice + "regions"
|
||||||
|
|
29
structs.go
29
structs.go
|
@ -1349,6 +1349,12 @@ type Role struct {
|
||||||
// This is a combination of bit masks; the presence of a certain permission can
|
// 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.
|
// be checked by performing a bitwise AND between this int and the permission.
|
||||||
Permissions int64 `json:"permissions,string"`
|
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
|
// Mention returns a string which mentions the role
|
||||||
|
@ -1356,6 +1362,23 @@ func (r *Role) Mention() string {
|
||||||
return fmt.Sprintf("<@&%s>", r.ID)
|
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
|
// RoleParams represents the parameters needed to create or update a Role
|
||||||
type RoleParams struct {
|
type RoleParams struct {
|
||||||
// The role's name
|
// The role's name
|
||||||
|
@ -1368,6 +1391,12 @@ type RoleParams struct {
|
||||||
Permissions *int64 `json:"permissions,omitempty,string"`
|
Permissions *int64 `json:"permissions,omitempty,string"`
|
||||||
// Whether this role is mentionable
|
// Whether this role is mentionable
|
||||||
Mentionable *bool `json:"mentionable,omitempty"`
|
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
|
// Roles are a collection of Role
|
||||||
|
|
Loading…
Reference in a new issue