From 43df7aeda735fe84adaeae10a55738e2e4101c72 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Tue, 4 Mar 2025 13:20:14 -0500 Subject: [PATCH] Fix lint smells and update model usage in update. --- cogs/commands/update.py | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/cogs/commands/update.py b/cogs/commands/update.py index 02c2d13..fc6aadd 100644 --- a/cogs/commands/update.py +++ b/cogs/commands/update.py @@ -1,22 +1,20 @@ -""" -Commands for updating information/variables held in database. -""" +"""Commands for updating information/variables held in database.""" import nextcord from nextcord.ext import commands from sqlalchemy import select from sqlalchemy.orm import Session +from sqlmodel import col -from database.db import Guild, engine +from database.db import engine +from database.models import Guild from utilities.utils import autofill_users_in_guild from .views.update_username_verify import UpdateUsernameVerifyView class UpdateCog(commands.Cog, name="Update commands."): - """ - Class holds commands and views needed for updating things in bot. - """ + """Class holds commands and views needed for updating things in bot.""" def __init__(self, bot: commands.Bot): """ @@ -28,17 +26,13 @@ class UpdateCog(commands.Cog, name="Update commands."): self._bot: commands.Bot = bot @commands.Cog.listener() - async def on_ready(self): - """ - Called when cog is loaded. Adds views required for DataManagement commands. - """ + async def on_ready(self) -> None: + """Called when cog is loaded. Adds views required for DataManagement commands.""" self._bot.add_view(UpdateUsernameVerifyView()) @nextcord.slash_command() - async def update(self, interaction: nextcord.Interaction): - """ - Parent slash command for updating things. Never called. - """ + async def update(self, interaction: nextcord.Interaction) -> None: + """Parent slash command for updating things. Never called.""" @update.subcommand(description="Request a username update. Admins must approve.") async def username( @@ -46,10 +40,11 @@ class UpdateCog(commands.Cog, name="Update commands."): interaction: nextcord.Interaction, old_username: str = nextcord.SlashOption(description="Username currently stored in highscores.", required=True), new_username: str = nextcord.SlashOption(description="Username to update to.", required=True), - ): + ) -> None: """ - Creates a request to send to admins for changing a username. Uses - UpdateUsernameVerifyView to do the work. + Creates a request to send to admins for changing a username. + + Uses UpdateUsernameVerifyView to do the work. Args: interaction (nextcord.Interaction): Interaction that invoked the command @@ -57,9 +52,13 @@ class UpdateCog(commands.Cog, name="Update commands."): new_username (str): Username to replace old with. """ with Session(engine) as session: - stmt = select(Guild.VerificationChannel).where(Guild.GuildId == interaction.guild_id) + stmt = select(col(Guild.verification_channel)).where(col(Guild.id) == interaction.guild_id) verify_channel = interaction.guild.get_channel(session.scalar(stmt)) + if not isinstance(verify_channel, nextcord.TextChannel): + await interaction.send("Verification channel not set. Cannot process request.", ephemeral=True) + return + embed: nextcord.Embed = nextcord.Embed(title="Username change request.") embed.add_field(name="Old Username", value=old_username) embed.add_field(name="New Username", value=new_username) @@ -71,12 +70,12 @@ class UpdateCog(commands.Cog, name="Update commands."): await interaction.send("Request sent to admins for verification.", ephemeral=True) @username.on_autocomplete("old_username") - async def all_users_autocomplete(self, interaction: nextcord.Interaction, username: str): + async def all_users_autocomplete(self, interaction: nextcord.Interaction, username: str) -> None: """ Sends response from autofill_users_in_guild back to update_username for autocompletion of old_username. Args: interaction (nextcord.Interaction): Interaction with command. - old_username (str): String to run autocompletion against. + username (str): String to run autocompletion against. """ await interaction.response.send_autocomplete(autofill_users_in_guild(interaction.guild_id, username))