← back to browse
goat command

xl

No description

0
views
0
likes
0
installs
raw source
const axios = require("axios");
const fs = require("fs");
const path = require("path");

module.exports = {
 config: {
 name: 'xl',
 version: '1.0',
 author: "Chitron Bhattacharjee",
 countDown: 10,
 role: 0,
 longDescription: {
 en: 'Generate an image from text using SDXL.'
 },
 category: 'image',
 guide: {
 en: '{pn} prompt [--ar=<ratio>] or [--ar <ratio>]'
 }
 },

 onStart: async function ({ message, api, args, event, usersData }) {
 const cost = 50;

 if (!args[0]) {
 return message.reply(`๐Ÿ˜ก Please enter a text prompt\nExample: \n+xl a cat\n+xl a girl --ar 2:3`);
 }

 // Check and deduct coins
 const userData = await usersData.get(event.senderID);
 const balance = userData.money || 0;

 if (balance < cost) {
 return message.reply(`โŒ | You need at least ${cost} coins.\n๐Ÿ’ฐ Your balance: ${balance}`);
 }

 await usersData.set(event.senderID, { money: balance - cost });

 message.reply("๐Ÿ’ธ ๐“ฃ๐“ฑ๐“ฒ๐“ผ ๐“ฌ๐“ธ๐“ผ๐“ฝ โบโ“ฟ ๐“ฌ๐“ธ๐“ฒ๐“ท๐“ผ\nโณ ๐“–๐“ฎ๐“ท๐“ฎ๐“ป๐“ช๐“ฝ๐“ฒ๐“ท๐“ฐ ๐“ฒ๐“ถ๐“ช๐“ฐ๐“ฎ...");

 let ratio = "1:1";
 const ratioIndex = args.findIndex(arg => arg.startsWith("--ar="));
 if (ratioIndex !== -1) {
 ratio = args[ratioIndex].split("=")[1];
 args.splice(ratioIndex, 1);
 } else {
 const flagIndex = args.findIndex(arg => arg === "--ar");
 if (flagIndex !== -1 && args[flagIndex + 1]) {
 ratio = args[flagIndex + 1];
 args.splice(flagIndex, 2);
 }
 }

 const prompt = args.join(" ");
 const query = `xl31?prompt=${encodeURIComponent(prompt)}&ratio=${ratio}`;
 const imageURL = `https://smfahim.xyz/${query}`;
 const startTime = Date.now();

 try {
 const res = await axios.get(imageURL, { responseType: "arraybuffer" });

 const folder = path.join(__dirname, "cache");
 if (!fs.existsSync(folder)) fs.mkdirSync(folder);

 const filePath = path.join(folder, `${Date.now()}_xl.png`);
 fs.writeFileSync(filePath, res.data);

 const timeTaken = ((Date.now() - startTime) / 1000).toFixed(2);

 await message.reply({
 body: `๐Ÿ–ผ๏ธ ๐“ง๐“› ๐“œ๐“ธ๐“ญ๐“ฎ๐“ต ๐“˜๐“ถ๐“ช๐“ฐ๐“ฎ\nโฑ๏ธ Time taken: ${timeTaken} sec`,
 attachment: fs.createReadStream(filePath)
 });

 api.setMessageReaction("โœ…", event.messageID, () => {}, true);
 } catch (err) {
 console.error("XL gen error:", err);
 api.setMessageReaction("โŒ", event.messageID, () => {}, true);
 message.reply("โŒ | Failed to generate image.");
 }
 }
};

View raw file