mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 10:51:05 -05:00
Created a new constants.py file to store the REACTIONS dictionary
Updated all files to import REACTIONS from constants.py instead of reactions.py: queue_processor.py message_handler.py reactions.py (now only contains reaction handling functions) events.py (now imports REACTIONS from constants.py and handle_archived_reaction from reactions.py) core.py queue_handler.py processor/init.py
This commit is contained in:
@@ -7,7 +7,8 @@ import traceback
|
||||
from typing import TYPE_CHECKING, Dict, Any, Optional
|
||||
from datetime import datetime
|
||||
|
||||
from ..processor.reactions import REACTIONS, handle_archived_reaction
|
||||
from ..processor.constants import REACTIONS
|
||||
from ..processor.reactions import handle_archived_reaction
|
||||
from .guild import initialize_guild_components, cleanup_guild_components
|
||||
from .error_handler import error_manager
|
||||
from .response_handler import response_manager
|
||||
|
||||
@@ -1,40 +1,45 @@
|
||||
"""Video processing module for VideoArchiver"""
|
||||
|
||||
from .core import VideoProcessor
|
||||
from .reactions import REACTIONS
|
||||
from .constants import REACTIONS
|
||||
from .progress_tracker import ProgressTracker
|
||||
from .message_handler import MessageHandler
|
||||
from .queue_handler import QueueHandler
|
||||
|
||||
# Export public classes and constants
|
||||
__all__ = [
|
||||
'VideoProcessor',
|
||||
'REACTIONS',
|
||||
'ProgressTracker',
|
||||
'MessageHandler',
|
||||
'QueueHandler'
|
||||
"VideoProcessor",
|
||||
"REACTIONS",
|
||||
"ProgressTracker",
|
||||
"MessageHandler",
|
||||
"QueueHandler",
|
||||
]
|
||||
|
||||
# Create a shared progress tracker instance for module-level access
|
||||
progress_tracker = ProgressTracker()
|
||||
|
||||
|
||||
# Export progress tracking functions that wrap the instance methods
|
||||
def update_download_progress(url, progress_data):
|
||||
"""Update download progress for a specific URL"""
|
||||
progress_tracker.update_download_progress(url, progress_data)
|
||||
|
||||
|
||||
def complete_download(url):
|
||||
"""Mark a download as complete"""
|
||||
progress_tracker.complete_download(url)
|
||||
|
||||
|
||||
def increment_download_retries(url):
|
||||
"""Increment retry count for a download"""
|
||||
progress_tracker.increment_download_retries(url)
|
||||
|
||||
|
||||
def get_download_progress(url=None):
|
||||
"""Get download progress for a specific URL or all downloads"""
|
||||
return progress_tracker.get_download_progress(url)
|
||||
|
||||
|
||||
def get_active_operations():
|
||||
"""Get all active operations"""
|
||||
return progress_tracker.get_active_operations()
|
||||
|
||||
13
videoarchiver/processor/constants.py
Normal file
13
videoarchiver/processor/constants.py
Normal file
@@ -0,0 +1,13 @@
|
||||
"""Constants for VideoProcessor"""
|
||||
|
||||
# Reaction emojis
|
||||
REACTIONS = {
|
||||
'queued': '📹',
|
||||
'processing': '⚙️',
|
||||
'success': '✅',
|
||||
'error': '❌',
|
||||
'archived': '🔄', # New reaction for already archived videos
|
||||
'numbers': ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣'],
|
||||
'progress': ['⬛', '🟨', '🟩'],
|
||||
'download': ['0️⃣', '2️⃣', '4️⃣', '6️⃣', '8️⃣', '🔟']
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
import logging
|
||||
import asyncio
|
||||
from enum import Enum
|
||||
from typing import Optional, Tuple, Dict, Any
|
||||
from typing import Optional, Tuple, Dict, Any, List
|
||||
from datetime import datetime
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
@@ -13,7 +13,7 @@ from .queue_handler import QueueHandler
|
||||
from .progress_tracker import ProgressTracker
|
||||
from .status_display import StatusDisplay
|
||||
from .cleanup_manager import CleanupManager
|
||||
from .reactions import REACTIONS
|
||||
from .constants import REACTIONS
|
||||
|
||||
logger = logging.getLogger("VideoArchiver")
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import discord
|
||||
from .url_extractor import URLExtractor
|
||||
from .message_validator import MessageValidator
|
||||
from .queue_processor import QueueProcessor
|
||||
from .reactions import REACTIONS
|
||||
from .constants import REACTIONS
|
||||
|
||||
logger = logging.getLogger("VideoArchiver")
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import discord
|
||||
from typing import Dict, Optional, Tuple, Any
|
||||
from datetime import datetime
|
||||
|
||||
from .reactions import REACTIONS
|
||||
from .constants import REACTIONS
|
||||
from .progress_tracker import ProgressTracker
|
||||
|
||||
logger = logging.getLogger("VideoArchiver")
|
||||
@@ -305,3 +305,14 @@ class QueueHandler:
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to update download progress reaction: {e}")
|
||||
|
||||
def is_healthy(self) -> bool:
|
||||
"""Check if handler is healthy"""
|
||||
# Check if any downloads are stuck
|
||||
current_time = datetime.utcnow()
|
||||
for url, task in self._active_downloads.items():
|
||||
if not task.done() and task.get_coro().cr_frame.f_locals.get('start_time'):
|
||||
start_time = task.get_coro().cr_frame.f_locals['start_time']
|
||||
if (current_time - start_time).total_seconds() > 3600: # 1 hour timeout
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -8,7 +8,7 @@ from datetime import datetime
|
||||
import discord
|
||||
|
||||
from ..queue.models import QueueItem
|
||||
from .reactions import REACTIONS
|
||||
from .constants import REACTIONS
|
||||
|
||||
logger = logging.getLogger("VideoArchiver")
|
||||
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
"""Reaction emojis and reaction management for VideoProcessor"""
|
||||
"""Reaction handling for VideoProcessor"""
|
||||
|
||||
import logging
|
||||
import asyncio
|
||||
import discord
|
||||
|
||||
logger = logging.getLogger("VideoArchiver")
|
||||
from .constants import REACTIONS
|
||||
|
||||
# Reaction emojis
|
||||
REACTIONS = {
|
||||
'queued': '📹',
|
||||
'processing': '⚙️',
|
||||
'success': '✅',
|
||||
'error': '❌',
|
||||
'archived': '🔄', # New reaction for already archived videos
|
||||
'numbers': ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣'],
|
||||
'progress': ['⬛', '🟨', '🟩'],
|
||||
'download': ['0️⃣', '2️⃣', '4️⃣', '6️⃣', '8️⃣', '🔟']
|
||||
}
|
||||
logger = logging.getLogger("VideoArchiver")
|
||||
|
||||
async def handle_archived_reaction(message: discord.Message, user: discord.User, db) -> None:
|
||||
"""Handle reaction to archived video message"""
|
||||
|
||||
Reference in New Issue
Block a user