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

Function handler

plugins/disappear.js:8–85  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

6 description: 'Enable or disable disappearing messages in chat',
7 usage: '.disappear off | .disappear 24h | .disappear 7d | .disappear 90d',
8 async handler(sock, message, args, context) {
9 const chatId = context.chatId || message.key.remoteJid;
10 const channelInfo = context.channelInfo || {};
11 const isGroup = chatId.endsWith('@g.us');
12 const senderId = context.senderId || message.key.participant || message.key.remoteJid;
13 const senderIsOwnerOrSudo = context.senderIsOwnerOrSudo || false;
14 // Permission check
15 if (isGroup && !senderIsOwnerOrSudo) {
16 const { isSenderAdmin } = await isAdmin(sock, chatId, senderId);
17 if (!isSenderAdmin) {
18 return await sock.sendMessage(chatId, {
19 text: '❌ Only group admins or bot owner can change disappearing messages.',
20 ...channelInfo
21 }, { quoted: message });
22 }
23 }
24 if (!isGroup && !senderIsOwnerOrSudo && !message.key.fromMe) {
25 return await sock.sendMessage(chatId, {
26 text: '❌ Only the bot owner can change disappearing messages in DMs.',
27 ...channelInfo
28 }, { quoted: message });
29 }
30 const input = args[0]?.toLowerCase();
31 if (!input) {
32 return await sock.sendMessage(chatId, {
33 text: `*⏳ DISAPPEARING MESSAGES*\n\n` +
34 `*Usage:*\n` +
35 `• \`.disappear off\` — Disable\n` +
36 `• \`.disappear 24h\` — 24 hours\n` +
37 `• \`.disappear 7d\` — 7 days (default)\n` +
38 `• \`.disappear 90d\` — 90 days`,
39 ...channelInfo
40 }, { quoted: message });
41 }
42 const durations = {
43 'off': false,
44 '0': false,
45 '24h': 86400,
46 '1d': 86400,
47 '7d': 604800,
48 '1w': 604800,
49 '90d': 7776000,
50 '3m': 7776000,
51 };
52 if (!(input in durations)) {
53 return await sock.sendMessage(chatId, {
54 text: `❌ Invalid option: *${input}*\n\nChoose: \`off\`, \`24h\`, \`7d\`, \`90d\``,
55 ...channelInfo
56 }, { quoted: message });
57 }
58 const seconds = durations[input];
59 try {
60 await sock.sendMessage(chatId, {
61 disappearingMessagesInChat: seconds === false ? false : seconds
62 });
63 const labels = {
64 'off': '❌ Disappearing messages *disabled*',
65 '0': '❌ Disappearing messages *disabled*',

Callers

nothing calls this directly

Calls 1

isAdminFunction · 0.85

Tested by

no test coverage detected