From b8e4b2cf56a883dbe5d8ca2a236a84c7f283050e Mon Sep 17 00:00:00 2001 From: diamondburned Date: Wed, 28 Oct 2020 19:44:04 -0700 Subject: [PATCH] Gateway: Added an Event to Intents map for convenience --- gateway/identify.go | 22 -------------------- gateway/intents.go | 30 +++++++++++++++++++++++++++ gateway/intents_map.go | 47 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 gateway/intents.go create mode 100644 gateway/intents_map.go diff --git a/gateway/identify.go b/gateway/identify.go index e5d7ed7..d8b1dc2 100644 --- a/gateway/identify.go +++ b/gateway/identify.go @@ -55,28 +55,6 @@ func (i *IdentifyData) SetShard(id, num int) { i.Shard[0], i.Shard[1] = id, num } -// Intents for the new Discord API feature, documented at -// https://discordapp.com/developers/docs/topics/gateway#gateway-intents. -type Intents uint32 - -const ( - IntentGuilds Intents = 1 << iota - IntentGuildMembers - IntentGuildBans - IntentGuildEmojis - IntentGuildIntegrations - IntentGuildWebhooks - IntentGuildInvites - IntentGuildVoiceStates - IntentGuildPresences - IntentGuildMessages - IntentGuildMessageReactions - IntentGuildMessageTyping - IntentDirectMessages - IntentDirectMessageReactions - IntentDirectMessageTyping -) - type Identifier struct { IdentifyData diff --git a/gateway/intents.go b/gateway/intents.go new file mode 100644 index 0000000..d858e3f --- /dev/null +++ b/gateway/intents.go @@ -0,0 +1,30 @@ +package gateway + +// Intents for the new Discord API feature, documented at +// https://discordapp.com/developers/docs/topics/gateway#gateway-intents. +type Intents uint32 + +const ( + IntentGuilds Intents = 1 << iota + IntentGuildMembers + IntentGuildBans + IntentGuildEmojis + IntentGuildIntegrations + IntentGuildWebhooks + IntentGuildInvites + IntentGuildVoiceStates + IntentGuildPresences + IntentGuildMessages + IntentGuildMessageReactions + IntentGuildMessageTyping + IntentDirectMessages + IntentDirectMessageReactions + IntentDirectMessageTyping +) + +// PrivilegedIntents contains a list of privileged intents that Discord requires +// bots to have these intents explicitly enabled in the Developer Portal. +var PrivilegedIntents = []Intents{ + IntentGuildPresences, + IntentGuildMembers, +} diff --git a/gateway/intents_map.go b/gateway/intents_map.go new file mode 100644 index 0000000..9aa1bc4 --- /dev/null +++ b/gateway/intents_map.go @@ -0,0 +1,47 @@ +package gateway + +// EventIntents maps event types to intents. +var EventIntents = map[string]Intents{ + "GUILD_CREATE": IntentGuilds, + "GUILD_UPDATE": IntentGuilds, + "GUILD_DELETE": IntentGuilds, + "GUILD_ROLE_CREATE": IntentGuilds, + "GUILD_ROLE_UPDATE": IntentGuilds, + "GUILD_ROLE_DELETE": IntentGuilds, + "CHANNEL_CREATE": IntentGuilds, + "CHANNEL_UPDATE": IntentGuilds, + "CHANNEL_DELETE": IntentGuilds, + "CHANNEL_PINS_UPDATE": IntentGuilds | IntentDirectMessages, + + "GUILD_MEMBER_ADD": IntentGuildMembers, + "GUILD_MEMBER_REMOVE": IntentGuildMembers, + "GUILD_MEMBER_UPDATE": IntentGuildMembers, + + "GUILD_BAN_ADD": IntentGuildBans, + "GUILD_BAN_REMOVE": IntentGuildBans, + + "GUILD_EMOJIS_UPDATE": IntentGuildEmojis, + + "GUILD_INTEGRATIONS_UPDATE": IntentGuildIntegrations, + + "WEBHOOKS_UPDATE": IntentGuildWebhooks, + + "INVITE_CREATE": IntentGuildInvites, + "INVITE_DELETE": IntentGuildInvites, + + "VOICE_STATE_UPDATE": IntentGuildVoiceStates, + + "PRESENCE_UPDATE": IntentGuildPresences, + + "MESSAGE_CREATE": IntentGuildMessages | IntentDirectMessages, + "MESSAGE_UPDATE": IntentGuildMessages | IntentDirectMessages, + "MESSAGE_DELETE": IntentGuildMessages | IntentDirectMessages, + "MESSAGE_DELETE_BULK": IntentGuildMessages, + + "MESSAGE_REACTION_ADD": IntentGuildMessageReactions | IntentDirectMessageReactions, + "MESSAGE_REACTION_REMOVE": IntentGuildMessageReactions | IntentDirectMessageReactions, + "MESSAGE_REACTION_REMOVE_ALL": IntentGuildMessageReactions | IntentDirectMessageReactions, + "MESSAGE_REACTION_REMOVE_EMOJI": IntentGuildMessageReactions | IntentDirectMessageReactions, + + "TYPING_START": IntentGuildMessageTyping | IntentDirectMessageTyping, +}