Create command skeletons. Update set to conform to min and max values decided in create.

This commit is contained in:
alwayscompiling
2022-12-07 22:24:38 -05:00
parent 91e57c6555
commit 88cec73644
3 changed files with 133 additions and 37 deletions
+44 -36
View File
@@ -11,7 +11,7 @@ from sqlalchemy.orm import Session
# pylint: disable=import-error
from utilities.sql_data_classes import CategoryGroup, Guild, engine
from utilities.utils import autofill_groups
from utilities.utils import autofill_groups, MAX_LINE_LENGTH
class SetCog(commands.Cog, name="Set command."):
@@ -30,39 +30,6 @@ class SetCog(commands.Cog, name="Set command."):
Parent slash command for setting settings. Never called.
"""
@set.subcommand(
description="Set character length for a category. Can cut off username/score. Affects all categories."
)
async def category_pad_length(
self,
interaction: nextcord.Interaction,
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:
"""
Changes guild's category pad length.
Args:
interaction (nextcord.Interaction): Interaction that invoked the command
group_id (str): String representation of Group id to set pad length in. Is SlashOption.
length (int): Number of characters. Is SlashOption. Defaults to 26.
"""
with Session(engine) as session:
stmt = (
select(CategoryGroup)
.where(CategoryGroup.GuildId == interaction.guild_id)
.where(CategoryGroup.GroupId == int(group_id))
)
group = session.scalar(stmt)
group.PadLength = length
session.commit()
await interaction.response.send_message(
f"Category pad length set to {length} for {group.GroupName}", ephemeral=True
)
@set.subcommand(description="Registers the channel for a Category Group's messages.")
async def group_output_channel(
self,
@@ -101,6 +68,45 @@ class SetCog(commands.Cog, name="Set command."):
session.commit()
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
@set.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
),
length: int = nextcord.SlashOption(
description="Number of characters alloted to a category.",
required=True,
default=26,
min_value=7,
max_value=MAX_LINE_LENGTH,
),
) -> None:
"""
Changes guild's category pad length.
Args:
interaction (nextcord.Interaction): Interaction that invoked the command
group_id (str): String representation of Group id to set pad length in. Is SlashOption.
length (int): Number of characters. Is SlashOption. Defaults to 26.
"""
with Session(engine) as session:
stmt = (
select(CategoryGroup)
.where(CategoryGroup.GuildId == interaction.guild_id)
.where(CategoryGroup.GroupId == int(group_id))
)
group = session.scalar(stmt)
group.PadLength = length
session.commit()
await interaction.response.send_message(
f"Category pad length set to {length} for {group.GroupName}", ephemeral=True
)
@set.subcommand(description="Registers the channel for submission messages.")
async def submission_channel(
self,
@@ -139,7 +145,9 @@ class SetCog(commands.Cog, name="Set command."):
group_id: str = nextcord.SlashOption(
name="group", description="Group to change username length of.", required=True
),
length: int = nextcord.SlashOption(description="Number of characters.", required=True, default=12),
length: int = nextcord.SlashOption(
description="Number of characters.", required=True, default=12, min_value=1, max_value=30
),
) -> None:
"""
Changes guild's username length limit.
@@ -191,7 +199,7 @@ class SetCog(commands.Cog, name="Set command."):
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
@group_output_channel.on_autocomplete("group_id")
@category_pad_length.on_autocomplete("group_id")
@pad_length.on_autocomplete("group_id")
@username_length.on_autocomplete("group_id")
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str):
"""