Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Module } = require("../main");
- const fs = require("fs");
- const ffmpeg = require("fluent-ffmpeg");
- const {
- bass,
- sticker,
- addExif,
- attp,
- gtts,
- gis,
- aiTTS,
- getBuffer,
- } = require("./utils");
- const config = require("../config");
- const axios = require("axios");
- const fileType = require("file-type");
- const { getTempPath, getTempSubdir } = require("../core/helpers");
- const getFileType = async (buffer) => {
- try {
- if (fileType.fileTypeFromBuffer) {
- return await fileType.fileTypeFromBuffer(buffer);
- }
- if (fileType.fromBuffer) {
- return await fileType.fromBuffer(buffer);
- }
- return await fileType(buffer);
- } catch (error) {
- console.log("file-type detection failed:", error);
- return null;
- }
- };
- let MODE = config.MODE,
- STICKER_DATA = config.STICKER_DATA;
- const { getString } = require("./utils/lang");
- const Lang = getString("converters");
- Module(
- {
- pattern: "look ?(.*)",
- fromMe: false,
- use: "search",
- desc: "Searches for an image on Google Images and sends the requested number of results.",
- },
- async (message, match) => {
- if (!match[1]) return await message.send("*_Need a search term!_*");
- let splitInput = match[1].split(",");
- let count = parseInt(splitInput[1] || 5);
- await message.send(`*_Searching for ${count} images..._*`);
- const buffer = Math.ceil(count * 0.5);
- let results = await gis(splitInput[0], count + buffer);
- if (results.length < 1) return await message.send("*_No results found!_*");
- // buffer and send with success tracking since many URLs have access issues
- let successCount = 0;
- let i = 0;
- const imagesToSend = [];
- while (successCount < count && i < results.length) {
- try {
- const imageBuffer = await getBuffer(results[i]);
- imagesToSend.push({ image: imageBuffer });
- successCount++;
- } catch (e) {
- console.log(`Failed to buffer image ${i + 1}:`, e.message);
- if (i === results.length - 1 && successCount < count) {
- let moreResults = await gis(splitInput[0], buffer, {
- page: Math.floor(i / 10) + 1,
- });
- if (moreResults.length > 0) {
- results = results.concat(moreResults);
- }
- }
- }
- i++;
- }
- if (imagesToSend.length === 0) {
- return await message.send("*_Failed to download any images_*");
- }
- try {
- await message.client.albumMessage(
- message.jid,
- imagesToSend,
- message.data
- );
- } catch (e) {
- console.log("Album send failed:", e.message);
- for (const img of imagesToSend) {
- try {
- await message.sendMessage(img, "image", { quoted: message.data });
- } catch (sendErr) {
- console.log("Failed to send individual image:", sendErr.message);
- }
- }
- }
- if (successCount < count) {
- await message.send(
- `*_Only able to download ${successCount}/${count} images. Some URLs had access issues._*`
- );
- }
- }
- );
- Module(
- {
- pattern: "stc ?(.*)",
- fromMe: false,
- use: "edit",
- desc: Lang.STICKER_DESC,
- },
- async (message, match) => {
- if (match[1] && match[1].trim() !== "") {
- var result = await attp(match[1].trim());
- var exif = {
- author: STICKER_DATA.split(";")[1] || "",
- packname: message.senderName,
- categories: STICKER_DATA.split(";")[2] || "๐",
- android: "https://github.com/souravkl11/Raganork-md/",
- ios: "https://github.com/souravkl11/Raganork-md/",
- };
- return await message.sendMessage(
- fs.readFileSync(await addExif(result, exif)),
- "sticker"
- );
- }
- if (message.reply_message === false)
- return await message.send(Lang.STICKER_NEED_REPLY);
- var exif = {
- author: STICKER_DATA.split(";")[1] || "",
- packname: message.senderName,
- categories: STICKER_DATA.split(";")[2] || "๐",
- android: "https://github.com/souravkl11/Raganork-md/",
- ios: "https://github.com/souravkl11/Raganork-md/",
- };
- // handle album
- if (message.reply_message.album) {
- const albumData = await message.reply_message.download();
- const allFiles = [...(albumData.images || []), ...(albumData.videos || [])];
- if (allFiles.length === 0) return await message.send("_No media in album_");
- await message.send(`_Converting ${allFiles.length} stickers..._`);
- for (const file of allFiles) {
- try {
- const isVideo = albumData.videos?.includes(file);
- const stickerFile = fs.readFileSync(
- await addExif(
- await sticker(file, isVideo ? "video" : "image"),
- exif
- )
- );
- await message.sendMessage(stickerFile, "sticker", {
- quoted: message.quoted,
- });
- } catch (err) {
- console.error("Failed to convert album sticker:", err);
- }
- }
- return;
- }
- var savedFile = await message.reply_message.download();
- if (message.reply_message.image === true) {
- return await message.sendMessage(
- fs.readFileSync(await addExif(await sticker(savedFile), exif)),
- "sticker",
- { quoted: message.quoted }
- );
- } else {
- return await message.sendMessage(
- fs.readFileSync(await addExif(await sticker(savedFile, "video"), exif)),
- "sticker",
- { quoted: message.quoted }
- );
- }
- }
- );
- Module(
- {
- pattern: "audio ?(.*)",
- fromMe: false,
- use: "edit",
- desc: Lang.MP3_DESC,
- },
- async (message) => {
- if (
- !message.reply_message ||
- (!message.reply_message.video &&
- !message.reply_message.audio &&
- !message.reply_message.document &&
- !message.reply_message.album)
- )
- return await message.sendReply(Lang.MP3_NEED_REPLY);
- // handle album
- if (message.reply_message.album) {
- const albumData = await message.reply_message.download();
- const videoFiles = albumData.videos || [];
- if (videoFiles.length === 0) {
- return await message.send("_No video files in album. MP3 requires video/audio files._");
- }
- await message.send(`_Converting ${videoFiles.length} files to mp3..._`);
- for (let i = 0; i < videoFiles.length; i++) {
- try {
- const file = videoFiles[i];
- const outputPath = getTempPath(`album_${i}.mp3`);
- await new Promise((resolve, reject) => {
- ffmpeg(file)
- .save(outputPath)
- .on("end", resolve)
- .on("error", reject);
- });
- await message.sendMessage(
- fs.readFileSync(outputPath),
- "audio",
- { quoted: message.quoted }
- );
- } catch (err) {
- console.error("Failed to convert album mp3:", err);
- }
- }
- return;
- }
- let savedFile = await message.reply_message.download();
- const audioPath = getTempPath(`audio_${Date.now()}.m4a`);
- ffmpeg(savedFile)
- .audioCodec("aac")
- .outputOptions(["-movflags", "faststart", "-q:a", "100"])
- .noVideo()
- .output(audioPath)
- .on("end", async () => {
- try {
- const stream = fs.createReadStream(audioPath);
- await message.sendReply({ stream }, "audio", {
- mimetype: "audio/mp4",
- });
- stream.destroy();
- await new Promise((resolve) => setTimeout(resolve, 100));
- if (fs.existsSync(audioPath)) {
- fs.unlinkSync(audioPath);
- }
- } catch (err) {
- console.error("Error sending audio:", err);
- }
- })
- .on("error", (err) => {
- console.error("FFmpeg error:", err);
- if (fs.existsSync(audioPath)) fs.unlinkSync(audioPath);
- })
- .run();
- }
- );
- Module(
- {
- pattern: "tke ?(.*)",
- use: "edit",
- fromMe: false,
- desc: "Changes sticker/audio pack & author name. Title, artist, thumbnail etc.",
- },
- async (m, match) => {
- if (!m.reply_message)
- return await m.sendMessage("_Reply to an audio or a sticker_");
- var audiomsg = m.reply_message.audio;
- var stickermsg = m.reply_message.sticker;
- var q = await m.reply_message.download();
- if (stickermsg) {
- if (match[1] !== "") {
- var exif = {
- author: match[1].includes(";") ? match[1].split(";")[1] : "",
- packname: match[1].includes(";") ? match[1].split(";")[0] : match[1],
- categories: config.STICKER_DATA.split(";")[2] || "๐",
- android: "https://github.com/souravkl11/raganork-md/",
- ios: "https://github.com/souravkl11/raganork-md/",
- };
- } else {
- var exif = {
- author: config.STICKER_DATA.split(";")[1] || "",
- packname: config.STICKER_DATA.split(";")[0] || "",
- categories: config.STICKER_DATA.split(";")[2] || "๐",
- android: "https://github.com/souravkl11/raganork-md/",
- ios: "https://github.com/souravkl11/raganork-md/",
- };
- }
- return await m.client.sendMessage(
- m.jid,
- { sticker: fs.readFileSync(await addExif(q, exif)) },
- { quoted: m.quoted }
- );
- }
- if (!stickermsg && audiomsg) {
- let inf =
- match[1] !== ""
- ? match[1]
- : config.AUDIO_DATA === "default"
- ? "Ryzn- Audio title here;Raganork - Artist;https://i.ibb.co/s98DyMMq/NL-1.png"
- : config.AUDIO_DATA;
- if (config.AUDIO_DATA == "default") {
- await m.sendReply(
- `_Using default audio metadata, use .setvar AUDIO_INFO=title;artist;imageurl to change_`
- );
- }
- let spl = inf.split(";"),
- image = spl[2]
- ? await getBuffer(spl[2])
- : await getBuffer(
- config.BOT_INFO.split(";")?.[3] === "default"
- ? "https://i.ibb.co/s98DyMMq/NL-1.png"
- : config.BOT_INFO.split(";")[3]
- ),
- res = await addID3(
- q,
- spl[0],
- spl[1] ? spl[1] : config.AUDIO_DATA.split(";")[1],
- "Raganork Engine",
- image
- );
- await m.client.sendMessage(
- m.jid,
- {
- audio: res,
- mimetype: "audio/mp4",
- },
- {
- quoted: m.quoted,
- ptt: false,
- }
- );
- }
- if (!audiomsg && !stickermsg)
- return await m.client.sendMessage(
- m.jid,
- {
- text: "_Reply to an audio or a sticker_",
- },
- {
- quoted: m.data,
- }
- );
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment