Heavy work on the image detection code, fixed mention prefixes not being properly registered
This commit is contained in:
parent
6cd9878632
commit
cf5c649384
57 changed files with 240 additions and 443 deletions
|
@ -27,6 +27,8 @@ MASHAPE=
|
|||
GOOGLE=
|
||||
# Put DBL/top.gg token here
|
||||
DBL=
|
||||
# Put Tenor API key here (used for obtaining raw tenor GIF urls)
|
||||
TENOR=
|
||||
|
||||
# Put headless Chrome IP here
|
||||
CHROME=172.17.0.1:9222
|
||||
|
|
49
api/index.js
49
api/index.js
|
@ -2,51 +2,32 @@ require("dotenv").config();
|
|||
const magick = require("../utils/image.js");
|
||||
const { version } = require("../package.json");
|
||||
const express = require("express");
|
||||
const multer = require("multer");
|
||||
const path = require("path");
|
||||
const storage = multer.diskStorage({
|
||||
destination: function(req, file, cb) {
|
||||
cb(null, "/tmp/");
|
||||
},
|
||||
filename: function(req, file, cb) {
|
||||
cb(null, Date.now() + path.extname(file.originalname));
|
||||
}
|
||||
});
|
||||
const upload = multer({ storage: storage });
|
||||
const execPromise = require("util").promisify(require("child_process").exec);
|
||||
const app = express();
|
||||
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("/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);
|
||||
}
|
||||
if (!isValidJSON(req.body.data)) return res.sendStatus(400);
|
||||
|
||||
const object = JSON.parse(req.body.data);
|
||||
app.post("/run", express.json(), async (req, res, next) => {
|
||||
const object = req.body;
|
||||
if (!magick.check(object.cmd)) return res.sendStatus(400);
|
||||
|
||||
object.path = req.file ? req.file.path : null;
|
||||
object.type = type.split("/")[1];
|
||||
|
||||
try {
|
||||
let type;
|
||||
if (object.path) {
|
||||
type = await magick.getType(object.path);
|
||||
if (!type) {
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
object.type = type.split("/")[1];
|
||||
const delay = (await execPromise(`ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate ${object.path}`)).stdout.replace("\n", "");
|
||||
object.delay = (100 / delay.split("/")[0]) * delay.split("/")[1];
|
||||
}
|
||||
|
||||
const data = await magick.run(object, true);
|
||||
res.contentType(type);
|
||||
res.contentType(type ? type : "png");
|
||||
res.send(data);
|
||||
} catch (e) {
|
||||
next(e);
|
||||
|
|
|
@ -4,17 +4,15 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "watermark",
|
||||
path: image.path,
|
||||
water: "./assets/images/9gag.png",
|
||||
gravity: 6,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
gravity: 6
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `9gag.${image.type}`
|
||||
name: `9gag.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,18 +4,16 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "watermark",
|
||||
path: image.path,
|
||||
water: "./assets/images/bandicam.png",
|
||||
gravity: 2,
|
||||
resize: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
resize: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `bandicam.${image.type}`
|
||||
name: `bandicam.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,16 +4,14 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "blur",
|
||||
path: image.path,
|
||||
sharp: false,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
sharp: false
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `blur.${image.type}`
|
||||
name: `blur.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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 blurple!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "blurple",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `blurple.${image.type}`
|
||||
name: `blurple.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -6,17 +6,15 @@ 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("<a:processing:479351417102925854> Processing... This might take a while");
|
||||
const outputFinal = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "caption",
|
||||
path: image.path,
|
||||
caption: newArgs.join(" "),
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
caption: newArgs.join(" ")
|
||||
});
|
||||
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
|
||||
return {
|
||||
file: outputFinal,
|
||||
name: `caption.${image.type}`
|
||||
file: buffer,
|
||||
name: `caption.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -6,17 +6,15 @@ 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("<a:processing:479351417102925854> Processing... This might take a while");
|
||||
const outputFinal = await magick.run({
|
||||
const { buffer, type } = 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(" "),
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
caption: newArgs.length !== 0 ? newArgs.join(" ") : words.sort(() => 0.5 - Math.random()).slice(0, Math.floor(Math.random() * words.length + 1)).join(" ")
|
||||
});
|
||||
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
|
||||
return {
|
||||
file: outputFinal,
|
||||
name: `caption2.${image.type}`
|
||||
file: buffer,
|
||||
name: `caption2.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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 add radial blur!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type} = await magick.run({
|
||||
cmd: "circle",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `circle.${image.type}`
|
||||
name: `circle.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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 crop!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "crop",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `crop.${image.type}`
|
||||
name: `crop.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,18 +4,16 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "watermark",
|
||||
path: image.path,
|
||||
water: "./assets/images/deviantart.png",
|
||||
gravity: 5,
|
||||
resize: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
resize: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `deviantart.${image.type}`
|
||||
name: `deviantart.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,16 +4,14 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "explode",
|
||||
path: image.path,
|
||||
amount: -1,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
amount: -1
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `explode.${image.type}`
|
||||
name: `explode.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -19,16 +19,14 @@ exports.run = async (message, args) => {
|
|||
} catch (e) {
|
||||
return `${message.author.mention}, that isn't a flag!`;
|
||||
}
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "flag",
|
||||
path: image.path,
|
||||
overlay: path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
overlay: path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `flag.${image.type}`
|
||||
name: `flag.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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 flip!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "flip",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `flip.${image.type}`
|
||||
name: `flip.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,16 +4,14 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "flip",
|
||||
path: image.path,
|
||||
flop: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
flop: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `flop.${image.type}`
|
||||
name: `flop.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -5,16 +5,14 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "freeze",
|
||||
path: image.path,
|
||||
loop: false,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
loop: false
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `freeze.${image.type}`
|
||||
name: `freeze.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,18 +4,16 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "watermark",
|
||||
path: image.path,
|
||||
water: "./assets/images/funky.png",
|
||||
gravity: 3,
|
||||
resize: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
resize: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `funky.${image.type}`
|
||||
name: `funky.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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 GameXplain thumbnail meme!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "gamexplain",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `gamexplain.${image.type}`
|
||||
name: `gamexplain.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,11 +4,9 @@ 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("<a:processing:479351417102925854> Processing... This might take a while");
|
||||
const buffer = await magick.run({
|
||||
const { buffer } = await magick.run({
|
||||
cmd: "globe",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
|
||||
return {
|
||||
|
|
|
@ -4,16 +4,14 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "mirror",
|
||||
path: image.path,
|
||||
first: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
first: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `haah.${image.type}`
|
||||
name: `haah.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -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.run({
|
||||
const { buffer } = await magick.run({
|
||||
cmd: "homebrew",
|
||||
caption: args.join(" ").toLowerCase().replace(/\n/g, " ")
|
||||
});
|
||||
|
|
|
@ -4,16 +4,14 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "mirror",
|
||||
path: image.path,
|
||||
vertical: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
vertical: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `hooh.${image.type}`
|
||||
name: `hooh.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,18 +4,16 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "watermark",
|
||||
path: image.path,
|
||||
water: "./assets/images/hypercam.png",
|
||||
gravity: 1,
|
||||
resize: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
resize: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `hypercam.${image.type}`
|
||||
name: `hypercam.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,19 +4,17 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "watermark",
|
||||
path: image.path,
|
||||
water: "./assets/images/ifunny.png",
|
||||
gravity: 8,
|
||||
resize: true,
|
||||
append: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
append: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `ifunny.${image.type}`
|
||||
name: `ifunny.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,16 +4,14 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "explode",
|
||||
path: image.path,
|
||||
amount: 1,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
amount: 1
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `implode.${image.type}`
|
||||
name: `implode.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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 invert!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "invert",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `invert.${image.type}`
|
||||
name: `invert.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "jpeg",
|
||||
path: image.path
|
||||
});
|
||||
|
|
|
@ -4,15 +4,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 Super Smash Bros. leak meme!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "leak",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `leak.${image.type}`
|
||||
name: `leak.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -5,16 +5,14 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "freeze",
|
||||
path: image.path,
|
||||
loop: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
loop: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `loop.${image.type}`
|
||||
name: `loop.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,16 +4,14 @@ 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("<a:processing:479351417102925854> Processing... This might take a while");
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "magik",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
|
||||
return {
|
||||
file: buffer,
|
||||
name: `magik.${image.type}`
|
||||
name: `magik.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -7,17 +7,15 @@ 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(/(?<!\\),/).map(elem => elem.trim());
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "meme",
|
||||
path: image.path,
|
||||
top: topText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'"),
|
||||
bottom: bottomText ? bottomText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'") : "",
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
bottom: bottomText ? bottomText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'") : ""
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `meme.${image.type}`
|
||||
name: `meme.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,18 +4,16 @@ 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 MemeCenter watermark!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "watermark",
|
||||
path: image.path,
|
||||
water: "./assets/images/memecenter.png",
|
||||
gravity: 9,
|
||||
mc: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
mc: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `memecenter.${image.type}`
|
||||
name: `memecenter.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -7,18 +7,16 @@ 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("<a:processing:479351417102925854> Processing... This might take a while");
|
||||
const [topText, bottomText] = newArgs.join(" ").split(/(?<!\\),/).map(elem => elem.trim());
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "motivate",
|
||||
path: image.path,
|
||||
top: topText.replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'"),
|
||||
bottom: bottomText ? bottomText.replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'") : "",
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
bottom: bottomText ? bottomText.replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'") : ""
|
||||
});
|
||||
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
|
||||
return {
|
||||
file: buffer,
|
||||
name: `motivate.${image.type}`
|
||||
name: `motivate.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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 pixelate!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "resize",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `pixelate.${image.type}`
|
||||
name: `pixelate.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "reverse",
|
||||
path: image.path,
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
|
|
|
@ -4,15 +4,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 Scott the Woz TV meme!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "scott",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `scott.${image.type}`
|
||||
name: `scott.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,16 +4,14 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "sharpen",
|
||||
path: image.path,
|
||||
sharp: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
sharp: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `sharpen.${image.type}`
|
||||
name: `sharpen.${type}`
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -4,18 +4,16 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "watermark",
|
||||
path: image.path,
|
||||
water: "./assets/images/shutterstock.png",
|
||||
gravity: 5,
|
||||
resize: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
resize: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `shutterstock.${image.type}`
|
||||
name: `shutterstock.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -6,12 +6,10 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "speed",
|
||||
path: image.path,
|
||||
slow: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
slow: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
|
|
|
@ -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(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'");
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "sonic",
|
||||
text: wrap(cleanedMessage, {width: 15, indent: ""})
|
||||
});
|
||||
|
|
|
@ -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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "reverse",
|
||||
path: image.path,
|
||||
soos: true,
|
||||
|
|
|
@ -5,11 +5,9 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "speed",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
|
|
|
@ -4,11 +4,9 @@ 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("<a:processing:479351417102925854> Processing... This might take a while");
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "spin",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
|
||||
return {
|
||||
|
|
|
@ -4,16 +4,14 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "resize",
|
||||
path: image.path,
|
||||
stretch: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
stretch: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `stretch.${image.type}`
|
||||
name: `stretch.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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 swirl!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "swirl",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `swirl.${image.type}`
|
||||
name: `swirl.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "tile",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `tile.${image.type}`
|
||||
name: `tile.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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 Trump meme!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "trump",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `trump.${image.type}`
|
||||
name: `trump.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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 mirror!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "mirror",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `waaw.${image.type}`
|
||||
name: `waaw.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "wall",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `wall.${image.type}`
|
||||
name: `wall.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,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 "who did this" meme!`;
|
||||
const buffer = await magick.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "wdt",
|
||||
path: image.path,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
path: image.path
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `wdt.${image.type}`
|
||||
name: `wdt.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,16 +4,14 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "resize",
|
||||
path: image.path,
|
||||
wide: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
wide: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `wide.${image.type}`
|
||||
name: `wide.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,17 +4,15 @@ 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.run({
|
||||
const { buffer, type } = await magick.run({
|
||||
cmd: "mirror",
|
||||
path: image.path,
|
||||
vertical: true,
|
||||
first: true,
|
||||
type: image.type.toUpperCase(),
|
||||
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
|
||||
first: true
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
name: `woow.${image.type}`
|
||||
name: `woow.${type}`
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@ module.exports = async (message) => {
|
|||
|
||||
// prefix can be a mention or a set of special characters
|
||||
const guildDB = message.channel.guild ? await database.guilds.findOne({ id: message.channel.guild.id }).lean().exec() : null;
|
||||
const prefix = message.channel.guild ? (message.content.startsWith(message.channel.guild.members.get(client.user.id).mention) ? `${message.channel.guild.members.get(client.user.id).mention} ` : guildDB.prefix) : "";
|
||||
// there's a bit of a workaround here due to member.mention not accounting for both mention types
|
||||
const prefix = message.channel.guild ? (message.content.startsWith(message.channel.guild.members.get(client.user.id).mention) ? `${message.channel.guild.members.get(client.user.id).mention} ` : (message.content.startsWith(`<@${client.user.id}>`) ? `<@${client.user.id}> ` : guildDB.prefix)) : "";
|
||||
|
||||
// ignore other stuff
|
||||
if (message.content.startsWith(prefix) === false) return;
|
||||
|
|
116
package-lock.json
generated
116
package-lock.json
generated
|
@ -139,12 +139,6 @@
|
|||
"color-convert": "^1.9.0"
|
||||
}
|
||||
},
|
||||
"append-field": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",
|
||||
"integrity": "sha1-HjRA6RXwsSA9I3SOeO3XubW0PlY=",
|
||||
"optional": true
|
||||
},
|
||||
"aproba": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
|
||||
|
@ -338,42 +332,6 @@
|
|||
"node-gyp-build": "~3.7.0"
|
||||
}
|
||||
},
|
||||
"busboy": {
|
||||
"version": "0.2.14",
|
||||
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz",
|
||||
"integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM=",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"dicer": "0.2.5",
|
||||
"readable-stream": "1.1.x"
|
||||
},
|
||||
"dependencies": {
|
||||
"isarray": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
|
||||
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=",
|
||||
"optional": true
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "1.1.14",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
|
||||
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.1",
|
||||
"isarray": "0.0.1",
|
||||
"string_decoder": "~0.10.x"
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
|
||||
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"bytes": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
|
||||
|
@ -730,42 +688,6 @@
|
|||
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz",
|
||||
"integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups="
|
||||
},
|
||||
"dicer": {
|
||||
"version": "0.2.5",
|
||||
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz",
|
||||
"integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8=",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"readable-stream": "1.1.x",
|
||||
"streamsearch": "0.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"isarray": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
|
||||
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=",
|
||||
"optional": true
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "1.1.14",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
|
||||
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.1",
|
||||
"isarray": "0.0.1",
|
||||
"string_decoder": "~0.10.x"
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
|
||||
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"dijkstrajs": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dijkstrajs/-/dijkstrajs-1.0.1.tgz",
|
||||
|
@ -1310,16 +1232,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"form-data": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
|
||||
"integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==",
|
||||
"requires": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
}
|
||||
},
|
||||
"forwarded": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
|
||||
|
@ -1914,22 +1826,6 @@
|
|||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
|
||||
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
|
||||
},
|
||||
"multer": {
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/multer/-/multer-1.4.2.tgz",
|
||||
"integrity": "sha512-xY8pX7V+ybyUpbYMxtjM9KAiD9ixtg5/JkeKUTD6xilfDv0vzzOFcCp4Ljb1UU3tSOM3VTZtKo63OmzOrGi3Cg==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"append-field": "^1.0.0",
|
||||
"busboy": "^0.2.11",
|
||||
"concat-stream": "^1.5.2",
|
||||
"mkdirp": "^0.5.1",
|
||||
"object-assign": "^4.1.1",
|
||||
"on-finished": "^2.3.0",
|
||||
"type-is": "^1.6.4",
|
||||
"xtend": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"mute-stream": {
|
||||
"version": "0.0.7",
|
||||
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz",
|
||||
|
@ -2730,12 +2626,6 @@
|
|||
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=",
|
||||
"optional": true
|
||||
},
|
||||
"streamsearch": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
|
||||
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo=",
|
||||
"optional": true
|
||||
},
|
||||
"string-width": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
|
||||
|
@ -3150,12 +3040,6 @@
|
|||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz",
|
||||
"integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA=="
|
||||
},
|
||||
"xtend": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
||||
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
|
||||
"optional": true
|
||||
},
|
||||
"y18n": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
"emoji-regex": "^8.0.0",
|
||||
"eris": "^0.13.3",
|
||||
"file-type": "^13.1.2",
|
||||
"form-data": "^3.0.0",
|
||||
"jsqr": "^1.3.1",
|
||||
"lavacord": "^1.1.9",
|
||||
"moment": "^2.29.1",
|
||||
|
@ -55,7 +54,6 @@
|
|||
"bufferutil": "^4.0.1",
|
||||
"erlpack": "github:abalabahaha/erlpack",
|
||||
"express": "^4.17.1",
|
||||
"multer": "^1.4.2",
|
||||
"zlib-sync": "^0.1.6"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,67 @@
|
|||
const magick = require("../build/Release/image.node");
|
||||
const fetch = require("node-fetch");
|
||||
const { promisify } = require("util");
|
||||
const FormData = require("form-data");
|
||||
const fs = require("fs");
|
||||
const AbortController = require("abort-controller");
|
||||
const fileType = require("file-type");
|
||||
const execPromise = promisify(require("child_process").exec);
|
||||
|
||||
const formats = ["image/jpeg", "image/png", "image/webp", "image/gif"];
|
||||
|
||||
exports.run = async (object, fromAPI = false) => {
|
||||
if (process.env.API === "true" && !fromAPI) {
|
||||
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}/run`, {
|
||||
method: "POST",
|
||||
body: form,
|
||||
headers: form.getHeaders()
|
||||
body: JSON.stringify(object),
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
});
|
||||
return await req.buffer();
|
||||
const buffer = await req.buffer();
|
||||
return {
|
||||
buffer: buffer,
|
||||
type: req.headers.get("content-type").split("/")[1]
|
||||
};
|
||||
} else {
|
||||
let type;
|
||||
if (!fromAPI && object.path) {
|
||||
type = (await this.getType(object.path)).split("/")[1];
|
||||
object.type = type;
|
||||
const delay = (await execPromise(`ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate ${object.path}`)).stdout.replace("\n", "");
|
||||
object.delay = (100 / delay.split("/")[0]) * delay.split("/")[1];
|
||||
}
|
||||
const data = await promisify(magick[object.cmd])(object);
|
||||
return data;
|
||||
return fromAPI ? data : {
|
||||
buffer: data,
|
||||
type: type
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
exports.check = (cmd) => {
|
||||
return magick[cmd] ? true : false;
|
||||
};
|
||||
|
||||
exports.getType = async (image) => {
|
||||
let type;
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => {
|
||||
controller.abort();
|
||||
}, 25000);
|
||||
try {
|
||||
const imageRequest = await fetch(image, { signal: controller.signal, highWaterMark: 512 });
|
||||
const imageBuffer = await imageRequest.buffer();
|
||||
const imageType = await fileType.fromBuffer(imageBuffer);
|
||||
if (imageType && formats.includes(imageType.mime)) {
|
||||
type = imageType.mime;
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.name === "AbortError") {
|
||||
throw Error("Timed out");
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
return type;
|
||||
};
|
|
@ -1,50 +1,32 @@
|
|||
const fetch = require("node-fetch");
|
||||
const AbortController = require("abort-controller");
|
||||
const fileType = require("file-type");
|
||||
const { promisify } = require("util");
|
||||
const { writeFile } = require("fs").promises;
|
||||
const execPromise = promisify(require("child_process").exec);
|
||||
const urlRegex = /(?:\w+:)?\/\/(\S+)/;
|
||||
|
||||
// this checks if the file is, in fact, an image
|
||||
const typeCheck = async (image, image2, gifv = false) => {
|
||||
// download the file to a buffer
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => {
|
||||
controller.abort();
|
||||
}, 25000);
|
||||
// gets the proper image paths
|
||||
const getImage = async (image, image2, gifv = false) => {
|
||||
try {
|
||||
const imageRequest = await fetch(image, { signal: controller.signal });
|
||||
const imageBuffer = await imageRequest.buffer();
|
||||
if (imageBuffer.size >= 25 * 1024 * 1024) return;
|
||||
// get the file type
|
||||
const imageType = await fileType.fromBuffer(imageBuffer);
|
||||
// check if the file is a jpeg, png, or webp
|
||||
const formats = ["image/jpeg", "image/png", "image/webp", "image/gif"];
|
||||
if (gifv) formats.push("video/mp4");
|
||||
if (imageType && formats.includes(imageType.mime)) {
|
||||
// if it is, then return the url with the file type
|
||||
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${imageType.ext}`;
|
||||
await writeFile(path, imageBuffer);
|
||||
const payload = {
|
||||
type: imageType.ext !== "mp4" ? (imageType.ext === "jpg" ? "jpeg" : imageType.ext) : "gif",
|
||||
path: path,
|
||||
url: image2
|
||||
};
|
||||
if (payload.type === "gif") payload.delay = (await execPromise(`ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate ${path}`)).stdout.replace("\n", "");
|
||||
return payload;
|
||||
} else {
|
||||
// if not, then return false
|
||||
return false;
|
||||
let requestImage = image;
|
||||
if (gifv) {
|
||||
if (image2.includes("tenor.com") && process.env.TENOR !== "") {
|
||||
const data = await fetch(`https://api.tenor.com/v1/gifs?ids=${image2.split("-").pop()}&key=${process.env.TENOR}`);
|
||||
const json = await data.json();
|
||||
console.log(json.results[0].media[0].gif.url);
|
||||
requestImage = json.results[0].media[0].gif.url;
|
||||
} else if (image2.includes("giphy.com")) {
|
||||
requestImage = `https://media0.giphy.com/media/${image2.split("-").pop()}/giphy.gif`;
|
||||
} else if (image2.includes("imgur.com")) {
|
||||
requestImage = image.replace(".mp4", ".gif");
|
||||
}
|
||||
}
|
||||
const payload = {
|
||||
url: image2,
|
||||
path: requestImage
|
||||
};
|
||||
return payload;
|
||||
} catch (error) {
|
||||
if (error.name === "AbortError") {
|
||||
throw Error("Timed out");
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -52,25 +34,23 @@ const checkImages = async (message) => {
|
|||
let type;
|
||||
// first check the embeds
|
||||
if (message.embeds.length !== 0) {
|
||||
// embeds can have 2 possible entries with images, we check the thumbnail first
|
||||
// embeds can vary in types, we check for tenor gifs first
|
||||
if (message.embeds[0].type === "gifv") {
|
||||
type = await typeCheck(message.embeds[0].video.url, message.embeds[0].video.url, true);
|
||||
} else if (message.embeds[0].thumbnail) {
|
||||
type = await typeCheck(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url);
|
||||
// if there isn't a thumbnail check the image area
|
||||
} else if (message.embeds[0].image) {
|
||||
type = await typeCheck(message.embeds[0].image.proxy_url, message.embeds[0].image.url);
|
||||
type = await getImage(message.embeds[0].video.url, message.embeds[0].url, true);
|
||||
// then we check for other image types
|
||||
} else if (message.embeds[0].type === "video" || message.embeds[0].type === "image") {
|
||||
type = await getImage(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url);
|
||||
// finally we check both possible image fields for "generic" embeds
|
||||
} else if (message.embeds[0].type === "rich") {
|
||||
if (message.embeds[0].thumbnail) {
|
||||
type = await getImage(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url);
|
||||
} else if (message.embeds[0].image) {
|
||||
type = await getImage(message.embeds[0].image.proxy_url, message.embeds[0].image.url);
|
||||
}
|
||||
}
|
||||
// then check the attachments
|
||||
} else if (message.attachments.length !== 0) {
|
||||
// get type of file
|
||||
type = await typeCheck(message.attachments[0].proxy_url, message.attachments[0].url);
|
||||
// if there's nothing in the attachments check the urls in the message if there are any
|
||||
} else if (urlRegex.test(message.content)) {
|
||||
// get url
|
||||
const url = message.content.match(urlRegex);
|
||||
// get type of file
|
||||
type = await typeCheck(url[0], url[0]);
|
||||
} else if (message.attachments.length !== 0 && message.attachments[0].width) {
|
||||
type = await getImage(message.attachments[0].proxy_url, message.attachments[0].url);
|
||||
}
|
||||
// if the file is an image then return it
|
||||
return type ? type : false;
|
||||
|
|
Loading…
Reference in a new issue