Add commands to edit username length and category pad.
This commit is contained in:
+24
-1
@@ -16,6 +16,7 @@ class Guild:
|
|||||||
Args:
|
Args:
|
||||||
guild_id (int): Discord Guild id of new Guild
|
guild_id (int): Discord Guild id of new Guild
|
||||||
"""
|
"""
|
||||||
|
self._category_pad_length: int = 25
|
||||||
self._guild_id: int = guild_id
|
self._guild_id: int = guild_id
|
||||||
self._highscore_channel_id: int = 0
|
self._highscore_channel_id: int = 0
|
||||||
self._submission_channel_id: int = 0
|
self._submission_channel_id: int = 0
|
||||||
@@ -45,6 +46,7 @@ class Guild:
|
|||||||
Guild: Populated Guild object
|
Guild: Populated Guild object
|
||||||
"""
|
"""
|
||||||
guild = cls(guild_id)
|
guild = cls(guild_id)
|
||||||
|
guild.category_pad_length = data["category_pad_length"]
|
||||||
guild.highscore_channel = data["highscore_channel_id"]
|
guild.highscore_channel = data["highscore_channel_id"]
|
||||||
guild.submission_channel = data["submission_channel_id"]
|
guild.submission_channel = data["submission_channel_id"]
|
||||||
guild.username_length = data["username_length"]
|
guild.username_length = data["username_length"]
|
||||||
@@ -56,10 +58,30 @@ class Guild:
|
|||||||
|
|
||||||
return guild
|
return guild
|
||||||
|
|
||||||
|
@property
|
||||||
|
def category_pad_length(self) -> int:
|
||||||
|
"""
|
||||||
|
Getter for Category Pad Length.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: Length to pad each category entry.
|
||||||
|
"""
|
||||||
|
return self._category_pad_length
|
||||||
|
|
||||||
|
@category_pad_length.setter
|
||||||
|
def category_pad_length(self, length: int) -> None:
|
||||||
|
"""
|
||||||
|
Setter for Category Pad Length.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
length (int): New length to set.
|
||||||
|
"""
|
||||||
|
self._category_pad_length = length
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def guild_id(self) -> int:
|
def guild_id(self) -> int:
|
||||||
"""
|
"""
|
||||||
Getter for Guild id
|
Getter for Guild id.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: Guild id
|
int: Guild id
|
||||||
@@ -190,6 +212,7 @@ class Guild:
|
|||||||
"""
|
"""
|
||||||
data: dict = {}
|
data: dict = {}
|
||||||
|
|
||||||
|
data["category_pad_length"] = self.category_pad_length
|
||||||
data["highscore_channel_id"] = self.highscore_channel
|
data["highscore_channel_id"] = self.highscore_channel
|
||||||
data["submission_channel_id"] = self.submission_channel
|
data["submission_channel_id"] = self.submission_channel
|
||||||
data["tables"] = {}
|
data["tables"] = {}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
Commands for managing the Guild's settings.
|
Commands for managing the Guild's settings.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from nextcord.ext import commands
|
from typing import Optional
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from highscores import highscores_data # pylint: disable=import-error
|
from highscores import highscores_data # pylint: disable=import-error
|
||||||
|
|
||||||
@@ -28,7 +30,7 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
async def highscore(
|
async def highscore(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
channel: nextcord.abc.GuildChannel = nextcord.SlashOption(
|
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
channel_types=[nextcord.ChannelType.text],
|
channel_types=[nextcord.ChannelType.text],
|
||||||
@@ -55,7 +57,7 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
async def submission(
|
async def submission(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
channel: nextcord.abc.GuildChannel = nextcord.SlashOption(
|
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
channel_types=[nextcord.ChannelType.text],
|
channel_types=[nextcord.ChannelType.text],
|
||||||
@@ -82,7 +84,7 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
async def verify(
|
async def verify(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
channel: nextcord.abc.GuildChannel = nextcord.SlashOption(
|
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
channel_types=[nextcord.ChannelType.text],
|
channel_types=[nextcord.ChannelType.text],
|
||||||
@@ -105,8 +107,53 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
guild.verification_channel = channel_id
|
guild.verification_channel = channel_id
|
||||||
highscores_data.save_guild_data(guild)
|
highscores_data.save_guild_data(guild)
|
||||||
|
|
||||||
# @nextcord.slash_command()
|
@nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
|
||||||
# async def set(self):
|
async def set(self, interaction: nextcord.Interaction):
|
||||||
# """
|
"""
|
||||||
# Parent slash command for setting settings. Never called.
|
Parent slash command for setting settings. Never called.
|
||||||
# """
|
"""
|
||||||
|
|
||||||
|
@set.subcommand(
|
||||||
|
description="Set character length for a category. Can cut off usernames if is too short. Affects all categories."
|
||||||
|
)
|
||||||
|
async def category_pad_length(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
length: Optional[int] = nextcord.SlashOption(
|
||||||
|
description="Number of characters.", required=True, default=25
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Changes guild's category pad length.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||||
|
length (int): Number of characters. Is SlashOption. Defaults to 25.
|
||||||
|
"""
|
||||||
|
|
||||||
|
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 (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)
|
||||||
|
|||||||
Reference in New Issue
Block a user