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