-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (46 loc) · 2.22 KB
/
Copy pathmain.py
File metadata and controls
59 lines (46 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import asyncio
import logging
from aiogram import Bot, Dispatcher
from aiogram.filters import Command
from teletube.config import BOT_TOKEN, LOG_LEVEL_STR, BOT_NAME
from teletube.handlers import (
cmd_start, cmd_help, cmd_addvideo, cmd_leaderboard, cmd_leaderboardpic,
cmd_myprofile, cmd_achievements, cmd_daily, cmd_shop, cb_shop_buy,
admin_add_currency, admin_add_subs, admin_delete_db, admin_stats
)
def _setup_logging():
logging.basicConfig(level=getattr(logging, LOG_LEVEL_STR, logging.INFO), format="%(asctime)s | %(levelname)s | %(message)s")
logger = logging.getLogger(__name__)
return logger
async def main():
logger = _setup_logging()
if not BOT_TOKEN:
logger.critical("BOT_TOKEN is missing. Set it in .env")
return
bot = Bot(token=BOT_TOKEN)
dp = Dispatcher()
dp.message.register(cmd_start, Command(commands=["start"]))
dp.message.register(cmd_help, Command(commands=["help", "info"]))
dp.message.register(cmd_addvideo, Command(commands=["addvideo", "add", "video", "newvideo", "publishvideo", "publish"]))
dp.message.register(cmd_leaderboard, Command(commands=["leaderboard", "lp"]))
dp.message.register(cmd_leaderboardpic, Command(commands=["leaderboardpic", "lppic"]))
dp.message.register(cmd_myprofile, Command(commands=["myprofile"]))
dp.message.register(cmd_achievements, Command(commands=["achievements"]))
dp.message.register(cmd_daily, Command(commands=["daily"]))
dp.message.register(cmd_shop, Command(commands=["shop"]))
dp.message.register(admin_add_currency, Command(commands=["CHEATaddcoins"]))
dp.message.register(admin_add_subs, Command(commands=["CHEATaddsub"]))
dp.message.register(admin_delete_db, Command(commands=["CHEATDeleteDatabase"]))
dp.message.register(admin_stats, Command(commands=["botstats"]))
dp.callback_query.register(cb_shop_buy, lambda c: c.data and c.data.startswith("shop_buy:"))
logger.info("%s is starting...", BOT_NAME)
try:
await dp.start_polling(bot)
finally:
await bot.session.close()
if __name__ == "__main__":
logger = _setup_logging()
try:
asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
logger.info("Stopped by user")