46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
"""Main application entry point"""
|
|
|
|
import asyncio
|
|
import logging
|
|
from aiogram import Bot, Dispatcher
|
|
from aiogram.fsm.storage.memory import MemoryStorage
|
|
from app.core.config import get_settings
|
|
from app.bot import register_handlers
|
|
from app.db.database import engine, Base
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def main():
|
|
"""Main bot application"""
|
|
settings = get_settings()
|
|
|
|
# Create database tables
|
|
Base.metadata.create_all(bind=engine)
|
|
logger.info("Database tables created")
|
|
|
|
# Initialize bot and dispatcher
|
|
bot = Bot(token=settings.bot_token)
|
|
storage = MemoryStorage()
|
|
dp = Dispatcher(storage=storage)
|
|
|
|
# Register handlers
|
|
register_handlers(dp)
|
|
logger.info("Handlers registered")
|
|
|
|
# Start polling
|
|
logger.info("Bot polling started")
|
|
try:
|
|
await dp.start_polling(bot, allowed_updates=dp.resolve_used_update_types())
|
|
finally:
|
|
await bot.session.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|