MCPcopy Create free account
hub / github.com/Xchristech2/Zenitsu-Bot / viewonceCommand

Function viewonceCommand

commands/viewonce.js:3–24  ·  view source on GitHub ↗
(sock, chatId, message)

Source from the content-addressed store, hash-verified

1const { downloadContentFromMessage } = require('@whiskeysockets/baileys');
2
3async function viewonceCommand(sock, chatId, message) {
4 // Extract quoted imageMessage or videoMessage from your structure
5 const quoted = message.message?.extendedTextMessage?.contextInfo?.quotedMessage;
6 const quotedImage = quoted?.imageMessage;
7 const quotedVideo = quoted?.videoMessage;
8
9 if (quotedImage && quotedImage.viewOnce) {
10 // Download and send the image
11 const stream = await downloadContentFromMessage(quotedImage, 'image');
12 let buffer = Buffer.from([]);
13 for await (const chunk of stream) buffer = Buffer.concat([buffer, chunk]);
14 await sock.sendMessage(chatId, { image: buffer, fileName: 'media.jpg', caption: quotedImage.caption || '' }, { quoted: message });
15 } else if (quotedVideo && quotedVideo.viewOnce) {
16 // Download and send the video
17 const stream = await downloadContentFromMessage(quotedVideo, 'video');
18 let buffer = Buffer.from([]);
19 for await (const chunk of stream) buffer = Buffer.concat([buffer, chunk]);
20 await sock.sendMessage(chatId, { video: buffer, fileName: 'media.mp4', caption: quotedVideo.caption || '' }, { quoted: message });
21 } else {
22 await sock.sendMessage(chatId, { text: '❌ Please reply to a view-once image or video.' }, { quoted: message });
23 }
24}
25
26module.exports = viewonceCommand;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected