Add command to edit is_validated.
This commit is contained in:
+54
-3
@@ -47,7 +47,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
category_id (str): String representation of Category id to register channel to. Is SlashOption.
|
category_id (str): String representation of Category id to register channel to. Is SlashOption.
|
||||||
size (int): Size to set. Is SlashOption.
|
size (int): Size to set. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
stmt = select(Category).where(col(CategoryGroup.id == group_id)).where(col(Category.id) == int(category_id))
|
stmt = select(Category).where(col(CategoryGroup.id) == group_id).where(col(Category.id) == int(category_id))
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
category = session.scalar(stmt)
|
category = session.scalar(stmt)
|
||||||
@@ -95,7 +95,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
category_id (str): String representation of Category id to register channel to. Is SlashOption.
|
category_id (str): String representation of Category id to register channel to. Is SlashOption.
|
||||||
ascending (bool): Boolean to set. Determines whether scores are sorted ascending or not. Is SlashOption.
|
ascending (bool): Boolean to set. Determines whether scores are sorted ascending or not. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
stmt = select(Category).where(col(CategoryGroup.id == group_id)).where(col(Category.id) == int(category_id))
|
stmt = select(Category).where(col(CategoryGroup.id) == group_id).where(col(Category.id) == int(category_id))
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
category = session.scalar(stmt)
|
category = session.scalar(stmt)
|
||||||
@@ -122,6 +122,55 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
f"{category.name} is_ascending has been updated to {ascending}.", ephemeral=True
|
f"{category.name} is_ascending has been updated to {ascending}.", ephemeral=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@category.subcommand(description="Update the is_validated value for a category.")
|
||||||
|
async def is_validated(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
group_id: str = nextcord.SlashOption(
|
||||||
|
name="group", description="Category Group that Category is in.", required=True
|
||||||
|
),
|
||||||
|
category_id: str = nextcord.SlashOption(
|
||||||
|
name="category", description="Category to update is_ascending of.", required=True
|
||||||
|
),
|
||||||
|
validated: bool = nextcord.SlashOption( # noqa: FBT001
|
||||||
|
description="Whether the scores need to be validated.", required=True
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Command to update a category's is_validated boolean.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
|
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||||
|
category_id (str): String representation of Category id to register channel to. Is SlashOption.
|
||||||
|
validated (bool): Boolean to set. Determines whether scores are validated or not. Is SlashOption.
|
||||||
|
"""
|
||||||
|
stmt = select(Category).where(col(CategoryGroup.id) == group_id).where(col(Category.id) == int(category_id))
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
|
category = session.scalar(stmt)
|
||||||
|
if category is None:
|
||||||
|
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||||
|
return
|
||||||
|
category.is_validated = validated
|
||||||
|
# session.add(category) test if this is needed. SQLAlchemy can do the update without adding.
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
# Use the relationship to get group category is in.
|
||||||
|
group = category.category_group
|
||||||
|
if group is None:
|
||||||
|
agon_logger.warning(f"{category.name}:{category.id} group relationship was None.")
|
||||||
|
|
||||||
|
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == group_id)
|
||||||
|
group = session.scalar(stmt)
|
||||||
|
if group is None:
|
||||||
|
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f"{category.name} is_validated has been updated to {validated}.", ephemeral=True
|
||||||
|
)
|
||||||
|
|
||||||
@set.subcommand(description="Commands for editing a group.")
|
@set.subcommand(description="Commands for editing a group.")
|
||||||
async def group(self, interaction: nextcord.Interaction) -> None:
|
async def group(self, interaction: nextcord.Interaction) -> None:
|
||||||
"""Parent slash subcommand for setting group settings. Never called."""
|
"""Parent slash subcommand for setting group settings. Never called."""
|
||||||
@@ -290,6 +339,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
|
|
||||||
@category_size.on_autocomplete("category_id")
|
@category_size.on_autocomplete("category_id")
|
||||||
@is_ascending.on_autocomplete("category_id")
|
@is_ascending.on_autocomplete("category_id")
|
||||||
|
@is_validated.on_autocomplete("category_id")
|
||||||
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str) -> None:
|
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.
|
||||||
@@ -304,8 +354,9 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@category_size.on_autocomplete("group_id")
|
@category_size.on_autocomplete("group_id")
|
||||||
@output_channel.on_autocomplete("group_id")
|
|
||||||
@is_ascending.on_autocomplete("group_id")
|
@is_ascending.on_autocomplete("group_id")
|
||||||
|
@is_validated.on_autocomplete("group_id")
|
||||||
|
@output_channel.on_autocomplete("group_id")
|
||||||
@pad_length.on_autocomplete("group_id")
|
@pad_length.on_autocomplete("group_id")
|
||||||
@username_length.on_autocomplete("group_id")
|
@username_length.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:
|
||||||
|
|||||||
Reference in New Issue
Block a user