add quote command

This commit is contained in:
Nexus 2023-03-27 23:16:28 +01:00
parent 6de20b85e0
commit 05cda74662
2 changed files with 27 additions and 2 deletions

View file

@ -1,4 +1,5 @@
{
"python.linting.pycodestyleEnabled": true,
"python.linting.enabled": false
"python.linting.pycodestyleEnabled": false,
"python.linting.enabled": false,
"python.analysis.typeCheckingMode": "basic"
}

View file

@ -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):