Untitled
unknown
javascript
a year ago
949 B
3
Indexable
const fs = require("fs"); require("dotenv").config(); const downloadFolderName = process.env.PATH_FILES; const handleMedia = async (msg) => { const media = await msg.downloadMedia(); let fileName = media.filename; if (!fileName) { const timestamp = Date.now(); const fileExtension = getFileExtension(media.mimetype); fileName = `${timestamp}.${fileExtension}`; } fs.writeFileSync(`${downloadFolderName}/${fileName}`, media.data, "base64"); console.log(`Downloaded ${fileName}`); // ChatGPT with "msg.body" fs.renameSync( `${downloadFolderName}/${fileName}`, `${downloadFolderName}/ib#@_${fileName}` ); console.log(`Renamed ib#@_${fileName}`); msg.react("👍"); }; const getFileExtension = (mimetype) => { const pattern = /([^\/;]+)(?:;|$)/; const extensionMatch = mimetype.match(pattern); return extensionMatch[1]; }; module.exports = { handleMedia, };
Editor is loading...
Leave a Comment