From ce5390893832bfee1bff2b42a9165d52f782797e Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Wed, 8 May 2024 15:58:26 -0400 Subject: [PATCH] fix(emojiinfo): seperated the slash command from the normal command --- emojiinfo/emojiinfo.py | 59 +++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/emojiinfo/emojiinfo.py b/emojiinfo/emojiinfo.py index 156b1d0..df30008 100644 --- a/emojiinfo/emojiinfo.py +++ b/emojiinfo/emojiinfo.py @@ -53,23 +53,12 @@ class EmojiInfo(commands.Cog): color = discord.Color.from_rgb(*dominant_color) return color - @commands.hybrid_command(name="emoji") - @app_commands.describe( - emoji="What emoji would you like to get information on?", - ephemeral="Would you like the response to be hidden?" - ) - async def emoji(self, ctx: commands.Context, emoji: str, ephemeral: bool = False) -> None: - """Retrieve information about an emoji.""" - await ctx.defer(ephemeral=ephemeral) - - emoji: PartialEmoji = PartialEmoji.from_str(self, value=emoji) - + async def get_emoji_info(self, emoji: PartialEmoji) -> tuple[str, str]: if emoji.is_unicode_emoji(): try: emoji_url = await self.fetch_twemoji(unicode_emoji=emoji.name) - except Exception: - await ctx.send("Please provide a valid emoji!", ephemeral=ephemeral) - return + except Exception as e: + raise e else: emoji_url = emoji.url @@ -86,7 +75,7 @@ class EmojiInfo(commands.Cog): aliases = f"{bold('Aliases:')} {', '.join(emoji.aliases)}\n" if emoji.aliases else "" group = f"{bold('Group:')} {emoji.group}\n" - string: str = ( + return ( f"{name}" f"{emoji_id}" f"{bold('Native:')} {emoji.is_unicode_emoji()}\n" @@ -95,12 +84,46 @@ class EmojiInfo(commands.Cog): f"{bold('Animated:')} {emoji.animated}\n" f"{bold('Markdown:')} {markdown}\n" f"{bold('URL:')} [Click Here]({emoji_url})" - ) + ), emoji_url + + @app_commands.command(name="emoji") + @app_commands.describe( + emoji="What emoji would you like to get information on?", + ephemeral="Would you like the response to be hidden?" + ) + async def emoji_slash(self, interaction: discord.Interaction, emoji: str, ephemeral: bool) -> None: + """Retrieve information about an emoji.""" + interaction.response.defer(ephemeral=ephemeral) + + emoji: PartialEmoji = PartialEmoji.from_str(self, value=emoji) + + try: + string, emoji_url, = await self.get_emoji_info(emoji) + except Exception: + return await interaction.followup.send("Please provide a valid emoji!") + + if await self.bot.embed_requested(channel=interaction.channel): + embed = embed = discord.Embed(title="Emoji Information", description=string, color = await self.fetch_primary_color(emoji_url) or await self.bot.get_embed_color(interaction.channel)) + embed.set_thumbnail(url=emoji_url) + + await interaction.followup.send(embed=embed) + else: + await interaction.followup.send(content=string) + + @commands.command(name="emoji") + async def emoji(self, ctx: commands.Context, *, emoji: str) -> None: + """Retrieve information about an emoji.""" + emoji: PartialEmoji = PartialEmoji.from_str(self, value=emoji) + + try: + string, emoji_url, = await self.get_emoji_info(emoji) + except Exception: + return await ctx.send("Please provide a valid emoji!") if await ctx.embed_requested(): embed = embed = discord.Embed(title="Emoji Information", description=string, color = await self.fetch_primary_color(emoji_url) or await ctx.embed_color) embed.set_thumbnail(url=emoji_url) - await ctx.send(embed=embed, ephemeral=ephemeral) + await ctx.send(embed=embed) else: - await ctx.send(content=string, ephemeral=ephemeral) + await ctx.send(content=string)