Update functions for username length being in group.

This commit is contained in:
alwayscompiling
2022-12-04 10:54:54 -05:00
parent b7dd44a028
commit f4ec272567
3 changed files with 58 additions and 44 deletions
+28 -20
View File
@@ -159,8 +159,36 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
f"Category pad length set to {length} for {group.GroupName}", ephemeral=True
)
@set.subcommand(description="Set username length for a Group of Categories.")
async def username_length(
self,
interaction: nextcord.Interaction,
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),
) -> None:
"""
Changes guild's username length limit.
Args:
interaction (nextcord.Interaction): Interaction that invoked the command
length (int): Number of characters. Is SlashOption. Defaults to 12.
"""
stmt = (
select(CategoryGroup)
.where(CategoryGroup.GuildId == interaction.guild_id)
.where(CategoryGroup.GroupId == int(group_id))
)
group = session.scalar(stmt)
group.UsernameLength = length
session.commit()
await interaction.response.send_message(f"Username length set to {length}.", ephemeral=True)
@group_output_channel.on_autocomplete("group_id")
@category_pad_length.on_autocomplete("group_id")
@username_length.on_autocomplete("group_id")
async def group_id_autocomplete(self, interaction: nextcord.Interaction, group_id: str):
"""
Sends results from autofill_groups back to group_output_channel for autocompletion of group_id.
@@ -170,23 +198,3 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
group_id (str): String to run autocompletion against.
"""
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
@set.subcommand(description="Set username length. Limits all submissions to this length.")
async def username_length(
self,
interaction: nextcord.Interaction,
length: int = nextcord.SlashOption(description="Number of characters.", required=True, default=12),
) -> None:
"""
Changes guild's username length limit.
Args:
interaction (nextcord.Interaction): Interaction that invoked the command
length (int): Number of charactesr. Is SlashOption. Defaults to 12.
"""
stmt = select(Guild).where(Guild.GuildId == interaction.guild_id)
guild = session.scalar(stmt)
guild.UsernameLength = length
session.commit()
await interaction.response.send_message(f"Username length set to {length}", ephemeral=True)