Includes join verification button, discuss-comment cleanup for non-members, and SQLite persistence. Made-with: Cursor
41 lines
952 B
Python
41 lines
952 B
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import logging
|
|
|
|
from aiogram import Bot, Dispatcher
|
|
|
|
from .config import load_config
|
|
from .db import Database
|
|
from .handlers import register_handlers, sweeper_loop
|
|
|
|
|
|
async def main() -> None:
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
cfg = load_config()
|
|
logging.getLogger("bot").info(
|
|
"Starting with chat_id=%s db_path=%s verify_window=%ss thanks_ttl=%ss",
|
|
cfg.chat_id,
|
|
cfg.db_path,
|
|
cfg.verify_window_seconds,
|
|
cfg.thanks_ttl_seconds,
|
|
)
|
|
bot = Bot(token=cfg.bot_token)
|
|
dp = Dispatcher()
|
|
|
|
db = Database(cfg.db_path)
|
|
await db.connect()
|
|
|
|
await register_handlers(dp, cfg=cfg, db=db)
|
|
|
|
asyncio.create_task(sweeper_loop(bot=bot, cfg=cfg, db=db))
|
|
try:
|
|
await dp.start_polling(bot, allowed_updates=dp.resolve_used_update_types())
|
|
finally:
|
|
await db.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|
|
|