2020-02-13 19:29:42 +00:00
|
|
|
const gm = require("gm").subClass({
|
|
|
|
imageMagick: true
|
|
|
|
});
|
|
|
|
|
|
|
|
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!`;
|
2020-04-23 22:38:01 +00:00
|
|
|
const newArgs = args.filter(item => !item.includes(image.url) );
|
2020-02-13 19:29:42 +00:00
|
|
|
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("<a:processing:479351417102925854> Processing... This might take a while");
|
2020-04-23 22:38:01 +00:00
|
|
|
const [topText, bottomText] = newArgs.join(" ").split(/(?<!\\),/).map(elem => elem.trim());
|
2020-02-13 19:29:42 +00:00
|
|
|
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
|
|
|
|
const text = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
|
|
|
|
const text2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
|
2020-04-10 03:03:03 +00:00
|
|
|
const buffer = await gm().in("(").in(image.path).coalesce().scale(500, 500).borderColor("black").border(5, 5).out(")").borderColor("white").border(3, 3).bufferPromise("miff", image.delay);
|
2020-03-15 23:54:57 +00:00
|
|
|
await gm(buffer).coalesce().background("black").gravity("Center").extent(600, "%[fx:s.h+50]").writePromise(file);
|
2020-02-21 00:26:49 +00:00
|
|
|
const size2 = await gm(file).sizePromise();
|
2020-03-02 16:13:49 +00:00
|
|
|
await gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(56).gravity("Center").out(`pango:${topText.replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'")}`).gravity("South").out("-splice", bottomText ? "0x0" : "0x20").writePromise(text);
|
2020-02-21 00:26:49 +00:00
|
|
|
const size3 = await gm(text).sizePromise();
|
2020-03-09 12:39:46 +00:00
|
|
|
const command2 = gm(file).gravity("North").coalesce().extent(600, size2.height + size3.height).out("null:", "(", text, "-set", "page", `+0+${size2.height}`, ")", "-layers", "composite", "-layers", "optimize");
|
2020-02-21 00:26:49 +00:00
|
|
|
let resultBuffer;
|
|
|
|
if (bottomText) {
|
2020-03-02 16:13:49 +00:00
|
|
|
await gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(28).gravity("Center").out(`pango:${bottomText.replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'")}`).gravity("South").out("-splice", "0x20").writePromise(text2);
|
2020-02-21 00:26:49 +00:00
|
|
|
const size4 = await gm(text2).sizePromise();
|
2020-03-15 17:54:51 +00:00
|
|
|
resultBuffer = await gm(await command2.bufferPromise(image.type, image.delay)).gravity("North").coalesce().extent(600, size2.height + size3.height + size4.height).out("null:", "(", text2, "-set", "page", `+0+${size2.height + size3.height}`, ")", "-layers", "composite", "-layers", "optimize").bufferPromise(image.type, image.delay);
|
2020-02-21 00:26:49 +00:00
|
|
|
} else {
|
2020-03-15 17:54:51 +00:00
|
|
|
resultBuffer = await command2.bufferPromise(image.type, image.delay);
|
2020-02-21 00:26:49 +00:00
|
|
|
}
|
|
|
|
processMessage.delete();
|
2020-04-12 19:51:48 +00:00
|
|
|
return {
|
2020-02-21 00:26:49 +00:00
|
|
|
file: resultBuffer,
|
2020-02-25 20:45:47 +00:00
|
|
|
name: `motivate.${image.type}`
|
2020-04-12 19:51:48 +00:00
|
|
|
};
|
2020-02-13 19:29:42 +00:00
|
|
|
};
|
|
|
|
|
2020-04-25 04:21:05 +00:00
|
|
|
exports.aliases = ["motivational", "motiv", "demotiv", "demotivational", "poster", "motivation"];
|
2020-02-13 19:29:42 +00:00
|
|
|
exports.category = 5;
|
2020-03-15 23:54:57 +00:00
|
|
|
exports.help = "Creates a motivational poster";
|