2019-09-13 20:02:41 +00:00
|
|
|
const { spawn } = require("child_process");
|
|
|
|
|
|
|
|
exports.run = async (message, args) => {
|
2019-12-02 20:47:22 +00:00
|
|
|
message.channel.sendTyping();
|
2019-09-13 20:02:41 +00:00
|
|
|
const image = await require("../utils/imagedetect.js")(message);
|
|
|
|
if (image === undefined) return `${message.author.mention}, you need to provide an image to generate a meme!`;
|
2020-01-08 01:17:04 +00:00
|
|
|
if (image.type === "gif") return `${message.author.mention}, this command doesn't work with GIFs!`;
|
2019-09-13 20:02:41 +00:00
|
|
|
if (args.length === 0) return `${message.author.mention}, you need to provide some text to generate a meme!`;
|
|
|
|
const [topText, bottomText] = args.join(" ").split(",").map(elem => elem.trim());
|
|
|
|
const child = spawn("./utils/meme.sh", [topText.toUpperCase().replace(/\\/g, "\\\\"), bottomText ? bottomText.toUpperCase().replace(/\\/g, "\\\\") : ""]);
|
2019-11-11 20:54:19 +00:00
|
|
|
child.stdin.write(image.data);
|
2019-09-13 20:02:41 +00:00
|
|
|
child.stdin.end();
|
|
|
|
const chunks = [];
|
|
|
|
child.stdout.on("data", (data) => {
|
|
|
|
chunks.push(data);
|
|
|
|
});
|
|
|
|
child.once("error", (error) => {
|
2019-12-10 15:53:43 +00:00
|
|
|
if (error) throw error;
|
2019-09-13 20:02:41 +00:00
|
|
|
});
|
|
|
|
child.stderr.once("data", (error) => {
|
2020-01-06 00:02:24 +00:00
|
|
|
if (error) throw new Error(error.toString());
|
2019-09-13 20:02:41 +00:00
|
|
|
});
|
|
|
|
child.stdout.once("close", () => {
|
|
|
|
const data = Buffer.concat(chunks);
|
|
|
|
return message.channel.createMessage("", {
|
|
|
|
file: data,
|
|
|
|
name: "meme.png"
|
|
|
|
});
|
|
|
|
});
|
2019-12-02 20:47:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.category = 5;
|
2019-12-05 16:58:46 +00:00
|
|
|
exports.help = "Generates a meme from an image (separate top/bottom text with a comma)";
|
|
|
|
exports.params = "[top text], {bottom text}";
|