(sock, message, args, context)
| 6 | usage: '.archivechat <archive|unarchive>', |
| 7 | ownerOnly: true, |
| 8 | async handler(sock, message, args, context) { |
| 9 | const chatId = context.chatId || message.key.remoteJid; |
| 10 | const channelInfo = context.channelInfo || {}; |
| 11 | const rawText = context.rawText || ''; |
| 12 | // Auto-detect from command name |
| 13 | const isUnarchive = rawText.toLowerCase().startsWith('.unarchive'); |
| 14 | const action = args[0]?.toLowerCase() || (isUnarchive ? 'unarchive' : 'archive'); |
| 15 | if (!['archive', 'unarchive'].includes(action)) { |
| 16 | return await sock.sendMessage(chatId, { |
| 17 | text: `*📦 ARCHIVE CHAT*\n\n*Usage:*\n• \`.archivechat archive\` — Archive this chat\n• \`.archivechat unarchive\` — Unarchive this chat\n\n_Or use aliases: \`.archive\` / \`.unarchive\`_`, |
| 18 | ...channelInfo |
| 19 | }, { quoted: message }); |
| 20 | } |
| 21 | const shouldArchive = action === 'archive'; |
| 22 | try { |
| 23 | const lastMsg = message; |
| 24 | await sock.chatModify({ |
| 25 | archive: shouldArchive, |
| 26 | lastMessages: [ |
| 27 | { |
| 28 | key: lastMsg.key, |
| 29 | messageTimestamp: lastMsg.messageTimestamp |
| 30 | } |
| 31 | ] |
| 32 | }, chatId); |
| 33 | await sock.sendMessage(chatId, { |
| 34 | text: shouldArchive |
| 35 | ? `📦 *Chat archived!*` |
| 36 | : `📂 *Chat unarchived!*`, |
| 37 | ...channelInfo |
| 38 | }, { quoted: message }); |
| 39 | } |
| 40 | catch (e) { |
| 41 | console.error('[ARCHIVECHAT] Error:', e.message); |
| 42 | await sock.sendMessage(chatId, { |
| 43 | text: `❌ Failed to ${action} chat: ${e.message}`, |
| 44 | ...channelInfo |
| 45 | }, { quoted: message }); |
| 46 | } |
| 47 | } |
| 48 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected