UNPKG

@getsolara/solara.canvas

Version:

Optional canvas and image manipulation functionality for @getsolara/solara.js

34 lines 2.05 kB
const { AttachmentBuilder } = require('discord.js'); module.exports = { name: "$captchaCard", description: "Generates a Captcha image. Use $captchaKey separately. Args: captchaKey;[backgroundURL?];[borderColor?];[overlayOpacity?]", takesBrackets: true, execute: async (context, args) => { if (context.client.canvasInitialized === false) { return "[Error: $captchaCard requires canvas features to be enabled. Ensure @getsolara/solara.canvas is installed and configured correctly.]"; } if (!args[0]) return "[Error: $captchaCard requires the captchaKey (use $captchaKey)]"; const [key, background, border, opacityStr] = args; const opacity = opacityStr ? parseFloat(opacityStr) : undefined; if (opacity !== undefined && isNaN(opacity)) return "[Error: Invalid opacity value for $captchaCard. Must be a number.]"; try { const canvafy = require("canvafy"); const builder = new canvafy.Captcha().setCaptchaKey(key); if (background) builder.setBackground("image", background); if (border) builder.setBorder(border); if (opacity !== undefined) builder.setOverlayOpacity(opacity); const imageBuffer = await builder.build(); const attachment = new AttachmentBuilder(imageBuffer, { name: `captcha-${context.user?.id || Date.now()}.png` }); context.attachments = context.attachments || []; context.attachments.push(attachment); return ""; } catch (e) { if (e.code === 'MODULE_NOT_FOUND' && e.message.includes('canvafy')) { console.error("Solara.canvas ($captchaCard): 'canvafy' module not found. This is a dependency of @getsolara/solara.canvas."); return "[Error: $captchaCard - canvafy module missing.]"; } console.error("Solara.canvas Error ($captchaCard):", e); return `[Error generating captcha card: ${e.message}]`; } } };