Variable name changes for clarification and fixing runtime issues.
This commit is contained in:
@@ -96,7 +96,7 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
||||
user_name: str = nextcord.SlashOption(description="User to delete.", required=True),
|
||||
):
|
||||
"""
|
||||
Removes a user from a category. Uses autofill functions to fill out group_id, category_name, and user_name.
|
||||
Removes a user from a category. Uses autofill functions to fill out group_id, category_id, and user_name.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
@@ -144,36 +144,34 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
||||
await send_highscore_message(interaction.guild.get_channel(group.ChannelId), group)
|
||||
await interaction.response.send_message(f'User "{user_name}" removed from all categories.', ephemeral=True)
|
||||
|
||||
@from_category.on_autocomplete("table_name")
|
||||
@from_group.on_autocomplete("table_name")
|
||||
async def autocomplete_table(self, interaction: nextcord.Interaction, table_name: str):
|
||||
@from_category.on_autocomplete("group_id")
|
||||
@from_group.on_autocomplete("group_id")
|
||||
async def autocomplete_table(self, interaction: nextcord.Interaction, group_id: str):
|
||||
"""
|
||||
Autocomplete function for table names.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
table_name (str): String to be autocompleted with Table name.
|
||||
group_id (str): String to be autocompleted with Table name.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, table_name))
|
||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||
|
||||
@from_category.on_autocomplete("category_name")
|
||||
async def autocomplete_category(self, interaction: nextcord.Interaction, category_name: str, table_name: str):
|
||||
@from_category.on_autocomplete("category_id")
|
||||
async def autocomplete_category(self, interaction: nextcord.Interaction, category_id: str, group_id: str):
|
||||
"""
|
||||
Autocomplete function for category names.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
category_name (str): String to be autocompleted with Category name.
|
||||
table_name (str): Table to find Category from.
|
||||
category_id (str): String to be autocompleted with Category name.
|
||||
group_id (str): Table to find Category from.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(
|
||||
autofill_categories(interaction.guild_id, table_name, category_name)
|
||||
)
|
||||
await interaction.response.send_autocomplete(autofill_categories(interaction.guild_id, group_id, category_id))
|
||||
|
||||
@from_category.on_autocomplete("user_name")
|
||||
@from_group.on_autocomplete("user_name")
|
||||
async def autocomplete_user(
|
||||
self, interaction: nextcord.Interaction, user_name: str, table_name: str, category_name: Optional[str]
|
||||
self, interaction: nextcord.Interaction, user_name: str, group_id: str, category_id: Optional[int] = 0
|
||||
):
|
||||
"""
|
||||
Autocomplete functions for user names.
|
||||
@@ -181,11 +179,11 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
user_name (str): String to be autocompleted with User name.
|
||||
table_name (str): Table to find category from.
|
||||
category_name (Optional[str]): Category to find User from, can be None.
|
||||
group_id (int): Group to find category from.
|
||||
category_id (Optional[int]): Category to find User from, can be 0.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(
|
||||
autofill_users_in_group_category(interaction.guild_id, table_name, category_name, user_name)
|
||||
autofill_users_in_group_category(interaction.guild_id, group_id, category_id, user_name)
|
||||
)
|
||||
|
||||
@nextcord.slash_command(description="Request a username update. Admins must approve.")
|
||||
|
||||
@@ -139,14 +139,14 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
||||
|
||||
await interaction.response.send_message(f"Updated table {group.GroupName}!", ephemeral=True)
|
||||
|
||||
@refresh_group.on_autocomplete("table_name")
|
||||
async def refresh_table_autofill(self, interaction: nextcord.Interaction, table_name: str):
|
||||
@refresh_group.on_autocomplete("group_id")
|
||||
async def refresh_table_autofill(self, interaction: nextcord.Interaction, group_id: str):
|
||||
"""
|
||||
Collects list of table names and compares to input table name for autocomplete assistance.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with command.
|
||||
table_name (str): String to run autocomplete compared to.
|
||||
group_id (str): String to run autocomplete compared to.
|
||||
"""
|
||||
|
||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, table_name))
|
||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||
|
||||
@@ -33,7 +33,9 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
||||
async def group_output_channel(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
category_group: nextcord.SlashOption(description="Category Group to assign to channel.", required=True),
|
||||
group_id: Optional[int] = nextcord.SlashOption(
|
||||
description="Category Group to assign to channel.", required=True
|
||||
),
|
||||
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
||||
description="Channel to register",
|
||||
required=False,
|
||||
@@ -46,6 +48,7 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||
group_id (Optional[int]): Group to register channel to. Is SlashOption.
|
||||
channel (nextcord.abc.GuildChannel, optional): Channel to register
|
||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||
"""
|
||||
@@ -55,7 +58,7 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.GroupId == category_group)
|
||||
.where(CategoryGroup.GroupId == group_id)
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
group.ChannelId = channel_id
|
||||
@@ -130,7 +133,9 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
||||
async def category_pad_length(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
category_group: nextcord.SlashOption(description="Category Group to assign to channel.", required=True),
|
||||
group_id: Optional[int] = nextcord.SlashOption(
|
||||
description="Category Group to assign to channel.", required=True
|
||||
),
|
||||
length: Optional[int] = nextcord.SlashOption(description="Number of characters.", required=True, default=26),
|
||||
) -> None:
|
||||
"""
|
||||
@@ -138,13 +143,14 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||
group_id (Optional[int]): Group to set pad length in. Is SlashOption.
|
||||
length (Optional[int]): Number of characters. Is SlashOption. Defaults to 26.
|
||||
"""
|
||||
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.GroupId == category_group)
|
||||
.where(CategoryGroup.GroupId == group_id)
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
group.PadLength = length
|
||||
@@ -153,17 +159,17 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
||||
f"Category pad length set to {length} for {group.GroupName}", ephemeral=True
|
||||
)
|
||||
|
||||
@group_output_channel.on_autocomplete("category_group")
|
||||
@category_pad_length.on_autocomplete("category_group")
|
||||
async def group_id_autocomplete(self, interaction: nextcord.Interaction, category_group: str):
|
||||
@group_output_channel.on_autocomplete("group_id")
|
||||
@category_pad_length.on_autocomplete("group_id")
|
||||
async def group_id_autocomplete(self, interaction: nextcord.Interaction, group_id: str):
|
||||
"""
|
||||
Sends results from autofill_groups back to group_output_channel for autocompletion of category_group.
|
||||
Sends results from autofill_groups back to group_output_channel for autocompletion of group_id.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with command.
|
||||
category_group (str): String to run autocompletion against.
|
||||
group_id (str): String to run autocompletion against.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, category_group))
|
||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||
|
||||
@set.subcommand(description="Set username length. Limits all submissions to this length.")
|
||||
async def username_length(
|
||||
|
||||
+8
-10
@@ -83,17 +83,15 @@ def autofill_groups(guild_id: int, group_begin: str) -> dict:
|
||||
return groups
|
||||
|
||||
|
||||
def autofill_users_in_group_category(
|
||||
guild_id: int, group_name: str, category_name: str, user_begin: str
|
||||
) -> "list[str]":
|
||||
def autofill_users_in_group_category(guild_id: int, group_id: int, category_id: int, user_begin: str) -> "list[str]":
|
||||
"""
|
||||
Returns list of users that match user_begin. Either all users in group or just users in category if category is
|
||||
not None. Might be expensive due to unioning all users in group.
|
||||
|
||||
Args:
|
||||
guild_id (int): Guild id corresponding to group and category.
|
||||
group_name (str): group to look in for category.
|
||||
category_name (str): Category to look in for users. Can be None if not looking for category.
|
||||
group_id (str): group to look in for category.
|
||||
category_id (str): Category to look in for users. Can be None if not looking for category.
|
||||
user_begin (str): Beginning of user name to search with. Can be empty.
|
||||
|
||||
Returns:
|
||||
@@ -104,22 +102,22 @@ def autofill_users_in_group_category(
|
||||
subq = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == guild_id)
|
||||
.where(CategoryGroup.GroupName == group_name)
|
||||
.where(CategoryGroup.GroupId == group_id)
|
||||
.subquery()
|
||||
)
|
||||
category_group = aliased(CategoryGroup, subq)
|
||||
|
||||
# If no category name, get all users in group.
|
||||
if category_name is None:
|
||||
# If no category id, get all users in group.
|
||||
if category_id == 0:
|
||||
subq = select(Category.CategoryId).where(Category.GroupId == category_group.GroupId).subquery()
|
||||
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(subq))
|
||||
|
||||
else:
|
||||
# get all users in category_name
|
||||
# get all users in category_id
|
||||
subq = (
|
||||
select(Category)
|
||||
.where(Category.GroupId == category_group.GroupId)
|
||||
.where(Category.CategoryName == category_name)
|
||||
.where(Category.CategoryId == category_id)
|
||||
.subquery()
|
||||
)
|
||||
category = aliased(Category, subq)
|
||||
|
||||
Reference in New Issue
Block a user