@inetafrica/open-claudia 1.2.7 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +43 -14
- package/bot.js +8 -4
- package/package.json +1 -1
- package/setup.js +6 -9
package/bin/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { execSync } = require("child_process");
|
|
4
|
+
const fs = require("fs");
|
|
4
5
|
const path = require("path");
|
|
5
6
|
|
|
6
7
|
const args = process.argv.slice(2);
|
|
@@ -8,6 +9,30 @@ const command = args[0] || "help";
|
|
|
8
9
|
|
|
9
10
|
const botDir = path.join(__dirname, "..");
|
|
10
11
|
|
|
12
|
+
function findBotProcesses() {
|
|
13
|
+
try {
|
|
14
|
+
if (process.platform === "win32") {
|
|
15
|
+
const out = execSync('tasklist /FI "IMAGENAME eq node.exe" /FO CSV /NH', { encoding: "utf-8" });
|
|
16
|
+
// Check if any node process has bot.js in its command line
|
|
17
|
+
const wmic = execSync('wmic process where "name=\'node.exe\'" get ProcessId,CommandLine /FORMAT:CSV 2>nul', { encoding: "utf-8" });
|
|
18
|
+
const pids = [];
|
|
19
|
+
for (const line of wmic.split("\n")) {
|
|
20
|
+
if (line.includes("bot.js") && line.includes("open-claudia")) {
|
|
21
|
+
const parts = line.trim().split(",");
|
|
22
|
+
const pid = parts[parts.length - 1];
|
|
23
|
+
if (pid) pids.push(pid.trim());
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return pids;
|
|
27
|
+
} else {
|
|
28
|
+
const out = execSync('ps -eo pid,command | grep "bot.js" | grep "open-claudia" | grep -v grep', { encoding: "utf-8" });
|
|
29
|
+
return out.trim().split("\n").map((l) => l.trim().split(/\s+/)[0]).filter(Boolean);
|
|
30
|
+
}
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
11
36
|
switch (command) {
|
|
12
37
|
case "setup":
|
|
13
38
|
require(path.join(botDir, "setup.js"));
|
|
@@ -24,33 +49,37 @@ switch (command) {
|
|
|
24
49
|
require(path.join(botDir, "setup.js"));
|
|
25
50
|
break;
|
|
26
51
|
|
|
27
|
-
case "stop":
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
console.log("Stopped.");
|
|
31
|
-
} catch (e) {
|
|
52
|
+
case "stop": {
|
|
53
|
+
const pids = findBotProcesses();
|
|
54
|
+
if (pids.length === 0) {
|
|
32
55
|
console.log("Not running.");
|
|
56
|
+
} else {
|
|
57
|
+
for (const pid of pids) {
|
|
58
|
+
try { process.kill(parseInt(pid, 10), "SIGTERM"); } catch (e) {}
|
|
59
|
+
}
|
|
60
|
+
console.log("Stopped.");
|
|
33
61
|
}
|
|
34
62
|
break;
|
|
63
|
+
}
|
|
35
64
|
|
|
36
|
-
case "logs":
|
|
65
|
+
case "logs": {
|
|
37
66
|
const configDir = require(path.join(botDir, "config-dir"));
|
|
38
67
|
const logFile = path.join(configDir, "bot.log");
|
|
39
68
|
try {
|
|
40
|
-
|
|
69
|
+
const content = fs.readFileSync(logFile, "utf-8");
|
|
70
|
+
const lines = content.split("\n");
|
|
71
|
+
console.log(lines.slice(-50).join("\n"));
|
|
41
72
|
} catch (e) {
|
|
42
73
|
console.log("No logs found.");
|
|
43
74
|
}
|
|
44
75
|
break;
|
|
76
|
+
}
|
|
45
77
|
|
|
46
|
-
case "status":
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
console.log("Running.");
|
|
50
|
-
} catch (e) {
|
|
51
|
-
console.log("Not running.");
|
|
52
|
-
}
|
|
78
|
+
case "status": {
|
|
79
|
+
const pids = findBotProcesses();
|
|
80
|
+
console.log(pids.length > 0 ? `Running (PID: ${pids.join(", ")}).` : "Not running.");
|
|
53
81
|
break;
|
|
82
|
+
}
|
|
54
83
|
|
|
55
84
|
default:
|
|
56
85
|
console.log(`
|
package/bot.js
CHANGED
|
@@ -61,8 +61,11 @@ const FULL_PATH = [
|
|
|
61
61
|
path.dirname(process.execPath),
|
|
62
62
|
FFMPEG ? path.dirname(FFMPEG) : null,
|
|
63
63
|
WHISPER_CLI ? path.dirname(WHISPER_CLI) : null,
|
|
64
|
-
|
|
65
|
-
].filter(Boolean).join("
|
|
64
|
+
...(process.platform === "win32"
|
|
65
|
+
? [process.env.APPDATA, process.env.LOCALAPPDATA].filter(Boolean).map((p) => path.join(p, "npm"))
|
|
66
|
+
: ["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin", "/usr/sbin", "/sbin"]
|
|
67
|
+
),
|
|
68
|
+
].filter(Boolean).join(path.delimiter);
|
|
66
69
|
|
|
67
70
|
const bot = new TelegramBot(TOKEN, {
|
|
68
71
|
polling: {
|
|
@@ -809,14 +812,15 @@ bot.onText(/\/upgrade$/, async (msg) => {
|
|
|
809
812
|
try {
|
|
810
813
|
execSync("npm install -g @inetafrica/open-claudia@latest 2>&1", {
|
|
811
814
|
encoding: "utf-8", timeout: 120000,
|
|
812
|
-
env: { ...process.env, PATH: FULL_PATH },
|
|
815
|
+
env: { ...process.env, PATH: FULL_PATH, HOME: process.env.HOME || require("os").homedir() },
|
|
813
816
|
});
|
|
814
817
|
// Read version from newly installed package
|
|
815
818
|
const root = execSync("npm root -g", { encoding: "utf-8", env: { ...process.env, PATH: FULL_PATH } }).trim();
|
|
816
819
|
const newPkg = JSON.parse(fs.readFileSync(path.join(root, "@inetafrica", "open-claudia", "package.json"), "utf-8"));
|
|
817
820
|
await send(`Installed v${newPkg.version}. Going offline to restart...`);
|
|
818
821
|
} catch (e) {
|
|
819
|
-
|
|
822
|
+
const errOutput = (e.stdout || e.stderr || e.message || "").slice(-500);
|
|
823
|
+
await send(`Upgrade failed:\n${errOutput}`);
|
|
820
824
|
return;
|
|
821
825
|
}
|
|
822
826
|
// Give Telegram time to deliver the message, then exit for launchd to restart
|
package/package.json
CHANGED
package/setup.js
CHANGED
|
@@ -138,20 +138,17 @@ function detectPlatform() {
|
|
|
138
138
|
return "other";
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
function
|
|
141
|
+
function findBinary(name) {
|
|
142
|
+
const cmd = process.platform === "win32" ? `where ${name} 2>nul` : `which ${name} 2>/dev/null`;
|
|
142
143
|
try {
|
|
143
|
-
const p = execSync(
|
|
144
|
+
const p = execSync(cmd, { encoding: "utf-8" }).trim().split("\n")[0];
|
|
144
145
|
return p || null;
|
|
145
146
|
} catch (e) { return null; }
|
|
146
147
|
}
|
|
147
148
|
|
|
148
|
-
function
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function findFfmpeg() {
|
|
153
|
-
try { return execSync("which ffmpeg 2>/dev/null", { encoding: "utf-8" }).trim() || null; } catch (e) { return null; }
|
|
154
|
-
}
|
|
149
|
+
function findClaude() { return findBinary("claude"); }
|
|
150
|
+
function findWhisper() { return findBinary("whisper-cli"); }
|
|
151
|
+
function findFfmpeg() { return findBinary("ffmpeg"); }
|
|
155
152
|
|
|
156
153
|
function findWhisperModel() {
|
|
157
154
|
const candidates = [
|