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.");
}
}
};