""" Commands for managing the Guild's settings. """ from typing import Optional import nextcord from nextcord.ext import commands from highscores import highscores_data # pylint: disable=import-error class SettingsManagementCog(commands.Cog, name="Settings Management"): """ Class holds commands for managing Guild's settings. """ def __init__(self) -> None: """ Default constructor for SettingsManagement class. Does nothing. """ @nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True)) async def register(self, interaction: nextcord.Interaction): """ Parent slash command, never called. """ @register.subcommand(description="Registers the channel for perminent highscores messages.") async def highscore( self, interaction: nextcord.Interaction, channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption( description="Channel to register", required=False, channel_types=[nextcord.ChannelType.text], default=None, ), ) -> None: """ Command function to register the highscore printing channel. Args: interaction (nextcord.Interaction): Interaction that invoked the command channel (nextcord.abc.GuildChannel, optional): Channel to register Is a SlashOption. Limited to text channels, Defaults to None. """ if not channel: channel = interaction.channel channel_id = channel.id guild = highscores_data.get_guild(interaction.guild_id) await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True) guild.highscore_channel = channel_id highscores_data.save_guild_data(guild) @register.subcommand(description="Registers the channel for submission messages.") async def submission( self, interaction: nextcord.Interaction, channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption( description="Channel to register", required=False, channel_types=[nextcord.ChannelType.text], default=None, ), ) -> None: """ Command function to register the submission message channel. Args: interaction (nextcord.Interaction): Interaction that invoked the command channel Optional[nextcord.abc.GuildChannel], optional): Channel to register Is a SlashOption. Limited to text channels, Defaults to None. """ if not channel: channel = interaction.channel channel_id = channel.id guild = highscores_data.get_guild(interaction.guild_id) await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True) guild.submission_channel = channel_id highscores_data.save_guild_data(guild) @register.subcommand(description="Registers the channel for verification messages.") async def verify( self, interaction: nextcord.Interaction, channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption( description="Channel to register", required=False, channel_types=[nextcord.ChannelType.text], default=None, ), ) -> None: """ Command function to register the verification message channel. Args: interaction (nextcord.Interaction): Interaction that invoked the command channel (Optional[nextcord.abc.GuildChannel], optional): Channel to register Is a SlashOption. Limited to text channels, Defaults to None. """ if not channel: channel = interaction.channel channel_id = channel.id guild = highscores_data.get_guild(interaction.guild_id) await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True) guild.verification_channel = channel_id highscores_data.save_guild_data(guild) @nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True)) async def set(self, interaction: nextcord.Interaction): """ 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, length: Optional[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 length (Optional[int]): Number of characters. Is SlashOption. Defaults to 26. """ guild = highscores_data.get_guild(interaction.guild_id) guild.category_pad_length = length highscores_data.save_guild_data(guild) await interaction.response.send_message( f"Category pad length set to {length}", ephemeral=True ) @set.subcommand(description="Set username length. Limits all submissions to this length.") async def username_length( self, interaction: nextcord.Interaction, length: Optional[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 (Optional[int]): Number of charactesr. Is SlashOption. Defaults to 12. """ guild = highscores_data.get_guild(interaction.guild_id) guild.username_length = length highscores_data.save_guild_data(guild) await interaction.response.send_message(f"Username length set to {length}", ephemeral=True)