43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""Main async bot module."""
|
|
from telebot.async_telebot import AsyncTeleBot
|
|
from bot.config import Config
|
|
from bot.database import init_db
|
|
from bot.handlers.group_handlers import register_group_handlers
|
|
from bot.handlers.private_handlers import register_private_handlers
|
|
from bot.handlers.command_handlers import register_command_handlers
|
|
from bot.logger import get_logger
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
async def create_bot() -> AsyncTeleBot:
|
|
"""Create and configure the bot."""
|
|
logger.info("Creating bot instance...")
|
|
|
|
# Validate configuration
|
|
Config.validate()
|
|
logger.debug("Configuration validated")
|
|
|
|
# Ensure BOT_TOKEN is not None
|
|
if not Config.BOT_TOKEN:
|
|
logger.error("BOT_TOKEN is required but not set")
|
|
raise ValueError("BOT_TOKEN is required")
|
|
|
|
# Initialize database
|
|
logger.info("Initializing database...")
|
|
await init_db()
|
|
logger.info("Database initialized")
|
|
|
|
# Create bot instance
|
|
bot = AsyncTeleBot(Config.BOT_TOKEN)
|
|
logger.info("Bot instance created")
|
|
|
|
# Register all handlers
|
|
logger.debug("Registering handlers...")
|
|
register_group_handlers(bot)
|
|
register_private_handlers(bot)
|
|
register_command_handlers(bot)
|
|
logger.info("All handlers registered")
|
|
|
|
return bot
|