gitscope
← marzneshin / v0.3.0-alpha / app/telegram/__init__.py
https://dev.kronoz.win/r/marzneshin.git
app/telegram/__init__.py · Python
Blame Raw
 1import importlib.util
 2from os.path import dirname
 3from config import TELEGRAM_API_TOKEN, TELEGRAM_PROXY_URL
 4from telebot.async_telebot import AsyncTeleBot
 5from telebot import asyncio_helper
 6
 7bot = None
 8if TELEGRAM_API_TOKEN:
 9    asyncio_helper.proxy = TELEGRAM_PROXY_URL
10    bot = AsyncTeleBot(TELEGRAM_API_TOKEN)
11
12handler_names = ["admin", "user"]
13
14
15async def start_bot():
16    if bot:
17        handler_dir = dirname(__file__) + "/handlers/"
18        for name in handler_names:
19            spec = importlib.util.spec_from_file_location(
20                name, f"{handler_dir}{name}.py"
21            )
22            spec.loader.exec_module(importlib.util.module_from_spec(spec))
23
24        from app.telegram import utils  # setup custom handlers
25
26        utils.setup()
27        await bot.polling()
28
29
30from .handlers.report import (  # noqa
31    report,
32    report_new_user,
33    report_user_modification,
34    report_user_deletion,
35    report_status_change,
36    report_user_usage_reset,
37    report_user_subscription_revoked,
38)
39
40__all__ = [
41    "bot",
42    "report",
43    "report_new_user",
44    "report_user_modification",
45    "report_user_deletion",
46    "report_status_change",
47    "report_user_usage_reset",
48    "report_user_subscription_revoked",
49]