fixed imports again

This commit is contained in:
pacnpal
2024-11-18 01:21:40 +00:00
parent d03e8dc8e8
commit fc06e54d8a
37 changed files with 879 additions and 882 deletions

View File

@@ -1,10 +1,11 @@
"""Core module for VideoArchiver cog"""
try:
# Try relative imports first
from .base import VideoArchiver
except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.core.base import VideoArchiver
# try:
# Try relative imports first
from .base import VideoArchiver
# except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.core.base import VideoArchiver
__all__ = ["VideoArchiver"]

View File

@@ -12,40 +12,41 @@ import discord # type: ignore
from redbot.core.bot import Red # type: ignore
from redbot.core.commands import GroupCog, Context # type: ignore
try:
# Try relative imports first
from .settings import Settings
from .lifecycle import LifecycleManager, LifecycleState
from .component_manager import ComponentManager, ComponentState
from .error_handler import error_manager, handle_command_error
from .response_handler import ResponseManager
from .commands.archiver_commands import setup_archiver_commands
from .commands.database_commands import setup_database_commands
from .commands.settings_commands import setup_settings_commands
from .events import setup_events, EventManager
from ..processor.core import VideoProcessor
from ..queue.manager import EnhancedVideoQueueManager
from ..ffmpeg.ffmpeg_manager import FFmpegManager
from ..database.video_archive_db import VideoArchiveDB
from ..config_manager import ConfigManager
from ..utils.exceptions import CogError, ErrorContext, ErrorSeverity
except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.core.settings import Settings
# from videoarchiver.core.lifecycle import LifecycleManager, LifecycleState
# from videoarchiver.core.component_manager import ComponentManager, ComponentState
# from videoarchiver.core.error_handler import error_manager, handle_command_error
# from videoarchiver.core.response_handler import ResponseManager
# from videoarchiver.core.commands.archiver_commands import setup_archiver_commands
# from videoarchiver.core.commands.database_commands import setup_database_commands
# from videoarchiver.core.commands.settings_commands import setup_settings_commands
# from videoarchiver.core.events import setup_events, EventManager
# from videoarchiver.processor.core import VideoProcessor
# from videoarchiver.queue.manager import EnhancedVideoQueueManager
# from videoarchiver.ffmpeg.ffmpeg_manager import FFmpegManager
# from videoarchiver.database.video_archive_db import VideoArchiveDB
# from videoarchiver.config_manager import ConfigManager
# from videoarchiver.utils.exceptions import CogError, ErrorContext, ErrorSeverity
# try:
# Try relative imports first
from .settings import Settings
from .lifecycle import LifecycleManager, LifecycleState
from .component_manager import ComponentManager, ComponentState
from .error_handler import error_manager, handle_command_error
from .response_handler import ResponseManager
from .commands.archiver_commands import setup_archiver_commands
from .commands.database_commands import setup_database_commands
from .commands.settings_commands import setup_settings_commands
from .events import setup_events, EventManager
from ..processor.core import VideoProcessor
from ..queue.manager import EnhancedVideoQueueManager
from ..ffmpeg.ffmpeg_manager import FFmpegManager
from ..database.video_archive_db import VideoArchiveDB
from ..config_manager import ConfigManager
from ..utils.exceptions import CogError, ErrorContext, ErrorSeverity
# except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.core.settings import Settings
# from videoarchiver.core.lifecycle import LifecycleManager, LifecycleState
# from videoarchiver.core.component_manager import ComponentManager, ComponentState
# from videoarchiver.core.error_handler import error_manager, handle_command_error
# from videoarchiver.core.response_handler import ResponseManager
# from videoarchiver.core.commands.archiver_commands import setup_archiver_commands
# from videoarchiver.core.commands.database_commands import setup_database_commands
# from videoarchiver.core.commands.settings_commands import setup_settings_commands
# from videoarchiver.core.events import setup_events, EventManager
# from videoarchiver.processor.core import VideoProcessor
# from videoarchiver.queue.manager import EnhancedVideoQueueManager
# from videoarchiver.ffmpeg.ffmpeg_manager import FFmpegManager
# from videoarchiver.database.video_archive_db import VideoArchiveDB
# from videoarchiver.config_manager import ConfigManager
# from videoarchiver.utils.exceptions import CogError, ErrorContext, ErrorSeverity
logger = logging.getLogger("VideoArchiver")

View File

