-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaintenance_bot.py
More file actions
58 lines (42 loc) · 1.65 KB
/
maintenance_bot.py
File metadata and controls
58 lines (42 loc) · 1.65 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
import asyncio
import json
import logging
import os
from aiogram import Bot, Dispatcher, F, Router
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode
from aiogram.types import Message
from data.config import config, locale
# Setup logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)-5.5s] %(message)s",
handlers=[logging.StreamHandler()])
# Setup bot
bot = Bot(token=config["bot"]["token"], default=DefaultBotProperties(parse_mode=ParseMode.HTML))
# Create dispatcher
dp = Dispatcher()
# Create maintenance router
maintenance_router = Router(name="maintenance")
maintenance_router.message.filter(F.chat.type == "private")
# Helper function to determine user language
async def get_user_language(user_id, language_code):
# Default to English if language not supported
if language_code not in locale['langs']:
return 'en'
return language_code
# Handler for all other messages
@maintenance_router.message()
async def maintenance_message(message: Message):
lang = await get_user_language(message.from_user.id, message.from_user.language_code)
# If language doesn't have maintenance message, use English
if 'maintenance' not in locale[lang]:
lang = 'en'
await message.answer(locale[lang]['maintenance'])
async def main() -> None:
# Include maintenance router
dp.include_router(maintenance_router)
# Start bot
bot_info = await bot.get_me()
logging.info(f'MAINTENANCE MODE: {bot_info.full_name} [@{bot_info.username}, id:{bot_info.id}]')
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())