feat(telegram): независимый жизненный цикл Telegram Bot и Watchdog + команда /heal (v1.2.28)
This commit is contained in:
@@ -790,6 +790,10 @@ function start_main() {
|
||||
}
|
||||
|
||||
function start_impl() {
|
||||
// Start Watchdog & Telegram Bot early so they remain active even if proxy configuration fails
|
||||
module_status(WATCHDOG_UC, [ "start-runtime" ]);
|
||||
module_status(TELEGRAM_UC, [ "start-runtime" ]);
|
||||
|
||||
let status = start_main();
|
||||
if (status != 0)
|
||||
return status;
|
||||
@@ -827,17 +831,6 @@ function start_impl() {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = module_status(WATCHDOG_UC, [ "start-runtime" ]);
|
||||
if (status != 0) {
|
||||
log_message("Failed to start Watchdog runtime", "fatal");
|
||||
return status;
|
||||
}
|
||||
|
||||
status = module_status(TELEGRAM_UC, [ "start-runtime" ]);
|
||||
if (status != 0) {
|
||||
log_message("Failed to start Telegram Bot runtime", "warn");
|
||||
}
|
||||
|
||||
module_background(DIAGNOSTICS_UC, [ "get-system-info" ]);
|
||||
return 0;
|
||||
}
|
||||
@@ -847,8 +840,6 @@ function stop_main() {
|
||||
|
||||
log_message("Stopping Tachyon", "info");
|
||||
module_success(DNS_FAILOVER_UC, [ "stop-runtime" ]);
|
||||
module_success(WATCHDOG_UC, [ "stop-runtime" ]);
|
||||
module_success(TELEGRAM_UC, [ "stop-runtime" ]);
|
||||
module_success(PRIORITY_UC, [ "stop-runtime" ]);
|
||||
module_success(SUBSCRIPTION_CACHE_UC, [ "stop-deferred-bootstrap-worker" ]);
|
||||
module_success(UPDATES_UC, [ "stop-list-update" ]);
|
||||
|
||||
@@ -394,6 +394,9 @@ function view_menu(token, chat_id, msg_id) {
|
||||
{ text: "💻 Устройства", callback_data: "/devices" },
|
||||
{ text: "🐕 Watchdog", callback_data: "/watchdog" }
|
||||
],
|
||||
[
|
||||
{ text: "🤖 ИИ-Самолечение", callback_data: "/heal" }
|
||||
],
|
||||
[
|
||||
{ text: "🩺 Диагностика", callback_data: "/doctor" },
|
||||
{ text: "🔄 Перезапуск", callback_data: "/restart" }
|
||||
@@ -935,6 +938,34 @@ function view_watchdog(token, chat_id, msg_id) {
|
||||
else send_message(token, chat_id, text, "HTML", keyboard);
|
||||
}
|
||||
|
||||
function exec_ai_heal(token, chat_id, msg_id) {
|
||||
send_message(token, chat_id, "🤖 <b>ИИ-Автомеханик выполняет диагностику и самолечение...</b>", "HTML");
|
||||
|
||||
command_status("/usr/bin/tachyon ai_heal");
|
||||
|
||||
let status_data = fs.readfile("/tmp/tachyon_ai_status.json");
|
||||
let text = "🤖 <b>[ИИ-Автомеханик Tachyon]</b>\n\n";
|
||||
if (status_data) {
|
||||
try {
|
||||
let st = json(status_data);
|
||||
if (st.last_incident) {
|
||||
text += "⚠️ <b>Устранён инцидент:</b> " + escape_html(st.last_incident.description || "") + "\n";
|
||||
text += "🔧 <b>Авто-решение:</b> " + escape_html(st.last_incident.resolution || "") + "\n\n";
|
||||
text += "Все системы приведены в штатную норму! 🟢";
|
||||
} else {
|
||||
text += "🟢 Все сетевые службы, DNS, nftables и память работают идеально.";
|
||||
}
|
||||
} catch(e) {
|
||||
text += "🟢 Диагностика завершена успешно.";
|
||||
}
|
||||
} else {
|
||||
text += "🟢 Диагностика завершена.";
|
||||
}
|
||||
|
||||
let keyboard = [[{ text: "⬅️ В меню", callback_data: "/menu" }]];
|
||||
send_message(token, chat_id, text, "HTML", keyboard);
|
||||
}
|
||||
|
||||
// ─── Dispatcher ──────────────────────────────────────────────────────────────
|
||||
|
||||
function dispatch_command(token, chat_id, text, msg_id) {
|
||||
@@ -944,6 +975,7 @@ function dispatch_command(token, chat_id, text, msg_id) {
|
||||
if (cmd == "/start" || cmd == "/menu") return view_menu(token, chat_id, msg_id);
|
||||
if (cmd == "/status") return view_status(token, chat_id, msg_id);
|
||||
if (cmd == "/runtime") return view_runtime(token, chat_id, msg_id);
|
||||
if (cmd == "/heal" || cmd == "/ai_heal") return exec_ai_heal(token, chat_id, msg_id);
|
||||
|
||||
if (cmd == "/outbounds") return view_outbounds(token, chat_id, msg_id);
|
||||
if (match(cmd, /^\/outbounds /)) {
|
||||
|
||||
Reference in New Issue
Block a user