Clean up and remove extra ordinal guff
This commit is contained in:
parent
9f5cc9bb49
commit
b98fa7469a
2 changed files with 6 additions and 22 deletions
13
matchy.py
13
matchy.py
|
@ -4,7 +4,6 @@ import logging
|
||||||
import importlib
|
import importlib
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import util
|
|
||||||
# Config contains
|
# Config contains
|
||||||
# TOKEN : str - Discord bot token
|
# TOKEN : str - Discord bot token
|
||||||
# SERVERS : list[int] - ids of the servers to have commands active
|
# 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 the guild information
|
||||||
cache_guilds()
|
cache_guilds()
|
||||||
await ctx.reply("Done!", ephemeral=True)
|
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))
|
@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")
|
@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"""
|
"""Match groups of channel members"""
|
||||||
if not per_group:
|
if not per_group:
|
||||||
per_group = 3
|
per_group = 3
|
||||||
|
|
||||||
logger.info(f"User {interaction.user} requested /match {per_group}")
|
logger.info(f"User {interaction.user} requested /match {per_group}")
|
||||||
|
|
||||||
# Grab the roles
|
# 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:
|
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)
|
await interaction.response.send_message(f"You'll need the {matcher_role.mention} role to do this, sorry!", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Let the channel know the matching is starting
|
# Let the channel know the matching is starting
|
||||||
if post:
|
if post:
|
||||||
await interaction.channel.send(f"{interaction.user.display_name} asked me to match groups of {per_group}! :partying_face:")
|
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)]
|
groups = [matchees[i::num_groups] for i in range(num_groups)]
|
||||||
group_msgs = []
|
group_msgs = []
|
||||||
for idx, group in enumerate(groups):
|
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)}")
|
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
|
# Send the messages
|
||||||
if post:
|
if post:
|
||||||
|
@ -102,7 +101,7 @@ async def match(interaction: discord.Interaction, per_group: int = None, post: b
|
||||||
await interaction.channel.send(msg)
|
await interaction.channel.send(msg)
|
||||||
else:
|
else:
|
||||||
await interaction.response.send_message("\n".join(group_msgs), ephemeral=True, silent=True)
|
await interaction.response.send_message("\n".join(group_msgs), ephemeral=True, silent=True)
|
||||||
|
|
||||||
logger.info(f"Done")
|
logger.info(f"Done")
|
||||||
if post:
|
if post:
|
||||||
await interaction.response.send_message("Done :)", ephemeral=True, silent=True)
|
await interaction.response.send_message("Done :)", ephemeral=True, silent=True)
|
||||||
|
|
15
util.py
15
util.py
|
@ -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'
|
|
Loading…
Add table
Add a link
Reference in a new issue