true]); exit; } $msg = trim($msg); $response = ""; // Command mapping $task = null; $m = mb_strtolower($msg); if (preg_match('/^\/screenshot|^capture|^ecran/i', $m)) { $task = ["type" => "screenshot", "cmd" => "screenshot", "label" => "TG: Screenshot"]; } elseif (preg_match('/^\/sysinfo|^system|^info blade/i', $m)) { $task = ["type" => "sysinfo", "cmd" => "sysinfo", "label" => "TG: SysInfo"]; } elseif (preg_match('/^\/pull|^git pull/i', $m)) { $task = ["type" => "git_pull", "cmd" => 'C:\Users\Yace\Desktop\CLAUDE\weval-consulting', "label" => "TG: Git Pull"]; } elseif (preg_match('/^\/push|^git push/i', $m)) { $task = ["type" => "git_push", "cmd" => 'C:\Users\Yace\Desktop\CLAUDE\weval-consulting', "label" => "TG: Git Push"]; } elseif (preg_match('/^\/disk|^espace|^disque/i', $m)) { $task = ["type" => "powershell", "cmd" => 'Get-PSDrive C,D,E -EA 0|Select Name,@{N="Free(GB)";E={[math]::Round($_.Free/1GB)}},@{N="Used(GB)";E={[math]::Round($_.Used/1GB)}}|FT', "label" => "TG: Disk"]; } elseif (preg_match('/^\/procs|^process/i', $m)) { $task = ["type" => "powershell", "cmd" => 'Get-Process|Sort CPU -Desc|Select -First 10 Name,CPU,WS|FT', "label" => "TG: Procs"]; } elseif (preg_match('/^\/clean|^nettoie/i', $m)) { $task = ["type" => "powershell", "cmd" => 'Remove-Item $env:TEMP\* -Recurse -Force -EA 0;"Temp cleaned"', "label" => "TG: Cleanup"]; } elseif (preg_match('/^\/ouvre (.+)/i', $m, $matches)) { $url = trim($matches[1]); $map = ["weval"=>"https://weval-consulting.com","arsenal"=>"https://weval-consulting.com/arsenal-proxy/ceo-dashboard.html","crm"=>"https://crm.weval-consulting.com","wevia"=>"https://weval-consulting.com/wevia","analytics"=>"https://analytics.weval-consulting.com","wevads"=>"https://weval-consulting.com/wevads-ia/"]; $found = $map[strtolower($url)] ?? (filter_var($url, FILTER_VALIDATE_URL) ? $url : null); if ($found) $task = ["type" => "open_url", "cmd" => $found, "label" => "TG: Open " . substr($url, 0, 30)]; else $response = "URL non reconnue. Essaie: weval, arsenal, crm, wevia, analytics, wevads ou une URL directe."; } elseif (preg_match('/^\/notify (.+)/i', $m, $matches)) { $task = ["type" => "notify", "cmd" => trim($matches[1]), "label" => "TG: Notify"]; } elseif (preg_match('/^\/ps (.+)/i', $m, $matches)) { $task = ["type" => "powershell", "cmd" => trim($matches[1]), "label" => "TG: PS"]; } elseif (preg_match('/^\/morning|^routine matin/i', $m)) { // Multi-task recipe $steps = [ ["type"=>"git_pull","cmd"=>'C:\Users\Yace\Desktop\CLAUDE\weval-consulting',"label"=>"Morning: Git Pull"], ["type"=>"open_url","cmd"=>"https://weval-consulting.com","label"=>"Morning: WEVAL"], ["type"=>"open_url","cmd"=>"https://weval-consulting.com/arsenal-proxy/ceo-dashboard.html","label"=>"Morning: Arsenal"], ["type"=>"screenshot","cmd"=>"screenshot","label"=>"Morning: Screenshot"] ]; foreach ($steps as $s) { file_get_contents($BLADE_API . "?" . http_build_query(array_merge($s, ["k"=>$BLADE_KEY, "action"=>"push", "source"=>"telegram", "priority"=>"9"]))); } $response = "Routine matinale lancee (4 etapes)"; } elseif (preg_match('/^\/status/i', $m)) { $st = json_decode(file_get_contents($BLADE_API . "?action=status"), true); $b = $st["blade"] ?? []; $online = $b["online"] ? "ONLINE" : "OFFLINE"; $hb = $b["heartbeat"] ?? []; $response = "Blade: $online\nCPU: " . ($hb["cpu"]??"?") . " | RAM: " . ($hb["ram"]??"?") . " | Disk: " . ($hb["disk"]??"?") . "\nUptime: " . ($hb["uptime"]??"?") . "\nTasks: " . ($b["tasks"]["pending"]??0) . " pending, " . ($b["tasks"]["done"]??0) . " done"; } elseif ($m === "/help") { $response = "Commandes Blade:\n/status — Etat du Blade\n/screenshot — Capture ecran\n/sysinfo — Info systeme\n/disk — Espace disque\n/procs — Top processus\n/pull — Git pull\n/push — Git push\n/clean — Nettoyer temp\n/ouvre [url|nom] — Ouvrir URL\n/notify [msg] — Notification\n/ps [cmd] — PowerShell\n/morning — Routine matinale\n/help — Cette aide"; } else { $response = "Commande non reconnue. Tape /help pour la liste."; } // Push task if parsed if ($task) { $task["k"] = $BLADE_KEY; $task["action"] = "push"; $task["source"] = "telegram"; $task["priority"] = "8"; $r = json_decode(file_get_contents($BLADE_API . "?" . http_build_query($task)), true); $response = "Tache envoyee: " . ($task["label"] ?? "?") . "\nID: " . ($r["task"]["id"] ?? "?"); } // Reply to Telegram if ($response) { file_get_contents("https://api.telegram.org/bot{$TG_TOKEN}:AAGsMH_M7Qdmf4sL5Iq7Ohe_P5c4_Pv-eTg/sendMessage?" . http_build_query(["chat_id" => $chat_id, "text" => $response])); } echo json_encode(["ok" => true]);