MCPcopy
hub / github.com/mruniquehacker/Knightbot-MD / stickercropCommand

Function stickercropCommand

commands/stickercrop.js:9–196  ·  view source on GitHub ↗
(sock, chatId, message)

Source from the content-addressed store, hash-verified

7const crypto = require('crypto');
8
9async function stickercropCommand(sock, chatId, message) {
10 // The message that will be quoted in the reply.
11 const messageToQuote = message;
12
13 // The message object that contains the media to be downloaded.
14 let targetMessage = message;
15
16 // If the message is a reply, the target media is in the quoted message.
17 if (message.message?.extendedTextMessage?.contextInfo?.quotedMessage) {
18 // We need to build a new message object for downloadMediaMessage to work correctly.
19 const quotedInfo = message.message.extendedTextMessage.contextInfo;
20 targetMessage = {
21 key: {
22 remoteJid: chatId,
23 id: quotedInfo.stanzaId,
24 participant: quotedInfo.participant
25 },
26 message: quotedInfo.quotedMessage
27 };
28 }
29
30 const mediaMessage = targetMessage.message?.imageMessage || targetMessage.message?.videoMessage || targetMessage.message?.documentMessage || targetMessage.message?.stickerMessage;
31
32 if (!mediaMessage) {
33 await sock.sendMessage(chatId, {
34 text: 'Please reply to an image/video/sticker with .crop, or send an image/video/sticker with .crop as the caption.',
35 contextInfo: {
36 forwardingScore: 999,
37 isForwarded: true,
38 forwardedNewsletterMessageInfo: {
39 newsletterJid: '120363161513685998@newsletter',
40 newsletterName: 'KnightBot MD',
41 serverMessageId: -1
42 }
43 }
44 },{ quoted: messageToQuote });
45 return;
46 }
47
48 try {
49 const mediaBuffer = await downloadMediaMessage(targetMessage, 'buffer', {}, {
50 logger: undefined,
51 reuploadRequest: sock.updateMediaMessage
52 });
53
54 if (!mediaBuffer) {
55 await sock.sendMessage(chatId, {
56 text: 'Failed to download media. Please try again.',
57 contextInfo: {
58 forwardingScore: 999,
59 isForwarded: true,
60 forwardedNewsletterMessageInfo: {
61 newsletterJid: '120363161513685998@newsletter',
62 newsletterName: 'KnightBot MD',
63 serverMessageId: -1
64 }
65 }
66 });

Callers 1

handleMessagesFunction · 0.85

Calls 2

execFunction · 0.85
downloadMediaMessageFunction · 0.70

Tested by

no test coverage detected