@inetafrica/open-claudia 1.1.8 → 1.2.0
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 +46 -7
- package/package.json +1 -1
package/bot.js
CHANGED
|
@@ -172,6 +172,7 @@ bot.setMyCommands([
|
|
|
172
172
|
{ command: "status", description: "Session & settings info" },
|
|
173
173
|
{ command: "stop", description: "Cancel running task" },
|
|
174
174
|
{ command: "end", description: "End current session" },
|
|
175
|
+
{ command: "version", description: "Show current version" },
|
|
175
176
|
{ command: "restart", description: "Restart the bot" },
|
|
176
177
|
{ command: "upgrade", description: "Upgrade and restart" },
|
|
177
178
|
{ command: "help", description: "Show all commands" },
|
|
@@ -820,6 +821,11 @@ bot.onText(/\/help/, (msg) => {
|
|
|
820
821
|
].join("\n"));
|
|
821
822
|
});
|
|
822
823
|
|
|
824
|
+
bot.onText(/\/version$/, (msg) => {
|
|
825
|
+
if (!isAuthorized(msg)) return;
|
|
826
|
+
send(`Open Claudia v${CURRENT_VERSION}`);
|
|
827
|
+
});
|
|
828
|
+
|
|
823
829
|
bot.onText(/\/restart$/, async (msg) => {
|
|
824
830
|
if (!isOwner(msg)) return;
|
|
825
831
|
await send("Restarting...");
|
|
@@ -831,13 +837,14 @@ bot.onText(/\/upgrade$/, async (msg) => {
|
|
|
831
837
|
if (!isOwner(msg)) return;
|
|
832
838
|
await send("Upgrading...");
|
|
833
839
|
try {
|
|
834
|
-
|
|
840
|
+
execSync("npm install -g @inetafrica/open-claudia@latest 2>&1", {
|
|
835
841
|
encoding: "utf-8", timeout: 60000,
|
|
836
842
|
env: { ...process.env, PATH: FULL_PATH },
|
|
837
843
|
});
|
|
838
|
-
|
|
839
|
-
const
|
|
840
|
-
|
|
844
|
+
// Read version from newly installed package
|
|
845
|
+
const root = execSync("npm root -g", { encoding: "utf-8", env: { ...process.env, PATH: FULL_PATH } }).trim();
|
|
846
|
+
const newPkg = JSON.parse(fs.readFileSync(path.join(root, "@inetafrica", "open-claudia", "package.json"), "utf-8"));
|
|
847
|
+
await send(`Upgraded: v${CURRENT_VERSION} → v${newPkg.version}. Restarting...`);
|
|
841
848
|
} catch (e) {
|
|
842
849
|
await send(`Upgrade failed: ${e.message}`);
|
|
843
850
|
return;
|
|
@@ -1193,9 +1200,41 @@ bot.on("message", async (msg) => {
|
|
|
1193
1200
|
if (!requireSession(msg)) return;
|
|
1194
1201
|
|
|
1195
1202
|
let prompt = msg.text;
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1203
|
+
const reply = msg.reply_to_message;
|
|
1204
|
+
if (reply) {
|
|
1205
|
+
let ctx = "";
|
|
1206
|
+
if (reply.text) {
|
|
1207
|
+
ctx = reply.text;
|
|
1208
|
+
}
|
|
1209
|
+
if (reply.caption) {
|
|
1210
|
+
ctx += (ctx ? "\n" : "") + reply.caption;
|
|
1211
|
+
}
|
|
1212
|
+
if (reply.document) {
|
|
1213
|
+
const fileName = reply.document.file_name || "unknown";
|
|
1214
|
+
const filePath = path.join(FILES_DIR, fileName);
|
|
1215
|
+
if (fs.existsSync(filePath)) {
|
|
1216
|
+
ctx += (ctx ? "\n" : "") + `[Attached file: ${fileName} at ${filePath}]`;
|
|
1217
|
+
} else {
|
|
1218
|
+
// Download the file from the replied message
|
|
1219
|
+
try {
|
|
1220
|
+
const file = await bot.getFile(reply.document.file_id);
|
|
1221
|
+
const fileUrl = `https://api.telegram.org/file/bot${TOKEN}/${file.file_path}`;
|
|
1222
|
+
await new Promise((resolve, reject) => {
|
|
1223
|
+
const out = fs.createWriteStream(filePath);
|
|
1224
|
+
https.get(fileUrl, (res) => { res.pipe(out); out.on("finish", () => { out.close(); resolve(); }); }).on("error", reject);
|
|
1225
|
+
});
|
|
1226
|
+
ctx += (ctx ? "\n" : "") + `[Attached file: ${fileName} at ${filePath}]`;
|
|
1227
|
+
} catch (e) {
|
|
1228
|
+
ctx += (ctx ? "\n" : "") + `[Attached file: ${fileName} — could not download]`;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
if (reply.photo) {
|
|
1233
|
+
ctx += (ctx ? "\n" : "") + "[Attached photo]";
|
|
1234
|
+
}
|
|
1235
|
+
if (ctx) {
|
|
1236
|
+
prompt = `Replying to message:\n---\n${ctx.length > 1000 ? ctx.slice(0, 1000) + "..." : ctx}\n---\n\n${msg.text}`;
|
|
1237
|
+
}
|
|
1199
1238
|
}
|
|
1200
1239
|
|
|
1201
1240
|
await runClaude(prompt, currentSession.dir, msg.message_id);
|