mrmBot-Matrix/commands/motivate.js
2021-03-19 10:26:17 -05:00

26 lines
1.5 KiB
JavaScript

const magick = require("../utils/image.js");
exports.run = async (message, args) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image/GIF to make a motivational poster!`;
const newArgs = args.filter(item => !item.includes(image.url) );
if (args.length === 0) return `${message.author.mention}, you need to provide some text to make a motivational poster!`;
const processMessage = await message.channel.createMessage(`${process.env.PROCESSING_EMOJI || "<a:processing:479351417102925854>"} Processing... This might take a while`);
const [topText, bottomText] = newArgs.join(" ").split(/(?<!\\),/).map(elem => elem.trim());
const { buffer, type } = await magick.run({
cmd: "motivate",
path: image.path,
top: topText.replaceAll("&", "\\&amp;").replaceAll(">", "\\&gt;").replaceAll("<", "\\&lt;").replaceAll("\"", "\\&quot;").replaceAll("'", "\\&apos;").replaceAll("%", "\\%"),
bottom: bottomText ? bottomText.replaceAll("&", "\\&amp;").replaceAll(">", "\\&gt;").replaceAll("<", "\\&lt;").replaceAll("\"", "\\&quot;").replaceAll("'", "\\&apos;").replaceAll("%", "\\%") : "",
type: image.type
});
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
return {
file: buffer,
name: `motivate.${type}`
};
};
exports.aliases = ["motivational", "motiv", "demotiv", "demotivational", "poster", "motivation"];
exports.category = 5;
exports.help = "Creates a motivational poster";