forked from mahmud-aura/HINATA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoli.js
More file actions
66 lines (55 loc) · 1.94 KB
/
Copy pathpoli.js
File metadata and controls
66 lines (55 loc) · 1.94 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const axios = require("axios");
const fs = require("fs");
const path = require("path");
const baseApiUrl = async () => {
const base = await axios.get("https://raw.githubusercontent.com/mahmudx7/exe/main/baseApiUrl.json");
return base.data.mahmud;
};
module.exports = {
config: {
name: "poli",
author: "MahMUD",
version: "1.7",
cooldowns: 10,
role: 0,
category: "Image gen",
guide: {
en: "{p}poli <prompt>"
}
},
onStart: async function ({ message, args, api, event }) {
if (args.length === 0) {
return api.sendMessage("❌ | Please provide a prompt.", event.threadID, event.messageID);
}
const prompt = args.join(" ");
const cacheDir = path.join(__dirname, "cache");
if (!fs.existsSync(cacheDir)) fs.mkdirSync(cacheDir);
api.sendMessage("𝐖𝐚𝐢𝐭 𝐤𝐨𝐫𝐨 𝐣𝐚𝐧 <😘", event.threadID, event.messageID);
try {
const styles = ["ultra detailed", "4k resolution", "realistic lighting", "artstation", "digital painting"];
const imagePaths = [];
for (let i = 0; i < 4; i++) {
const enhancedPrompt = `${prompt}, ${styles[i % styles.length]}`;
const response = await axios.post(`${await baseApiUrl()}/api/poli/generate`, {
prompt: enhancedPrompt
}, {
responseType: "arraybuffer",
headers: {
"author": module.exports.config.author
}
});
const filePath = path.join(cacheDir, `generated_${Date.now()}_${i}.png`);
fs.writeFileSync(filePath, response.data);
imagePaths.push(filePath);
}
const attachments = imagePaths.map(p => fs.createReadStream(p));
message.reply({
body: "✅ | Here are images generated from your prompt:",
attachment: attachments
});
} catch (error) {
console.error("Image generation error:", error);
message.reply("❌ | Couldn't generate images. Try again later.");
}
}
};