Properly check database writability
This commit is contained in:
parent
d97ab8b34e
commit
f25d05ec42
@ -14,13 +14,11 @@ class Stats(commands.Cog):
|
|||||||
if not os.path.exists("data"):
|
if not os.path.exists("data"):
|
||||||
os.makedirs("data")
|
os.makedirs("data")
|
||||||
|
|
||||||
connection = sqlite3.connect("data/count.db")
|
if not os.access("data/count.db", os.W_OK):
|
||||||
if not connection:
|
LOG.error("Cannot write to data/count.db - check permissions")
|
||||||
LOG.error(
|
return
|
||||||
"Could not create connection to database. Likely permissions"
|
|
||||||
" issue."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
connection = sqlite3.connect("data/count.db")
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS count (command_name, count, PRIMARY"
|
"CREATE TABLE IF NOT EXISTS count (command_name, count, PRIMARY"
|
||||||
@ -34,9 +32,6 @@ class Stats(commands.Cog):
|
|||||||
@tasks.loop(seconds=30)
|
@tasks.loop(seconds=30)
|
||||||
async def dump_count(self):
|
async def dump_count(self):
|
||||||
connection = sqlite3.connect("data/count.db")
|
connection = sqlite3.connect("data/count.db")
|
||||||
if not connection:
|
|
||||||
LOG.warning("No database connection. Skipping dump.")
|
|
||||||
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
for command_name, count in self.bot.temp_command_count.items():
|
for command_name, count in self.bot.temp_command_count.items():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user