1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-27 09:12:53 +00:00

discord: Add Icon/Emoji & Tags to Role (#313)

* discord: Add Icon/Emoji & Tags to Role
* oops :P
* Add Icon/Emoji to api/role
* Fix doc
* Fixes
This commit is contained in:
Ven 2022-02-18 03:07:03 +01:00 committed by GitHub
parent 209e6282b0
commit c0bfc217ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 0 deletions

View file

@ -70,6 +70,15 @@ type CreateRoleData struct {
// Default: false
Mentionable bool `json:"mentionable,omitempty"`
// Icon is the icon of the role. Requires the guild to have the ROLE_ICONS feature.
//
// Default: null
Icon *Image `json:"icon,omitempty"`
// UnicodeEmoji is the role's unicode emoji. Requires the guild to have the ROLE_ICONS feature.
//
// Default: null
UnicodeEmoji string `json:"unicode_emoji,omitempty"`
AddRoleData `json:"-"`
}
@ -133,6 +142,13 @@ type ModifyRoleData struct {
// Mentionable specifies whether the role should be mentionable.
Mentionable option.NullableBool `json:"mentionable,omitempty"`
// Icon is the icon of the role. Requires the guild to have the ROLE_ICONS feature.
// This value is nullable.
// To reset the role's icon, set this to NullImage.
Icon *Image `json:"icon,omitempty"`
// UnicodeEmoji is the role's unicode emoji. Requires the guild to have the ROLE_ICONS feature.
UnicodeEmoji option.NullableString `json:"unicode_emoji,omitempty"`
AddRoleData `json:"-"`
}

View file

@ -305,6 +305,22 @@ type Role struct {
Managed bool `json:"managed"`
// Mentionable specifies whether this role is mentionable.
Mentionable bool `json:"mentionable"`
// Icon is the icon hash of this role.
Icon Hash `json:"icon,omitempty"`
// UnicodeEmoji is the unicode emoji of this role.
UnicodeEmoji string `json:"unicode_emoji,omitempty"`
// Tags are the RoleTags of this role.
Tags RoleTags `json:"tags,omitempty"`
}
type RoleTags struct {
// BotID is the id of the bot this role belongs to.
BotID UserID `json:"bot_id,omitempty"`
// IntegrationID is the id of the integration this role belongs to.
IntegrationID IntegrationID `json:"integration_id,omitempty"`
// PremiumSubscriber specifies whether this is the guild's premium subscriber role.
PremiumSubscriber bool `json:"premium_subscriber,omitempty"`
}
// CreatedAt returns a time object representing when the role was created.
@ -317,6 +333,24 @@ func (r Role) Mention() string {
return r.ID.Mention()
}
// IconURL returns the URL to the role icon png.
// An empty string is returned if there's no icon.
func (r Role) IconURL() string {
return r.IconURLWithType(PNGImage)
}
// IconURLWithType returns the URL to the role icon using the passed
// ImageType. An empty string is returned if there's no icon.
//
// Supported ImageTypes: PNG, JPEG, WebP
func (r Role) IconURLWithType(t ImageType) string {
if r.Icon == "" {
return ""
}
return "https://cdn.discordapp.com/role-icons/" + r.ID.String() + "/" + t.format(r.Icon)
}
// https://discord.com/developers/docs/resources/guild#guild-member-object
//
// The field user won't be included in the member object attached to