Add refresh table command.

This commit is contained in:
alwayscompiling
2022-11-16 16:30:34 -05:00
parent 792a225987
commit 1858f0c37d
2 changed files with 63 additions and 1 deletions
+52 -1
View File
@@ -2,6 +2,8 @@
Commands for managing/displaying the highscores messages.
"""
from typing import Optional
from nextcord.ext import commands
import nextcord
@@ -69,7 +71,7 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
or edits the existing message.
Args:
interaction (nextcord.Interaction): Interaction that invoked the command
interaction (nextcord.Interaction): Interaction that invoked the command.
"""
guild = highscores_data.get_guild(interaction.guild_id)
print(f"Printing out highscores information in channel {guild.highscore_channel}")
@@ -99,3 +101,52 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
highscores_data.save_guild_data(guild)
await interaction.send(f"Posted all tables to <#{channel.id}>.", ephemeral=True)
@nextcord.slash_command(
description="Manually refresh a table. Use when changing settings or data manually changed.",
default_member_permissions=nextcord.Permissions(administrator=True),
)
async def refresh_table(
self,
interaction: nextcord.Interaction,
table_name: Optional[str] = nextcord.SlashOption(
description="Name of table.", required=True
),
) -> None:
"""
Refreshes a table given by user.
Args:
interaction (nextcord.Interaction): Interaction that invoked the command.
table (Optional[str]): Table name to refresh. Not optional. Is SlashOption.
"""
guild = highscores_data.get_guild(interaction.guild_id)
table = guild.get_table(table_name)
channel = interaction.guild.get_channel(guild.highscore_channel)
message: nextcord.Message = await send_highscore_message(channel, guild, table)
await message.edit(view=SubmissionCreateButton(self.bot))
await interaction.response.send_message(f"Updated table {table_name}!", ephemeral=True)
@refresh_table.on_autocomplete("table_name")
async def autofill_tables(self, interaction: nextcord.Interaction, table_name: str):
"""
Collects list of table names and compares to input table name for autocomplete assistance.
Args:
interaction (nextcord.Interaction): Interaction with command.
table (str): String to run autocomplete compared to.
"""
if not table_name:
await interaction.response.send_autocomplete(
highscores_data.get_guild(interaction.guild_id).get_tables().keys()
)
return
near_table = [
name
for name in highscores_data.get_guild(interaction.guild_id).get_tables().keys()
if name.lower().startswith(table_name.lower())
]
await interaction.response.send_autocomplete(near_table)