Removed node version check, promisified many gm calls

This commit is contained in:
TheEssem 2020-02-20 18:26:49 -06:00
parent 1c9d40041b
commit 1e259ab312
24 changed files with 187 additions and 276 deletions

3
app.js
View file

@ -1,6 +1,3 @@
// check if using node 10 or higher
if (process.version.slice(1).split(".")[0] < 10) throw new Error("Node 10.0.0 or higher is required. Update Node on your system.");
// load config from .env file
require("dotenv").config();

View file

@ -8,15 +8,13 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to add a Bandicam watermark!`;
const watermark = "./assets/images/bandicam.png";
gm(image.path).size(async (error, size) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("North").resize(null, size.height).out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `bandicam.${image.outputType}`
});
});
};
exports.aliases = ["bandi"];

View file

@ -9,14 +9,11 @@ exports.run = async (message, args) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image/GIF to add a caption!`;
if (args.length === 0) return `${message.author.mention}, you need to provide some text to add a caption!`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
gm(image.path).size(async (error, size) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
const command = gm().out("-size", `${size.width}x`).background("white").fill("black").font("./assets/caption.otf", size.width / 10).gravity("Center").out(`caption:${args.join(" ")}`);
const output = await gmToBuffer(command, "png");
gm(output).size(async (error, size2) => {
if (error) throw error;
gm(output).gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).stream(async (error, output2) => {
if (error) throw error;
const size2 = await gm(output).sizePromise();
const output2 = await gm(output).gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).streamPromise();
const command3 = gm(output2).out("-alpha", "set").background("none").out("(").out(image.path).out("-coalesce").out(")").colorspace("sRGB").out("-set", "page", "%[fx:u.w]x%[fx:u.h+v.h]+%[fx:t?(u.w-v.w)/2:0]+%[fx:t?u.h:0]").out("-coalesce").out("null:").out("-insert", 1).out("-layers", "composite");
const outputFinal = await gmToBuffer(command3, image.outputType);
await processMessage.delete();
@ -25,9 +22,6 @@ exports.run = async (message, args) => {
file: outputFinal,
name: `caption.${image.outputType}`
});
});
});
});
};
exports.aliases = ["gifc", "gcaption", "ifcaption", "ifunnycaption"];

View file

@ -8,15 +8,13 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to add a DeviantArt watermark!`;
const watermark = "./assets/images/deviantart.png";
gm(image.path).size(async (error, size) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `deviantart.${image.outputType}`
});
});
};
exports.aliases = ["da", "deviant"];

View file

@ -8,15 +8,13 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to add New Funky Mode!`;
const watermark = "./assets/images/funky.png";
gm(image.path).size(async (error, size) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, size.height).out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `funky.${image.outputType}`
});
});
};
exports.aliases = ["funkymode", "newfunkymode", "funkykong"];

View file

@ -1,5 +1,3 @@
// really don't like this file
const gm = require("gm").subClass({
imageMagick: true
});
@ -11,21 +9,15 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to mirror!`;
const data = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.path).size((error, size) => {
if (error) throw error;
gm(image.path).coalesce().gravity("West").crop("50%", 0).out("+repage").write(data2, (error) => {
if (error) throw error;
gm(data2).flop().write(data, async (error) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
await gm(image.path).coalesce().gravity("West").crop("50%", 0).out("+repage").writePromise(data2);
await gm(data2).flop().writePromise(data);
const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+${size.width / 2}+0`).out("-layers", "Composite");
const buffer = await gmToBuffer(command, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `haah.${image.outputType}`
});
});
});
});
};
exports.aliases = ["magik4", "mirror2"];

View file

@ -1,5 +1,3 @@
// really don't like this file
const gm = require("gm").subClass({
imageMagick: true
});
@ -11,21 +9,15 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to mirror!`;
const data = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.path).size((error, size) => {
if (error) throw error;
gm(image.path).coalesce().gravity("South").crop(0, "50%").out("+repage").write(data2, (error) => {
if (error) throw error;
gm(data2).flip().write(data, async (error) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
await gm(image.path).coalesce().gravity("South").crop(0, "50%").out("+repage").writePromise(data2);
await gm(data2).flip().writePromise(data);
const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+0+${size.height / 2}`).out("-layers", "Composite");
const buffer = await gmToBuffer(command, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `hooh.${image.outputType}`
});
});
});
});
};
exports.aliases = ["magik6", "mirror4"];

