Add category and group subcommand structure.
This commit is contained in:
+49
-45
@@ -22,7 +22,11 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
async def set(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for setting settings. Never called."""
|
||||
|
||||
@set.subcommand(description="")
|
||||
@set.subcommand("Commands for editing a category.")
|
||||
async def category(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash subcommand for setting category settings. Never called."""
|
||||
|
||||
@category.subcommand(description="Update the number of entries to show for a category.", name="size")
|
||||
async def category_size(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
@@ -67,43 +71,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
await interaction.response.send_message(f"{category.name} size has been updated to {size}.", ephemeral=True)
|
||||
|
||||
@set.subcommand(description="Registers the channel for a Category Group's messages.")
|
||||
async def group_output_channel(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(
|
||||
name="group", description="Category Group to assign to channel.", required=True
|
||||
),
|
||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
||||
description="Channel to register",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command function to register a CategoryGroup's output channel.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||
channel (nextcord.abc.GuildChannel, optional): Channel to register.
|
||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||
"""
|
||||
channel_id = interaction.channel.id if not channel else channel.id
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.id) == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
group.ChannelId = channel_id
|
||||
session.commit()
|
||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||
|
||||
@set.subcommand(description="Update the is_ascending value for a category.")
|
||||
@category.subcommand(description="Update the is_ascending value for a category.")
|
||||
async def is_ascending(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
@@ -155,15 +123,51 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
f"{category.name} is_ascending has been updated to {ascending}.", ephemeral=True
|
||||
)
|
||||
|
||||
@set.subcommand(
|
||||
@set.subcommand(description="Commands for editing a group.")
|
||||
async def group(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash subcommand for setting group settings. Never called."""
|
||||
|
||||
@group.subcommand(description="Registers the channel for a Group's messages.")
|
||||
async def output_channel(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group to assign to channel.", required=True),
|
||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
||||
description="Channel to register",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command function to register a CategoryGroup's output channel.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||
channel (nextcord.abc.GuildChannel, optional): Channel to register.
|
||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||
"""
|
||||
channel_id = interaction.channel.id if not channel else channel.id
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.id) == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
group.ChannelId = channel_id
|
||||
session.commit()
|
||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||
|
||||
@group.subcommand(
|
||||
description="Set character length for a category. Can cut off username/score. Affects all categories."
|
||||
)
|
||||
async def pad_length(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(
|
||||
name="group", description="Category Group to assign pad length to.", required=True
|
||||
),
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group to assign pad length to.", required=True),
|
||||
length: int = nextcord.SlashOption(
|
||||
description="Number of characters alloted to a category.",
|
||||
required=True,
|
||||
@@ -193,7 +197,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
f"Category pad length set to {length} for {group.name}", ephemeral=True
|
||||
)
|
||||
|
||||
@set.subcommand(
|
||||
@group.subcommand(
|
||||
description="Registers the channel for submission messages. Currently this information is deprecated."
|
||||
)
|
||||
async def submission_channel(
|
||||
@@ -223,7 +227,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
session.commit()
|
||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||
|
||||
@set.subcommand(description="Set username length for a Group of Categories.")
|
||||
@group.subcommand(description="Set username length for a Group of Categories.")
|
||||
async def username_length(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
@@ -297,7 +301,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
)
|
||||
|
||||
@category_size.on_autocomplete("group_id")
|
||||
@group_output_channel.on_autocomplete("group_id")
|
||||
@output_channel.on_autocomplete("group_id")
|
||||
@is_ascending.on_autocomplete("group_id")
|
||||
@pad_length.on_autocomplete("group_id")
|
||||
@username_length.on_autocomplete("group_id")
|
||||
|
||||
Reference in New Issue
Block a user