import disnake
from disnake.ext import commands
import embedManager as embeds
import aiohttp
class UtilityCog(commands.Cog):
    """actions, 18+"""

    def __init__(self, bot: commands.Bot):
        self.bot = bot
    
    @commands.slash_command()
    async def actions(inter):
        # Here you can paste some code, it will run for every invoked sub-command.
        pass


    # Ping command
    @actions.sub_command(name="waifu",description="Get the bots latency.")
    @commands.cooldown(rate= 1, per= 10, type= commands.BucketType.member)
    async def waifu(self, inter: disnake.ApplicationCommandInteraction):
        async with aiohttp.ClientSession() as session:
            async with session.get('https://api.waifu.pics/sfw/waifu') as response:
                response.raise_for_status()  # Raise an exception if the request was not successful
                data = await response.json()
                image_url = data['url']
                await inter.response.send_message(image_url)   
 
    @actions.sub_command(name="kiss",description="Get the bots latency.")
    @commands.cooldown(rate= 1, per= 10, type= commands.BucketType.member)
    async def kiss(self, inter: disnake.ApplicationCommandInteraction):
        """Get the bot's current websocket latency."""
        await inter.response.send_message(embed=embeds.createEmbed(f"🏓 Pong!",f"Latency is {round(self.bot.latency * 1000)}ms"))
    
    @actions.sub_command(name="love",description="pics 18+")
    @commands.is_nsfw()
    @commands.cooldown(rate= 1, per= 10, type= commands.BucketType.member)
    async def love(self, inter: disnake.ApplicationCommandInteraction):
        """Get the bot's current websocket latency."""
        await inter.response.send_message(embed=embeds.createEmbed(f"🏓 Pong!",f"Latency is {round(self.bot.latency * 1000)}ms"))

    
    async def love_error(ctx, error):
        if isinstance(error, commands.NSFWChannelRequired):
            await ctx.respond(embed=embeds.createErrorEmbed(f"This command can only be used in NSFW channels."), ephemeral=True)
        else:
            raise error
        
    @actions.sub_command(name="pat",description="Get the bots latency.")
    @commands.cooldown(rate= 1, per= 10, type= commands.BucketType.member)
    async def pat(self, inter: disnake.ApplicationCommandInteraction):
        """Get the bot's current websocket latency."""
        await inter.response.send_message(embed=embeds.createEmbed(f"🏓 Pong!",f"Latency is {round(self.bot.latency * 1000)}ms"))
    
    @actions.sub_command(name="bite",description="Get the bots latency.")
    @commands.cooldown(rate= 1, per= 10, type= commands.BucketType.member)
    async def bite(self, inter: disnake.ApplicationCommandInteraction):
        """Get the bot's current websocket latency."""
        await inter.response.send_message(embed=embeds.createEmbed(f"🏓 Pong!",f"Latency is {round(self.bot.latency * 1000)}ms"))

    @actions.sub_command(name="kill",description="Get the bots latency.")
    @commands.cooldown(rate= 1, per= 10, type= commands.BucketType.member)
    async def kill(self, inter: disnake.ApplicationCommandInteraction):
        """Get the bot's current websocket latency."""
        await inter.response.send_message(embed=embeds.createEmbed(f"🏓 Pong!",f"Latency is {round(self.bot.latency * 1000)}ms"))

    @actions.sub_command(name="lick",description="Get the bots latency.")
    @commands.cooldown(rate= 1, per= 10, type= commands.BucketType.member)
    async def lick(self, inter: disnake.ApplicationCommandInteraction):
        """Get the bot's current websocket latency."""
        await inter.response.send_message(embed=embeds.createEmbed(f"🏓 Pong!",f"Latency is {round(self.bot.latency * 1000)}ms"))
    
    @actions.sub_command(name="hug",description="Get the bots latency.")
    @commands.cooldown(rate= 1, per= 10, type= commands.BucketType.member)
    async def hug(self, inter: disnake.ApplicationCommandInteraction):
        """Get the bot's current websocket latency."""
        await inter.response.send_message(embed=embeds.createEmbed(f"🏓 Pong!",f"Latency is {round(self.bot.latency * 1000)}ms"))

    @actions.sub_command(name="nom",description="Get the bots latency.")
    @commands.cooldown(rate= 1, per= 10, type= commands.BucketType.member)
    async def nom(self, inter: disnake.ApplicationCommandInteraction):
        """Get the bot's current websocket latency."""
        await inter.response.send_message(embed=embeds.createEmbed(f"🏓 Pong!",f"Latency is {round(self.bot.latency * 1000)}ms"))
    
def setup(bot: commands.Bot):
    bot.add_cog(UtilityCog(bot))