// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const fs = require("fs-extra"); const path = require("path"); const { loadImage, createCanvas } = require("canvas"); module.exports = { config: { name: "pori", version: "2.0.0", author: "omseks → Goat Bot V2", countDown: 10, role: 0, shortDescription: { en: "Pori tweet post" }, longDescription: { en: "Create a Pori tweet-style image with custom text." }, category: "edit-img", guide: { en: "{pn} [text]" } }, // ═════════════════════════════════════════════ // 📝 TEXT WRAP FUNCTION // ═════════════════════════════════════════════ wrapText(ctx, text, maxWidth) { const words = text.split(/\s+/); const lines = []; let line = ""; for (const word of words) { const testLine = line ? `${line} ${word}` : word; if (ctx.measureText(testLine).width <= maxWidth) { line = testLine; } else { if (line) { lines.push(line); } // যদি একটি শব্দই maxWidth-এর চেয়ে বড় হয় if (ctx.measureText(word).width > maxWidth) { let temp = ""; for (const char of word) { const test = temp + char; if (ctx.measureText(test).width <= maxWidth) { temp = test; } else { if (temp) lines.push(temp); temp = char; } } line = temp; } else { line = word; } } } if (line) { lines.push(line); } return lines; }, // ═════════════════════════════════════════════ // 🚀 COMMAND START // ═════════════════════════════════════════════ onStart: async function ({ api, event, args }) { const { threadID, messageID } = event; const text = args.join(" ").trim(); if (!text) { return api.sendMessage( "❌ ছবিতে লেখার জন্য কিছু লিখুন!\n\nউদাহরণ:\npori Hello Pori ❤️", threadID, messageID ); } const cacheDir = path.join(__dirname, "cache"); await fs.ensureDir(cacheDir); const pathImg = path.join( cacheDir, `pori_${Date.now()}.jpg` ); try { // ═══════════════════════════════════════════ // 🖼️ DOWNLOAD BASE IMAGE // ═══════════════════════════════════════════ const imageURL = "https://i.postimg.cc/4yk8DBrh/Pics-Art-08-16-10-20-47.jpg"; const response = await axios.get(imageURL, { responseType: "arraybuffer", timeout: 30000, headers: { "User-Agent": "Mozilla/5.0" } }); await fs.writeFile( pathImg, Buffer.from(response.data) ); // ═══════════════════════════════════════════ // 🎨 CREATE CANVAS // ═══════════════════════════════════════════ const baseImage = await loadImage(pathImg); const canvas = createCanvas( baseImage.width, baseImage.height ); const ctx = canvas.getContext("2d"); ctx.drawImage( baseImage, 0, 0, canvas.width, canvas.height ); // ═══════════════════════════════════════════ // ✍️ TEXT SETTINGS // ═══════════════════════════════════════════ let fontSize = 250; ctx.font = `400 ${fontSize}px Arial, sans-serif`; while ( ctx.measureText(text).width > 2600 && fontSize > 20 ) { fontSize--; ctx.font = `400 ${fontSize}px Arial, sans-serif`; } ctx.fillStyle = "#000000"; ctx.textAlign = "start"; ctx.textBaseline = "alphabetic"; // ═══════════════════════════════════════════ // 📝 WRAP TEXT // ═══════════════════════════════════════════ const lines = this.wrapText( ctx, text, 1160 ); // ═══════════════════════════════════════════ // 📌 DRAW EACH LINE // ═══════════════════════════════════════════ const x = 60; const startY = 165; const lineHeight = fontSize * 1.15; lines.forEach((line, index) => { ctx.fillText( line, x, startY + index * lineHeight ); }); // ═══════════════════════════════════════════ // 💾 SAVE IMAGE // ═══════════════════════════════════════════ const imageBuffer = canvas.toBuffer("image/jpeg"); await fs.writeFile( pathImg, imageBuffer ); // ═══════════════════════════════════════════ // 📤 SEND IMAGE // ═══════════════════════════════════════════ await api.sendMessage( { attachment: fs.createReadStream(pathImg) }, threadID, messageID ); } catch (error) { console.error("PORI ERROR:", error); return api.sendMessage( "❌ ছবি তৈরি করতে সমস্যা হয়েছে!\n\nকিছুক্ষণ পরে আবার চেষ্টা করুন।", threadID, messageID ); } finally { // ═══════════════════════════════════════════ // 🗑️ DELETE CACHE // ═══════════════════════════════════════════ setTimeout(async () => { try { if (await fs.pathExists(pathImg)) { await fs.remove(pathImg); } } catch (error) { console.error( "Pori cache delete error:", error ); } }, 5000); } } };