39 lines
1.8 KiB
Python
39 lines
1.8 KiB
Python
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='tetoimage', description='Get a random image of Kasane 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))
|