From 959d657e1c78d87ab0d0f52838793d80b07be941 Mon Sep 17 00:00:00 2001 From: Emma Alyx Wunder Date: Thu, 23 Feb 2023 01:58:26 +0100 Subject: [PATCH 1/8] Added support for the icon and unicode_emoji role struct fields --- endpoints.go | 4 ++++ structs.go | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/endpoints.go b/endpoints.go index a2a05fe3e..04b937552 100644 --- a/endpoints.go +++ b/endpoints.go @@ -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" diff --git a/structs.go b/structs.go index 64e077f23..575bb99b7 100644 --- a/structs.go +++ b/structs.go @@ -1239,6 +1239,12 @@ 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 @@ -1246,6 +1252,23 @@ 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 From 90b85ba95afcff631900d83f83b30e4b41ccd0c2 Mon Sep 17 00:00:00 2001 From: Earlopain Date: Mon, 24 Jul 2023 14:13:34 +0200 Subject: [PATCH 2/8] feat(roles): Add flags --- structs.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/structs.go b/structs.go index 575bb99b7..5eba859f1 100644 --- a/structs.go +++ b/structs.go @@ -1245,8 +1245,23 @@ type Role struct { // The emoji assigned to this role. UnicodeEmoji string `json:"unicode_emoji"` + + // The flags of the role, which describe extra features of a role. + // 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 flag. + Flags RoleFlags `json:"flags"` } +// RoleFlags is the flags of "role" (see RoleFlags* consts) +// https://discord.com/developers/docs/topics/permissions#role-object-role-flags +type RoleFlags int + +// Block containing known RoleFlags values +const ( + // RoleFlagInPrompt Role can be selected by members in an onboarding prompt. + RoleFlagInPrompt RoleFlags = 1 << 0 +) + // Mention returns a string which mentions the role func (r *Role) Mention() string { return fmt.Sprintf("<@&%s>", r.ID) From d065696a60822be0540c0501cac8fbdf628c282c Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Mon, 7 Aug 2023 13:28:18 +0200 Subject: [PATCH 3/8] Update structs.go Co-authored-by: Fedor Lapshin --- structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structs.go b/structs.go index 5eba859f1..082be0685 100644 --- a/structs.go +++ b/structs.go @@ -1256,7 +1256,7 @@ type Role struct { // https://discord.com/developers/docs/topics/permissions#role-object-role-flags type RoleFlags int -// Block containing known RoleFlags values +// Block containing known RoleFlags values. const ( // RoleFlagInPrompt Role can be selected by members in an onboarding prompt. RoleFlagInPrompt RoleFlags = 1 << 0 From 0e15f3596621a5c6be31589eddcc23e9199dd3aa Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Mon, 7 Aug 2023 13:31:47 +0200 Subject: [PATCH 4/8] Update structs.go Co-authored-by: Fedor Lapshin --- structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structs.go b/structs.go index 082be0685..f03f30a17 100644 --- a/structs.go +++ b/structs.go @@ -1258,7 +1258,7 @@ type RoleFlags int // Block containing known RoleFlags values. const ( - // RoleFlagInPrompt Role can be selected by members in an onboarding prompt. + // RoleFlagInPrompt indicates a Role to be selectable by members in an onboarding prompt. RoleFlagInPrompt RoleFlags = 1 << 0 ) From 7e5d8c06d35ae740f9836da076affb3e1274e183 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:23:29 +0100 Subject: [PATCH 5/8] Update structs.go Co-authored-by: Fedor Lapshin --- structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structs.go b/structs.go index 996af127a..c0e2f5dc6 100644 --- a/structs.go +++ b/structs.go @@ -1362,7 +1362,7 @@ type Role struct { Flags RoleFlags `json:"flags"` } -// RoleFlags is the flags of "role" (see RoleFlags* consts) +// RoleFlags represent the flags of a Role. // https://discord.com/developers/docs/topics/permissions#role-object-role-flags type RoleFlags int From 9e77772c1b811e73ce6588510fc6538b9d6229e3 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:23:35 +0100 Subject: [PATCH 6/8] Update structs.go Co-authored-by: Fedor Lapshin --- structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structs.go b/structs.go index c0e2f5dc6..3fb8cf191 100644 --- a/structs.go +++ b/structs.go @@ -1368,7 +1368,7 @@ type RoleFlags int // Block containing known RoleFlags values. const ( - // RoleFlagInPrompt indicates a Role to be selectable by members in an onboarding prompt. + // RoleFlagInPrompt indicates whether the Role is selectable by members in an onboarding prompt. RoleFlagInPrompt RoleFlags = 1 << 0 ) From a86e8eabadb1653c4d980243cb4cceff7452e6d5 Mon Sep 17 00:00:00 2001 From: Fedor Lapshin Date: Thu, 7 Mar 2024 18:39:38 +0300 Subject: [PATCH 7/8] docs: rephrase --- structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structs.go b/structs.go index 3fb8cf191..26e88fbea 100644 --- a/structs.go +++ b/structs.go @@ -1356,7 +1356,7 @@ type Role struct { // The emoji assigned to this role. UnicodeEmoji string `json:"unicode_emoji"` - // The flags of the role, which describe extra features of a role. + // The flags of the role, which describe its extra features. // 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 flag. Flags RoleFlags `json:"flags"` From 223b461a21cf2325bc632dd97641c60a35721d10 Mon Sep 17 00:00:00 2001 From: Fedor Lapshin Date: Thu, 7 Mar 2024 18:42:59 +0300 Subject: [PATCH 8/8] docs: fix wording --- structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structs.go b/structs.go index 26e88fbea..b2a32256c 100644 --- a/structs.go +++ b/structs.go @@ -1357,7 +1357,7 @@ type Role struct { UnicodeEmoji string `json:"unicode_emoji"` // The flags of the role, which describe its extra features. - // 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 flag can // be checked by performing a bitwise AND between this int and the flag. Flags RoleFlags `json:"flags"` }