-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
97 lines (77 loc) · 3.59 KB
/
main.py
File metadata and controls
97 lines (77 loc) · 3.59 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
import sys
import asyncio
import platform
import subprocess
CONFIG_FILE = "config.py"
def is_interactive():
return sys.stdin.isatty()
# ============================================================
# 1️⃣ SETUP WIZARD — запускается только если интерактивный шелл
# ============================================================
def setup_wizard():
print("\n" + "="*40)
print(" 🛠 SETUP WIZARD")
print("="*40)
use_discord = input("1. Включить Discord бота? (y/n): ").lower().strip() == 'y'
discord_token = input(" -> DISCORD_TOKEN: ").strip() if use_discord else ""
discord_owner = input(" -> Discord Owner Username: ").strip() if use_discord else ""
use_telegram = input("\n2. Включить Telegram бота? (y/n): ").lower().strip() == 'y'
telegram_token = input(" -> TELEGRAM_TOKEN: ").strip() if use_telegram else ""
telegram_owner = input(" -> Telegram Owner ID: ").strip() if use_telegram else ""
webhook_url = ""
if use_telegram:
webhook_url = input(" -> Telegram Webhook URL (пусто = polling): ").strip()
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
f.write(f'''# Auto-generated config
ENABLE_DISCORD = {use_discord}
DISCORD_TOKEN = "{discord_token}"
DISCORD_OWNER = "{discord_owner}"
ENABLE_TELEGRAM = {use_telegram}
TELEGRAM_TOKEN = "{telegram_token}"
TELEGRAM_OWNER = "{telegram_owner}"
TELEGRAM_WEBHOOK_URL = "{webhook_url}"
''')
print("\n✅ Config created! Перезапусти программу.\n")
sys.exit(0)
# ============================================================
# 2️⃣ Проверка наличия конфига
# ============================================================
if not os.path.exists(CONFIG_FILE):
if is_interactive():
setup_wizard()
else:
print("[CONFIG] Файл config.py не найден. Создайте его вручную или запустите интерактивно.")
print("Пример:\nENABLE_DISCORD = False\nENABLE_TELEGRAM = True\nTELEGRAM_TOKEN = 'yourtoken'\n")
sys.exit(1)
import config
# ============================================================
# 3️⃣ Установка зависимостей
# ============================================================
REQUIRED = ["psutil"]
if getattr(config, "ENABLE_DISCORD", False): REQUIRED.append("discord.py")
if getattr(config, "ENABLE_TELEGRAM", False): REQUIRED.append("python-telegram-bot==20.*")
for lib in REQUIRED:
try:
__import__(lib.split("==")[0].replace("-", "_"))
except ImportError:
subprocess.check_call([sys.executable, "-m", "pip", "install", lib])
# ============================================================
# 4️⃣ Запуск соответствующего бота
# ============================================================
async def main():
if config.ENABLE_DISCORD and not config.ENABLE_TELEGRAM:
from bot_discord import run_discord
await run_discord()
elif config.ENABLE_TELEGRAM and not config.ENABLE_DISCORD:
from bot_telegram import run_telegram
await run_telegram()
elif config.ENABLE_DISCORD and config.ENABLE_TELEGRAM:
print("⚠️ Один процесс — один бот. Включи только один в config.py")
sys.exit(1)
else:
print("❌ Ни один бот не включен в config.py")
if __name__ == "__main__":
if platform.system() == "Windows":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())