-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (52 loc) · 2 KB
/
main.py
File metadata and controls
60 lines (52 loc) · 2 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
58
59
60
import asyncio
import logging
from data.config import config
from data.loader import scheduler, bot, dp, setup_db
from handlers.admin import admin_router
from handlers.advert import advert_router
from handlers.get_music import music_router
from handlers.link_dispatcher import link_router
from handlers.get_video import video_router
from handlers.lang import lang_router
from handlers.user import user_router
from handlers.get_inline import inline_router
from handlers.inline_slideshow import slideshow_router, cleanup_all_slideshows
from media_types import close_http_session
from stats.misc import update_overall_stats, update_daily_stats
from tiktok_api import ProxyManager, TikTokClient
async def main() -> None:
await setup_db(config["bot"]["db_url"])
# Initialize proxy manager if configured
if config["proxy"]["proxy_file"]:
ProxyManager.initialize(
proxy_file=config["proxy"]["proxy_file"],
include_host=config["proxy"]["include_host"],
)
logging.info("Proxy manager initialized")
scheduler.start()
dp.include_routers(
user_router,
lang_router,
admin_router,
advert_router,
link_router,
video_router,
music_router,
inline_router,
slideshow_router,
)
bot_info = await bot.get_me()
logging.info(f"{bot_info.full_name} [@{bot_info.username}, id:{bot_info.id}]")
try:
await dp.start_polling(bot)
finally:
# Cleanup shared resources on shutdown
logging.info("Shutting down: cleaning up TikTokClient resources...")
await TikTokClient.close_curl_session() # curl_cffi session for media downloads
await TikTokClient.close_connector() # aiohttp connector for URL resolution
TikTokClient.shutdown_executor()
await close_http_session() # aiohttp session for thumbnail/cover downloads
cleanup_all_slideshows()
logging.info("TikTokClient resources cleaned up")
if __name__ == "__main__":
asyncio.run(main())