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:
pacnpal
2024-11-16 01:04:08 +00:00
parent 46250b14d0
commit 01a9067368
3 changed files with 70 additions and 166 deletions

View File

@@ -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."""