Cloner / plugins /save.js
𝗗𝗔𝗥𝗥𝗘𝗟𝗟 𝗠𝗨𝗖𝗛𝗘𝗥𝗜 ⚡
SUBZERO - MD
8d8d92b unverified
raw
history blame
2.26 kB
/*╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺
⭐PROJECT NAME:
SUBZERO WHATSAPP MD BOT
⭐DEVELOPER
MR FRANK
⭐ MY TEAM
XERO CODERS
⭐ OUR WEBSITE
https://github.com/ZwSyntax/SUBZERO-MD
© TRY DECRYPTING IF YOU CAN⚠
╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺*/
const config = require('../config');
const { cmd, commands } = require('../command');
const fs = require('fs');
const path = require('path');
cmd({
pattern: "save",
react: "📁",
alias: ["store"],
desc: "Save and send back a media file (image, video, or audio).",
category: "media",
use: ".save <caption>",
filename: __filename,
},
async (conn, mek, m, { quoted, q, reply }) => {
try {
if (!quoted) {
return reply("❌ Reply to a media message (video, image, or audio) with the `.save` command.");
}
const messageType = quoted.mtype;
let mediaType;
// Determine the type of media
if (/video/.test(messageType)) {
mediaType = "video";
} else if (/image/.test(messageType)) {
mediaType = "image";
} else if (/audio/.test(messageType)) {
mediaType = "audio";
} else {
return reply("❌ Only video, image, or audio messages are supported.");
}
// Download and save the media file
const mediaPath = await conn.downloadAndSaveMediaMessage(quoted);
const filePath = path.resolve(mediaPath);
// Send the saved media back
const mediaMessage = {
caption: q || '',
}
mediaMessage[mediaType] = { url: `file://${filePath}` }
await conn.sendMessage(m.sender, mediaMessage, { quoted: mek })
await reply("✅ Successfully saved and sent the media file.")
} catch (error) {
console.error(error);
reply("❌ Failed to save and send the media. Please try again.")
}
});