feat: Implement TetoImageCog to fetch and display random images of Kasane Teto
This commit is contained in:
parent
af1c9fa40c
commit
70e46f525e
38
cogs/teto_image_cog.py
Normal file
38
cogs/teto_image_cog.py
Normal file
@ -0,0 +1,38 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiohttp
|
||||
|
||||
class TetoImageCog(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.teto_url = "https://slipstreamm.dev/teto"
|
||||
self.footer_url = "https://slipstreamm.dev/teto-web"
|
||||
|
||||
@commands.hybrid_command(name='teto')
|
||||
async def get_teto_image(self, ctx):
|
||||
"""Gets a random image of Kasane Teto."""
|
||||
async with ctx.typing():
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(self.teto_url, allow_redirects=False) as response:
|
||||
if response.status == 302:
|
||||
image_url = response.headers.get('Location')
|
||||
if image_url:
|
||||
embed = discord.Embed(
|
||||
title="Random Teto Image",
|
||||
color=discord.Color.red()
|
||||
)
|
||||
embed.set_image(url=image_url)
|
||||
embed.set_footer(text="Random Teto Image Website", icon_url=None, url=self.footer_url)
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
await ctx.send("Could not get the image URL from the redirect.")
|
||||
else:
|
||||
await ctx.send(f"Unexpected response status: {response.status}")
|
||||
except aiohttp.ClientConnectorError as e:
|
||||
await ctx.send(f"Could not connect to the image service: {e}")
|
||||
except Exception as e:
|
||||
await ctx.send(f"An error occurred: {e}")
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(TetoImageCog(bot))
|
Loading…
x
Reference in New Issue
Block a user