From: Georgios Atheridis Date: Tue, 17 Jan 2023 08:57:14 +0000 (+0000) Subject: added single use discord invite X-Git-Url: https://git.atheridis.org/?a=commitdiff_plain;h=ce4e0bdcfe2a57545b978beb486d57cc4424dfc4;p=ihaspeks%2Faptbot-ihaspeks.git added single use discord invite --- diff --git a/ihaspeks/commands/discord.py b/ihaspeks/commands/discord.py new file mode 100644 index 0000000..2a93177 --- /dev/null +++ b/ihaspeks/commands/discord.py @@ -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"])