diff --git a/api/index.js b/api/index.js index d92f0ac..b7822f5 100644 --- a/api/index.js +++ b/api/index.js @@ -18,50 +18,36 @@ const port = 3000; const formats = ["image/jpeg", "image/png", "image/webp", "image/gif"]; +function isValidJSON(json) { + try { + JSON.parse(json); + } catch (e) { + return false; + } + return true; +} + app.get("/", (req, res) => { res.send(`esmBot v${version}`); }); -app.post("/:method", upload.single("image"), async (req, res, next) => { +app.post("/run", upload.single("image"), async (req, res, next) => { const type = req.file ? (req.file.mimetype === "video/mp4" ? "image/gif" : req.file.mimetype) : "image/png"; if (!formats.includes(type)) { return res.sendStatus(400); } - const object = { - cmd: req.params.method, - path: req.file ? req.file.path : null, - type: type.split("/")[1], - delay: req.query.delay ? parseInt(req.query.delay) : 0 - }; - for (const param of Object.keys(req.query)) { - if (param === "delay") continue; - switch (param) { - case "sharp": - case "flop": - case "loop": - case "vertical": - case "first": - case "stretch": - case "wide": - case "soos": - case "slow": - case "resize": - case "append": - case "mc": - if (req.query[param] === "true") { - object[param] = true; - } else { - object[param] = false; - } - break; - default: - object[param] = req.query[param]; - break; - } - } + if (!isValidJSON(req.body.data)) return res.sendStatus(400); + + const object = JSON.parse(req.body.data); + + if (!magick.check(object.cmd)) return res.sendStatus(400); + + object.path = req.file ? req.file.path : null; + object.type = type.split("/")[1]; try { - const data = await magick(object, true); + const data = await magick.run(object, true); + res.contentType(type); res.send(data); } catch (e) { next(e); diff --git a/commands/9gag.js b/commands/9gag.js index 188ef66..8354525 100644 --- a/commands/9gag.js +++ b/commands/9gag.js @@ -4,7 +4,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 add a 9GAG watermark!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "watermark", path: image.path, water: "./assets/images/9gag.png", diff --git a/commands/bandicam.js b/commands/bandicam.js index 87f2625..97dc90f 100644 --- a/commands/bandicam.js +++ b/commands/bandicam.js @@ -4,7 +4,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 add a Bandicam watermark!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "watermark", path: image.path, water: "./assets/images/bandicam.png", diff --git a/commands/blur.js b/commands/blur.js index 2c2151d..df89e6f 100644 --- a/commands/blur.js +++ b/commands/blur.js @@ -4,7 +4,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 blur!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "blur", path: image.path, sharp: false, diff --git a/commands/blurple.js b/commands/blurple.js index 92e2a45..60d5ba7 100644 --- a/commands/blurple.js +++ b/commands/blurple.js @@ -4,7 +4,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 make blurple!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "blurple", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/caption.js b/commands/caption.js index 270762b..cd9d169 100644 --- a/commands/caption.js +++ b/commands/caption.js @@ -6,7 +6,7 @@ exports.run = async (message, args) => { const newArgs = args.filter(item => !item.includes(image.url) ); if (args.length === 0) return `${message.author.mention}, you need to provide some text to add a caption!`; const processMessage = await message.channel.createMessage(" Processing... This might take a while"); - const outputFinal = await magick({ + const outputFinal = await magick.run({ cmd: "caption", path: image.path, caption: newArgs.join(" "), diff --git a/commands/caption2.js b/commands/caption2.js index 03ebdbe..15c464d 100644 --- a/commands/caption2.js +++ b/commands/caption2.js @@ -6,7 +6,7 @@ exports.run = async (message, args) => { if (image === undefined) return `${message.author.mention}, you need to provide an image/GIF to add a caption!`; const newArgs = args.filter(item => !item.includes(image.url) ); const processMessage = await message.channel.createMessage(" Processing... This might take a while"); - const outputFinal = await magick({ + const outputFinal = await magick.run({ cmd: "captionTwo", path: image.path, caption: newArgs.length !== 0 ? newArgs.join(" ") : words.sort(() => 0.5 - Math.random()).slice(0, Math.floor(Math.random() * words.length + 1)).join(" "), diff --git a/commands/circle.js b/commands/circle.js index ef1b4de..482dc26 100644 --- a/commands/circle.js +++ b/commands/circle.js @@ -4,7 +4,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 add radial blur!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "circle", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/crop.js b/commands/crop.js index 9604e3a..4690274 100644 --- a/commands/crop.js +++ b/commands/crop.js @@ -4,7 +4,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 crop!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "crop", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/deviantart.js b/commands/deviantart.js index 67d2e8c..04f2437 100644 --- a/commands/deviantart.js +++ b/commands/deviantart.js @@ -4,7 +4,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 add a DeviantArt watermark!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "watermark", path: image.path, water: "./assets/images/deviantart.png", diff --git a/commands/explode.js b/commands/explode.js index 49fcab1..4ef32c7 100644 --- a/commands/explode.js +++ b/commands/explode.js @@ -4,7 +4,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 explode!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "explode", path: image.path, amount: -1, diff --git a/commands/flag.js b/commands/flag.js index 127cab7..b2c42a8 100644 --- a/commands/flag.js +++ b/commands/flag.js @@ -19,7 +19,7 @@ exports.run = async (message, args) => { } catch (e) { return `${message.author.mention}, that isn't a flag!`; } - const buffer = await magick({ + const buffer = await magick.run({ cmd: "flag", path: image.path, overlay: path, diff --git a/commands/flip.js b/commands/flip.js index cddce92..6a0b78f 100644 --- a/commands/flip.js +++ b/commands/flip.js @@ -4,7 +4,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 flip!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "flip", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/flop.js b/commands/flop.js index b5fdff7..dc113e8 100644 --- a/commands/flop.js +++ b/commands/flop.js @@ -4,7 +4,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 flop!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "flip", path: image.path, flop: true, diff --git a/commands/freeze.js b/commands/freeze.js index c9ae38f..f9cdfa7 100644 --- a/commands/freeze.js +++ b/commands/freeze.js @@ -5,7 +5,7 @@ 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 freeze!`; if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "freeze", path: image.path, loop: false, diff --git a/commands/funky.js b/commands/funky.js index 03b616e..a2aed0c 100644 --- a/commands/funky.js +++ b/commands/funky.js @@ -4,7 +4,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 add New Funky Mode!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "watermark", path: image.path, water: "./assets/images/funky.png", diff --git a/commands/gamexplain.js b/commands/gamexplain.js index 14ef21a..3bb89b9 100644 --- a/commands/gamexplain.js +++ b/commands/gamexplain.js @@ -4,7 +4,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 make a GameXplain thumbnail meme!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "gamexplain", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/globe.js b/commands/globe.js index bc2d87b..8862e92 100644 --- a/commands/globe.js +++ b/commands/globe.js @@ -4,7 +4,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 spin!`; const processMessage = await message.channel.createMessage(" Processing... This might take a while"); - const buffer = await magick({ + const buffer = await magick.run({ cmd: "globe", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/haah.js b/commands/haah.js index ed830b5..6a06910 100644 --- a/commands/haah.js +++ b/commands/haah.js @@ -4,7 +4,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 mirror!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "mirror", path: image.path, first: true, diff --git a/commands/homebrew.js b/commands/homebrew.js index bf6875c..0500ee8 100644 --- a/commands/homebrew.js +++ b/commands/homebrew.js @@ -3,7 +3,7 @@ const magick = require("../utils/image.js"); exports.run = async (message, args) => { if (args.length === 0) return `${message.author.mention}, you need to provide some text to make a Homebrew Channel edit!`; message.channel.sendTyping(); - const buffer = await magick({ + const buffer = await magick.run({ cmd: "homebrew", caption: args.join(" ").toLowerCase().replace(/\n/g, " ") }); diff --git a/commands/hooh.js b/commands/hooh.js index b823094..3944b21 100644 --- a/commands/hooh.js +++ b/commands/hooh.js @@ -4,7 +4,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 mirror!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "mirror", path: image.path, vertical: true, diff --git a/commands/hypercam.js b/commands/hypercam.js index 10735b6..5e23e5d 100644 --- a/commands/hypercam.js +++ b/commands/hypercam.js @@ -4,7 +4,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 add a Hypercam watermark!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "watermark", path: image.path, water: "./assets/images/hypercam.png", diff --git a/commands/ifunny.js b/commands/ifunny.js index 051f419..ca0e074 100644 --- a/commands/ifunny.js +++ b/commands/ifunny.js @@ -4,7 +4,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 add a iFunny watermark!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "watermark", path: image.path, water: "./assets/images/ifunny.png", diff --git a/commands/implode.js b/commands/implode.js index 3eeb182..1ff9cec 100644 --- a/commands/implode.js +++ b/commands/implode.js @@ -4,7 +4,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 implode!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "explode", path: image.path, amount: 1, diff --git a/commands/invert.js b/commands/invert.js index 93c0083..11bcca0 100644 --- a/commands/invert.js +++ b/commands/invert.js @@ -4,7 +4,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 invert!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "invert", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/jpeg.js b/commands/jpeg.js index 61ed1f2..83e027d 100644 --- a/commands/jpeg.js +++ b/commands/jpeg.js @@ -4,7 +4,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 add more JPEG!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "jpeg", path: image.path }); diff --git a/commands/leak.js b/commands/leak.js index 8c6b041..195b06a 100644 --- a/commands/leak.js +++ b/commands/leak.js @@ -4,7 +4,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 make a Super Smash Bros. leak meme!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "leak", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/loop.js b/commands/loop.js index 33b0cec..1492aab 100644 --- a/commands/loop.js +++ b/commands/loop.js @@ -5,7 +5,7 @@ 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 loop!`; if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "freeze", path: image.path, loop: true, diff --git a/commands/magik.js b/commands/magik.js index ff64816..6a06e65 100644 --- a/commands/magik.js +++ b/commands/magik.js @@ -4,7 +4,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 add some magik!`; const processMessage = await message.channel.createMessage(" Processing... This might take a while"); - const buffer = await magick({ + const buffer = await magick.run({ cmd: "magik", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/meme.js b/commands/meme.js index c44d471..90c155e 100644 --- a/commands/meme.js +++ b/commands/meme.js @@ -7,7 +7,7 @@ exports.run = async (message, args) => { const newArgs = args.filter(item => !item.includes(image.url) ); if (args.length === 0) return `${message.author.mention}, you need to provide some text to generate a meme!`; const [topText, bottomText] = newArgs.join(" ").split(/(? elem.trim()); - const buffer = await magick({ + const buffer = await magick.run({ cmd: "meme", path: image.path, top: topText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/ { 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 add a MemeCenter watermark!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "watermark", path: image.path, water: "./assets/images/memecenter.png", diff --git a/commands/motivate.js b/commands/motivate.js index b243cfb..94851d1 100644 --- a/commands/motivate.js +++ b/commands/motivate.js @@ -7,7 +7,7 @@ exports.run = async (message, args) => { 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(" Processing... This might take a while"); const [topText, bottomText] = newArgs.join(" ").split(/(? elem.trim()); - const buffer = await magick({ + const buffer = await magick.run({ cmd: "motivate", path: image.path, top: topText.replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/ { 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 pixelate!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "resize", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/reverse.js b/commands/reverse.js index ddac0e2..3d76e71 100644 --- a/commands/reverse.js +++ b/commands/reverse.js @@ -5,7 +5,7 @@ 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 reverse!`; if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "reverse", path: image.path, delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0 diff --git a/commands/scott.js b/commands/scott.js index 5610958..7d7b955 100644 --- a/commands/scott.js +++ b/commands/scott.js @@ -4,7 +4,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 make a Scott the Woz TV meme!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "scott", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/sharpen.js b/commands/sharpen.js index 9196a4b..66cde8c 100644 --- a/commands/sharpen.js +++ b/commands/sharpen.js @@ -4,7 +4,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 sharpen!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "sharpen", path: image.path, sharp: true, diff --git a/commands/shutterstock.js b/commands/shutterstock.js index 21bc9e4..2270eaa 100644 --- a/commands/shutterstock.js +++ b/commands/shutterstock.js @@ -4,7 +4,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 add a Shutterstock watermark!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "watermark", path: image.path, water: "./assets/images/shutterstock.png", diff --git a/commands/slow.js b/commands/slow.js index ab6ae96..7272a9e 100644 --- a/commands/slow.js +++ b/commands/slow.js @@ -6,7 +6,7 @@ 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 slow down!`; if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "speed", path: image.path, slow: true, diff --git a/commands/sonic.js b/commands/sonic.js index 9b3284d..fb29c6f 100644 --- a/commands/sonic.js +++ b/commands/sonic.js @@ -5,7 +5,7 @@ exports.run = async (message, args) => { if (args.length === 0) return `${message.author.mention}, you need to provide some text to make a Sonic meme!`; message.channel.sendTyping(); const cleanedMessage = args.join(" ").replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/ { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide a GIF to loop!`; if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "reverse", path: image.path, soos: true, diff --git a/commands/speed.js b/commands/speed.js index 954051e..7815778 100644 --- a/commands/speed.js +++ b/commands/speed.js @@ -5,7 +5,7 @@ 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") return `${message.author.mention}, that isn't a GIF!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "speed", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/spin.js b/commands/spin.js index 59cb3a3..2871be1 100644 --- a/commands/spin.js +++ b/commands/spin.js @@ -4,7 +4,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 spin!`; const processMessage = await message.channel.createMessage(" Processing... This might take a while"); - const buffer = await magick({ + const buffer = await magick.run({ cmd: "spin", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/stretch.js b/commands/stretch.js index c89029e..4e1572c 100644 --- a/commands/stretch.js +++ b/commands/stretch.js @@ -4,7 +4,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!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "resize", path: image.path, stretch: true, diff --git a/commands/swirl.js b/commands/swirl.js index a5b00f9..09faaff 100644 --- a/commands/swirl.js +++ b/commands/swirl.js @@ -4,7 +4,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 swirl!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "swirl", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/tile.js b/commands/tile.js index 1939866..24ab605 100644 --- a/commands/tile.js +++ b/commands/tile.js @@ -4,7 +4,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 tile!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "tile", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/trump.js b/commands/trump.js index 5f3744a..3dcc95b 100644 --- a/commands/trump.js +++ b/commands/trump.js @@ -4,7 +4,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 make a Trump meme!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "trump", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/waaw.js b/commands/waaw.js index a6aeaa6..abf180d 100644 --- a/commands/waaw.js +++ b/commands/waaw.js @@ -4,7 +4,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 mirror!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "mirror", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/wall.js b/commands/wall.js index d1631f7..d86ddbd 100644 --- a/commands/wall.js +++ b/commands/wall.js @@ -4,7 +4,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 make a wall from!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "wall", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/wdt.js b/commands/wdt.js index 131455d..b1d27e4 100644 --- a/commands/wdt.js +++ b/commands/wdt.js @@ -4,7 +4,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 make a "who did this" meme!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "wdt", path: image.path, type: image.type.toUpperCase(), diff --git a/commands/wide.js b/commands/wide.js index d1ae5a3..06fe61d 100644 --- a/commands/wide.js +++ b/commands/wide.js @@ -4,7 +4,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!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "resize", path: image.path, wide: true, diff --git a/commands/woow.js b/commands/woow.js index 669c2f5..1102a34 100644 --- a/commands/woow.js +++ b/commands/woow.js @@ -4,7 +4,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 mirror!`; - const buffer = await magick({ + const buffer = await magick.run({ cmd: "mirror", path: image.path, vertical: true, diff --git a/package-lock.json b/package-lock.json index 173520d..c6be7f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -69,9 +69,9 @@ "integrity": "sha1-nKUs2jY/aZxpRmwqbM2q2RPqenM=" }, "@types/node": { - "version": "14.10.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.10.1.tgz", - "integrity": "sha512-aYNbO+FZ/3KGeQCEkNhHFRIzBOUgc7QvcVNKXbfnhDkSfwUv91JsQQa10rDgKSTSLkXZ1UIyPe4FJJNVgw1xWQ==" + "version": "14.11.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.11.5.tgz", + "integrity": "sha512-jVFzDV6NTbrLMxm4xDSIW/gKnk8rQLF9wAzLWIOg+5nU6ACrIMndeBdXci0FGtqJbP9tQvm6V39eshc96TO2wQ==" }, "abort-controller": { "version": "3.0.0", @@ -224,39 +224,12 @@ } }, "bl": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.3.tgz", - "integrity": "sha512-fs4G6/Hu4/EE+F75J8DuN/0IpQqNjAdC7aEQv7Qt8MHGUH7Ckv2MwTEEeN9QehD0pfIDkMI1bkHYkKy7xHyKIg==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz", + "integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==", "requires": { - "buffer": "^5.5.0", - "inherits": "^2.0.4", - "readable-stream": "^3.4.0" - }, - "dependencies": { - "buffer": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", - "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", - "requires": { - "base64-js": "^1.0.2", - "ieee754": "^1.1.4" - } - }, - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - }, - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - } + "readable-stream": "^2.3.5", + "safe-buffer": "^5.1.1" } }, "bluebird": { @@ -1847,9 +1820,9 @@ "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==" }, "moment": { - "version": "2.27.0", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.27.0.tgz", - "integrity": "sha512-al0MUK7cpIcglMv3YF13qSgdAIqxHTO7brRtaz3DlSULbqfazqkc5kEjNrLDOM7fsjshoFIihnU8snrP7zUvhQ==" + "version": "2.29.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz", + "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==" }, "moment-duration-format": { "version": "2.3.2", @@ -1857,37 +1830,26 @@ "integrity": "sha512-cBMXjSW+fjOb4tyaVHuaVE/A5TqkukDWiOfxxAjY+PEqmmBQlLwn+8OzwPiG3brouXKY5Un4pBjAeB6UToXHaQ==" }, "mongodb": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.0.tgz", - "integrity": "sha512-/XWWub1mHZVoqEsUppE0GV7u9kanLvHxho6EvBxQbShXTKYF9trhZC2NzbulRGeG7xMJHD8IOWRcdKx5LPjAjQ==", + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.2.tgz", + "integrity": "sha512-sSZOb04w3HcnrrXC82NEh/YGCmBuRgR+C1hZgmmv4L6dBz4BkRse6Y8/q/neXer9i95fKUBbFi4KgeceXmbsOA==", "requires": { - "bl": "^2.2.0", + "bl": "^2.2.1", "bson": "^1.1.4", "denque": "^1.4.1", "require_optional": "^1.0.1", "safe-buffer": "^5.1.2", "saslprep": "^1.0.0" - }, - "dependencies": { - "bl": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz", - "integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==", - "requires": { - "readable-stream": "^2.3.5", - "safe-buffer": "^5.1.1" - } - } } }, "mongoose": { - "version": "5.10.2", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.10.2.tgz", - "integrity": "sha512-VO5eZawEMFh2gx9XPg9ZafzFg5eIVs4R7PW6kK1MFqBq34YD7GomkalYWVt02HctvTPDI1mkXsm52LXNZR1NxA==", + "version": "5.10.8", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.10.8.tgz", + "integrity": "sha512-hbpFhOU6rWkWPkekUeSJxqWwzsjVQZ9xPg4WmWA1HJ8YDvjyNye1xbp82fw67BpnyvcjHxyU3/YhujsOCx55yw==", "requires": { "bson": "^1.1.4", "kareem": "2.3.1", - "mongodb": "3.6.0", + "mongodb": "3.6.2", "mongoose-legacy-pluralize": "1.0.2", "mpath": "0.7.0", "mquery": "3.2.2", @@ -2012,9 +1974,9 @@ } }, "node-addon-api": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.0.1.tgz", - "integrity": "sha512-YUpjl57P55u2yUaKX5Bgy4t5s6SCNYMg+62XNg+k41aYbBL1NgWrZfcgljR5MxDxHDjzl0qHDNtH6SkW4DXNCA==" + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.0.2.tgz", + "integrity": "sha512-+D4s2HCnxPd5PjjI0STKwncjXTUKKqm74MDMz9OPXavjsGmjkvwgLtA5yoxJUdmpj52+2u+RrXgPipahKczMKg==" }, "node-emoji": { "version": "1.10.0", @@ -2641,13 +2603,13 @@ "optional": true }, "sharp": { - "version": "0.26.0", - "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.26.0.tgz", - "integrity": "sha512-MNldekb9ZnliJAD+qP6uBTf3Wd6HaDVhKYbxXG+SQDvit9fa+2X4wECJvMRF8FLdY4saojrz3BHsnt4OmJw7xg==", + "version": "0.26.1", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.26.1.tgz", + "integrity": "sha512-9MhwS4ys8pnwBH7MtnBdLzUv+cb24QC4xbzzQL6A+1MQ4Se2V6oPHEX8TIGIZUPRKi6S1kJPVNzt/Xqqp6/H3Q==", "requires": { "color": "^3.1.2", "detect-libc": "^1.0.3", - "node-addon-api": "^3.0.0", + "node-addon-api": "^3.0.2", "npmlog": "^4.1.2", "prebuild-install": "^5.3.5", "semver": "^7.3.2", @@ -2899,6 +2861,32 @@ "readable-stream": "^3.1.1" }, "dependencies": { + "bl": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.3.tgz", + "integrity": "sha512-fs4G6/Hu4/EE+F75J8DuN/0IpQqNjAdC7aEQv7Qt8MHGUH7Ckv2MwTEEeN9QehD0pfIDkMI1bkHYkKy7xHyKIg==", + "requires": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + }, + "dependencies": { + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + } + } + }, + "buffer": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz", + "integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==", + "requires": { + "base64-js": "^1.0.2", + "ieee754": "^1.1.4" + } + }, "readable-stream": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", diff --git a/package.json b/package.json index 52d8a1b..6692cb9 100644 --- a/package.json +++ b/package.json @@ -34,17 +34,17 @@ "form-data": "^3.0.0", "jsqr": "^1.3.1", "lavacord": "^1.1.9", - "moment": "^2.27.0", + "moment": "^2.29.1", "moment-duration-format": "^2.3.2", - "mongoose": "^5.10.2", - "node-addon-api": "^3.0.1", + "mongoose": "^5.10.8", + "node-addon-api": "^3.0.2", "node-emoji": "^1.10.0", "node-fetch": "^2.6.1", "node-tweet": "^0.1.4", "puppeteer-core": "^2.1.1", "qrcode": "^1.4.4", "retrotext": "github:TheEssem/retrotext", - "sharp": "^0.26.0", + "sharp": "^0.26.1", "winston": "^3.3.3" }, "devDependencies": { diff --git a/utils/client.js b/utils/client.js index 9fbbf8b..a6f8c8b 100644 --- a/utils/client.js +++ b/utils/client.js @@ -11,8 +11,7 @@ const client = new Client(process.env.TOKEN, { GUILD_ROLE_CREATE: true, GUILD_ROLE_DELETE: true, GUILD_ROLE_UPDATE: true, - TYPING_START: true, - USER_UPDATE: true + TYPING_START: true }, maxShards: "auto" }); diff --git a/utils/image.js b/utils/image.js index ef9726f..3ae53d3 100644 --- a/utils/image.js +++ b/utils/image.js @@ -4,22 +4,23 @@ const { promisify } = require("util"); const FormData = require("form-data"); const fs = require("fs"); -module.exports = async (object, fromAPI = false) => { +exports.run = async (object, fromAPI = false) => { if (process.env.API === "true" && !fromAPI) { - const params = []; - for (const element of Object.keys(object)) { - params.push(`${element}=${encodeURIComponent(object[element])}`); - } const form = new FormData(); + form.append("data", JSON.stringify(object)); if (object.path) form.append("image", fs.createReadStream(object.path)); - const req = await fetch(`${process.env.API_URL}/${object.cmd}?${params.join("&")}`, { + const req = await fetch(`${process.env.API_URL}/run`, { method: "POST", body: form, headers: form.getHeaders() }); - return object.cmd === "qrread" ? await req.json() : await req.buffer(); + return await req.buffer(); } else { const data = await promisify(magick[object.cmd])(object); return data; } +}; + +exports.check = (cmd) => { + return magick[cmd] ? true : false; }; \ No newline at end of file