@inetafrica/open-claudia 1.1.6 → 1.1.8
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 +47 -6
- 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" },
|
|
@@ -154,8 +178,10 @@ bot.setMyCommands([
|
|
|
154
178
|
]);
|
|
155
179
|
|
|
156
180
|
// Temp dir for media
|
|
157
|
-
const TEMP_DIR = path.join(
|
|
181
|
+
const TEMP_DIR = path.join(CONFIG_DIR, "media");
|
|
182
|
+
const FILES_DIR = path.join(CONFIG_DIR, "files");
|
|
158
183
|
if (!fs.existsSync(TEMP_DIR)) fs.mkdirSync(TEMP_DIR, { recursive: true });
|
|
184
|
+
if (!fs.existsSync(FILES_DIR)) fs.mkdirSync(FILES_DIR, { recursive: true });
|
|
159
185
|
|
|
160
186
|
// ── Persistent state ───────────────────────────────────────────────
|
|
161
187
|
const STATE_FILE = path.join(CONFIG_DIR, "state.json");
|
|
@@ -1092,11 +1118,26 @@ bot.on("document", async (msg) => {
|
|
|
1092
1118
|
if (!isAuthorized(msg)) return;
|
|
1093
1119
|
if (!requireSession(msg)) return;
|
|
1094
1120
|
try {
|
|
1095
|
-
const
|
|
1096
|
-
const
|
|
1097
|
-
|
|
1098
|
-
const
|
|
1099
|
-
|
|
1121
|
+
const fileName = msg.document.file_name || `file-${Date.now()}`;
|
|
1122
|
+
const mime = msg.document.mime_type || "";
|
|
1123
|
+
// Save with original name to files dir
|
|
1124
|
+
const savePath = path.join(FILES_DIR, fileName);
|
|
1125
|
+
const file = await bot.getFile(msg.document.file_id);
|
|
1126
|
+
const fileUrl = `https://api.telegram.org/file/bot${TOKEN}/${file.file_path}`;
|
|
1127
|
+
await new Promise((resolve, reject) => {
|
|
1128
|
+
const out = fs.createWriteStream(savePath);
|
|
1129
|
+
https.get(fileUrl, (res) => { res.pipe(out); out.on("finish", () => { out.close(); resolve(); }); }).on("error", reject);
|
|
1130
|
+
});
|
|
1131
|
+
const caption = msg.caption || "";
|
|
1132
|
+
const isImage = mime.startsWith("image/");
|
|
1133
|
+
let prompt;
|
|
1134
|
+
if (isImage) {
|
|
1135
|
+
prompt = `Image file saved at ${savePath}\n\nView it, then: ${caption || "Describe this image. If code/UI/error — explain and fix."}`;
|
|
1136
|
+
} else {
|
|
1137
|
+
prompt = `File received: ${fileName} (${mime})\nSaved at: ${savePath}\n\nRead this file and ${caption || "summarize its contents. If it's code, explain what it does. If it's a document, give key points."}`;
|
|
1138
|
+
}
|
|
1139
|
+
await send(`File saved: ${fileName}`, { replyTo: msg.message_id });
|
|
1140
|
+
await runClaude(prompt, currentSession.dir, msg.message_id);
|
|
1100
1141
|
} catch (err) { await send(`Failed: ${err.message}`); }
|
|
1101
1142
|
});
|
|
1102
1143
|
|