-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (45 loc) · 1.61 KB
/
main.py
File metadata and controls
55 lines (45 loc) · 1.61 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
import asyncio
import logging
import sys
from aiogram import Bot, Dispatcher
from aiogram.client.session.aiohttp import AiohttpSession
from aiogram.client.telegram import TelegramAPIServer
from config import BOT_TOKEN, LOCAL_API_SERVER_URL, NAS_ROOT_PATH, CATEGORIES
from handlers import commands, files, search, folders
from utils.storage import ensure_nas_structure
# Configure logging to be more professional
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
stream=sys.stdout
)
logger = logging.getLogger(__name__)
async def main():
# 1. Initialize NAS structure
ensure_nas_structure(NAS_ROOT_PATH, CATEGORIES)
# 2. Configure Local Bot API Server
session = AiohttpSession(
api=TelegramAPIServer.from_base(LOCAL_API_SERVER_URL)
)
# 3. Initialize Bot and Dispatcher
bot = Bot(token=BOT_TOKEN)
dp = Dispatcher()
# 4. Register Routers
dp.include_router(commands.router)
dp.include_router(files.router)
dp.include_router(search.router)
dp.include_router(folders.router)
# 5. Start Polling
logger.info("--- Starting Files-Node-Bot ---")
logger.info(f"Local Server: {LOCAL_API_SERVER_URL}")
logger.info(f"NAS Root: {NAS_ROOT_PATH}")
# Skip updates to avoid flooding on restart
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
logger.info("Bot stopped by user.")
except Exception as e:
logger.critical(f"Critical error: {e}", exc_info=True)