feat: added unicode emoji support for coco
This commit is contained in:
parent
8c2d290266
commit
183f8b29b0
1 changed files with 40 additions and 15 deletions
|
@ -70,7 +70,11 @@ class Galaxy(commands.Cog):
|
||||||
@commands.Cog.listener('on_message')
|
@commands.Cog.listener('on_message')
|
||||||
async def cocoreact(self, message):
|
async def cocoreact(self, message):
|
||||||
if message.guild is not None:
|
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()
|
cocotarget = await self.config.guild(message.guild).cocotarget()
|
||||||
if cocotarget == 0:
|
if cocotarget == 0:
|
||||||
return
|
return
|
||||||
|
@ -82,13 +86,32 @@ class Galaxy(commands.Cog):
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def coco_list(self, ctx: commands.Context):
|
async def coco_list(self, ctx: commands.Context):
|
||||||
"""Checks who Coco is currently set to."""
|
"""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()
|
cocotarget = await self.config.guild(ctx.guild).cocotarget()
|
||||||
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()}).")
|
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)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
coco = app_commands.Group(name='coco', guild_only=True, description="This group handles the autoreact functionality.")
|
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):
|
def extract_id(self, input_string):
|
||||||
match = re.search(r'(?<=:)\d+(?=>)', input_string)
|
match = re.search(r'(?<=:)\d+(?=>)', input_string)
|
||||||
if match:
|
if match:
|
||||||
|
@ -101,19 +124,21 @@ class Galaxy(commands.Cog):
|
||||||
async def coco_emoji(self, interaction: discord.Interaction, emoji: str = None):
|
async def coco_emoji(self, interaction: discord.Interaction, emoji: str = None):
|
||||||
"""Sets Coco's emoji."""
|
"""Sets Coco's emoji."""
|
||||||
if emoji:
|
if emoji:
|
||||||
emoji_id = self.extract_id(input_string=emoji)
|
if self.check_if_discord_unicode_emoji(emoji) is True:
|
||||||
try:
|
await self.config.guild(interaction.guild).cocoemoji.set(emoji)
|
||||||
emoji_obj = await interaction.guild.fetch_emoji(emoji_id)
|
embed=discord.Embed(color=await self.bot.get_embed_color(None), description=f"Coco's emoji has been set to {emoji}.")
|
||||||
except discord.NotFound or discord.HTTPException as error:
|
await interaction.response.send_message(embed=embed)
|
||||||
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)
|
else:
|
||||||
return
|
emoji_id = self.extract_id(input_string=emoji)
|
||||||
await self.config.guild(interaction.guild).cocoemoji.set(emoji_obj.id)
|
emoji_obj = self.bot.get_emoji(emoji_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}).")
|
if emoji_obj is None:
|
||||||
await interaction.response.send_message(embed=embed)
|
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)
|
||||||
|
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:
|
else:
|
||||||
await self.config.guild(interaction.guild).cocoemoji.set(1028535684757209118)
|
await self.config.guild(interaction.guild).cocoemoji.set('💀')
|
||||||
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 💀.")
|
||||||
embed=discord.Embed(color=await self.bot.get_embed_color(None), description=f"Coco's emoji has been set to {emoji} (1028535684757209118).")
|
|
||||||
await interaction.response.send_message(embed=embed)
|
await interaction.response.send_message(embed=embed)
|
||||||
|
|
||||||
@coco.command(name="set")
|
@coco.command(name="set")
|
||||||
|
|
Loading…
Reference in a new issue