mrmBot-Matrix/commands/sonic.js
2019-09-13 15:02:41 -05:00

23 lines
No EOL
1.1 KiB
JavaScript

const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
const tempy = require("tempy");
const wrap = require("../utils/wrap.js");
exports.run = async (message, args) => {
if (args.length === 0) return `${message.author.mention}, you need to provide an image to make a Sonic meme!`;
message.channel.sendTyping();
const template = "./assets/images/sonic.jpg";
const file = tempy.file({ extension: "png" });
const cleanedMessage = args.join(" ").replace(/&/g, "\\&amp;").replace(/>/g, "\\&gt;").replace(/</g, "\\&lt;");
gm(474, 332).out("+size").gravity("Center").out("-pointsize", 40).out("-font", "Bitstream Vera Sans").out(`pango:${wrap(cleanedMessage, {width: 15, indent: ""})}`).negative().out("-fuzz", "30%").transparent("black").write(file, async (error) => {
if (error) console.error;
const command = gm(template).composite(file).gravity("Center").geometry("474x332+160+10");
const resultBuffer = await gmToBuffer(command);
return message.channel.createMessage("", {
file: resultBuffer,
name: "sonic.png"
});
});
};