From b98fa7469a20a8a25ec2ac848a7ed15fb190ae34 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Fri, 9 Aug 2024 14:12:28 +0100 Subject: [PATCH] Clean up and remove extra ordinal guff --- matchy.py | 13 ++++++------- util.py | 15 --------------- 2 files changed, 6 insertions(+), 22 deletions(-) delete mode 100644 util.py diff --git a/matchy.py b/matchy.py index edbfacc..e401880 100755 --- a/matchy.py +++ b/matchy.py @@ -4,7 +4,6 @@ import logging import importlib from discord import app_commands from discord.ext import commands -import util # Config contains # TOKEN : str - Discord bot token # SERVERS : list[int] - ids of the servers to have commands active @@ -47,7 +46,7 @@ async def sync(ctx: discord.ext.commands.context.Context): # Cache the guild information cache_guilds() await ctx.reply("Done!", ephemeral=True) - + @bot.tree.command(description = "Match matchees into groups", guilds = list(g for g in guilds if g.id in config.SERVERS)) @app_commands.describe(per_group = "Matchees per group (default 3+)", post = "Post to channel") @@ -56,7 +55,7 @@ async def match(interaction: discord.Interaction, per_group: int = None, post: b """Match groups of channel members""" if not per_group: per_group = 3 - + logger.info(f"User {interaction.user} requested /match {per_group}") # Grab the roles @@ -70,7 +69,7 @@ async def match(interaction: discord.Interaction, per_group: int = None, post: b if matcher_role not in interaction.user.roles: await interaction.response.send_message(f"You'll need the {matcher_role.mention} role to do this, sorry!", ephemeral=True) return - + # Let the channel know the matching is starting if post: await interaction.channel.send(f"{interaction.user.display_name} asked me to match groups of {per_group}! :partying_face:") @@ -92,9 +91,9 @@ async def match(interaction: discord.Interaction, per_group: int = None, post: b groups = [matchees[i::num_groups] for i in range(num_groups)] group_msgs = [] for idx, group in enumerate(groups): - mentions = [m.mention for m in group] + mentions = ", ".join([m.mention for m in group]) logger.info(f"Sending group: {list(m.name for m in group)}") - group_msgs.append(f"{util.get_ordinal(idx+1)} group: " + ", ".join(mentions)) + group_msgs.append(f"Matched up {mentions}!") # Send the messages if post: @@ -102,7 +101,7 @@ async def match(interaction: discord.Interaction, per_group: int = None, post: b await interaction.channel.send(msg) else: await interaction.response.send_message("\n".join(group_msgs), ephemeral=True, silent=True) - + logger.info(f"Done") if post: await interaction.response.send_message("Done :)", ephemeral=True, silent=True) diff --git a/util.py b/util.py deleted file mode 100644 index c0db10b..0000000 --- a/util.py +++ /dev/null @@ -1,15 +0,0 @@ -# Get the ordinal for an int -def get_ordinal(num : int): - if num > 9: - secondToLastDigit = str(num)[-2] - if secondToLastDigit == '1': - return str(num)+'th' - lastDigit = num % 10 - if (lastDigit == 1): - return str(num)+'st' - elif (lastDigit == 2): - return str(num)+'nd' - elif (lastDigit == 3): - return str(num)+'rd' - else: - return str(num)+'th' \ No newline at end of file