From f25d05ec4228713e6cdd68bb393a71d93078028d Mon Sep 17 00:00:00 2001 From: Parker Date: Tue, 19 Nov 2024 21:53:38 -0600 Subject: [PATCH] Properly check database writability --- code/cogs/owner/stats.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/code/cogs/owner/stats.py b/code/cogs/owner/stats.py index 258b102..5409bfb 100644 --- a/code/cogs/owner/stats.py +++ b/code/cogs/owner/stats.py @@ -14,13 +14,11 @@ class Stats(commands.Cog): if not os.path.exists("data"): os.makedirs("data") - connection = sqlite3.connect("data/count.db") - if not connection: - LOG.error( - "Could not create connection to database. Likely permissions" - " issue." - ) + if not os.access("data/count.db", os.W_OK): + LOG.error("Cannot write to data/count.db - check permissions") + return + connection = sqlite3.connect("data/count.db") cursor = connection.cursor() cursor.execute( "CREATE TABLE IF NOT EXISTS count (command_name, count, PRIMARY" @@ -34,9 +32,6 @@ class Stats(commands.Cog): @tasks.loop(seconds=30) async def dump_count(self): connection = sqlite3.connect("data/count.db") - if not connection: - LOG.warning("No database connection. Skipping dump.") - cursor = connection.cursor() for command_name, count in self.bot.temp_command_count.items():