@@ -8,19 +8,19 @@ from enum import Enum, auto
from pathlib import Path
from typing import TYPE_CHECKING, Dict, Any, Optional, TypedDict, ClassVar
try:
#try:
# Try relative imports first
from ..utils.file_ops import cleanup_downloads
from ..utils.exceptions import CleanupError, ErrorContext, ErrorSeverity
except ImportError:
from ..utils.file_ops import cleanup_downloads
from ..utils.exceptions import CleanupError, ErrorContext, ErrorSeverity
#except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.file_ops import cleanup_downloads
# from videoarchiver.utils.exceptions import CleanupError, ErrorContext, ErrorSeverity
if TYPE_CHECKING:
try:
from .base import VideoArchiver
except ImportError:
#try:
from .base import VideoArchiver
#except ImportError:
# from videoarchiver.core.base import VideoArchiver
logger = logging.getLogger("VideoArchiver")

View File

@@ -6,9 +6,9 @@
from typing import TYPE_CHECKING
if TYPE_CHECKING:
try:
from .base import VideoArchiver
except ImportError:
# try:
from .base import VideoArchiver
# except ImportError:
# from videoarchiver.core.base import VideoArchiver
def setup_commands(cog: "VideoArchiver") -> None:

View File

@@ -20,22 +20,23 @@ from datetime import datetime
from pathlib import Path
import importlib
try:
# Try relative imports first
from ..utils.exceptions import ComponentError, ErrorContext, ErrorSeverity
from ..utils.path_manager import PathManager
from ..config_manager import ConfigManager
from ..processor.core import VideoProcessor
from ..queue.manager import EnhancedVideoQueueManager
from ..ffmpeg.ffmpeg_manager import FFmpegManager
except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.exceptions import ComponentError, ErrorContext, ErrorSeverity
# from videoarchiver.utils.path_manager import PathManager
# from videoarchiver.config_manager import ConfigManager
# from videoarchiver.processor.core import VideoProcessor
# from videoarchiver.queue.manager import EnhancedVideoQueueManager
# from videoarchiver.ffmpeg.ffmpeg_manager import FFmpegManager
# try:
# Try relative imports first
from ..utils.exceptions import ComponentError, ErrorContext, ErrorSeverity
from ..utils.path_manager import PathManager
from ..config_manager import ConfigManager
from ..processor.core import VideoProcessor
from ..queue.manager import EnhancedVideoQueueManager
from ..ffmpeg.ffmpeg_manager import FFmpegManager
# except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.exceptions import ComponentError, ErrorContext, ErrorSeverity
# from videoarchiver.utils.path_manager import PathManager
# from videoarchiver.config_manager import ConfigManager
# from videoarchiver.processor.core import VideoProcessor
# from videoarchiver.queue.manager import EnhancedVideoQueueManager
# from videoarchiver.ffmpeg.ffmpeg_manager import FFmpegManager
logger = logging.getLogger("VideoArchiver")

View File

@@ -14,49 +14,49 @@ from redbot.core.commands import ( # type: ignore
CommandError
)
try:
#try:
# Try relative imports first
from ..utils.exceptions import (
VideoArchiverError,
ErrorSeverity,
ErrorContext,
ProcessorError,
ValidationError,
DisplayError,
URLExtractionError,
MessageHandlerError,
QueueHandlerError,
QueueProcessorError,
FFmpegError,
DatabaseError,
HealthCheckError,
TrackingError,
NetworkError,
ResourceExhaustedError,
ConfigurationError
)
from ..core.response_handler import response_manager
except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.exceptions import (
VideoArchiverError,
ErrorSeverity,
ErrorContext,
ProcessorError,
ValidationError,
DisplayError,
URLExtractionError,
MessageHandlerError,
QueueHandlerError,
QueueProcessorError,
FFmpegError,
DatabaseError,
HealthCheckError,
TrackingError,
NetworkError,
ResourceExhaustedError,
ConfigurationError
)
from ..utils.exceptions import (
VideoArchiverError,
ErrorSeverity,
ErrorContext,
ProcessorError,
ValidationError,
DisplayError,
URLExtractionError,
MessageHandlerError,
QueueHandlerError,
QueueProcessorError,
FFmpegError,
DatabaseError,
HealthCheckError,
TrackingError,
NetworkError,
ResourceExhaustedError,
ConfigurationError
)
from ..core.response_handler import response_manager
# except ImportError:
# # Fall back to absolute imports if relative imports fail
# # from videoarchiver.utils.exceptions import (
# VideoArchiverError,
# ErrorSeverity,
# ErrorContext,
# ProcessorError,
# ValidationError,
# DisplayError,
# URLExtractionError,
# MessageHandlerError,
# QueueHandlerError,
# QueueProcessorError,
# FFmpegError,
# DatabaseError,
# HealthCheckError,
# TrackingError,
# NetworkError,
# ResourceExhaustedError,
# ConfigurationError
# )
# from videoarchiver.core.response_handler import response_manager
logger = logging.getLogger("VideoArchiver")

