Print error/warning if database connection cannot be made
This commit is contained in:
parent
226a5cd118
commit
d97ab8b34e
@ -3,7 +3,7 @@ import sqlite3
|
|||||||
import discord
|
import discord
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from utils.config import BOT_COLOR
|
from utils.config import BOT_COLOR, LOG
|
||||||
|
|
||||||
|
|
||||||
class Stats(commands.Cog):
|
class Stats(commands.Cog):
|
||||||
@ -15,6 +15,12 @@ class Stats(commands.Cog):
|
|||||||
os.makedirs("data")
|
os.makedirs("data")
|
||||||
|
|
||||||
connection = sqlite3.connect("data/count.db")
|
connection = sqlite3.connect("data/count.db")
|
||||||
|
if not connection:
|
||||||
|
LOG.error(
|
||||||
|
"Could not create connection to database. Likely permissions"
|
||||||
|
" issue."
|
||||||
|
)
|
||||||
|
|
||||||
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"
|
||||||
@ -28,6 +34,9 @@ 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