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

Function handler

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

Source from the content-addressed store, hash-verified

45 usage: '.delcmd <text>',
46 ownerOnly: true,
47 async handler(sock, message, args, context) {
48 const { chatId } = context;
49 let hash = args.join(' ');
50 if (message.message?.extendedTextMessage?.contextInfo?.quotedMessage?.stickerMessage) {
51 const fileSha256 = message.message.extendedTextMessage.contextInfo.quotedMessage.stickerMessage.fileSha256;
52 if (fileSha256) {
53 hash = Buffer.from(fileSha256).toString('base64');
54 }
55 }
56 if (!hash) {
57 return await sock.sendMessage(chatId, {
58 text: '✳️ Please enter the command name or reply to a sticker'
59 }, { quoted: message });
60 }
61 const stickers = await getStickerCommands();
62 // Find by text name if hash not found
63 if (!stickers[hash]) {
64 const found = Object.entries(stickers).find(([, v]) => v.text === hash);
65 if (found)
66 hash = found[0];
67 }
68 if (stickers[hash] && stickers[hash].locked) {
69 return await sock.sendMessage(chatId, {
70 text: '✳️ You cannot delete this command'
71 }, { quoted: message });
72 }
73 if (!stickers[hash]) {
74 return await sock.sendMessage(chatId, {
75 text: '⚠️ Command not found'
76 }, { quoted: message });
77 }
78 delete stickers[hash];
79 await saveStickerCommands(stickers);
80 await sock.sendMessage(chatId, {
81 text: '✅ Command deleted'
82 }, { quoted: message });
83 }
84};

Callers

nothing calls this directly

Calls 2

getStickerCommandsFunction · 0.70
saveStickerCommandsFunction · 0.70

Tested by

no test coverage detected