Fix up guild storage and filtering for commands
This commit is contained in:
parent
0f8ed50032
commit
081fc629a6
1 changed files with 5 additions and 17 deletions
22
matchy.py
22
matchy.py
|
@ -32,18 +32,12 @@ def get_ordinal(num : int):
|
||||||
else:
|
else:
|
||||||
return str(num)+'th'
|
return str(num)+'th'
|
||||||
|
|
||||||
guilds = {}
|
guilds = []
|
||||||
def sync_guilds():
|
def sync_guilds():
|
||||||
# Cache the guild info
|
# Cache the guild info
|
||||||
for guild in bot.guilds:
|
for guild in bot.guilds:
|
||||||
if guild.id in config.SERVERS:
|
if guild.id in config.SERVERS:
|
||||||
guilds[guild.id] = { "guild" : guild }
|
guilds.append(guild)
|
||||||
|
|
||||||
# Grab the role info
|
|
||||||
for id in guilds:
|
|
||||||
guild = guilds[id]
|
|
||||||
guild["matchee"] = find_role_by_name(guild["guild"].roles, "Matchee")
|
|
||||||
guild["matcher"] = find_role_by_name(guild["guild"].roles, "Matcher")
|
|
||||||
|
|
||||||
print(f"Synced {len(guilds)} guild(s)")
|
print(f"Synced {len(guilds)} guild(s)")
|
||||||
|
|
||||||
|
@ -65,19 +59,13 @@ async def sync(ctx):
|
||||||
sync_guilds()
|
sync_guilds()
|
||||||
|
|
||||||
|
|
||||||
@bot.tree.command(description = "Match matchees into groups")
|
@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")
|
@app_commands.describe(per_group = "Matchees per group")
|
||||||
async def match(interaction: discord.Interaction, per_group: int):
|
async def match(interaction: discord.Interaction, per_group: int):
|
||||||
|
|
||||||
# Grab the guild
|
|
||||||
guild = guilds.get(interaction.guild.id, None)
|
|
||||||
if not guild:
|
|
||||||
await interaction.response.send_message("Server not registered :(", ephemeral=True)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Grab the roles
|
# Grab the roles
|
||||||
matchee = guild["matchee"]
|
matchee = find_role_by_name(interaction.guild.roles, "Matchee")
|
||||||
matcher = guild["matcher"]
|
matcher = find_role_by_name(interaction.guild.roles, "Matcher")
|
||||||
if not matchee or not matcher:
|
if not matchee or not matcher:
|
||||||
await interaction.response.send_message("Server has missing matchy roles :(", ephemeral=True)
|
await interaction.response.send_message("Server has missing matchy roles :(", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue