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

Function handler

plugins/maintenance.ts:30–93  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected