Add EmojiInfo cog #27

Merged
cswimr merged 27 commits from emoji into main 2024-05-08 16:07:30 -04:00
Showing only changes of commit ce53908938 - Show all commits

View file

@ -53,23 +53,12 @@ class EmojiInfo(commands.Cog):
color = discord.Color.from_rgb(*dominant_color) color = discord.Color.from_rgb(*dominant_color)
return color return color
@commands.hybrid_command(name="emoji") async def get_emoji_info(self, emoji: PartialEmoji) -> tuple[str, str]:
@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)
if emoji.is_unicode_emoji(): if emoji.is_unicode_emoji():
try: try:
emoji_url = await self.fetch_twemoji(unicode_emoji=emoji.name) emoji_url = await self.fetch_twemoji(unicode_emoji=emoji.name)
except Exception: except Exception as e:
await ctx.send("Please provide a valid emoji!", ephemeral=ephemeral) raise e
return
else: else:
emoji_url = emoji.url emoji_url = emoji.url
@ -86,7 +75,7 @@ class EmojiInfo(commands.Cog):
aliases = f"{bold('Aliases:')} {', '.join(emoji.aliases)}\n" if emoji.aliases else "" aliases = f"{bold('Aliases:')} {', '.join(emoji.aliases)}\n" if emoji.aliases else ""
group = f"{bold('Group:')} {emoji.group}\n" group = f"{bold('Group:')} {emoji.group}\n"
string: str = ( return (
f"{name}" f"{name}"
f"{emoji_id}" f"{emoji_id}"
f"{bold('Native:')} {emoji.is_unicode_emoji()}\n" f"{bold('Native:')} {emoji.is_unicode_emoji()}\n"
@ -95,12 +84,46 @@ class EmojiInfo(commands.Cog):
f"{bold('Animated:')} {emoji.animated}\n" f"{bold('Animated:')} {emoji.animated}\n"
f"{bold('Markdown:')} {markdown}\n" f"{bold('Markdown:')} {markdown}\n"
f"{bold('URL:')} [Click Here]({emoji_url})" 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(): 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 = 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) embed.set_thumbnail(url=emoji_url)
await ctx.send(embed=embed, ephemeral=ephemeral) await ctx.send(embed=embed)
else: else:
await ctx.send(content=string, ephemeral=ephemeral) await ctx.send(content=string)