re-structure

This commit is contained in:
pacnpal
2024-11-15 22:17:30 +00:00
parent 5fedd97b61
commit 97e0d9c279
3 changed files with 6 additions and 34 deletions

View File

@@ -2,7 +2,7 @@
from redbot.core.bot import Red from redbot.core.bot import Red
import asyncio import asyncio
import logging import logging
from .video_archiver import VideoArchiver from .core.base import VideoArchiver
from .exceptions import ProcessingError from .exceptions import ProcessingError
logger = logging.getLogger("VideoArchiver") logger = logging.getLogger("VideoArchiver")
@@ -10,7 +10,7 @@ logger = logging.getLogger("VideoArchiver")
async def setup(bot: Red) -> None: async def setup(bot: Red) -> None:
"""Load VideoArchiver.""" """Load VideoArchiver."""
try: try:
# Load main cog first # Load main cog
cog = VideoArchiver(bot) cog = VideoArchiver(bot)
await bot.add_cog(cog) await bot.add_cog(cog)
@@ -22,23 +22,7 @@ async def setup(bot: Red) -> None:
await bot.remove_cog(cog.__class__.__name__) await bot.remove_cog(cog.__class__.__name__)
raise ProcessingError("Initialization timed out") raise ProcessingError("Initialization timed out")
# Only load commands if main cog initialized successfully if not cog.ready.is_set():
if cog.ready.is_set():
try:
from .commands import VideoArchiverCommands
commands_cog = VideoArchiverCommands(
bot,
cog.config_manager,
cog.update_checker,
cog.processor
)
await bot.add_cog(commands_cog)
except Exception as e:
logger.error(f"Failed to load commands cog: {str(e)}")
# Clean up main cog if commands fail to load
await bot.remove_cog(cog.__class__.__name__)
raise
else:
logger.error("VideoArchiver failed to initialize") logger.error("VideoArchiver failed to initialize")
await bot.remove_cog(cog.__class__.__name__) await bot.remove_cog(cog.__class__.__name__)
raise ProcessingError("Initialization failed") raise ProcessingError("Initialization failed")
@@ -50,11 +34,6 @@ async def setup(bot: Red) -> None:
async def teardown(bot: Red) -> None: async def teardown(bot: Red) -> None:
"""Clean up when unloading.""" """Clean up when unloading."""
try: try:
# Remove commands cog first
if "VideoArchiverCommands" in bot.cogs:
await bot.remove_cog("VideoArchiverCommands")
# Then remove main cog
if "VideoArchiver" in bot.cogs: if "VideoArchiver" in bot.cogs:
await bot.remove_cog("VideoArchiver") await bot.remove_cog("VideoArchiver")
except Exception as e: except Exception as e:

View File

@@ -1,4 +1,4 @@
"""Re-export commands from core.commands""" """Re-export commands from core.base"""
from .core.commands import VideoArchiverCommands from .core.base import VideoArchiver
__all__ = ['VideoArchiverCommands'] __all__ = ['VideoArchiver']

View File

@@ -1,7 +0,0 @@
"""VideoArchiver cog for Red-DiscordBot"""
from .core import VideoArchiver
def setup(bot):
"""Load VideoArchiver cog."""
bot.add_cog(VideoArchiver(bot))