View File

@@ -9,15 +9,15 @@ from typing import TYPE_CHECKING, Dict, Any, Optional, TypedDict, ClassVar, List
import discord # type: ignore
try:
#try:
# Try relative imports first
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 ErrorManager
from .response_handler import response_manager
from ..utils.exceptions import EventError, ErrorContext, ErrorSeverity
except ImportError:
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 ErrorManager
from .response_handler import response_manager
from ..utils.exceptions import EventError, ErrorContext, ErrorSeverity
#except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.processor.constants import REACTIONS
# from videoarchiver.processor.reactions import handle_archived_reaction
@@ -27,9 +27,9 @@ except ImportError:
# from videoarchiver.utils.exceptions import EventError, ErrorContext, ErrorSeverity
if TYPE_CHECKING:
try:
from .base import VideoArchiver
except ImportError:
#try:
from .base import VideoArchiver
# except ImportError:
# from videoarchiver.core.base import VideoArchiver
logger = logging.getLogger("VideoArchiver")

View File

@@ -4,24 +4,25 @@ import logging
from pathlib import Path
from typing import TYPE_CHECKING, Dict, Any, Optional
try:
# Try relative imports first
from ..utils.download_core import DownloadCore
from ..utils.message_manager import MessageManager
from ..utils.file_ops import cleanup_downloads
from ..utils.exceptions import VideoArchiverError as ProcessingError
except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.download_core import DownloadCore
# from videoarchiver.utils.message_manager import MessageManager
# from videoarchiver.utils.file_ops import cleanup_downloads
# from videoarchiver.utils.exceptions import VideoArchiverError as ProcessingError
# try:
# Try relative imports first
from ..utils.download_core import DownloadCore
from ..utils.message_manager import MessageManager
from ..utils.file_ops import cleanup_downloads
from ..utils.exceptions import VideoArchiverError as ProcessingError
# except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.download_core import DownloadCore
# from videoarchiver.utils.message_manager import MessageManager
# from videoarchiver.utils.file_ops import cleanup_downloads
# from videoarchiver.utils.exceptions import VideoArchiverError as ProcessingError
if TYPE_CHECKING:
try:
from .base import VideoArchiver
except ImportError:
# from videoarchiver.core.base import VideoArchiver
# try:
from .base import VideoArchiver
# except ImportError:
# from videoarchiver.core.base import VideoArchiver
logger = logging.getLogger("VideoArchiver")

View File

@@ -4,20 +4,21 @@ from typing import TYPE_CHECKING, Optional, Dict, Any
import asyncio
import logging
try:
# Try relative imports first
from ..utils.exceptions import ComponentError, ErrorContext, ErrorSeverity
from .lifecycle import LifecycleState
except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.exceptions import ComponentError, ErrorContext, ErrorSeverity
# from videoarchiver.core.lifecycle import LifecycleState
# try:
# Try relative imports first
from ..utils.exceptions import ComponentError, ErrorContext, ErrorSeverity
from .lifecycle import LifecycleState
# except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.exceptions import ComponentError, ErrorContext, ErrorSeverity
# from videoarchiver.core.lifecycle import LifecycleState
if TYPE_CHECKING:
try:
from .base import VideoArchiver
except ImportError:
# from videoarchiver.core.base import VideoArchiver
# try:
from .base import VideoArchiver
# except ImportError:
# from videoarchiver.core.base import VideoArchiver
logger = logging.getLogger("VideoArchiver")
@@ -25,13 +26,13 @@ logger = logging.getLogger("VideoArchiver")
async def initialize_cog(cog: "VideoArchiver") -> None:
"""
Initialize all components with proper error handling.
This is a re-export of lifecycle_manager.initialize_cog with additional
error context and logging.
Args:
cog: VideoArchiver cog instance
Raises:
ComponentError: If initialization fails
"""
@@ -48,18 +49,18 @@ async def initialize_cog(cog: "VideoArchiver") -> None:
"Initialization",
"initialize_cog",
{"state": cog.lifecycle_manager.state_tracker.state.name},
ErrorSeverity.HIGH
)
ErrorSeverity.HIGH,
),
)
def init_callback(cog: "VideoArchiver", task: asyncio.Task) -> None:
"""
Handle initialization task completion.
This is a re-export of lifecycle_manager.init_callback with additional
error context and logging.
Args:
cog: VideoArchiver cog instance
task: Initialization task
@@ -67,7 +68,7 @@ def init_callback(cog: "VideoArchiver", task: asyncio.Task) -> None:
try:
logger.debug("Processing initialization task completion...")
cog.lifecycle_manager.init_callback(task)
# Log final state
state = cog.lifecycle_manager.state_tracker.state
if state == LifecycleState.READY:
@@ -76,7 +77,7 @@ def init_callback(cog: "VideoArchiver", task: asyncio.Task) -> None:
logger.error("Initialization failed")
else:
logger.warning(f"Unexpected state after initialization: {state.name}")
except Exception as e:
logger.error(f"Error in initialization callback: {str(e)}", exc_info=True)
# We don't raise here since this is a callback
@@ -85,10 +86,10 @@ def init_callback(cog: "VideoArchiver", task: asyncio.Task) -> None:
def get_init_status(cog: "VideoArchiver") -> Dict[str, Any]:
"""
Get initialization status information.
Args:
cog: VideoArchiver cog instance
Returns:
Dictionary containing initialization status
"""
@@ -103,8 +104,8 @@ def get_init_status(cog: "VideoArchiver") -> Dict[str, Any]:
"update_checker",
"ffmpeg_mgr",
"components",
"db"
"db",
]
),
"history": cog.lifecycle_manager.state_tracker.get_state_history()
"history": cog.lifecycle_manager.state_tracker.get_state_history(),
}

View File

@@ -7,26 +7,26 @@ from typing import Optional, Dict, Any, Set, List, Callable, TypedDict, ClassVar
from enum import Enum, auto
from datetime import datetime
try:
# try:
# Try relative imports first
from .cleanup import cleanup_resources, force_cleanup_resources
from ..utils.exceptions import (
VideoArchiverError,
ErrorContext,
ErrorSeverity,
ComponentError,
CleanupError,
)
except ImportError:
from .cleanup import cleanup_resources, force_cleanup_resources
from ..utils.exceptions import (
VideoArchiverError,
ErrorContext,
ErrorSeverity,
ComponentError,
CleanupError,
)
#except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.core.cleanup import cleanup_resources, force_cleanup_resources
# from videoarchiver.utils.exceptions import (
VideoArchiverError,
ErrorContext,
ErrorSeverity,
ComponentError,
CleanupError,
)
# VideoArchiverError,
# ErrorContext,
# ErrorSeverity,
# ComponentError,
# CleanupError,
# )
logger = logging.getLogger("VideoArchiver")

View File

@@ -7,12 +7,13 @@ from datetime import datetime
import discord # type: ignore
from redbot.core.commands import Context # type: ignore
try:
# Try relative imports first
from ..utils.exceptions import ErrorSeverity
except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.exceptions import ErrorSeverity
# try:
# Try relative imports first
from ..utils.exceptions import ErrorSeverity
# except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.exceptions import ErrorSeverity
logger = logging.getLogger("VideoArchiver")

View File

@@ -4,29 +4,35 @@ from typing import Dict, Any, List, Optional, Union, TypedDict, ClassVar
from dataclasses import dataclass, field
from enum import Enum, auto
try:
# Try relative imports first
from ..utils.exceptions import ConfigurationError, ErrorContext, ErrorSeverity
except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.exceptions import ConfigurationError, ErrorContext, ErrorSeverity
# try:
# Try relative imports first
from ..utils.exceptions import ConfigurationError, ErrorContext, ErrorSeverity
# except ImportError:
# Fall back to absolute imports if relative imports fail
# from videoarchiver.utils.exceptions import ConfigurationError, ErrorContext, ErrorSeverity
class VideoFormat(Enum):
"""Supported video formats"""
MP4 = "mp4"
WEBM = "webm"
MKV = "mkv"
class VideoQuality(Enum):
"""Video quality presets"""
LOW = "low" # 480p
LOW = "low" # 480p
MEDIUM = "medium" # 720p
HIGH = "high" # 1080p
HIGH = "high" # 1080p
ULTRA = "ultra" # 4K
class SettingCategory(Enum):
"""Setting categories"""
GENERAL = auto()
CHANNELS = auto()
PERMISSIONS = auto()
@@ -35,15 +41,19 @@ class SettingCategory(Enum):
PERFORMANCE = auto()
FEATURES = auto()
class ValidationResult(TypedDict):
"""Type definition for validation result"""
valid: bool
error: Optional[str]
details: Dict[str, Any]
@dataclass
class SettingDefinition:
"""Defines a setting's properties"""
name: str
category: SettingCategory
default_value: Any
@@ -66,8 +76,8 @@ class SettingDefinition:
"Settings",
"definition_validation",
{"setting": self.name},
ErrorSeverity.HIGH
)
ErrorSeverity.HIGH,
),
)
if self.min_value is not None and self.max_value is not None:
@@ -78,10 +88,11 @@ class SettingDefinition:
"Settings",
"definition_validation",
{"setting": self.name},
ErrorSeverity.HIGH
)
ErrorSeverity.HIGH,
),
)
class Settings:
"""Manages VideoArchiver settings"""
@@ -92,7 +103,7 @@ class Settings:
category=SettingCategory.GENERAL,
default_value=False,
description="Whether the archiver is enabled for this guild",
data_type=bool
data_type=bool,
),
"archive_channel": SettingDefinition(
name="archive_channel",
@@ -101,7 +112,7 @@ class Settings:
description="Channel where archived videos are posted",
data_type=int,
required=False,
error_message="Archive channel must be a valid channel ID"
error_message="Archive channel must be a valid channel ID",
),
"log_channel": SettingDefinition(
name="log_channel",
@@ -110,7 +121,7 @@ class Settings:
description="Channel for logging archiver actions",
data_type=int,
required=False,
error_message="Log channel must be a valid channel ID"
error_message="Log channel must be a valid channel ID",
),
"enabled_channels": SettingDefinition(
name="enabled_channels",
@@ -118,7 +129,7 @@ class Settings:
default_value=[],
description="Channels to monitor (empty means all channels)",
data_type=list,
error_message="Enabled channels must be a list of valid channel IDs"
error_message="Enabled channels must be a list of valid channel IDs",
),
"allowed_roles": SettingDefinition(
name="allowed_roles",
@@ -126,7 +137,7 @@ class Settings:
default_value=[],
description="Roles allowed to use archiver (empty means all roles)",
data_type=list,
error_message="Allowed roles must be a list of valid role IDs"
error_message="Allowed roles must be a list of valid role IDs",
),
"video_format": SettingDefinition(
name="video_format",
@@ -135,7 +146,7 @@ class Settings:
description="Format for archived videos",
data_type=str,
choices=[format.value for format in VideoFormat],
error_message=f"Video format must be one of: {', '.join(f.value for f in VideoFormat)}"
error_message=f"Video format must be one of: {', '.join(f.value for f in VideoFormat)}",
),
"video_quality": SettingDefinition(
name="video_quality",
@@ -144,7 +155,7 @@ class Settings:
description="Quality preset for archived videos",
data_type=str,
choices=[quality.value for quality in VideoQuality],
error_message=f"Video quality must be one of: {', '.join(q.value for q in VideoQuality)}"
error_message=f"Video quality must be one of: {', '.join(q.value for q in VideoQuality)}",
),
"max_file_size": SettingDefinition(
name="max_file_size",
@@ -154,7 +165,7 @@ class Settings:
data_type=int,
min_value=1,
max_value=100,
error_message="Max file size must be between 1 and 100 MB"
error_message="Max file size must be between 1 and 100 MB",
),
"message_duration": SettingDefinition(
name="message_duration",
@@ -164,7 +175,7 @@ class Settings:
data_type=int,
min_value=5,
max_value=300,
error_message="Message duration must be between 5 and 300 seconds"
error_message="Message duration must be between 5 and 300 seconds",
),
"message_template": SettingDefinition(
name="message_template",
@@ -172,7 +183,7 @@ class Settings:
default_value="{author} archived a video from {channel}",
description="Template for archive messages",
data_type=str,
error_message="Message template must contain {author} and {channel} placeholders"
error_message="Message template must contain {author} and {channel} placeholders",
),
"concurrent_downloads": SettingDefinition(
name="concurrent_downloads",
@@ -182,7 +193,7 @@ class Settings:
data_type=int,
min_value=1,
max_value=5,
error_message="Concurrent downloads must be between 1 and 5"
error_message="Concurrent downloads must be between 1 and 5",
),
"enabled_sites": SettingDefinition(
name="enabled_sites",
@@ -191,14 +202,14 @@ class Settings:
description="Sites to enable archiving for (None means all sites)",
data_type=list,
required=False,
error_message="Enabled sites must be a list of valid site identifiers"
error_message="Enabled sites must be a list of valid site identifiers",
),
"use_database": SettingDefinition(
name="use_database",
category=SettingCategory.FEATURES,
default_value=False,
description="Enable database tracking of archived videos",
data_type=bool
data_type=bool,
),
}
@@ -206,23 +217,25 @@ class Settings:
def get_setting_definition(cls, setting: str) -> Optional[SettingDefinition]:
"""
Get definition for a setting.
Args:
setting: Setting name
Returns:
Setting definition or None if not found
"""
return cls.SETTINGS.get(setting)
@classmethod
def get_settings_by_category(cls, category: SettingCategory) -> Dict[str, SettingDefinition]:
def get_settings_by_category(
cls, category: SettingCategory
) -> Dict[str, SettingDefinition]:
"""
Get all settings in a category.
Args:
category: Setting category
Returns:
Dictionary of settings in the category
"""
@@ -236,14 +249,14 @@ class Settings:
def validate_setting(cls, setting: str, value: Any) -> ValidationResult:
"""
Validate a setting value.
Args:
setting: Setting name
value: Value to validate
Returns:
Validation result dictionary
Raises:
ConfigurationError: If setting definition is not found
"""
@@ -252,18 +265,15 @@ class Settings:
raise ConfigurationError(
f"Unknown setting: {setting}",
context=ErrorContext(
"Settings",
"validation",
{"setting": setting},
ErrorSeverity.HIGH
)
"Settings", "validation", {"setting": setting}, ErrorSeverity.HIGH
),
)
details = {
"setting": setting,
"value": value,
"type": type(value).__name__,
"expected_type": definition.data_type.__name__
"expected_type": definition.data_type.__name__,
}
# Check type
@@ -271,15 +281,13 @@ class Settings:
return ValidationResult(
valid=False,
error=f"Invalid type: expected {definition.data_type.__name__}, got {type(value).__name__}",
details=details
details=details,
)
# Check required
if definition.required and value is None:
return ValidationResult(
valid=False,
error="Required setting cannot be None",
details=details
valid=False, error="Required setting cannot be None", details=details
)
# Check choices
@@ -287,7 +295,7 @@ class Settings:
return ValidationResult(
valid=False,
error=f"Value must be one of: {', '.join(map(str, definition.choices))}",
details=details
details=details,
)
# Check numeric bounds
@@ -296,13 +304,13 @@ class Settings:
return ValidationResult(
valid=False,
error=f"Value must be at least {definition.min_value}",
details=details
details=details,
)
if definition.max_value is not None and value > definition.max_value:
return ValidationResult(
valid=False,
error=f"Value must be at most {definition.max_value}",
details=details
details=details,
)
# Custom validation
@@ -313,42 +321,33 @@ class Settings:
return ValidationResult(
valid=False,
error=definition.error_message or "Validation failed",
details=details
details=details,
)
except Exception as e:
return ValidationResult(
valid=False,
error=str(e),
details=details
)
return ValidationResult(valid=False, error=str(e), details=details)
return ValidationResult(
valid=True,
error=None,
details=details
)
return ValidationResult(valid=True, error=None, details=details)
@property
def default_guild_settings(self) -> Dict[str, Any]:
"""
Default settings for guild configuration.
Returns:
Dictionary of default settings
"""
return {
name: definition.default_value
for name, definition in self.SETTINGS.items()
name: definition.default_value for name, definition in self.SETTINGS.items()
}
@classmethod
def get_setting_help(cls, setting: str) -> Optional[str]:
"""
Get help text for a setting.
Args:
setting: Setting name
Returns:
Help text or None if setting not found
"""
@@ -362,7 +361,7 @@ class Settings:
f"Description: {definition.description}",
f"Type: {definition.data_type.__name__}",
f"Required: {definition.required}",
f"Default: {definition.default_value}"
f"Default: {definition.default_value}",
]
if definition.choices: