Corrected autofill function return structures.
This commit is contained in:
@@ -91,8 +91,8 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
||||
async def from_category(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: int = nextcord.SlashOption(description="Group to delete user from.", required=True),
|
||||
category_id: int = nextcord.SlashOption(description="Category to delete user from.", required=True),
|
||||
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),
|
||||
user_name: str = nextcord.SlashOption(description="User to delete.", required=True),
|
||||
):
|
||||
"""
|
||||
@@ -100,21 +100,25 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (int): Group to remove user from. Is SlashOption.
|
||||
category_id (int): Category to remove user from. Is SlashOption.
|
||||
group_id (str): String representation of Group id to remove user from. Is SlashOption.
|
||||
category_id (str): String representation of Category id to remove user from. Is SlashOption.
|
||||
user_name (str): The user to remove. Is SlashOption.
|
||||
"""
|
||||
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == group_id)
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
||||
group = session.scalar(stmt)
|
||||
stmt = select(Score).where(Score.CategoryId == category_id)
|
||||
|
||||
stmt = select(Category.CategoryName).where(Category.CategoryId == int(category_id))
|
||||
category_name = session.scalar(stmt)
|
||||
|
||||
stmt = select(Score).where(Score.CategoryId == int(category_id))
|
||||
|
||||
for score in session.scalars(stmt):
|
||||
session.delete(score)
|
||||
session.commit()
|
||||
|
||||
await send_highscore_message(interaction.guild.get_channel(group.ChannelId), group)
|
||||
await interaction.response.send_message(f'User "{user_name}" removed from "{category_id}".', ephemeral=True)
|
||||
await interaction.response.send_message(f'User "{user_name}" removed from "{category_name}".', ephemeral=True)
|
||||
|
||||
@user.subcommand(description="Deletes a user's scores from entire group.")
|
||||
async def from_group(
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Commands for managing/displaying the highscores messages.
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
from typing import Optional, Union
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
@@ -115,20 +115,20 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
||||
async def refresh_group(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: int = nextcord.SlashOption(description="Name of table.", required=True),
|
||||
group_id: 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.
|
||||
group_id (int): Group id to refresh. Is SlashOption.
|
||||
group_id (str): Str representation of Group id to refresh. Is SlashOption.
|
||||
"""
|
||||
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.GroupId == group_id)
|
||||
.where(CategoryGroup.GroupId == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
|
||||
|
||||
+10
-9
@@ -16,7 +16,7 @@ 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) -> "list[str]":
|
||||
def autofill_categories(guild_id: int, group_name: str, 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.
|
||||
@@ -27,7 +27,7 @@ def autofill_categories(guild_id: int, group_name: str, category_begin: str) ->
|
||||
category_begin (str): The beginning of a category name to search with. Can be empty.
|
||||
|
||||
Returns:
|
||||
list[str]: List of all category names that start with category_begin.
|
||||
dict[str, str]: List of all category names that start with category_begin.
|
||||
"""
|
||||
|
||||
# search database for all category names
|
||||
@@ -39,7 +39,7 @@ def autofill_categories(guild_id: int, group_name: str, category_begin: str) ->
|
||||
)
|
||||
cat_group_alias = aliased(CategoryGroup, subq)
|
||||
stmt = select(Category).where(Category.GroupId == cat_group_alias.GroupId)
|
||||
categories_dict: dict = {cat.CategoryName: cat.CategoryId for cat in session.scalars(stmt)}
|
||||
categories_dict: dict = {cat.CategoryName: str(cat.CategoryId) for cat in session.scalars(stmt)}
|
||||
|
||||
# if string empty, return all category names
|
||||
if not category_begin:
|
||||
@@ -48,14 +48,14 @@ def autofill_categories(guild_id: int, group_name: str, category_begin: str) ->
|
||||
# else find all categories that start with category_begin
|
||||
# TODO is it better to have sql handle the starts with or python?
|
||||
categories: dict = {
|
||||
cat.CategoryName: cat.CategoryId
|
||||
for cat in categories_dict.items()
|
||||
if category_begin.lower() in cat.CategoryName.lower()
|
||||
cat_name: cat_id
|
||||
for cat_name, cat_id in categories_dict.items()
|
||||
if category_begin.lower() in cat_name.CategoryName.lower()
|
||||
}
|
||||
return categories
|
||||
|
||||
|
||||
def autofill_groups(guild_id: int, group_begin: str) -> dict:
|
||||
def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
||||
"""
|
||||
Returns all group names that start with group_begin. If group_begin is empty, returns list of all group names.
|
||||
|
||||
@@ -64,13 +64,14 @@ def autofill_groups(guild_id: int, group_begin: str) -> dict:
|
||||
group_begin (str): The beginning of a group name to search with. Can be empty.
|
||||
|
||||
Returns:
|
||||
dict: Dict of group names and ids where group name start with group_begin. Key is name, value is id.
|
||||
dict[str, str]: Dict of group names and ids where group name start with group_begin. Key is name, value is id.
|
||||
"""
|
||||
|
||||
# Select all groups in guild.
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == guild_id)
|
||||
|
||||
group_dict: dict = {group.GroupName: group.GroupId for group in session.scalars(stmt)}
|
||||
# dict has to have key values of same type for discord.
|
||||
group_dict: dict = {group.GroupName: str(group.GroupId) for group in session.scalars(stmt)}
|
||||
|
||||
# if string empty, return all group names
|
||||
if not group_begin:
|
||||
|
||||
Reference in New Issue
Block a user