@inetafrica/open-claudia 1.1.5 → 1.1.7
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 +26 -21
- package/package.json +1 -1
package/bot.js
CHANGED
|
@@ -130,6 +130,30 @@ bot.on("polling_error", (err) => {
|
|
|
130
130
|
}
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
+
// ── Update checker (every 5 mins) ──────────────────────────────────
|
|
134
|
+
const CURRENT_VERSION = require(path.join(__dirname, "package.json")).version;
|
|
135
|
+
let lastNotifiedVersion = null;
|
|
136
|
+
|
|
137
|
+
function checkForUpdates() {
|
|
138
|
+
https.get("https://registry.npmjs.org/@inetafrica/open-claudia/latest", (res) => {
|
|
139
|
+
let data = "";
|
|
140
|
+
res.on("data", (d) => { data += d; });
|
|
141
|
+
res.on("end", () => {
|
|
142
|
+
try {
|
|
143
|
+
const latest = JSON.parse(data).version;
|
|
144
|
+
if (latest && latest !== CURRENT_VERSION && latest !== lastNotifiedVersion) {
|
|
145
|
+
lastNotifiedVersion = latest;
|
|
146
|
+
bot.sendMessage(CHAT_ID, `Update available: v${CURRENT_VERSION} → v${latest}\n\nSend /upgrade to update.`);
|
|
147
|
+
}
|
|
148
|
+
} catch (e) {}
|
|
149
|
+
});
|
|
150
|
+
}).on("error", () => {});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Check on startup (after 30s) and every 5 minutes
|
|
154
|
+
setTimeout(checkForUpdates, 30000);
|
|
155
|
+
setInterval(checkForUpdates, 5 * 60 * 1000);
|
|
156
|
+
|
|
133
157
|
// ── Commands Menu ───────────────────────────────────────────────────
|
|
134
158
|
bot.setMyCommands([
|
|
135
159
|
{ command: "session", description: "Pick a project to work on" },
|
|
@@ -797,13 +821,7 @@ bot.onText(/\/help/, (msg) => {
|
|
|
797
821
|
bot.onText(/\/restart$/, async (msg) => {
|
|
798
822
|
if (!isOwner(msg)) return;
|
|
799
823
|
await send("Restarting...");
|
|
800
|
-
|
|
801
|
-
const child = spawn(process.execPath, [botPath], {
|
|
802
|
-
detached: true,
|
|
803
|
-
stdio: "ignore",
|
|
804
|
-
env: { ...process.env, PATH: FULL_PATH },
|
|
805
|
-
});
|
|
806
|
-
child.unref();
|
|
824
|
+
releaseLock();
|
|
807
825
|
setTimeout(() => process.exit(0), 500);
|
|
808
826
|
});
|
|
809
827
|
|
|
@@ -822,20 +840,7 @@ bot.onText(/\/upgrade$/, async (msg) => {
|
|
|
822
840
|
await send(`Upgrade failed: ${e.message}`);
|
|
823
841
|
return;
|
|
824
842
|
}
|
|
825
|
-
|
|
826
|
-
let botPath;
|
|
827
|
-
try {
|
|
828
|
-
const root = execSync("npm root -g", { encoding: "utf-8" }).trim();
|
|
829
|
-
botPath = path.join(root, "@inetafrica", "open-claudia", "bot.js");
|
|
830
|
-
} catch (e) {
|
|
831
|
-
botPath = path.join(__dirname, "bot.js");
|
|
832
|
-
}
|
|
833
|
-
const child = spawn(process.execPath, [botPath], {
|
|
834
|
-
detached: true,
|
|
835
|
-
stdio: "ignore",
|
|
836
|
-
env: { ...process.env, PATH: FULL_PATH },
|
|
837
|
-
});
|
|
838
|
-
child.unref();
|
|
843
|
+
releaseLock();
|
|
839
844
|
setTimeout(() => process.exit(0), 500);
|
|
840
845
|
});
|
|
841
846
|
|