Created
July 8, 2025 16:34
-
-
Save dipto-008/8e5b31cca03185588965ce23bb5af79e to your computer and use it in GitHub Desktop.
Hey noob ππ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios"); | |
const fs = require("fs"); | |
const path = require("path"); | |
module.exports = { | |
config: { | |
name: 'xl', | |
version: '1.0', | |
author: "Fahim_π’", | |
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("Photo wait... π₯΅ \nβ³ Image π₯΅..."); | |
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: `ποΈphoto done π₯΅\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."); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment