File size: 1,400 Bytes
2821330 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
const axios = require('axios');
const fs = require('fs');
const path = require('path');
module.exports.config = {
name: "imagine",
version: "1.0.0",
hasPermission: 0,
credits: "Jonell Magallanes",
description: "Generates an AI Image based on prompt",
usePrefix: false,
commandCategory: "media",
usages: "[prompt]",
cooldowns: 9
};
module.exports.run = async function ({ api, event, args, actions }) {
const { threadID, messageID } = event;
const prompt = args.join(" ");
if (!prompt) return api.sendMessage("Please provide a prompt for the image.", threadID, messageID);
api.setMessageReaction("📝", messageID, () => {}, true);
const imagePath = path.join(__dirname, 'cache', 'imagine.png');
if (!fs.existsSync(path.join(__dirname, 'cache'))) fs.mkdirSync(path.join(__dirname, 'cache'), { recursive: true });
try {
const response = await axios.get(`https://ccprojectapis.ddns.net/api/flux?prompt=${encodeURIComponent(prompt)}`, {
responseType: 'arraybuffer'
});
fs.writeFileSync(imagePath, response.data);
api.setMessageReaction("✅", messageID, () => {}, true);
api.sendMessage({
attachment: fs.createReadStream(imagePath)
}, threadID, messageID);
} catch (error) {
console.error("Error generating image:", error);
api.sendMessage(`❌ An error occurred: ${error.message}`, threadID, messageID);
}
};
|