Makes all application constants (except baseball positions) configurable via environment variables for greater deployment flexibility. Changes: - config.py: Added 18 new configurable fields to BotConfig * Discord limits (embed/field/description limits) * League settings (weeks, games, modern stats era) * Current season constants (SBA/PD) * API configuration (version, timeout, retries) * Draft settings (pick minutes, rounds) * Special team IDs (free agent team) * Role/channel names (help editor, players, news channel) * Base URLs (SBA website) - constants.py: Refactored to load from config * All constants now read from get_config() * Position sets remain static (PITCHER_POSITIONS, etc.) * Added documentation about configurability - .env.example: Added all new environment variables * Organized into logical sections with headers * Includes default values from config.py * Clear documentation for each setting Benefits: - Environment-specific configuration without code changes - Easy deployment across dev/staging/production - Season rollover requires only env variable updates - Team-specific customization (channels, roles, URLs) - Docker-friendly configuration management Backward Compatible: All defaults match previous hardcoded values 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
95 lines
2.4 KiB
Python
95 lines
2.4 KiB
Python
"""
|
|
Configuration management for Discord Bot v2.0
|
|
"""
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class BotConfig(BaseSettings):
|
|
"""Application configuration with environment variable support."""
|
|
|
|
# Discord settings
|
|
bot_token: str
|
|
guild_id: int
|
|
|
|
# Database API settings
|
|
api_token: str
|
|
db_url: str
|
|
|
|
# Discord Limits
|
|
discord_embed_limit: int = 6000
|
|
discord_field_value_limit: int = 1024
|
|
discord_embed_description_limit: int = 4096
|
|
|
|
# League settings
|
|
sba_season: int = 12
|
|
pd_season: int = 9
|
|
fa_lock_week: int = 14
|
|
sba_color: str = "a6ce39"
|
|
weeks_per_season: int = 18
|
|
games_per_week: int = 4
|
|
modern_stats_start_season: int = 8
|
|
|
|
# Current Season Constants
|
|
sba_current_season: int = 12
|
|
pd_current_season: int = 9
|
|
|
|
# API Constants
|
|
api_version: str = "v3"
|
|
default_timeout: int = 10
|
|
max_retries: int = 3
|
|
|
|
# Draft Constants
|
|
default_pick_minutes: int = 10
|
|
draft_rounds: int = 25
|
|
|
|
# Special Team IDs
|
|
free_agent_team_id: int = 498
|
|
|
|
# Role Names
|
|
help_editor_role_name: str = "Help Editor"
|
|
sba_players_role_name: str = "Season 12 Players"
|
|
|
|
# Channel Names
|
|
sba_network_news_channel: str = "sba-network-news"
|
|
|
|
# Base URLs
|
|
sba_base_url: str = "https://sba.manticorum.com"
|
|
|
|
# Application settings
|
|
log_level: str = "INFO"
|
|
environment: str = "development"
|
|
testing: bool = False
|
|
|
|
# Google Sheets settings
|
|
sheets_credentials_path: str = "/app/data/major-domo-service-creds.json"
|
|
|
|
# Optional Redis caching settings
|
|
redis_url: str = "" # Empty string means no Redis caching
|
|
redis_cache_ttl: int = 300 # 5 minutes default TTL
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
case_sensitive=False,
|
|
extra="ignore" # Ignore extra environment variables
|
|
)
|
|
|
|
@property
|
|
def is_development(self) -> bool:
|
|
"""Check if running in development mode."""
|
|
return self.environment.lower() == "development"
|
|
|
|
@property
|
|
def is_testing(self) -> bool:
|
|
"""Check if running in test mode."""
|
|
return self.testing
|
|
|
|
|
|
# Global configuration instance - lazily initialized to avoid import-time errors
|
|
_config = None
|
|
|
|
def get_config() -> BotConfig:
|
|
"""Get the global configuration instance."""
|
|
global _config
|
|
if _config is None:
|
|
_config = BotConfig() # type: ignore
|
|
return _config |