init auth and main function
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""Application constants."""
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class TaskStatus(str, Enum):
|
||||
"""Task status enum."""
|
||||
RUNNING = "running"
|
||||
COMPLETED = "completed"
|
||||
FAILED = "failed"
|
||||
CANCELLED = "cancelled"
|
||||
|
||||
|
||||
class TaskType(str, Enum):
|
||||
"""Type of background tasks."""
|
||||
VISIT = "visit"
|
||||
TWITCH_IRC = "twitch_irc"
|
||||
|
||||
|
||||
class ProxyStatus(str, Enum):
|
||||
"""Proxy status."""
|
||||
WORKING = "working"
|
||||
NOT_WORKING = "not_working"
|
||||
|
||||
|
||||
# Regex patterns
|
||||
URL_PATTERN = r'https?://[^\s<>"]+'
|
||||
|
||||
# Message templates
|
||||
WELCOME_MESSAGE = (
|
||||
"👋 **Бот для посещения страниц и мониторинга Twitch**\n\n"
|
||||
"**Команды:**\n"
|
||||
"/visit — запустить периодическое посещение\n"
|
||||
"/twitch_irc — мониторинг чата Twitch через IRC\n"
|
||||
"/stop — остановить все задачи\n"
|
||||
"/tasks — список активных задач\n"
|
||||
"/proxies — статистика прокси\n"
|
||||
"/help — подробная справка"
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
"""Custom exceptions for the application."""
|
||||
|
||||
|
||||
class BotError(Exception):
|
||||
"""Base exception for bot errors."""
|
||||
pass
|
||||
|
||||
|
||||
class ProxyError(BotError):
|
||||
"""Proxy related errors."""
|
||||
pass
|
||||
|
||||
|
||||
class ProxyTimeoutError(ProxyError):
|
||||
"""Raised when proxy acquisition times out."""
|
||||
pass
|
||||
|
||||
|
||||
class NoProxiesAvailableError(ProxyError):
|
||||
"""Raised when no proxies are available."""
|
||||
pass
|
||||
|
||||
|
||||
class BrowserError(BotError):
|
||||
"""Browser related errors."""
|
||||
pass
|
||||
|
||||
|
||||
class IRCError(BotError):
|
||||
"""IRC related errors."""
|
||||
pass
|
||||
|
||||
|
||||
class IRCConnectionError(IRCError):
|
||||
"""Raised when IRC connection fails."""
|
||||
pass
|
||||
|
||||
|
||||
class TaskError(BotError):
|
||||
"""Task related errors."""
|
||||
pass
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Logging configuration."""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from logging.handlers import RotatingFileHandler
|
||||
|
||||
|
||||
def setup_logger(
|
||||
name: str = "bot",
|
||||
log_level: int = logging.INFO,
|
||||
log_file: str = "logs/bot.log"
|
||||
) -> logging.Logger:
|
||||
"""
|
||||
Configure and return logger instance.
|
||||
|
||||
Args:
|
||||
name: Logger name
|
||||
log_level: Logging level
|
||||
log_file: Path to log file
|
||||
|
||||
Returns:
|
||||
Configured logger instance
|
||||
"""
|
||||
logger = logging.getLogger(name)
|
||||
logger.setLevel(log_level)
|
||||
|
||||
# Create formatters
|
||||
console_formatter = logging.Formatter(
|
||||
'%(asctime)s | %(levelname)-8s | %(name)s | %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S'
|
||||
)
|
||||
|
||||
file_formatter = logging.Formatter(
|
||||
'%(asctime)s | %(levelname)-8s | %(name)s | %(funcName)s:%(lineno)d | %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S'
|
||||
)
|
||||
|
||||
# Console handler
|
||||
console_handler = logging.StreamHandler(sys.stdout)
|
||||
console_handler.setLevel(log_level)
|
||||
console_handler.setFormatter(console_formatter)
|
||||
|
||||
# File handler
|
||||
if log_file:
|
||||
Path(log_file).parent.mkdir(parents=True, exist_ok=True)
|
||||
file_handler = RotatingFileHandler(
|
||||
log_file,
|
||||
maxBytes=10*1024*1024, # 10MB
|
||||
backupCount=5,
|
||||
encoding='utf-8'
|
||||
)
|
||||
file_handler.setLevel(log_level)
|
||||
file_handler.setFormatter(file_formatter)
|
||||
logger.addHandler(file_handler)
|
||||
|
||||
logger.addHandler(console_handler)
|
||||
|
||||
return logger
|
||||
|
||||
|
||||
logger = setup_logger()
|
||||
Reference in New Issue
Block a user