View file

@ -8,15 +8,13 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to add a Hypercam watermark!`;
const watermark = "./assets/images/hypercam.png";
gm(image.path).size(async (error, size) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, size.height).out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `hypercam.${image.outputType}`
});
});
};
exports.aliases = ["hcam"];

View file

@ -8,15 +8,13 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to add a iFunny watermark!`;
const watermark = "./assets/images/ifunny.png";
gm(image.path).size(async (error, size) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("South").resize(size.width, null).out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `ifunny.${image.outputType}`
});
});
};
exports.category = 5;

View file

@ -8,19 +8,15 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to add some magik!`;
if (image.type === "gif" || image.type === "mp4") return `${message.author.mention}, this command doesn't work with GIFs!`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
gm(image.data).resize(800, 800).stream("miff", (error, stream) => {
if (error) throw error;
gm(stream).out("-liquid-rescale", "400x400").stream(async (error, stream2) => {
if (error) throw error;
const data = gm(stream2).out("-liquid-rescale", "1200x1200");
const resultBuffer = await gmToBuffer(data);
const stream = await gm(image.path).coalesce().resize(600, 600).streamPromise("miff");
const stream2 = await gm(stream).out("-liquid-rescale", "300x300").streamPromise();
const data = gm(stream2).out("-liquid-rescale", "800x800");
const resultBuffer = await gmToBuffer(data, image.outputType);
await processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,
name: `magik.${image.outputType}`
});
});
});
};
exports.aliases = ["imagemagic", "imagemagick", "imagemagik", "magic", "magick", "cas", "liquid"];

View file

@ -12,24 +12,16 @@ exports.run = async (message, args) => {
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const file2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
const file3 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
gm(image.path).coalesce().resize(600, 600).noProfile().write(file, (error) => {
if (error) throw error;
gm(file).size((error, size) => {
if (error) throw error;
gm().out("-size", size.width).background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:<span foreground='white'>${topText.toUpperCase().replace(/&/g, "\\&amp;").replace(/>/g, "\\&gt;").replace(/</g, "\\&lt;").replace(/"/g, "\\&quot;").replace(/'/g, "\\&apos;")}</span>`).out(")", "(", "+clone").out("-channel", "A").out("-morphology", "EdgeOut", "Octagon", "+channel", "+level-colors", "black", ")").compose("DstOver").out(")", "-composite").write(file2, (error) => {
if (error) throw error;
gm().out("-size", size.width).background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:<span foreground='white'>${bottomText ? bottomText.toUpperCase().replace(/&/g, "\\&amp;").replace(/>/g, "\\&gt;").replace(/</g, "\\&lt;").replace(/"/g, "\\&quot;").replace(/'/g, "\\&apos;") : " "}</span>`).out(")", "(", "+clone").out("-channel", "A").out("-morphology", "EdgeOut", "Octagon", "+channel", "+level-colors", "black", ")").compose("DstOver").out(")", "-composite").write(file3, async (error) => {
if (error) throw error;
const data = gm(file).out("-coalesce").out("null:").gravity("North").out(file2).out("-layers", "composite").out("null:").gravity("South").out(file3).out("-layers", "composite");
await gm(image.path).coalesce().resize(600, 600).noProfile().writePromise(file);
const size = await gm(file).sizePromise();
await gm().out("-size", size.width).background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:<span foreground='white'>${topText.toUpperCase().replace(/&/g, "\\&amp;").replace(/>/g, "\\&gt;").replace(/</g, "\\&lt;").replace(/"/g, "\\&quot;").replace(/'/g, "\\&apos;")}</span>`).out(")", "(", "+clone").out("-channel", "A").out("-morphology", "EdgeOut", "Octagon", "+channel", "+level-colors", "black", ")").compose("DstOver").out(")", "-composite").writePromise(file2);
if (bottomText) await gm().out("-size", size.width).background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:<span foreground='white'>${bottomText.toUpperCase().replace(/&/g, "\\&amp;").replace(/>/g, "\\&gt;").replace(/</g, "\\&lt;").replace(/"/g, "\\&quot;").replace(/'/g, "\\&apos;")}</span>`).out(")", "(", "+clone").out("-channel", "A").out("-morphology", "EdgeOut", "Octagon", "+channel", "+level-colors", "black", ")").compose("DstOver").out(")", "-composite").writePromise(file3);
const data = gm(file).out("-coalesce").out("null:").gravity("North").out(file2).out("-layers", "composite").out("null:").gravity("South").out(bottomText ? file3 : "null:").out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `meme.${image.outputType}`
});
});
});
});
});
};
exports.category = 5;

