Update settings management to new database.
This commit is contained in:
@@ -5,12 +5,10 @@ Cog loader. Adds all command cogs to the bot.
|
|||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
# Command classes
|
# Command classes
|
||||||
|
from .data_management import DataManagementCog
|
||||||
from .message_management import MessageManagementCog
|
from .message_management import MessageManagementCog
|
||||||
from .settings_management import SettingsManagementCog
|
from .settings_management import SettingsManagementCog
|
||||||
from .data_management import DataManagementCog
|
|
||||||
|
|
||||||
# Views for commands
|
|
||||||
from .views.update_username_verify import UpdateUsernameVerifyView
|
|
||||||
|
|
||||||
# This function will be called when this extension is loaded.
|
# This function will be called when this extension is loaded.
|
||||||
# It is necessary to add these functions to the bot.
|
# It is necessary to add these functions to the bot.
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ from typing import Optional
|
|||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
from sqlalchemy import select
|
||||||
|
|
||||||
from highscores import highscores_data # pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
|
from highscores import CategoryGroup, Guild, session
|
||||||
|
from utilities.utils import autofill_groups
|
||||||
|
|
||||||
|
|
||||||
class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
||||||
@@ -26,10 +29,11 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
Parent slash command, never called.
|
Parent slash command, never called.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@register.subcommand(description="Registers the channel for perminent highscores messages.")
|
@register.subcommand(description="Registers the channel for a Category Group's messages.")
|
||||||
async def highscore(
|
async def group_output_channel(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
|
category_group: nextcord.SlashOption(description="Category Group to assign to channel.", required=True),
|
||||||
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
@@ -38,7 +42,7 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
),
|
),
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Command function to register the highscore printing channel.
|
Command function to register a CategoryGroup's output channel.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||||
@@ -48,10 +52,15 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
if not channel:
|
if not channel:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
channel_id = channel.id
|
channel_id = channel.id
|
||||||
guild = highscores_data.get_guild(interaction.guild_id)
|
stmt = (
|
||||||
|
select(CategoryGroup)
|
||||||
|
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||||
|
.where(CategoryGroup.GroupId == category_group)
|
||||||
|
)
|
||||||
|
group = session.scalar(stmt)
|
||||||
|
group.ChannelId = channel_id
|
||||||
|
session.commit()
|
||||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
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.")
|
@register.subcommand(description="Registers the channel for submission messages.")
|
||||||
async def submission(
|
async def submission(
|
||||||
@@ -75,10 +84,11 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
if not channel:
|
if not channel:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
channel_id = channel.id
|
channel_id = channel.id
|
||||||
guild = highscores_data.get_guild(interaction.guild_id)
|
stmt = select(Guild).where(Guild.GuildId == interaction.guild_id)
|
||||||
|
guild = session.scalar(stmt)
|
||||||
|
guild.SubmissionChannel = channel_id
|
||||||
|
session.commit()
|
||||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
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.")
|
@register.subcommand(description="Registers the channel for verification messages.")
|
||||||
async def verify(
|
async def verify(
|
||||||
@@ -102,10 +112,11 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
if not channel:
|
if not channel:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
channel_id = channel.id
|
channel_id = channel.id
|
||||||
guild = highscores_data.get_guild(interaction.guild_id)
|
stmt = select(Guild).where(Guild.GuildId == interaction.guild_id)
|
||||||
|
guild = session.scalar(stmt)
|
||||||
|
guild.VerificationChannel = channel_id
|
||||||
|
session.commit()
|
||||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
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))
|
@nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
|
||||||
async def set(self, interaction: nextcord.Interaction):
|
async def set(self, interaction: nextcord.Interaction):
|
||||||
@@ -119,9 +130,8 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
async def category_pad_length(
|
async def category_pad_length(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
length: Optional[int] = nextcord.SlashOption(
|
category_group: nextcord.SlashOption(description="Category Group to assign to channel.", required=True),
|
||||||
description="Number of characters.", required=True, default=26
|
length: Optional[int] = nextcord.SlashOption(description="Number of characters.", required=True, default=26),
|
||||||
),
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Changes guild's category pad length.
|
Changes guild's category pad length.
|
||||||
@@ -131,20 +141,35 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
length (Optional[int]): Number of characters. Is SlashOption. Defaults to 26.
|
length (Optional[int]): Number of characters. Is SlashOption. Defaults to 26.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
guild = highscores_data.get_guild(interaction.guild_id)
|
stmt = (
|
||||||
guild.category_pad_length = length
|
select(CategoryGroup)
|
||||||
highscores_data.save_guild_data(guild)
|
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||||
await interaction.response.send_message(
|
.where(CategoryGroup.GroupId == category_group)
|
||||||
f"Category pad length set to {length}", ephemeral=True
|
|
||||||
)
|
)
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
@group_output_channel.on_autocomplete("category_group")
|
||||||
|
@category_pad_length.on_autocomplete("category_group")
|
||||||
|
async def group_id_autocomplete(self, interaction: nextcord.Interaction, category_group: str):
|
||||||
|
"""
|
||||||
|
Sends results from autofill_groups back to group_output_channel for autocompletion of categoru_group.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction with command.
|
||||||
|
category_group (str): String to run autocompletion against.
|
||||||
|
"""
|
||||||
|
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, category_group))
|
||||||
|
|
||||||
@set.subcommand(description="Set username length. Limits all submissions to this length.")
|
@set.subcommand(description="Set username length. Limits all submissions to this length.")
|
||||||
async def username_length(
|
async def username_length(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
length: Optional[int] = nextcord.SlashOption(
|
length: Optional[int] = nextcord.SlashOption(description="Number of characters.", required=True, default=12),
|
||||||
description="Number of characters.", required=True, default=12
|
|
||||||
),
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Changes guild's username length limit.
|
Changes guild's username length limit.
|
||||||
@@ -153,7 +178,9 @@ class SettingsManagementCog(commands.Cog, name="Settings Management"):
|
|||||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||||
length (Optional[int]): Number of charactesr. Is SlashOption. Defaults to 12.
|
length (Optional[int]): Number of charactesr. Is SlashOption. Defaults to 12.
|
||||||
"""
|
"""
|
||||||
guild = highscores_data.get_guild(interaction.guild_id)
|
|
||||||
guild.username_length = length
|
stmt = select(Guild).where(Guild.GuildId == interaction.guild_id)
|
||||||
highscores_data.save_guild_data(guild)
|
guild = session.scalar(stmt)
|
||||||
|
guild.UsernameLength = length
|
||||||
|
session.commit()
|
||||||
await interaction.response.send_message(f"Username length set to {length}", ephemeral=True)
|
await interaction.response.send_message(f"Username length set to {length}", ephemeral=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user