feat: added unicode emoji support for coco

This commit is contained in:
Seaswimmer 2023-08-08 10:51:25 -04:00
parent 8c2d290266
commit 183f8b29b0
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -70,7 +70,11 @@ class Galaxy(commands.Cog):
@commands.Cog.listener('on_message')
async def cocoreact(self, message):
if message.guild is not None:
emoji = self.bot.get_emoji(await self.config.guild(message.guild).cocoemoji())
emoji_id = await self.config.guild(message.guild).cocoemoji()
if self.check_if_discord_unicode_emoji(emoji_id) is False:
emoji = self.bot.get_emoji(emoji_id)
elif self.check_if_discord_unicode_emoji(emoji_id) is True:
emoji = emoji_id
cocotarget = await self.config.guild(message.guild).cocotarget()
if cocotarget == 0:
return
@ -82,13 +86,32 @@ class Galaxy(commands.Cog):
@commands.guild_only()
async def coco_list(self, ctx: commands.Context):
"""Checks who Coco is currently set to."""
emoji = self.bot.get_emoji(await self.config.guild(ctx.guild).cocoemoji())
emoji_id = await self.config.guild(ctx.guild).cocoemoji()
cocotarget = await self.config.guild(ctx.guild).cocotarget()
if self.check_if_discord_unicode_emoji(emoji_id) is True:
emoji = emoji_id
embed = discord.Embed(color=await self.bot.get_embed_color(None), description=f"Coco is currently set to <@{cocotarget}> ({cocotarget}).\nCoco's emoji is currently set to {emoji}.")
else:
emoji = self.bot.get_emoji(emoji_id)
embed = discord.Embed(color=await self.bot.get_embed_color(None), description=f"Coco is currently set to <@{cocotarget}> ({cocotarget}).\nCoco's emoji is currently set to {emoji} ({await self.config.guild(ctx.guild).cocoemoji()}).")
await ctx.send(embed=embed)
coco = app_commands.Group(name='coco', guild_only=True, description="This group handles the autoreact functionality.")
def check_if_discord_unicode_emoji(self, emoji: str):
emoji_ranges = [
(0x1F600, 0x1F64F), # Emoticons
(0x1F300, 0x1F5FF), # Miscellaneous symbols and pictographs
(0x1F680, 0x1F6FF), # Transport and map symbols
(0x1F700, 0x1F77F), # Alchemical symbols
]
for char in emoji:
code_point = ord(char)
for start, end in emoji_ranges:
if start <= code_point <= end:
return True
return False
def extract_id(self, input_string):
match = re.search(r'(?<=:)\d+(?=>)', input_string)
if match:
@ -101,19 +124,21 @@ class Galaxy(commands.Cog):
async def coco_emoji(self, interaction: discord.Interaction, emoji: str = None):
"""Sets Coco's emoji."""
if emoji:
if self.check_if_discord_unicode_emoji(emoji) is True:
await self.config.guild(interaction.guild).cocoemoji.set(emoji)
embed=discord.Embed(color=await self.bot.get_embed_color(None), description=f"Coco's emoji has been set to {emoji}.")
await interaction.response.send_message(embed=embed)
else:
emoji_id = self.extract_id(input_string=emoji)
try:
emoji_obj = await interaction.guild.fetch_emoji(emoji_id)
except discord.NotFound or discord.HTTPException as error:
emoji_obj = self.bot.get_emoji(emoji_id)
if emoji_obj is None:
await interaction.response.send_message(content="You're trying to set the coco emoji to an emoji I don't have access to!", ephemeral=True)
return
await self.config.guild(interaction.guild).cocoemoji.set(emoji_obj.id)
embed=discord.Embed(color=await self.bot.get_embed_color(None), description=f"Coco's emoji has been set to {emoji_obj} ({emoji_obj.id}).")
await interaction.response.send_message(embed=embed)
else:
await self.config.guild(interaction.guild).cocoemoji.set(1028535684757209118)
emoji = self.bot.get_emoji(1028535684757209118)
embed=discord.Embed(color=await self.bot.get_embed_color(None), description=f"Coco's emoji has been set to {emoji} (1028535684757209118).")
await self.config.guild(interaction.guild).cocoemoji.set('💀')
embed=discord.Embed(color=await self.bot.get_embed_color(None), description=f"Coco's emoji has been set to 💀.")
await interaction.response.send_message(embed=embed)
@coco.command(name="set")