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

Function handler

plugins/setcmd.js:66–109  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

64 usage: '.setcmd <text>',
65 ownerOnly: true,
66 async handler(sock, message, args, context) {
67 const { chatId, senderId } = context;
68 if (!message.message?.extendedTextMessage?.contextInfo?.quotedMessage) {
69 return await sock.sendMessage(chatId, {
70 text: '✳️ Please reply to a sticker to set a command'
71 }, { quoted: message });
72 }
73 const quotedMsg = message.message.extendedTextMessage.contextInfo.quotedMessage;
74 if (!quotedMsg.stickerMessage) {
75 return await sock.sendMessage(chatId, {
76 text: '⚠️ Please reply to a sticker, not a regular message'
77 }, { quoted: message });
78 }
79 const fileSha256 = quotedMsg.stickerMessage.fileSha256;
80 if (!fileSha256) {
81 return await sock.sendMessage(chatId, {
82 text: '⚠️ File SHA256 not found'
83 }, { quoted: message });
84 }
85 const text = args.join(' ');
86 if (!text) {
87 return await sock.sendMessage(chatId, {
88 text: 'Command text is missing'
89 }, { quoted: message });
90 }
91 const stickers = await getStickerCommands();
92 const hash = Buffer.from(fileSha256).toString('base64');
93 if (stickers[hash] && stickers[hash].locked) {
94 return await sock.sendMessage(chatId, {
95 text: '⚠️ You do not have permission to change this sticker command'
96 }, { quoted: message });
97 }
98 stickers[hash] = {
99 text,
100 mentionedJid: message.message?.extendedTextMessage?.contextInfo?.mentionedJid || [],
101 creator: senderId,
102 at: Date.now(),
103 locked: false,
104 };
105 await saveStickerCommands(stickers);
106 await sock.sendMessage(chatId, {
107 text: '✅ Command saved successfully'
108 }, { quoted: message });
109 }
110};
111/*****************************************************************************
112 * *

Callers

nothing calls this directly

Calls 2

getStickerCommandsFunction · 0.70
saveStickerCommandsFunction · 0.70

Tested by

no test coverage detected