From c8539ee094db6bb2c4c7638bd4bace5d8b8df48b Mon Sep 17 00:00:00 2001 From: Isaac Beh Date: Wed, 29 Nov 2023 21:36:33 +1000 Subject: [PATCH] Removed ids from registration db & removed advent from pyright exception list --- pyproject.toml | 1 - uqcsbot/advent.py | 15 ++++++++++----- uqcsbot/models.py | 7 ++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 18bc281..2989fa3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,6 @@ build-backend = "poetry.core.masonry.api" [tool.pyright] strict = ["**"] exclude = [ - "**/advent.py", "**/bot.py", "**/error_handler.py", "**/events.py", diff --git a/uqcsbot/advent.py b/uqcsbot/advent.py index cb3754f..641d5d4 100644 --- a/uqcsbot/advent.py +++ b/uqcsbot/advent.py @@ -640,7 +640,7 @@ async def register_command(self, interaction: discord.Interaction, aoc_name: str @advent_command_group.command(name="register-force") @app_commands.describe( year="The year of Advent of Code this registration is for.", - discord_id="The discord ID number of the user. Note that this is not their username.", + discord_id_str="The discord ID number of the user. Note that this is not their username.", aoc_name="The name shown on Advent of Code.", aoc_id="The AOC id of the user.", ) @@ -648,13 +648,14 @@ async def register_admin_command( self, interaction: discord.Interaction, year: int, - discord_id: int, + discord_id_str: str, # str as discord can't handle integers this big aoc_name: Optional[str] = None, aoc_id: Optional[int] = None, ): """ Forces a registration entry to be created. For admin use only. Either aoc_name or aoc_id should be given. """ + discord_id = int(discord_id_str) if (aoc_name is None and aoc_id is None) or ( aoc_name is not None and aoc_id is not None ): @@ -752,15 +753,16 @@ async def unregister_command(self, interaction: discord.Interaction): @advent_command_group.command(name="unregister-force") @app_commands.describe( year="Year that the registration is for", - discord_id="The discord id to remove. Note that this is not the username.", + discord_id_str="The discord id to remove. Note that this is not the username.", ) async def unregister_admin_command( - self, interaction: discord.Interaction, year: int, discord_id: int + self, interaction: discord.Interaction, year: int, discord_id_str: str ): """ Forces a registration entry to be removed. For admin use only; assumes you know what you are doing. """ + discord_id = int(discord_id_str) await interaction.response.defer(thinking=True) discord_user = self.bot.uqcs_server.get_member(discord_id) @@ -930,6 +932,9 @@ async def add_winners_command( content=f"There were not enough eligible users to select winners (at least {required_number_of_potential_winners} needed; only {len(potential_winners)} found)." ) return + number_of_potential_winners = len( + potential_winners + ) # potential winners will be changed ahead, so we store this value for the award message match weights: case "Stars": @@ -977,7 +982,7 @@ async def add_winners_command( winners_message += " and " await interaction.edit_original_response( - content=f"The results are in! Out of {len(potential_winners)} potential participants, {winners_message} have recieved a prize from participating in Advent of Code: {prize}" + content=f"The results are in! Out of {number_of_potential_winners} potential participants, {winners_message} have recieved a prize from participating in Advent of Code: {prize}" ) @app_commands.checks.has_permissions(manage_guild=True) diff --git a/uqcsbot/models.py b/uqcsbot/models.py index 2a8fb5b..87744b7 100644 --- a/uqcsbot/models.py +++ b/uqcsbot/models.py @@ -30,14 +30,11 @@ class AOCWinners(Base): class AOCRegistrations(Base): __tablename__ = "aoc_registrations" - id: Mapped[int] = mapped_column( - "id", Integer, primary_key=True, nullable=False, autoincrement=True + discord_userid: Mapped[int] = mapped_column( + "discord_userid", BigInteger, primary_key=True, nullable=False ) aoc_userid: Mapped[int] = mapped_column("aoc_userid", Integer, nullable=False) year: Mapped[int] = mapped_column("year", Integer, nullable=False) - discord_userid: Mapped[int] = mapped_column( - "discord_userid", BigInteger, nullable=False - ) class MCWhitelist(Base):