1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 20:43:12 +00:00

refactor: Update database.py to use pathlib for reading migration files among other changes

This commit is contained in:
wlinator 2024-07-19 17:26:49 -04:00
parent 1993132f27
commit 82ffaf82d8
3 changed files with 17 additions and 21 deletions

View file

@ -2,6 +2,7 @@ import mysql.connector
from loguru import logger from loguru import logger
from mysql.connector import pooling from mysql.connector import pooling
import os import os
import pathlib
import re import re
from lib.constants import CONST from lib.constants import CONST
@ -81,9 +82,9 @@ def run_migrations():
continue continue
# Read and execute migration file # Read and execute migration file
with open(os.path.join(migrations_dir, migration_file)) as f: migration_sql = pathlib.Path(
migration_sql = f.read() os.path.join(migrations_dir, migration_file),
).read_text()
try: try:
# Split the migration file into individual statements # Split the migration file into individual statements
statements = re.split(r";\s*$", migration_sql, flags=re.MULTILINE) statements = re.split(r";\s*$", migration_sql, flags=re.MULTILINE)

View file

@ -36,14 +36,13 @@ class BlackJackButtons(View):
self.stop() self.stop()
async def interaction_check(self, interaction) -> bool: async def interaction_check(self, interaction) -> bool:
if interaction.user != self.ctx.author: 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:
return True 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): class ExchangeConfirmation(View):
@ -69,11 +68,10 @@ class ExchangeConfirmation(View):
self.stop() self.stop()
async def interaction_check(self, interaction) -> bool: async def interaction_check(self, interaction) -> bool:
if interaction.user != self.ctx.author: 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:
return True return True
await interaction.response.send_message(
"You can't use these buttons, they're someone else's!",
ephemeral=True,
)
return False

View file

@ -16,7 +16,4 @@ def seconds_until(hours, minutes):
if future_exec < now: if future_exec < now:
future_exec += datetime.timedelta(days=1) future_exec += datetime.timedelta(days=1)
# Calculate the time difference in seconds return (future_exec - now).total_seconds()
seconds_until_execution = (future_exec - now).total_seconds()
return seconds_until_execution