// code from goatstore // api: https://store.agi.bd const fs = require("fs-extra"); const path = require("path"); const { createCanvas, loadImage } = require("canvas"); module.exports = { config: { name: "mia", version: "4.0.0", author: "Clarence DK → Goat Bot V2", countDown: 5, role: 0, shortDescription: { en: "Create Mia comment image" }, longDescription: { en: "Add custom text to Mia comment template" }, category: "edit-img", guide: { en: "{pn} " }, dependencies: { canvas: "", "fs-extra": "" } }, wrapText(ctx, text, maxWidth) { const words = text.split(/\s+/); const lines = []; let line = ""; for (const word of words) { const test = line ? `${line} ${word}` : word; if (ctx.measureText(test).width <= maxWidth) { line = test; } else { if (line) { lines.push(line); } line = word; } } if (line) { lines.push(line); } return lines; }, onStart: async function ({ api, event, args }) { const { threadID, messageID } = event; const text = args.join(" ").trim(); if (!text) { return api.sendMessage( "❌ | Please enter your text!\n\n" + "Example:\n" + "mia Hello Baby ❤️", threadID, messageID ); } const cacheDir = path.join( __dirname, "cache" ); const assetsDir = path.join( __dirname, "assets" ); await fs.ensureDir(cacheDir); await fs.ensureDir(assetsDir); const templatePath = path.join( assetsDir, "mia.png" ); const outputPath = path.join( cacheDir, `mia_${Date.now()}.png` ); try { let baseImage; // ═══════════════════════════════════ // LOAD LOCAL TEMPLATE // ═══════════════════════════════════ if (await fs.pathExists(templatePath)) { baseImage = await loadImage(templatePath); } else { // ═══════════════════════════════ // FALLBACK TEMPLATE // ═══════════════════════════════ const width = 1400; const height = 600; const fallback = createCanvas( width, height ); const fctx = fallback.getContext("2d"); fctx.fillStyle = "#ffffff"; fctx.fillRect( 0, 0, width, height ); fctx.fillStyle = "#f1f1f1"; fctx.fillRect( 25, 25, width - 50, height - 50 ); fctx.fillStyle = "#222222"; fctx.font = "bold 45px Arial"; fctx.fillText( "MIA", 50, 85 ); baseImage = await loadImage( fallback.toBuffer("image/png") ); } // ═══════════════════════════════════ // CANVAS // ═══════════════════════════════════ const canvas = createCanvas( baseImage.width, baseImage.height ); const ctx = canvas.getContext("2d"); ctx.drawImage( baseImage, 0, 0, canvas.width, canvas.height ); // ═══════════════════════════════════ // TEXT SETTINGS // ═══════════════════════════════════ const maxWidth = 1160; let fontSize = 220; ctx.textAlign = "start"; ctx.textBaseline = "top"; ctx.fillStyle = "#000000"; // ═══════════════════════════════════ // AUTO FONT SIZE // ═══════════════════════════════════ while (fontSize > 25) { ctx.font = `bold ${fontSize}px Arial, sans-serif`; if ( ctx.measureText(text).width <= 2600 ) { break; } fontSize -= 2; } // ═══════════════════════════════════ // WRAP TEXT // ═══════════════════════════════════ ctx.font = `bold ${fontSize}px Arial, sans-serif`; const lines = this.wrapText( ctx, text, maxWidth ); // ═══════════════════════════════════ // DRAW TEXT // ═══════════════════════════════════ const x = 40; const y = 120; const lineHeight = fontSize * 1.18; for (let i = 0; i < lines.length; i++) { ctx.fillText( lines[i], x, y + i * lineHeight ); } // ═══════════════════════════════════ // SAVE IMAGE // ═══════════════════════════════════ const buffer = canvas.toBuffer("image/png"); await fs.writeFile( outputPath, buffer ); // ═══════════════════════════════════ // SEND IMAGE // ═══════════════════════════════════ return api.sendMessage( { attachment: fs.createReadStream(outputPath) }, threadID, async () => { try { if ( await fs.pathExists(outputPath) ) { await fs.remove(outputPath); } } catch (err) { console.error( "Mia cleanup error:", err ); } }, messageID ); } catch (error) { console.error( "MIA ERROR:", error ); try { if ( await fs.pathExists(outputPath) ) { await fs.remove(outputPath); } } catch (err) {} return api.sendMessage( "❌ | Image তৈরি করতে সমস্যা হয়েছে!\n\n" + "দয়া করে আবার চেষ্টা করুন।", threadID, messageID ); } } };