-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_dotenv
More file actions
55 lines (44 loc) · 1.64 KB
/
load_dotenv
File metadata and controls
55 lines (44 loc) · 1.64 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 os
import logging
import asyncio
from dotenv import load_dotenv # Добавляем это
from aiogram import Bot, Dispatcher, types, F
from aiogram.filters import Command
# Загружаем переменные из .env
load_dotenv()
# Логирование
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
# Берем токен из переменной окружения
TOKEN = os.getenv("BOT_TOKEN")
if not TOKEN:
logger.critical("❌ Ошибка: Токен бота не найден в файле .env!")
exit(1)
bot = Bot(token=TOKEN)
dp = Dispatcher()
# ============ ОБРАБОТЧИКИ ============
@dp.message(Command("start"))
async def cmd_start(message: types.Message):
logger.info(f"✅ /start от {message.from_user.id}")
await message.answer(
"🤖 **JD7 System: Secure Launch**\n\n"
"Бот успешно загрузил токен из системы защиты.\n"
"Все протоколы безопасности активны. 🛡"
)
@dp.message(Command("status"))
async def cmd_status(message: types.Message):
await message.answer("✅ Бот онлайн. Соединение зашифровано.")
# ============ ЗАПУСК ============
async def main():
logger.info("🤖 Запуск защищенной сессии...")
try:
await dp.start_polling(bot)
except Exception as e:
logger.error(f"❌ Критическая ошибка: {e}")
finally:
await bot.session.close()
if __name__ == "__main__":
asyncio.run(main())