Clarify parameter name for users, correct id usage for autofills.
This commit is contained in:
@@ -57,7 +57,7 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
|||||||
async def from_all(
|
async def from_all(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
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
|
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:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
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))
|
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):
|
for score in session.scalars(stmt):
|
||||||
session.delete(score)
|
session.delete(score)
|
||||||
session.commit()
|
session.commit()
|
||||||
@@ -85,14 +85,16 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
|||||||
for group in session.scalars(stmt):
|
for group in session.scalars(stmt):
|
||||||
await send_highscore_message(interaction.guild.get_channel(group.ChannelId), group)
|
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.")
|
@user.subcommand(description="Deletes a user's scores from a category.")
|
||||||
async def from_category(
|
async def from_category(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
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),
|
||||||
category_id: str = nextcord.SlashOption(description="Category 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),
|
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(
|
async def from_group(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
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),
|
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_category.on_autocomplete("group_id")
|
||||||
@from_group.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.
|
Autocomplete function for table names.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
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))
|
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||||
|
|
||||||
@@ -168,9 +170,11 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
category_id (str): String to be autocompleted with Category name.
|
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_category.on_autocomplete("user_name")
|
||||||
@from_group.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)
|
await interaction.send("Request sent to admins for verification.", ephemeral=True)
|
||||||
|
|
||||||
@update_username.on_autocomplete("old_username")
|
@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):
|
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.
|
Sends response from autofill_users_in_guild back to update_username for autocompletion of old_username.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
Commands for managing/displaying the highscores messages.
|
Commands for managing/displaying the highscores messages.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Optional, Union
|
from typing import Optional
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
@@ -115,7 +115,7 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
|||||||
async def refresh_group(
|
async def refresh_group(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
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:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Refreshes a table given by user.
|
Refreshes a table given by user.
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
async def group_output_channel(
|
async def group_output_channel(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
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(
|
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
@@ -131,7 +133,9 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
async def category_pad_length(
|
async def category_pad_length(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
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),
|
length: int = nextcord.SlashOption(description="Number of characters.", required=True, default=26),
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
+3
-3
@@ -16,14 +16,14 @@ from utilities.sql_alchemy_connection import Category, CategoryGroup, Guild, Sco
|
|||||||
MAX_LINE_LENGTH = 142
|
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.
|
Returns all category names that start with category_begin.
|
||||||
If category_begin is empty, returns list of all category names.
|
If category_begin is empty, returns list of all category names.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
guild_id (int): Guild id that holds the group and categories.
|
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.
|
category_begin (str): The beginning of a category name to search with. Can be empty.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -34,7 +34,7 @@ def autofill_categories(guild_id: int, group_name: str, category_begin: str) ->
|
|||||||
subq = (
|
subq = (
|
||||||
select(CategoryGroup)
|
select(CategoryGroup)
|
||||||
.where(CategoryGroup.GuildId == guild_id)
|
.where(CategoryGroup.GuildId == guild_id)
|
||||||
.where(CategoryGroup.GroupName == group_name)
|
.where(CategoryGroup.GroupId == group_id)
|
||||||
.subquery()
|
.subquery()
|
||||||
)
|
)
|
||||||
cat_group_alias = aliased(CategoryGroup, subq)
|
cat_group_alias = aliased(CategoryGroup, subq)
|
||||||
|
|||||||
Reference in New Issue
Block a user