MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MDX / handler

Function handler

plugins/update.ts:212–286  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

210 ownerOnly: true,
211
212 async handler(sock: any, message: any, args: any, context: BotContext) {
213 const { chatId, channelInfo } = context;
214
215 try {
216 await sock.sendMessage(chatId, {
217 text: '🔄 Updating the bot, please wait…',
218 ...channelInfo
219 }, { quoted: message });
220
221 let changesSummary = '';
222
223 if (await hasGitRepo()) {
224 const { oldRev, newRev, alreadyUpToDate, commits, files } = await updateViaGit();
225
226 if (alreadyUpToDate) {
227 changesSummary = `✅ Already up to date\nCurrent: ${newRev.substring(0, 7)}`;
228 } else {
229 changesSummary = `✅ Updated successfully!\n\n`;
230 changesSummary += `📌 Old: ${oldRev.substring(0, 7)}\n`;
231 changesSummary += `📌 New: ${newRev.substring(0, 7)}\n\n`;
232
233 if (commits) {
234 const commitLines = String(commits).split('\n').slice(0, 5);
235 changesSummary += `📝 Recent commits:\n${commitLines.map(c => `• ${c}`).join('\n')}\n\n`;
236 }
237
238 if (files) {
239 const fileLines = String(files).split('\n').slice(0, 10);
240 changesSummary += `📁 Changed files:\n${fileLines.map(f => `• ${f}`).join('\n')}`;
241 if (String(files).split('\n').length > 10) {
242 changesSummary += `\n... and ${String(files).split('\n').length - 10} more`;
243 }
244 }
245 }
246
247 await run('npm install --no-audit --no-fund');
248 } else {
249 const zipOverride = args[0] || null;
250 const { copiedFiles } = await updateViaZip(sock, chatId, message, zipOverride);
251
252 changesSummary = `✅ Updated from ZIP!\n\n`;
253 changesSummary += `📁 Files updated: ${copiedFiles.length}\n\n`;
254
255 if (copiedFiles.length > 0) {
256 const shown = copiedFiles.slice(0, 10);
257 changesSummary += `Recent changes:\n${shown.map(f => `• ${f}`).join('\n')}`;
258 if (copiedFiles.length > 10) {
259 changesSummary += `\n... and ${copiedFiles.length - 10} more files`;
260 }
261 }
262 }
263
264 try {
265 delete require.cache[require.resolve('../config')];
266 const newSettings = (await import('../config.js')).default;
267 const v = newSettings.version || 'unknown';
268 changesSummary += `\n\n🔖 Version: ${v}`;
269 } catch {}

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected