From 757302eb784d8317c5126b745205a4c712eccb5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Horonziak?= Date: Sat, 18 Apr 2020 22:30:51 +0200 Subject: [PATCH 1/7] Add intents --- discord.go | 1 + structs.go | 1 + 2 files changed, 2 insertions(+) diff --git a/discord.go b/discord.go index 74c7887..1944c15 100644 --- a/discord.go +++ b/discord.go @@ -74,6 +74,7 @@ func New(args ...interface{}) (s *Session, err error) { s.Identify.GuildSubscriptions = true s.Identify.Properties.OS = runtime.GOOS s.Identify.Properties.Browser = "DiscordGo v" + VERSION + s.Identify.Intents = 32767 // If no arguments are passed return the empty Session interface. if args == nil { diff --git a/structs.go b/structs.go index 5ce8769..43b39b5 100644 --- a/structs.go +++ b/structs.go @@ -959,6 +959,7 @@ type Identify struct { Shard *[2]int `json:"shard,omitempty"` Presence GatewayStatusUpdate `json:"presence,omitempty"` GuildSubscriptions bool `json:"guild_subscriptions"` + Intents int `json:"intents"` } // IdentifyProperties contains the "properties" portion of an Identify packet From 349da37386212f2236adcb8b3cf5e209f47544d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Horonziak?= Date: Sun, 19 Apr 2020 11:11:41 +0200 Subject: [PATCH 2/7] Refactor --- discord.go | 2 +- structs.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/discord.go b/discord.go index 1944c15..789ca68 100644 --- a/discord.go +++ b/discord.go @@ -74,7 +74,7 @@ func New(args ...interface{}) (s *Session, err error) { s.Identify.GuildSubscriptions = true s.Identify.Properties.OS = runtime.GOOS s.Identify.Properties.Browser = "DiscordGo v" + VERSION - s.Identify.Intents = 32767 + s.Identify.Intents = IntentsAllWithoutPrivileged // If no arguments are passed return the empty Session interface. if args == nil { diff --git a/structs.go b/structs.go index 43b39b5..944f899 100644 --- a/structs.go +++ b/structs.go @@ -1103,3 +1103,38 @@ const ( ErrCodeReactionBlocked = 90001 ) + +const ( + IntentsGuilds = 1 << iota + IntentsGuildMembers + IntentsGuildBans + IntentsGuildEmojis + IntentsGuildIntegrations + IntentsGuildWebhooks + IntentsGuildInvites + IntentsGuildVoiceStates + IntentsGuildPresences + IntentsGuildMessages + IntentsGuildMessageReactions + IntentsGuildMessageTyping + IntentsDirectMessagesMessages + IntentsDirectMessageReaction + IntentsDirectMessageTyping + + IntentsAllWithoutPrivileged = IntentsGuilds | + IntentsGuildBans | + IntentsGuildEmojis | + IntentsGuildIntegrations | + IntentsGuildWebhooks | + IntentsGuildInvites | + IntentsGuildVoiceStates | + IntentsGuildMessages | + IntentsGuildMessageReactions | + IntentsGuildMessageTyping | + IntentsDirectMessagesMessages | + IntentsDirectMessageReaction | + IntentsDirectMessageTyping + IntentsAll = IntentsAllWithoutPrivileged | + IntentsGuildMembers | + IntentsGuildPresences +) From d12e6550c69e59951f8d657753d51c24f6243377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Horonziak?= Date: Sun, 19 Apr 2020 17:36:35 +0200 Subject: [PATCH 3/7] Typos --- structs.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/structs.go b/structs.go index 944f899..3efc326 100644 --- a/structs.go +++ b/structs.go @@ -1117,8 +1117,8 @@ const ( IntentsGuildMessages IntentsGuildMessageReactions IntentsGuildMessageTyping - IntentsDirectMessagesMessages - IntentsDirectMessageReaction + IntentsDirectMessages + IntentsDirectMessageReactions IntentsDirectMessageTyping IntentsAllWithoutPrivileged = IntentsGuilds | @@ -1131,8 +1131,8 @@ const ( IntentsGuildMessages | IntentsGuildMessageReactions | IntentsGuildMessageTyping | - IntentsDirectMessagesMessages | - IntentsDirectMessageReaction | + IntentsDirectMessages | + IntentsDirectMessageReactions | IntentsDirectMessageTyping IntentsAll = IntentsAllWithoutPrivileged | IntentsGuildMembers | From 57c962912e21b67f877ccb17615de61a4f511db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Horonziak?= Date: Sun, 17 May 2020 19:52:52 +0200 Subject: [PATCH 4/7] Make intents optional field --- discord.go | 1 - structs.go | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/discord.go b/discord.go index 789ca68..74c7887 100644 --- a/discord.go +++ b/discord.go @@ -74,7 +74,6 @@ func New(args ...interface{}) (s *Session, err error) { s.Identify.GuildSubscriptions = true s.Identify.Properties.OS = runtime.GOOS s.Identify.Properties.Browser = "DiscordGo v" + VERSION - s.Identify.Intents = IntentsAllWithoutPrivileged // If no arguments are passed return the empty Session interface. if args == nil { diff --git a/structs.go b/structs.go index 3efc326..b706c18 100644 --- a/structs.go +++ b/structs.go @@ -959,7 +959,7 @@ type Identify struct { Shard *[2]int `json:"shard,omitempty"` Presence GatewayStatusUpdate `json:"presence,omitempty"` GuildSubscriptions bool `json:"guild_subscriptions"` - Intents int `json:"intents"` + Intents *Intent `json:"intents,omitempty"` } // IdentifyProperties contains the "properties" portion of an Identify packet @@ -1104,8 +1104,10 @@ const ( ErrCodeReactionBlocked = 90001 ) +type Intent int + const ( - IntentsGuilds = 1 << iota + IntentsGuilds Intent = 1 << iota IntentsGuildMembers IntentsGuildBans IntentsGuildEmojis @@ -1137,4 +1139,5 @@ const ( IntentsAll = IntentsAllWithoutPrivileged | IntentsGuildMembers | IntentsGuildPresences + IntentsNone Intent = 0 ) From de7803becd8a2b4230f8e0bca74f8f6d14acbba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Horonziak?= Date: Sun, 24 May 2020 08:34:29 +0200 Subject: [PATCH 5/7] Refactor --- discord.go | 1 + structs.go | 2 +- util.go | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/discord.go b/discord.go index 74c7887..1f5f5a0 100644 --- a/discord.go +++ b/discord.go @@ -74,6 +74,7 @@ func New(args ...interface{}) (s *Session, err error) { s.Identify.GuildSubscriptions = true s.Identify.Properties.OS = runtime.GOOS s.Identify.Properties.Browser = "DiscordGo v" + VERSION + s.Identify.Intents = MakeIntent(IntentsAllWithoutPrivileged) // If no arguments are passed return the empty Session interface. if args == nil { diff --git a/structs.go b/structs.go index b706c18..914bd4e 100644 --- a/structs.go +++ b/structs.go @@ -1139,5 +1139,5 @@ const ( IntentsAll = IntentsAllWithoutPrivileged | IntentsGuildMembers | IntentsGuildPresences - IntentsNone Intent = 0 + IntentsNone Intent = 0 ) diff --git a/util.go b/util.go index 02443ca..1dc3f47 100644 --- a/util.go +++ b/util.go @@ -15,3 +15,7 @@ func SnowflakeTimestamp(ID string) (t time.Time, err error) { t = time.Unix(timestamp/1000, 0) return } + +func MakeIntent(intents Intent) *Intent { + return &intents +} From 0e6ec53738e5708a55b48ca01e2d578c6d92c3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Horonziak?= Date: Sun, 24 May 2020 09:44:33 +0200 Subject: [PATCH 6/7] Move MakeIntent method --- structs.go | 5 +++++ util.go | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/structs.go b/structs.go index 914bd4e..a6b572e 100644 --- a/structs.go +++ b/structs.go @@ -1141,3 +1141,8 @@ const ( IntentsGuildPresences IntentsNone Intent = 0 ) + +// MakeIntent helps convert a gateway intent value for use in the Identify structure. +func MakeIntent(intents Intent) *Intent { + return &intents +} diff --git a/util.go b/util.go index 1dc3f47..02443ca 100644 --- a/util.go +++ b/util.go @@ -15,7 +15,3 @@ func SnowflakeTimestamp(ID string) (t time.Time, err error) { t = time.Unix(timestamp/1000, 0) return } - -func MakeIntent(intents Intent) *Intent { - return &intents -} From ee7a5ae519052b63b92c469670c816cbc295afb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Horonziak?= Date: Thu, 11 Jun 2020 12:26:34 +0200 Subject: [PATCH 7/7] Add missing comments --- structs.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/structs.go b/structs.go index a6b572e..750f18e 100644 --- a/structs.go +++ b/structs.go @@ -1104,8 +1104,11 @@ const ( ErrCodeReactionBlocked = 90001 ) +// Intent is the type of a Gateway Intent +// https://discord.com/developers/docs/topics/gateway#gateway-intents type Intent int +// Constants for the different bit offsets of intents const ( IntentsGuilds Intent = 1 << iota IntentsGuildMembers