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

Function handler

plugins/mute.js:9–47  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

7 groupOnly: true,
8 adminOnly: true,
9 async handler(sock, message, args, context) {
10 const { chatId, channelInfo } = context;
11 const durationInMinutes = args[0] ? parseInt(args[0], 10) : undefined;
12 try {
13 await sock.groupSettingUpdate(chatId, 'announcement');
14 if (durationInMinutes !== undefined && durationInMinutes > 0) {
15 const durationInMilliseconds = durationInMinutes * 60 * 1000;
16 await sock.sendMessage(chatId, {
17 text: `The group has been muted for ${durationInMinutes} minutes.`,
18 ...channelInfo
19 }, { quoted: message });
20 setTimeout(async () => {
21 try {
22 await sock.groupSettingUpdate(chatId, 'not_announcement');
23 await sock.sendMessage(chatId, {
24 text: 'The group has been unmuted.',
25 ...channelInfo
26 });
27 }
28 catch (unmuteError) {
29 console.error('Error unmuting group:', unmuteError);
30 }
31 }, durationInMilliseconds);
32 }
33 else {
34 await sock.sendMessage(chatId, {
35 text: 'The group has been muted.',
36 ...channelInfo
37 }, { quoted: message });
38 }
39 }
40 catch (error) {
41 console.error('Error muting/unmuting the group:', error);
42 await sock.sendMessage(chatId, {
43 text: 'An error occurred while muting/unmuting the group. Please try again.',
44 ...channelInfo
45 }, { quoted: message });
46 }
47 }
48};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected