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

Function handler

plugins/setpp.ts:13–63  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

11 description: 'Set or update the bot profile picture (owner only)',
12 usage: '.setpp (reply to an image)',
13 async handler(sock: any, message: any, args: any, context: BotContext) {
14 const chatId = context.chatId || message.key.remoteJid;
15
16 try {
17 const senderId = message.key.participant || message.key.remoteJid;
18 const isOwner = await isOwnerOrSudo(senderId, sock, chatId);
19
20 if (!message.key.fromMe && !isOwner) {
21 await sock.sendMessage(chatId, {
22 text: '*This command is only available for the owner!*'
23 }, { quoted: message });
24 return;
25 }
26 const quotedMessage = message.message?.extendedTextMessage?.contextInfo?.quotedMessage;
27 if (!quotedMessage) {
28 await sock.sendMessage(chatId, {
29 text: '⚠️ Please reply to an image with the .setpp command!'
30 }, { quoted: message });
31 return;
32 }
33 const imageMessage = quotedMessage.imageMessage || quotedMessage.stickerMessage;
34 if (!imageMessage) {
35 await sock.sendMessage(chatId, {
36 text: '*The replied message must contain an image!*'
37 }, { quoted: message });
38 return;
39 }
40 const tmpDir = path.join(process.cwd(), 'tmp');
41 if (!fs.existsSync(tmpDir)) fs.mkdirSync(tmpDir, { recursive: true });
42
43 const stream = await downloadContentFromMessage(imageMessage, 'image');
44 let buffer = Buffer.from([]);
45 for await (const chunk of stream) buffer = Buffer.concat([buffer, chunk]);
46
47 const imagePath = path.join(tmpDir, `profile_${Date.now()}.jpg`);
48 fs.writeFileSync(imagePath, buffer);
49
50 await sock.updateProfilePicture(sock.user.id, { url: imagePath });
51 fs.unlinkSync(imagePath);
52
53 await sock.sendMessage(chatId, {
54 text: '✅ Successfully updated bot profile picture!'
55 }, { quoted: message });
56
57 } catch(error: any) {
58 console.error('SetPP Command Error:', error);
59 await sock.sendMessage(chatId, {
60 text: '❌ Failed to update profile picture!'
61 }, { quoted: message });
62 }
63 }
64};

Callers

nothing calls this directly

Calls 1

isOwnerOrSudoFunction · 0.85

Tested by

no test coverage detected