Refactor database path resolution in cogs and improve cog loading error handling. Update database connections in Giveaway, Nightmode, and Owner cogs to use a centralized path resolver. Enhance cog loading feedback with success and failure messages.
This commit is contained in:
@@ -192,8 +192,17 @@ COG_CLASSES: tuple[type, ...] = (
|
||||
|
||||
|
||||
async def setup(bot: Axiom) -> None:
|
||||
loaded = 0
|
||||
for cog_cls in COG_CLASSES:
|
||||
await bot.add_cog(cog_cls(bot))
|
||||
print(Fore.RED + Style.BRIGHT + f"Loaded cog: {cog_cls.__name__}")
|
||||
try:
|
||||
await bot.add_cog(cog_cls(bot))
|
||||
loaded += 1
|
||||
print(Fore.GREEN + Style.BRIGHT + f"Loaded cog: {cog_cls.__name__}")
|
||||
except Exception as e:
|
||||
print(
|
||||
Fore.RED
|
||||
+ Style.BRIGHT
|
||||
+ f"Failed cog {getattr(cog_cls, '__name__', cog_cls)}: {type(e).__name__}: {e}"
|
||||
)
|
||||
|
||||
print(Fore.RED + Style.BRIGHT + f"All {BotName} Cogs loaded successfully.")
|
||||
print(Fore.GREEN + Style.BRIGHT + f"Loaded {loaded}/{len(COG_CLASSES)} {BotName} cogs.")
|
||||
|
||||
@@ -25,10 +25,11 @@ import os
|
||||
import aiohttp
|
||||
from utils.cv2 import CV2
|
||||
|
||||
db_folder = 'db'
|
||||
from utils.db_paths import db_path as resolve_db_path
|
||||
|
||||
db_file = 'giveaways.db'
|
||||
db_path = os.path.join(db_folder, db_file)
|
||||
connection = sqlite3.connect(db_path)
|
||||
giveaways_db_path = resolve_db_path(db_file)
|
||||
connection = sqlite3.connect(giveaways_db_path)
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
@@ -74,7 +75,7 @@ class Giveaway(commands.Cog):
|
||||
self.bot = bot
|
||||
|
||||
async def cog_load(self) -> None:
|
||||
self.connection = await aiosqlite.connect(db_path)
|
||||
self.connection = await aiosqlite.connect(giveaways_db_path)
|
||||
self.cursor = await self.connection.cursor()
|
||||
await self.check_for_ended_giveaways()
|
||||
self.GiveawayEnd.start()
|
||||
|
||||
@@ -19,11 +19,10 @@ from utils.Tools import *
|
||||
from utils.cv2 import CV2
|
||||
from discord.ui import TextDisplay, Separator, ActionRow, LayoutView, Container
|
||||
from utils.config import OWNER_IDS_STR
|
||||
from utils.db_paths import db_path as resolve_db_path
|
||||
|
||||
# Database setup
|
||||
db_folder = "db"
|
||||
db_file = "anti.db"
|
||||
db_path = os.path.join(db_folder, db_file)
|
||||
nightmode_db_path = resolve_db_path("anti.db")
|
||||
|
||||
|
||||
class Nightmode(commands.Cog):
|
||||
@@ -34,7 +33,7 @@ class Nightmode(commands.Cog):
|
||||
self.color = 0xFF0000
|
||||
|
||||
async def initialize_db(self):
|
||||
self.db = await aiosqlite.connect(db_path)
|
||||
self.db = await aiosqlite.connect(nightmode_db_path)
|
||||
await self.db.execute("""
|
||||
CREATE TABLE IF NOT EXISTS Nightmode (
|
||||
guildId TEXT,
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
from __future__ import annotations
|
||||
from utils.db_paths import db_path
|
||||
from utils.db_paths import db_path as resolve_db_path
|
||||
from discord.ext import commands
|
||||
from discord import *
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageFilter
|
||||
@@ -71,12 +71,12 @@ BACK_COMPAT_BADGE_DICT = DISCORD_BADGE_EMOJIS
|
||||
|
||||
db_folder = 'db'
|
||||
db_file = 'badges.db'
|
||||
db_path = os.path.join(db_folder, db_file)
|
||||
badges_db_path = resolve_db_path(db_file)
|
||||
FONT_PATH = os.path.join('utils', 'arial.ttf')
|
||||
|
||||
# --- Database Setup ---
|
||||
os.makedirs(db_folder, exist_ok=True)
|
||||
conn = sqlite3.connect(db_path)
|
||||
os.makedirs(os.path.dirname(badges_db_path) or 'db', exist_ok=True)
|
||||
conn = sqlite3.connect(badges_db_path)
|
||||
c = conn.cursor()
|
||||
|
||||
c.execute('CREATE TABLE IF NOT EXISTS badges (user_id INTEGER PRIMARY KEY)')
|
||||
@@ -136,7 +136,7 @@ class Owner(commands.Cog):
|
||||
self.client = client
|
||||
self.staff = set()
|
||||
self.np_cache = []
|
||||
self.db_path = db_path('np.db')
|
||||
self.db_path = resolve_db_path('np.db')
|
||||
self.stop_tour = False
|
||||
self.bot_owner_ids = BOT_OWNER_IDS
|
||||
self.client.loop.create_task(self.setup_database())
|
||||
|
||||
Reference in New Issue
Block a user