From 82ffaf82d89f3246a6d341e25749ffab56a6fb3e Mon Sep 17 00:00:00 2001 From: wlinator Date: Fri, 19 Jul 2024 17:26:49 -0400 Subject: [PATCH] refactor: Update database.py to use pathlib for reading migration files among other changes --- db/database.py | 7 ++++--- lib/interaction.py | 26 ++++++++++++-------------- lib/time.py | 5 +---- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/db/database.py b/db/database.py index a2d7e41..a40161e 100644 --- a/db/database.py +++ b/db/database.py @@ -2,6 +2,7 @@ import mysql.connector from loguru import logger from mysql.connector import pooling import os +import pathlib import re from lib.constants import CONST @@ -81,9 +82,9 @@ def run_migrations(): continue # Read and execute migration file - with open(os.path.join(migrations_dir, migration_file)) as f: - migration_sql = f.read() - + migration_sql = pathlib.Path( + os.path.join(migrations_dir, migration_file), + ).read_text() try: # Split the migration file into individual statements statements = re.split(r";\s*$", migration_sql, flags=re.MULTILINE) diff --git a/lib/interaction.py b/lib/interaction.py index 581fb6d..d71134a 100644 --- a/lib/interaction.py +++ b/lib/interaction.py @@ -36,14 +36,13 @@ class BlackJackButtons(View): self.stop() async def interaction_check(self, interaction) -> bool: - if interaction.user != self.ctx.author: - await interaction.response.send_message( - "You can't use these buttons, they're someone else's!", - ephemeral=True, - ) - return False - else: + if interaction.user == self.ctx.author: return True + await interaction.response.send_message( + "You can't use these buttons, they're someone else's!", + ephemeral=True, + ) + return False class ExchangeConfirmation(View): @@ -69,11 +68,10 @@ class ExchangeConfirmation(View): self.stop() async def interaction_check(self, interaction) -> bool: - if interaction.user != self.ctx.author: - await interaction.response.send_message( - "You can't use these buttons, they're someone else's!", - ephemeral=True, - ) - return False - else: + if interaction.user == self.ctx.author: return True + await interaction.response.send_message( + "You can't use these buttons, they're someone else's!", + ephemeral=True, + ) + return False diff --git a/lib/time.py b/lib/time.py index e553cd8..9d0b2f5 100644 --- a/lib/time.py +++ b/lib/time.py @@ -16,7 +16,4 @@ def seconds_until(hours, minutes): if future_exec < now: future_exec += datetime.timedelta(days=1) - # Calculate the time difference in seconds - seconds_until_execution = (future_exec - now).total_seconds() - - return seconds_until_execution + return (future_exec - now).total_seconds()