mrmBot-Matrix/commands/speed.js

35 lines
1.3 KiB
JavaScript
Raw Normal View History

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!`;
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
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);
return {
file: buffer,
name: "speed.gif"
};
} else {
if (!value.Scene) return `${message.author.mention}, that GIF is already too fast!`;
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);
return {
file: buffer,
name: "speed.gif"
};
}
2020-02-13 19:29:42 +00:00
};
exports.aliases = ["speedup", "fast", "gifspeed"];
exports.category = 5;
exports.help = "Makes a GIF faster";