mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
Added proper command validation in the on_message event handler to prevent interference with command processing
Added missing asyncio import in events.py Ensured all long-running operations are handled in background tasks Fixed task initialization and management in base.py
This commit is contained in:
@@ -7,51 +7,14 @@ from .exceptions import ProcessingError
|
||||
|
||||
logger = logging.getLogger("VideoArchiver")
|
||||
|
||||
# Global lock to prevent multiple concurrent setup attempts
|
||||
_setup_lock = asyncio.Lock()
|
||||
_setup_in_progress = False
|
||||
|
||||
async def setup(bot: Red) -> None:
|
||||
"""Load VideoArchiver."""
|
||||
global _setup_in_progress
|
||||
|
||||
# Use lock to prevent multiple concurrent setup attempts
|
||||
async with _setup_lock:
|
||||
try:
|
||||
# Check if setup is already in progress
|
||||
if _setup_in_progress:
|
||||
logger.warning("VideoArchiver setup already in progress, skipping")
|
||||
return
|
||||
|
||||
# Check if cog is already loaded
|
||||
if "VideoArchiver" in bot.cogs:
|
||||
logger.warning("VideoArchiver already loaded, skipping")
|
||||
return
|
||||
|
||||
_setup_in_progress = True
|
||||
|
||||
# Load main cog
|
||||
cog = VideoArchiver(bot)
|
||||
await bot.add_cog(cog)
|
||||
|
||||
# Wait for initialization to complete with timeout
|
||||
try:
|
||||
await asyncio.wait_for(cog.ready.wait(), timeout=30)
|
||||
except asyncio.TimeoutError:
|
||||
logger.error("VideoArchiver initialization timed out")
|
||||
await bot.remove_cog(cog.__class__.__name__)
|
||||
raise ProcessingError("Initialization timed out")
|
||||
|
||||
if not cog.ready.is_set():
|
||||
logger.error("VideoArchiver failed to initialize")
|
||||
await bot.remove_cog(cog.__class__.__name__)
|
||||
raise ProcessingError("Initialization failed")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to load VideoArchiver: {str(e)}")
|
||||
raise
|
||||
finally:
|
||||
_setup_in_progress = False
|
||||
try:
|
||||
cog = VideoArchiver(bot)
|
||||
await bot.add_cog(cog)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to load VideoArchiver: {str(e)}")
|
||||
raise
|
||||
|
||||
async def teardown(bot: Red) -> None:
|
||||
"""Clean up when unloading."""
|
||||
|
||||
Reference in New Issue
Block a user