mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-08-28 05:14:12 +00:00
docs: Add __init__ docstrings and refine type hints for client and command initializers.
This commit is contained in:
@@ -10,7 +10,14 @@ class ESPNClient:
|
||||
|
||||
BASE_URL = "http://site.api.espn.com/apis/site/v2/sports"
|
||||
|
||||
def __init__(self, logger=None, timeout: int = 10, session: Optional[aiohttp.ClientSession] = None):
|
||||
def __init__(self, logger: Optional[logging.Logger] = None, timeout: int = 10, session: Optional[aiohttp.ClientSession] = None):
|
||||
"""Initialize the ESPN API client.
|
||||
|
||||
Args:
|
||||
logger: Logger instance for error and info logging. If None, creates a default logger.
|
||||
timeout: Request timeout in seconds (default: 10)
|
||||
session: Optional existing aiohttp session to reuse. If None, creates new sessions as needed.
|
||||
"""
|
||||
self.logger = logger or logging.getLogger(__name__)
|
||||
self.timeout = aiohttp.ClientTimeout(total=timeout)
|
||||
self.session = session
|
||||
|
||||
@@ -15,7 +15,14 @@ class TheSportsDBClient:
|
||||
BASE_URL = "https://www.thesportsdb.com/api/v1/json"
|
||||
FREE_API_KEY = "123" # Free public API key
|
||||
|
||||
def __init__(self, logger=None, timeout: int = 10, session: Optional[aiohttp.ClientSession] = None):
|
||||
def __init__(self, logger: Optional[logging.Logger] = None, timeout: int = 10, session: Optional[aiohttp.ClientSession] = None):
|
||||
"""Initialize the TheSportsDB API client with rate limiting.
|
||||
|
||||
Args:
|
||||
logger: Logger instance for error and info logging. If None, creates a default logger.
|
||||
timeout: Request timeout in seconds (default: 10)
|
||||
session: Optional existing aiohttp session to reuse. If None, creates new sessions as needed.
|
||||
"""
|
||||
self.logger = logger or logging.getLogger(__name__)
|
||||
self.timeout = aiohttp.ClientTimeout(total=timeout)
|
||||
self.session = session
|
||||
|
||||
@@ -20,7 +20,7 @@ Team IDs should be periodically verified, especially after:
|
||||
"""
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from typing import List, Dict, Optional
|
||||
from typing import List, Dict, Optional, TYPE_CHECKING
|
||||
from .base_command import BaseCommand
|
||||
from ..models import MeshMessage
|
||||
from ..clients.espn_client import ESPNClient
|
||||
@@ -29,6 +29,9 @@ from ..clients.sports_mappings import (
|
||||
SPORT_EMOJIS, TEAM_MAPPINGS, LEAGUE_MAPPINGS
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..core import MeshCoreBot
|
||||
|
||||
|
||||
class SportsCommand(BaseCommand):
|
||||
"""Handles sports commands with ESPN API integration"""
|
||||
@@ -47,15 +50,20 @@ class SportsCommand(BaseCommand):
|
||||
# TheSportsDB client for leagues not supported by ESPN
|
||||
thesportsdb_client: Optional[TheSportsDBClient] = None
|
||||
|
||||
|
||||
def __init__(self, bot):
|
||||
|
||||
def __init__(self, bot: "MeshCoreBot"):
|
||||
"""Initialize the sports command with API clients and configuration.
|
||||
|
||||
Args:
|
||||
bot: The MeshCoreBot instance that owns this command.
|
||||
"""
|
||||
super().__init__(bot)
|
||||
self.url_timeout = 10 # seconds
|
||||
|
||||
|
||||
# Initialize API clients
|
||||
self.espn_client = ESPNClient(logger=self.logger, timeout=self.url_timeout)
|
||||
self.thesportsdb_client = TheSportsDBClient(logger=self.logger)
|
||||
|
||||
|
||||
# Load default teams from config
|
||||
self.default_teams = self.load_default_teams()
|
||||
# Note: allowed_channels is now loaded by BaseCommand from config
|
||||
|
||||
Reference in New Issue
Block a user