mrmBot-Matrix/commands/soos.js
adroitwhiz 3de4858b5a
Clean up image API code paths (#49)
* Document image.js a bit

* Close image.js sockets in all code paths

I'm not sure whether sockets get GC'd when the function returns

* Remove getFormat

It was only called from one place, and the object property names were
quite confusing

* Clean up image.js conditional a bit

I had to write out an entire truth table for this and work it all out
Thinking hard

* Move actual ImageMagick calling into separate file

This gets rid of the weird, brain-melting ouroboros of code that
recurses across threads and processes.

* Reduce amount of getType wrangling

This amounted to an awful lot of dead conditionals after the image
commands were all modified to pass in image types anyway. This has also
led to two different implementations diverging, which causes bugs like
GIF commands applied to non-GIFs erroring instead of providing a
user-friendly message.

* Unify image-runner return type, clarify image type

This allows us to remove the fromAPI parameter from image-runner, and
helps greatly clarify the behavior around image types.

* Deduplicate GIF code, fix "not a GIF" handling

The special "nogif" value is now stored as the image type instead of its
value, as the value must always be a Buffer now--no loosely-typed
shenanigans.
2021-01-09 19:50:29 -06:00

24 lines
No EOL
783 B
JavaScript

const magick = require("../utils/image.js");
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 loop!`;
const { buffer, type } = await magick.run({
cmd: "reverse",
path: image.path,
soos: true,
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0,
onlyGIF: true,
type: image.type
});
if (type === "nogif") return `${message.author.mention}, that isn't a GIF!`;
return {
file: buffer,
name: `soos.${type}`
};
};
exports.aliases = ["bounce"];
exports.category = 5;
exports.help = "\"Loops\" a GIF by reversing it when it's finished";