Remove all references to table. Remove a dead function. Fix some code smells.

This commit is contained in:
2025-02-20 17:23:57 -05:00
parent 36dad683d8
commit 327126307d
7 changed files with 29 additions and 65 deletions
+1 -1
View File
@@ -147,7 +147,7 @@ class CreateCog(commands.Cog, name="Create Cog"):
@category.on_autocomplete("group_id") @category.on_autocomplete("group_id")
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None: async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
""" """
Collects list of table names and compares to input table name for autocomplete assistance. Collects list of group names and compares to input group name for autocomplete assistance.
Args: Args:
interaction (nextcord.Interaction): Interaction with command. interaction (nextcord.Interaction): Interaction with command.
+10 -10
View File
@@ -18,7 +18,7 @@ from utilities.utils import (
from .views.delete_confirm import DeleteConfirmView, create_delete_id from .views.delete_confirm import DeleteConfirmView, create_delete_id
class DeleteCog(commands.Cog, name="Table Management"): class DeleteCog(commands.Cog, name="Delete Cog"):
"""Class holds commands for deleting.""" """Class holds commands for deleting."""
def __init__(self) -> None: def __init__(self) -> None:
@@ -32,7 +32,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
async def all(self, interaction: nextcord.Interaction) -> None: async def all(self, interaction: nextcord.Interaction) -> None:
"""Subcommand parent for deleting all of a thing. Never called.""" """Subcommand parent for deleting all of a thing. Never called."""
@all.subcommand(description="Clears highscores channel of all table messages. Does not change data.") @all.subcommand(description="Clears highscores channel of all highscore messages. Does not change data.")
async def channel_messages( async def channel_messages(
self, self,
interaction: nextcord.Interaction, interaction: nextcord.Interaction,
@@ -69,16 +69,16 @@ class DeleteCog(commands.Cog, name="Table Management"):
for group in groups: for group in groups:
try: try:
table_message: nextcord.Message = await channel.fetch_message(group.MessageId) message: nextcord.Message = await channel.fetch_message(group.MessageId)
await table_message.delete() await message.delete()
except nextcord.NotFound: except nextcord.NotFound:
# silently ignore that messages are not found. They got deleted already. # silently ignore that messages are not found. They got deleted already.
pass pass
await interaction.send("Table messages deleted.", ephemeral=True) await interaction.send("Highscore messages deleted.", ephemeral=True)
@all.subcommand( @all.subcommand(
description="Removes all of a user's scores. Warning: data is destroyed, use with case.", description="Removes all of a user's scores. Warning: data is destroyed, use with care.",
) )
async def users( async def users(
self, self,
@@ -90,7 +90,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
""" """
Searches all of guild's scores data for any score from the user and removes. Searches all of guild's scores data for any score from the user and removes.
Updates table message is user was removed from that table. Updates highscore message if user was removed from that Category Group.
Args: Args:
interaction (nextcord.Interaction): Interaction that invoked the command. interaction (nextcord.Interaction): Interaction that invoked the command.
@@ -112,7 +112,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
for group in session.scalars(stmt): for group in session.scalars(stmt):
await send_highscore_message(session, interaction.guild, group) await send_highscore_message(session, interaction.guild, group)
await interaction.send(f'User "{user_name}" was removed from all tables.', ephemeral=True) await interaction.send(f'User "{user_name}" was removed from all Category Groups.', ephemeral=True)
@delete.subcommand(description="Delete a category from a group. Deletion is perminant.") @delete.subcommand(description="Delete a category from a group. Deletion is perminant.")
async def category( async def category(
@@ -225,7 +225,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
@group.on_autocomplete("group_id") @group.on_autocomplete("group_id")
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None: async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
""" """
Autocomplete function for table names. Autocomplete function for group names.
Args: Args:
interaction (nextcord.Interaction): Interaction that invoked the command. interaction (nextcord.Interaction): Interaction that invoked the command.
@@ -264,7 +264,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
""" """
await interaction.response.send_autocomplete( await interaction.response.send_autocomplete(
autofill_users_in_group_category( autofill_users_in_group_category(
interaction.guild_id, int(group_id), category_id if category_id else 0, user_name interaction.guild_id, int(group_id), int(category_id) if category_id else 0, user_name
) )
) )
+1 -1
View File
@@ -27,7 +27,7 @@ class HelpCog(commands.Cog, name="Help commands."):
help_str: str = "Welcome to Agon! Three simple steps are needed to get started." help_str: str = "Welcome to Agon! Three simple steps are needed to get started."
help_str += '1.) Set a channel to receive submission verifications with "/set verify_channel."\n' help_str += '1.) Set a channel to receive submission verifications with "/set verify_channel."\n'
help_str += "This channel is used to allow moderators to check if a submission is real/valid.\n\n" help_str += "This channel is used to allow moderators to check if a submission is real/valid.\n\n"
help_str += '2.) Set up your highscore tables! Use "/create group" to first create a group message in the' help_str += '2.) Set up your highscores! Use "/create group" to first create a group message in the'
help_str += 'channel you would like and then use "/create category" to create a category in that group message!' help_str += 'channel you would like and then use "/create category" to create a category in that group message!'
help_str += "\n\n" help_str += "\n\n"
help_str += '3.) Users can then submit scores with the "/submit" command.' help_str += '3.) Users can then submit scores with the "/submit" command.'
+13 -20
View File
@@ -14,13 +14,11 @@ from utilities.utils import autofill_groups, send_highscore_message
class RefreshCog(commands.Cog, name="Refresh Cog"): class RefreshCog(commands.Cog, name="Refresh Cog"):
""" """Class holds commands for refreshing."""
Class holds commands for refreshing.
"""
def __init__(self, bot: commands.Bot) -> None: def __init__(self, bot: commands.Bot) -> None:
""" """
Default constructor for RefreshCog class Default constructor for RefreshCog class.
Args: Args:
bot (commands.Bot): Bot object. Required to register submission button view. bot (commands.Bot): Bot object. Required to register submission button view.
@@ -28,19 +26,17 @@ class RefreshCog(commands.Cog, name="Refresh Cog"):
self._bot = bot self._bot = bot
@nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True)) @nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
async def refresh(self, interaction: nextcord.Interaction): async def refresh(self, interaction: nextcord.Interaction) -> None:
""" """Parent slash command for refreshing things. Never called."""
Parent slash command for refreshing things. Never called.
"""
@refresh.subcommand(description="Manually refresh a table. Use when changing settings or data manually changed.") @refresh.subcommand(description="Manually refresh a group. Use when changing settings or data manually changed.")
async def group( async def group(
self, self,
interaction: nextcord.Interaction, interaction: nextcord.Interaction,
group_id: str = nextcord.SlashOption(name="group", description="Name of Group.", required=True), group_id: str = nextcord.SlashOption(name="group", description="Name of Group.", required=True),
) -> None: ) -> None:
""" """
Refreshes a table given by user. Refreshes a group given by user.
Args: Args:
interaction (nextcord.Interaction): Interaction that invoked the command. interaction (nextcord.Interaction): Interaction that invoked the command.
@@ -57,22 +53,19 @@ class RefreshCog(commands.Cog, name="Refresh Cog"):
message: nextcord.Message = await send_highscore_message(session, interaction.guild, group) message: nextcord.Message = await send_highscore_message(session, interaction.guild, group)
await message.edit(view=SubmissionCreateButton(self._bot)) await message.edit(view=SubmissionCreateButton(self._bot))
await interaction.response.send_message(f"Updated table {group.GroupName}!", ephemeral=True) await interaction.response.send_message(f"Updated group {group.GroupName}!", ephemeral=True)
@refresh.subcommand() @refresh.subcommand()
async def all(self, interaction: nextcord.Interaction): async def all(self, interaction: nextcord.Interaction) -> None:
""" """Subcommand parent for refreshing all things. Never called."""
Subcommand parent for refreshing all things. Never called.
"""
@all.subcommand(description="Triggers post/update of highscores to registered highscore channels.") @all.subcommand(description="Triggers post/update of highscores to registered highscore channels.")
async def groups(self, interaction: nextcord.Interaction) -> None: async def groups(self, interaction: nextcord.Interaction) -> None:
""" """
A command which posts the highscore in the registered channel. A command which posts the highscore in the registered channel.
Sends warning if no channel has been registered.
Either creates new messages for each table if one doesn't exist Sends warning if no channel has been registered. Either creates new messages for each group if one doesn't
or edits the existing message. exist or edits the existing message.
Args: Args:
interaction (nextcord.Interaction): Interaction that invoked the command. interaction (nextcord.Interaction): Interaction that invoked the command.
@@ -90,9 +83,9 @@ class RefreshCog(commands.Cog, name="Refresh Cog"):
await interaction.send(f"Posted all groups in {interaction.guild.name}'s highscores.", ephemeral=True) await interaction.send(f"Posted all groups in {interaction.guild.name}'s highscores.", ephemeral=True)
@group.on_autocomplete("group_id") @group.on_autocomplete("group_id")
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str): async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
""" """
Collects list of table names and compares to input table name for autocomplete assistance. Collects list of group names and compares to input group name for autocomplete assistance.
Args: Args:
interaction (nextcord.Interaction): Interaction with command. interaction (nextcord.Interaction): Interaction with command.
+1 -1
View File
@@ -208,7 +208,7 @@ class SubmissionCog(commands.Cog):
@submit.on_autocomplete("group_id") @submit.on_autocomplete("group_id")
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None: async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
""" """
Autocomplete function for table names. Autocomplete function for group names.
Args: Args:
interaction (nextcord.Interaction): Interaction that invoked the command. interaction (nextcord.Interaction): Interaction that invoked the command.
+3 -3
View File
@@ -87,9 +87,9 @@ class ViewCog(commands.Cog, name="View Command"):
await interaction.response.send_message(content=message_str) await interaction.response.send_message(content=message_str)
@leaderboard.on_autocomplete("group_id") @leaderboard.on_autocomplete("group_id")
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str): async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
""" """
Autocomplete function for table names. Autocomplete function for group names.
Args: Args:
interaction (nextcord.Interaction): Interaction that invoked the command. interaction (nextcord.Interaction): Interaction that invoked the command.
@@ -98,7 +98,7 @@ class ViewCog(commands.Cog, name="View Command"):
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id)) await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
@leaderboard.on_autocomplete("category_id") @leaderboard.on_autocomplete("category_id")
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str): async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str) -> None:
""" """
Autocomplete function for category names. Autocomplete function for category names.
-29
View File
@@ -2,7 +2,6 @@
Contains various utlity functions for highscores bot Contains various utlity functions for highscores bot
""" """
import json
import time import time
import nextcord import nextcord
@@ -400,31 +399,3 @@ async def submit_score(
group = session.scalar(stmt) group = session.scalar(stmt)
await send_highscore_message(session, interaction.guild, group) await send_highscore_message(session, interaction.guild, group)
def add_preset_configuration(guild_id: int, config_str: str) -> None:
"""
Adds an example configuration to a Guild. Uses guild id to know which guild and
config name to open a file in example_config.
Args:
guild_id (int): Guild id to add config to
config_str (str): Config name to add
"""
with Session(engine) as session:
with open(f"example_config/{config_str}.json", encoding="utf-8") as file:
config = json.load(file)
for group_name, categorys in config["tables"].items():
group_obj = CategoryGroup(GroupName=group_name, GuildId=guild_id)
session.add(group_obj)
for category_name in categorys:
cat_obj = Category(
CategoryName=category_name,
Size=config["table_size"],
IsTimeRecord=config["categories"][category_name]["is_time_record"],
IsAscending=config["categories"][category_name]["ascending"],
)
session.add(cat_obj)
session.commit()