MCPcopy
hub / github.com/mruniquehacker/Knightbot-MD / updateCommand

Function updateCommand

commands/update.js:193–227  ·  view source on GitHub ↗
(sock, chatId, message, zipOverride)

Source from the content-addressed store, hash-verified

191}
192
193async function updateCommand(sock, chatId, message, zipOverride) {
194 const senderId = message.key.participant || message.key.remoteJid;
195 const isOwner = await isOwnerOrSudo(senderId, sock, chatId);
196
197 if (!message.key.fromMe && !isOwner) {
198 await sock.sendMessage(chatId, { text: 'Only bot owner or sudo can use .update' }, { quoted: message });
199 return;
200 }
201 try {
202 // Minimal UX
203 await sock.sendMessage(chatId, { text: '🔄 Updating the bot, please wait…' }, { quoted: message });
204 if (await hasGitRepo()) {
205 // silent
206 const { oldRev, newRev, alreadyUpToDate, commits, files } = await updateViaGit();
207 // Short message only: version info
208 const summary = alreadyUpToDate ? `✅ Already up to date: ${newRev}` : `✅ Updated to ${newRev}`;
209 console.log('[update] summary generated');
210 // silent
211 await run('npm install --no-audit --no-fund');
212 } else {
213 const { copiedFiles } = await updateViaZip(sock, chatId, message, zipOverride);
214 // silent
215 }
216 try {
217 const v = require('../settings').version || '';
218 await sock.sendMessage(chatId, { text: `✅ Update done. Restarting…` }, { quoted: message });
219 } catch {
220 await sock.sendMessage(chatId, { text: '✅ Restared Successfully\n Type .ping to check latest version.' }, { quoted: message });
221 }
222 await restartProcess(sock, chatId, message);
223 } catch (err) {
224 console.error('Update failed:', err);
225 await sock.sendMessage(chatId, { text: `❌ Update failed:\n${String(err.message || err)}` }, { quoted: message });
226 }
227}
228
229module.exports = updateCommand;
230

Callers 1

handleMessagesFunction · 0.85

Calls 6

isOwnerOrSudoFunction · 0.85
hasGitRepoFunction · 0.85
updateViaGitFunction · 0.85
runFunction · 0.85
updateViaZipFunction · 0.85
restartProcessFunction · 0.85

Tested by

no test coverage detected