2020-02-21 00:26:49 +00:00
|
|
|
const {
|
|
|
|
exec
|
|
|
|
} = require("child_process");
|
2020-02-13 19:29:42 +00:00
|
|
|
const util = require("util");
|
|
|
|
const gm = require("gm").subClass({
|
|
|
|
imageMagick: true
|
|
|
|
});
|
|
|
|
|
|
|
|
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 a GIF to speed up!`;
|
2020-02-25 20:45:47 +00:00
|
|
|
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
|
2020-02-21 00:26:49 +00:00
|
|
|
const value = await gm(image.path).identifyPromise();
|
|
|
|
const delay = value.Delay ? value.Delay[0].split("x") : [0, 100];
|
|
|
|
if (Math.round(parseInt(delay[0]) / 2) >= 2) {
|
2020-03-15 17:54:51 +00:00
|
|
|
const buffer = await gm().delay(`${parseInt(delay[0]) / 2}x${delay[1]}`).out(image.path).bufferPromise(image.type, image.delay);
|
2020-04-12 19:51:48 +00:00
|
|
|
return {
|
2020-02-21 00:26:49 +00:00
|
|
|
file: buffer,
|
|
|
|
name: "speed.gif"
|
2020-04-12 19:51:48 +00:00
|
|
|
};
|
2020-02-21 00:26:49 +00:00
|
|
|
} else {
|
2020-04-03 22:51:05 +00:00
|
|
|
if (!value.Scene) return `${message.author.mention}, that GIF is already too fast!`;
|
2020-02-21 00:26:49 +00:00
|
|
|
const numbers = (await util.promisify(exec)(`seq 0 2 ${value.Scene.length}`)).stdout.split("\n").join(",");
|
2020-03-15 17:54:51 +00:00
|
|
|
const buffer = await gm().out("(").out(image.path).coalesce().out(")").out("-delete", numbers).bufferPromise(image.type, image.delay);
|
2020-04-12 19:51:48 +00:00
|
|
|
return {
|
2020-02-21 00:26:49 +00:00
|
|
|
file: buffer,
|
|
|
|
name: "speed.gif"
|
2020-04-12 19:51:48 +00:00
|
|
|
};
|
2020-02-21 00:26:49 +00:00
|
|
|
}
|
2020-02-13 19:29:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.aliases = ["speedup", "fast", "gifspeed"];
|
|
|
|
exports.category = 5;
|
|
|
|
exports.help = "Makes a GIF faster";
|