gitscope
← marzneshin / v0.1.2 / 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(name, f"{handler_dir}{name}.py")
20            spec.loader.exec_module(importlib.util.module_from_spec(spec))
21
22        from app.telegram import utils # setup custom handlers
23        utils.setup()
24        await bot.polling()
25
26
27from .handlers.report import (  # noqa
28    report,
29    report_new_user,
30    report_user_modification,
31    report_user_deletion,
32    report_status_change,
33    report_user_usage_reset,
34    report_user_subscription_revoked
35)
36
37__all__ = [
38    "bot",
39    "report",
40    "report_new_user",
41    "report_user_modification",
42    "report_user_deletion",
43    "report_status_change",
44    "report_user_usage_reset",
45    "report_user_subscription_revoked"
46]