From 8c8c0f10709b40405e2b111e5e983a56d7c6635d Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 8 Jul 2022 17:28:46 +0100 Subject: feat(gateway): Add intents class --- discord/intents.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 discord/intents.py diff --git a/discord/intents.py b/discord/intents.py new file mode 100644 index 0000000..e9a412f --- /dev/null +++ b/discord/intents.py @@ -0,0 +1,52 @@ +""" + Contains constants and functions for managing the various gateway intents. + + If you do not specify an intent, the gateway will not send events related to it. Events that are not part of an + intent are always sent. Message content, guild presences and guild members are privileged intents - you must + enable them in the Discord developer portal. +""" +from enum import Enum, unique + + +@unique +class Intents(Enum): + """ + Constants for the gateway intents, with their numerical values. + + See more at: https://discord.com/developers/docs/topics/gateway#gateway-intents + """ + GUILDS = 0 + GUILD_MEMBERS = 1 + GUILD_BANS = 2 + GUILD_EMOJIS_AND_STICKERS = 3 + GUILD_INTEGRATIONS = 4 + GUILD_WEBHOOKS = 5 + GUILD_INVITES = 6 + GUILD_VOICE_STATES = 7 + GUILD_PRESENCES = 8 + GUILD_MESSAGES = 9 + GUILD_MESSAGE_REACTIONS = 10 + GUILD_MESSAGE_TYPING = 11 + DIRECT_MESSAGES = 12 + DIRECT_MESSAGE_REACTIONS = 13 + DIRECT_MESSAGE_TYPING = 14 + MESSAGE_CONTENT = 15 + GUILD_SCHEDULED_EVENTS = 16 + AUTO_MODERATION_CONFIGURATION = 20 + AUTO_MODERATION_EXECUTION = 21 + + +def gen_number(intents: list[Intents]): + """ + Generates the number used to tell the gateway which intents are active. + + **Parameters:** + - intents (list[Intents]): A list of active intents + + **Returns:** + - int: The number used as an argument for the gateway connection. + """ + number = 1 + for i in intents: + number << i.value() + return number -- cgit 1.4.1-2-gfad0