about summary refs log tree commit diff stats
path: root/discord
diff options
context:
space:
mode:
authorNoah <mounderfod@gmail.com>2022-07-08 17:28:46 +0100
committerNoah <mounderfod@gmail.com>2022-07-08 17:28:46 +0100
commit8c8c0f10709b40405e2b111e5e983a56d7c6635d (patch)
tree45e731bd00077baf7b1a8e87a697d98f2b147db9 /discord
parent9f617f76f5de31747af6b8b01db0663cd5718765 (diff)
downloaddiscobra-8c8c0f10709b40405e2b111e5e983a56d7c6635d.tar.gz
feat(gateway): Add intents class
Diffstat (limited to 'discord')
-rw-r--r--discord/intents.py52
1 files changed, 52 insertions, 0 deletions
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