From 05cda7466293665876b76bdf56de63ae027cff14 Mon Sep 17 00:00:00 2001 From: nex Date: Mon, 27 Mar 2023 23:16:28 +0100 Subject: [PATCH] add quote command --- .vscode/settings.json | 5 +++-- cogs/other.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8d955a5..912b9f5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { - "python.linting.pycodestyleEnabled": true, - "python.linting.enabled": false + "python.linting.pycodestyleEnabled": false, + "python.linting.enabled": false, + "python.analysis.typeCheckingMode": "basic" } \ No newline at end of file diff --git a/cogs/other.py b/cogs/other.py index 3d184ba..4bffb3a 100644 --- a/cogs/other.py +++ b/cogs/other.py @@ -954,6 +954,30 @@ class OtherCog(commands.Cog): ) await ctx.send_modal(TextModal()) + + @commands.slash_command() + @commands.cooldown(5, 10, commands.BucketType.user) + @commands.max_concurrency(1, commands.BucketType.user) + async def quote(self, ctx: discord.ApplicationContext): + """Generates a random quote""" + await ctx.defer() + try: + response = await self.http.get("https://inspirobot.me/api?generate=true") + except (ConnectionError, httpx.HTTPError, httpx.NetworkError) as e: + return await ctx.respond("Failed to get quote. " + str(e)) + if response.status_code != 200: + return await ctx.respond(f"Failed to get quote. Status code: {response.status_code}") + url = response.text + try: + response = await self.http.get(url) + except (ConnectionError, httpx.HTTPError, httpx.NetworkError) as e: + return await ctx.respond(url) + else: + if response.status_code != 200: + return await ctx.respond(url) + x = io.BytesIO(response.content) + x.seek(0) + await ctx.respond(file=discord.File(x, filename="quote.jpg")) def setup(bot):