Clarify parameter name for users, correct id usage for autofills.

This commit is contained in:
alwayscompiling
2022-12-02 17:02:44 -05:00
parent bed07d440b
commit 52305c0107
4 changed files with 28 additions and 20 deletions
+17 -13
View File
@@ -57,7 +57,7 @@ class DataManagementCog(commands.Cog, name="Table Management"):
async def from_all(
self,
interaction: nextcord.Interaction,
username: str = nextcord.SlashOption(
user_name: str = nextcord.SlashOption(
description="User to remove scores for. Note: This is not always a user's discord name.", required=True
),
):
@@ -67,13 +67,13 @@ class DataManagementCog(commands.Cog, name="Table Management"):
Args:
interaction (nextcord.Interaction): Interaction that invoked the command.
username (str): User to remove from highscores
user_name (str): User to remove from highscores
"""
stmt = select(distinct(Score.CategoryId)).where(Score.UserName == username)
stmt = select(distinct(Score.CategoryId)).where(Score.UserName == user_name)
category_ids: "list[int]" = list(session.scalars(stmt))
stmt = select(Score).where(Score.UserName == username)
stmt = select(Score).where(Score.UserName == user_name)
for score in session.scalars(stmt):
session.delete(score)
session.commit()
@@ -85,14 +85,16 @@ class DataManagementCog(commands.Cog, name="Table Management"):
for group in session.scalars(stmt):
await send_highscore_message(interaction.guild.get_channel(group.ChannelId), group)
await interaction.send(f'User "{username}" was removed from all tables.')
await interaction.send(f'User "{user_name}" was removed from all tables.')
@user.subcommand(description="Deletes a user's scores from a category.")
async def from_category(
self,
interaction: nextcord.Interaction,
group_id: str = nextcord.SlashOption(description="Group to delete user from.", required=True),
category_id: str = nextcord.SlashOption(description="Category to delete user from.", required=True),
group_id: str = nextcord.SlashOption(name="Group", description="Group to delete user from.", required=True),
category_id: str = nextcord.SlashOption(
name="Category", description="Category to delete user from.", required=True
),
user_name: str = nextcord.SlashOption(description="User to delete.", required=True),
):
"""
@@ -124,7 +126,7 @@ class DataManagementCog(commands.Cog, name="Table Management"):
async def from_group(
self,
interaction: nextcord.Interaction,
group_id: str = nextcord.SlashOption(description="Group to delete user from.", required=True),
group_id: str = nextcord.SlashOption(name="Group", description="Group to delete user from.", required=True),
user_name: str = nextcord.SlashOption(description="User to delete.", required=True),
):
"""
@@ -150,13 +152,13 @@ class DataManagementCog(commands.Cog, name="Table Management"):
@from_category.on_autocomplete("group_id")
@from_group.on_autocomplete("group_id")
async def autocomplete_table(self, interaction: nextcord.Interaction, group_id: str):
async def autocomplete_group(self, interaction: nextcord.Interaction, group_id: str):
"""
Autocomplete function for table names.
Args:
interaction (nextcord.Interaction): Interaction that invoked the command.
group_id (str): String to be autocompleted with Table name.
group_id (str): String to be autocompleted with Group name.
"""
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
@@ -168,9 +170,11 @@ class DataManagementCog(commands.Cog, name="Table Management"):
Args:
interaction (nextcord.Interaction): Interaction that invoked the command.
category_id (str): String to be autocompleted with Category name.
group_id (str): Table to find Category from.
group_id (str): Group to find Category from.
"""
await interaction.response.send_autocomplete(autofill_categories(interaction.guild_id, group_id, category_id))
await interaction.response.send_autocomplete(
autofill_categories(interaction.guild_id, int(group_id), category_id)
)
@from_category.on_autocomplete("user_name")
@from_group.on_autocomplete("user_name")
@@ -220,7 +224,7 @@ class DataManagementCog(commands.Cog, name="Table Management"):
await interaction.send("Request sent to admins for verification.", ephemeral=True)
@update_username.on_autocomplete("old_username")
@from_all.on_autocomplete("username")
@from_all.on_autocomplete("user_name")
async def username_autofill(self, interaction: nextcord.Interaction, username: str):
"""
Sends response from autofill_users_in_guild back to update_username for autocompletion of old_username.
+2 -2
View File
@@ -2,7 +2,7 @@
Commands for managing/displaying the highscores messages.
"""
from typing import Optional, Union
from typing import Optional
import nextcord
from nextcord.ext import commands
@@ -115,7 +115,7 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
async def refresh_group(
self,
interaction: nextcord.Interaction,
group_id: str = nextcord.SlashOption(description="Name of table.", required=True),
group_id: str = nextcord.SlashOption(name="Group", description="Name of Group.", required=True),
) -> None:
"""
Refreshes a table given by user.
+6 -2
View File
@@ -33,7 +33,9 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
async def group_output_channel(
self,
interaction: nextcord.Interaction,
group_id: str = nextcord.SlashOption(description="Category Group to assign to channel.", required=True),
group_id: str = nextcord.SlashOption(
name="Group", description="Category Group to assign to channel.", required=True
),
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
description="Channel to register",
required=False,
@@ -131,7 +133,9 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
async def category_pad_length(
self,
interaction: nextcord.Interaction,
group_id: str = nextcord.SlashOption(description="Category Group to assign pad length to.", required=True),
group_id: str = nextcord.SlashOption(
name="Group", description="Category Group to assign pad length to.", required=True
),
length: int = nextcord.SlashOption(description="Number of characters.", required=True, default=26),
) -> None:
"""
+3 -3
View File
@@ -16,14 +16,14 @@ from utilities.sql_alchemy_connection import Category, CategoryGroup, Guild, Sco
MAX_LINE_LENGTH = 142
def autofill_categories(guild_id: int, group_name: str, category_begin: str) -> "dict[str, str]":
def autofill_categories(guild_id: int, group_id: int, category_begin: str) -> "dict[str, str]":
"""
Returns all category names that start with category_begin.
If category_begin is empty, returns list of all category names.
Args:
guild_id (int): Guild id that holds the group and categories.
group_name (str): Group name to search in.
group_id (int): Group id to search in.
category_begin (str): The beginning of a category name to search with. Can be empty.
Returns:
@@ -34,7 +34,7 @@ def autofill_categories(guild_id: int, group_name: str, category_begin: str) ->
subq = (
select(CategoryGroup)
.where(CategoryGroup.GuildId == guild_id)
.where(CategoryGroup.GroupName == group_name)
.where(CategoryGroup.GroupId == group_id)
.subquery()
)
cat_group_alias = aliased(CategoryGroup, subq)