Add refresh table command.
This commit is contained in:
@@ -202,6 +202,17 @@ class Guild:
|
|||||||
return self._table_map[table_name]
|
return self._table_map[table_name]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_tables(self) -> dict:
|
||||||
|
"""
|
||||||
|
Getter for dict of table names and tables.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: Dictionary consisting of the Table Names and the Table object itself.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# I don't know if this is const data. Don't want to allow data to be written as a result of this function.
|
||||||
|
return self._table_map
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
"""
|
"""
|
||||||
Creates python dictionary object from class data.
|
Creates python dictionary object from class data.
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
Commands for managing/displaying the highscores messages.
|
Commands for managing/displaying the highscores messages.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
import nextcord
|
import nextcord
|
||||||
|
|
||||||
@@ -69,7 +71,7 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
|||||||
or edits the existing message.
|
or edits the existing message.
|
||||||
|
|
||||||
Args:
|
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)
|
guild = highscores_data.get_guild(interaction.guild_id)
|
||||||
print(f"Printing out highscores information in channel {guild.highscore_channel}")
|
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)
|
highscores_data.save_guild_data(guild)
|
||||||
|
|
||||||
await interaction.send(f"Posted all tables to <#{channel.id}>.", ephemeral=True)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user