added single use discord invite
authorGeorgios Atheridis <georgios@atheridis.org>
Tue, 17 Jan 2023 08:57:14 +0000 (08:57 +0000)
committerGeorgios Atheridis <georgios@atheridis.org>
Tue, 17 Jan 2023 09:01:28 +0000 (09:01 +0000)
ihaspeks/commands/discord.py [new file with mode: 0644]

diff --git a/ihaspeks/commands/discord.py b/ihaspeks/commands/discord.py
new file mode 100644 (file)
index 0000000..2a93177
--- /dev/null
@@ -0,0 +1,55 @@
+from aptbot.bot import Message, Commands, Bot
+import os
+import tools.smart_privmsg
+import requests
+import logging
+
+logger = logging.getLogger(__name__)
+
+PERMISSION = 99
+PREFIX = "?"
+DESCRIPTION = ""
+USER_COOLDOWN = 600
+GLOBAL_COOLDOWN = 5
+
+DISCORD_API = os.getenv("DISCORD_API")
+
+PEKS_CHANNEL_ID = 806590801311301652
+
+
+def main(bot: Bot, message: Message):
+    try:
+        response = requests.post(
+            f"https://discord.com/api/v10/channels/{PEKS_CHANNEL_ID}/invites",
+            headers={
+                "Authorization": f"Bot {DISCORD_API}",
+                "Content-Type": "application/json",
+            },
+            json={
+                "max_age": 300,
+                "max_uses": 1,
+                "unique": True,
+            },
+        )
+    except Exception as e:
+        logger.exception(e)
+        msg = "Sorry, I'm unable to create a discord link at this time. \
+            Please contact IHasPeks#6552 or Yorugo#4966 \
+            on discord to send you an invite."
+        tools.smart_privmsg.send(bot, message, msg, reply=message.tags["id"])
+        return
+
+    if response.status_code != 200:
+        logger.critical(
+            f"Unable to create a discord link. \
+            Status code: {response.status_code}. With content: {response.content}"
+        )
+        msg = "Sorry, I'm unable to create a discord link at this time. \
+            Please contact IHasPeks#6552 or Yorugo#4966 \
+            on discord to send you an invite."
+        tools.smart_privmsg.send(bot, message, msg, reply=message.tags["id"])
+        return
+    msg = f"https://discord.gg/{response.json()['code']} don't forget to verify\
+        yourselves on #rules channel, enjoy your time! Discordblob"
+
+    tools.smart_privmsg.send(bot, message, msg, reply=message.tags["id"])