(sock, message, args, context)
| 22 | usage: '.maintenance [minutes / stop]', |
| 23 | ownerOnly: true, |
| 24 | async handler(sock, message, args, context) { |
| 25 | const chatId = context.chatId || message.key.remoteJid; |
| 26 | const input = args[0]?.toLowerCase(); |
| 27 | if (input === 'stop' || input === 'off') { |
| 28 | if (activeMaintenanceTimer) { |
| 29 | clearTimeout(activeMaintenanceTimer); |
| 30 | activeMaintenanceTimer = null; |
| 31 | } |
| 32 | const allCommands = Array.from(CommandHandler.commands.values()); |
| 33 | allCommands.forEach(cmd => { |
| 34 | if (cmd.category !== 'owner') { |
| 35 | CommandHandler.disabledCommands.delete(cmd.command.toLowerCase()); |
| 36 | } |
| 37 | }); |
| 38 | return await sock.sendMessage(chatId, { text: '✅ *MAINTENANCE ENDED EARLY*\nAll commands are now active.' }, { quoted: message }); |
| 39 | } |
| 40 | const minutes = parseInt(input, 10); |
| 41 | if (isNaN(minutes) || minutes <= 0) { |
| 42 | return await sock.sendMessage(chatId, { text: '❌ Usage: .maintenance [minutes] OR .maintenance stop' }, { quoted: message }); |
| 43 | } |
| 44 | try { |
| 45 | if (activeMaintenanceTimer) |
| 46 | clearTimeout(activeMaintenanceTimer); |
| 47 | const allCommands = Array.from(CommandHandler.commands.values()); |
| 48 | let affectedCount = 0; |
| 49 | allCommands.forEach(cmd => { |
| 50 | if (cmd.category !== 'owner' && cmd.command !== 'maintenance') { |
| 51 | const key = cmd.command.toLowerCase(); |
| 52 | if (!CommandHandler.disabledCommands.has(key)) { |
| 53 | CommandHandler.disabledCommands.add(key); |
| 54 | affectedCount++; |
| 55 | } |
| 56 | } |
| 57 | }); |
| 58 | await sock.sendMessage(chatId, { |
| 59 | text: `⚠️ *MAINTENANCE MODE STARTING*\n\n` + |
| 60 | `Locked: ${affectedCount} commands\n` + |
| 61 | `Duration: ${minutes}m\n\n` + |
| 62 | `_Type ".maintenance stop" to enable commands early._` |
| 63 | }, { quoted: message }); |
| 64 | activeMaintenanceTimer = setTimeout(async () => { |
| 65 | allCommands.forEach(cmd => { |
| 66 | if (cmd.category !== 'owner') { |
| 67 | CommandHandler.disabledCommands.delete(cmd.command.toLowerCase()); |
| 68 | } |
| 69 | }); |
| 70 | activeMaintenanceTimer = null; |
| 71 | await sock.sendMessage(chatId, { text: '✅ *MAINTENANCE FINISHED*\nCommands re-enabled automatically.' }); |
| 72 | }, minutes * 60000); |
| 73 | } |
| 74 | catch (error) { |
| 75 | console.error('Maintenance Error:', error); |
| 76 | await sock.sendMessage(chatId, { text: '❌ Action failed.' }, { quoted: message }); |
| 77 | } |
| 78 | } |
| 79 | }; |
| 80 | /***************************************************************************** |
| 81 | * * |
nothing calls this directly
no outgoing calls
no test coverage detected