View file

@ -9,12 +9,10 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to add a MemeCenter watermark!`;
const watermark = "./assets/images/memecenter.png";
let resultBuffer;
gm(image.path).size(async (error, size) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
const command = gm(image.path).coalesce().background("white").extent(size.width, size.height + 15).out("null:").out(watermark).gravity("SouthEast").compose("over").out("-layers", "composite");
const output = await gmToBuffer(command, image.outputType);
gm(output).size(async (error, size2) => {
if (error) throw error;
const size2 = await gm(output).sizePromise();
resultBuffer = output;
if (size.width !== size2.width) {
const command2 = gm(output).gravity("West").chop(size2.width - size.width, 0);
@ -24,8 +22,6 @@ exports.run = async (message) => {
file: resultBuffer,
name: `memecenter.${image.outputType}`
});
});
});
};
exports.aliases = ["memec", "mcenter"];

View file

@ -10,51 +10,30 @@ exports.run = async (message, args) => {
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
const [topText, bottomText] = args.join(" ").split(",").map(elem => elem.trim());
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const file2 = `/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`;
gm().in("(").in(image.path).coalesce().resize(500, 500).borderColor("black").border(5, 5).out(")").borderColor("white").border(3, 3).out("-layers", "optimize").write(file, (error) => {
if (error) throw error;
gm(file).size((error, size) => {
if (error) throw error;
gm(file).coalesce().background("black").gravity("Center").extent(600, size.height + 50).out("+swap").write(file2, () => {
// this is commented out because it was causing some issues and I couldn't find an elegant solution
// if (error) throw error;
gm(file2).size((error, size2) => {
if (error) throw error;
gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(56).gravity("Center").out(`pango:${topText}`).gravity("South").out("-splice", bottomText ? "0x0" : "0x20").write(text, (error) => {
if (error) throw error;
gm(text).size(async (error, size3) => {
if (error) throw error;
const command = gm(file2).gravity("North").coalesce().background("black").extent(600, size2.height + size3.height).out("null:", "(", text, "-set", "page", `+0+${size2.height}`, ")", "-layers", "composite", "-layers", "optimize");
const command = gm().in("(").in(image.path).coalesce().resize(500, 500).borderColor("black").border(5, 5).out(")").borderColor("white").border(3, 3);
const buffer = await gmToBuffer(command, "miff");
const size = await gm(buffer).sizePromise();
await gm(buffer).coalesce().background("black").gravity("Center").extent(600, size.height + 50).writePromise(file);
const size2 = await gm(file).sizePromise();
await gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(56).gravity("Center").out(`pango:${topText}`).gravity("South").out("-splice", bottomText ? "0x0" : "0x20").writePromise(text);
const size3 = await gm(text).sizePromise();
const command2 = gm(file).gravity("North").coalesce().background("black").extent(600, size2.height + size3.height).out("null:", "(", text, "-set", "page", `+0+${size2.height}`, ")", "-layers", "composite", "-layers", "optimize");
let resultBuffer;
if (bottomText) {
gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(28).gravity("Center").out(`pango:${bottomText}`).gravity("South").out("-splice", "0x20").write(text2, (error) => {
if (error) throw error;
gm(text2).size(async (error, size4) => {
if (error) throw error;
const command2 = gm(await gmToBuffer(command, image.outputType)).gravity("North").coalesce().background("black").extent(600, size2.height + size3.height + size4.height).out("null:", "(", text2, "-set", "page", `+0+${size2.height + size3.height}`, ")", "-layers", "composite", "-layers", "optimize");
const resultBuffer = await gmToBuffer(command2, image.outputType);
processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,
name: `motivate.${image.outputType}`
});
});
});
await gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(28).gravity("Center").out(`pango:${bottomText}`).gravity("South").out("-splice", "0x20").writePromise(text2);
const size4 = await gm(text2).sizePromise();
const command3 = gm(await gmToBuffer(command2, image.outputType)).gravity("North").coalesce().background("black").extent(600, size2.height + size3.height + size4.height).out("null:", "(", text2, "-set", "page", `+0+${size2.height + size3.height}`, ")", "-layers", "composite", "-layers", "optimize");
resultBuffer = await gmToBuffer(command3, image.outputType);
} else {
const resultBuffer = await gmToBuffer(command, image.outputType);
resultBuffer = await gmToBuffer(command2, image.outputType);
}
processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,
name: `motivate.${image.outputType}`
});
}
});
});
});
});
});
});
};
exports.aliases = ["motivational", "motiv", "demotiv", "demotivational", "poster"];

View file

@ -8,15 +8,13 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to add a Shutterstock watermark!`;
const watermark = "./assets/images/shutterstock.png";
gm(image.path).size(async (error, size) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
const command = gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite");
const buffer = await gmToBuffer(command, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `shutterstock.${image.outputType}`
});
});
};
exports.aliases = ["stock", "stockphoto"];

View file

@ -10,15 +10,13 @@ exports.run = async (message, args) => {
const template = "./assets/images/sonic.jpg";
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
const cleanedMessage = args.join(" ").replace(/&/g, "\\&amp;").replace(/>/g, "\\&gt;").replace(/</g, "\\&lt;").replace(/"/g, "\\&quot;").replace(/'/g, "\\&apos;");
gm(474, 332).out("+size").background("none").gravity("Center").out("-pointsize", 72).out("-font", "Bitstream Vera Sans").out(`pango:<span foreground="white">${wrap(cleanedMessage, {width: 15, indent: ""})}</span>`).write(file, async (error) => {
if (error) throw error;
await gm(474, 332).out("+size").background("none").gravity("Center").out("-pointsize", 72).out("-font", "Bitstream Vera Sans").out(`pango:<span foreground="white">${wrap(cleanedMessage, {width: 15, indent: ""})}</span>`).writePromise(file);
const command = gm(template).composite(file).gravity("Center").geometry("474x332+160+10");
const buffer = await gmToBuffer(command, "png", "sonic");
return message.channel.createMessage("", {
file: buffer,
name: "sonic.png"
});
});
};
exports.category = 4;

View file

@ -1,4 +1,6 @@
const { exec } = require("child_process");
const {
exec
} = require("child_process");
const util = require("util");
const gm = require("gm").subClass({
imageMagick: true
@ -10,13 +12,13 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide a GIF to speed up!`;
if (image.type !== "gif" && image.type !== "mp4") return `${message.author.mention}, that isn't a GIF!`;
gm(image.path).identify(async (error, value) => {
if (error) throw error;
const value = await gm(image.path).identifyPromise();
const delay = value.Delay ? value.Delay[0].split("x") : [0, 100];
if (Math.round(parseInt(delay[0]) / 2) >= 2) {
const data = gm().delay(`${parseInt(delay[0]) / 2}x${delay[1]}`).out(image.path);
const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", {
file: await gmToBuffer(data, image.outputType),
file: buffer,
name: "speed.gif"
});
} else {
@ -28,7 +30,6 @@ exports.run = async (message) => {
name: "speed.gif"
});
}
});
};
exports.aliases = ["speedup", "fast", "gifspeed"];

View file

@ -7,15 +7,13 @@ exports.run = async (message) => {
message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to tile!`;
gm(image.path).coalesce().command("montage").out("-duplicate").out(24).tile("5x5").geometry("+0+0").stream("miff", async (error, output) => {
if (error) throw error;
const output = await gm(image.path).coalesce().command("montage").out("-duplicate").out(24).tile("5x5").geometry("+0+0").streamPromise("miff");
const data = gm(output).coalesce().resize("800x800>");
const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `tile.${image.outputType}`
});
});
};
exports.aliases = ["wall2"];

View file

@ -1,5 +1,3 @@
// really don't like this file
const gm = require("gm").subClass({
imageMagick: true
});
@ -11,21 +9,15 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to mirror!`;
const data = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.path).size((error, size) => {
if (error) throw error;
gm(image.path).coalesce().gravity("East").crop("50%", 0).out("+repage").write(data2, (error) => {
if (error) throw error;
gm(data2).flop().write(data, async (error) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
await gm(image.path).coalesce().gravity("East").crop("50%", 0).out("+repage").writePromise(data2);
await gm(data2).flop().writePromise(data);
const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+${size.width / 2}+0`).out("-layers", "Composite");
const buffer = await gmToBuffer(command, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `waaw.${image.outputType}`
});
});
});
});
};
exports.aliases = ["magik3", "mirror"];

View file

@ -7,15 +7,13 @@ exports.run = async (message) => {
message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to make a wall from!`;
gm(image.path).coalesce().resize(128).stream("miff", async (error, output) => {
if (error) throw error;
const output = await gm(image.path).coalesce().resize(128).streamPromise("miff");
const data = gm(output).coalesce().virtualPixel("tile").matteColor("none").out("-background", "none").resize("512x512!").out("-distort").out("Perspective").out("0,0,57,42 0,128,63,130 128,0,140,60 128,128,140,140");
const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `wall.${image.outputType}`
});
});
};
exports.category = 5;

View file

@ -8,7 +8,7 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to make a "who did this" meme!`;
const template = "./assets/images/whodidthis.png";
const command = gm(template).coalesce().out("null:").out(image.path).gravity("Center").resize("374x374>").out("-layers", "composite");
const command = gm(template).out("null:").out("(").out(image.path).coalesce().out(")").gravity("Center").resize("374x374>").out("-layers", "composite");
const buffer = await gmToBuffer(command, image.outputType);
return message.channel.createMessage("", {
file: buffer,

View file

@ -7,8 +7,7 @@ exports.run = async (message) => {
message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to stretch!`;
gm(image.path).size(async (error, size) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
if (size.width > 10000) return `${message.author.mention}, this image is too wide!`;
const data = gm(image.path).coalesce().resize(`${(size.width * 19) / 2}x${size.height / 2}!`);
const buffer = await gmToBuffer(data, image.outputType);
@ -16,7 +15,6 @@ exports.run = async (message) => {
file: buffer,
name: `wide.${image.outputType}`
});
});
};
exports.aliases = ["w19", "wide19"];

View file

@ -1,5 +1,3 @@
// really don't like this file
const gm = require("gm").subClass({
imageMagick: true
});
@ -11,21 +9,15 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to mirror!`;
const data = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.path).size((error, size) => {
if (error) throw error;
gm(image.path).coalesce().gravity("North").crop(0, "50%").out("+repage").write(data2, (error) => {
if (error) throw error;
gm(data2).flip().write(data, async (error) => {
if (error) throw error;
const size = await gm(image.path).sizePromise();
await gm(image.path).coalesce().gravity("North").crop(0, "50%").out("+repage").writePromise(data2);
await gm(data2).flip().writePromise(data);
const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+0+${size.height / 2}`).out("-layers", "Composite");
const buffer = await gmToBuffer(command, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `woow.${image.outputType}`
});
});
});
});
};
exports.aliases = ["magik5", "mirror3"];

View file

@ -1,3 +1,5 @@
const gm = require("gm");
const { promisify } = require("util");
const client = require("../utils/client.js");
const database = require("../utils/database.js");
const logger = require("../utils/logger.js");
@ -33,6 +35,12 @@ module.exports = async () => {
setTimeout(activityChanger, 900000);
})();
// add gm extensions
gm.prototype.writePromise = promisify(gm.prototype.write);
gm.prototype.streamPromise = promisify(gm.prototype.stream);
gm.prototype.sizePromise = promisify(gm.prototype.size);
gm.prototype.identifyPromise = promisify(gm.prototype.identify);
// tweet stuff
if (twitter !== null && twitter.active === false) {
const blocks = await twitter.client.get("blocks/ids", { stringify_ids: true });

View file

@ -33,7 +33,7 @@ const paginationEmbed = async (message, pages, timeout = 120000) => {
if (manageMessages) msg.removeReaction("🔢", userID);
});
}).catch(error => {
if (error) throw error;
throw error;
});
break;
case "▶":