@inetafrica/open-claudia 1.1.4 → 1.1.6
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/bot.js +32 -22
- package/package.json +1 -1
package/bot.js
CHANGED
|
@@ -98,9 +98,38 @@ const FULL_PATH = [
|
|
|
98
98
|
"/usr/local/bin", "/usr/bin", "/bin", "/usr/sbin", "/sbin",
|
|
99
99
|
].filter(Boolean).join(":");
|
|
100
100
|
|
|
101
|
-
const bot = new TelegramBot(TOKEN, {
|
|
101
|
+
const bot = new TelegramBot(TOKEN, {
|
|
102
|
+
polling: {
|
|
103
|
+
autoStart: true,
|
|
104
|
+
params: { timeout: 30 },
|
|
105
|
+
},
|
|
106
|
+
});
|
|
102
107
|
const vault = new Vault(VAULT_FILE);
|
|
103
108
|
|
|
109
|
+
// ── Auto-reconnect on polling errors ───────────────────────────────
|
|
110
|
+
let reconnectTimer = null;
|
|
111
|
+
bot.on("polling_error", (err) => {
|
|
112
|
+
const msg = err.message || "";
|
|
113
|
+
console.error("Polling error:", msg);
|
|
114
|
+
if (msg.includes("ETIMEDOUT") || msg.includes("ECONNRESET") || msg.includes("ENOTFOUND") || msg.includes("EFATAL")) {
|
|
115
|
+
if (reconnectTimer) return; // Already scheduled
|
|
116
|
+
console.log("Network lost. Reconnecting in 10s...");
|
|
117
|
+
reconnectTimer = setTimeout(async () => {
|
|
118
|
+
reconnectTimer = null;
|
|
119
|
+
try {
|
|
120
|
+
await bot.stopPolling();
|
|
121
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
122
|
+
await bot.startPolling();
|
|
123
|
+
console.log("Reconnected.");
|
|
124
|
+
} catch (e) {
|
|
125
|
+
console.error("Reconnect failed:", e.message);
|
|
126
|
+
// launchd will restart us if we exit
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
}, 10000);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
104
133
|
// ── Commands Menu ───────────────────────────────────────────────────
|
|
105
134
|
bot.setMyCommands([
|
|
106
135
|
{ command: "session", description: "Pick a project to work on" },
|
|
@@ -768,13 +797,7 @@ bot.onText(/\/help/, (msg) => {
|
|
|
768
797
|
bot.onText(/\/restart$/, async (msg) => {
|
|
769
798
|
if (!isOwner(msg)) return;
|
|
770
799
|
await send("Restarting...");
|
|
771
|
-
|
|
772
|
-
const child = spawn(process.execPath, [botPath], {
|
|
773
|
-
detached: true,
|
|
774
|
-
stdio: "ignore",
|
|
775
|
-
env: { ...process.env, PATH: FULL_PATH },
|
|
776
|
-
});
|
|
777
|
-
child.unref();
|
|
800
|
+
releaseLock();
|
|
778
801
|
setTimeout(() => process.exit(0), 500);
|
|
779
802
|
});
|
|
780
803
|
|
|
@@ -793,20 +816,7 @@ bot.onText(/\/upgrade$/, async (msg) => {
|
|
|
793
816
|
await send(`Upgrade failed: ${e.message}`);
|
|
794
817
|
return;
|
|
795
818
|
}
|
|
796
|
-
|
|
797
|
-
let botPath;
|
|
798
|
-
try {
|
|
799
|
-
const root = execSync("npm root -g", { encoding: "utf-8" }).trim();
|
|
800
|
-
botPath = path.join(root, "@inetafrica", "open-claudia", "bot.js");
|
|
801
|
-
} catch (e) {
|
|
802
|
-
botPath = path.join(__dirname, "bot.js");
|
|
803
|
-
}
|
|
804
|
-
const child = spawn(process.execPath, [botPath], {
|
|
805
|
-
detached: true,
|
|
806
|
-
stdio: "ignore",
|
|
807
|
-
env: { ...process.env, PATH: FULL_PATH },
|
|
808
|
-
});
|
|
809
|
-
child.unref();
|
|
819
|
+
releaseLock();
|
|
810
820
|
setTimeout(() => process.exit(0), 500);
|
|
811
821
|
});
|
|
812
822
|
|