Fix lots of code dupe

This commit is contained in:
Dragon Fire
2020-10-29 12:43:24 -04:00
parent 0eebc256df
commit fd647e14e7
20 changed files with 60 additions and 126 deletions
+2 -10
View File
@@ -1,6 +1,7 @@
const Command = require('../../structures/Command');
const gm = require('gm').subClass({ imageMagick: true });
const request = require('node-superfetch');
const { magikToBuffer } = require('../../util/Util');
module.exports = class ImplodeCommand extends Command {
constructor(client) {
@@ -45,20 +46,11 @@ module.exports = class ImplodeCommand extends Command {
const magik = gm(body);
magik.implode(level / 100);
magik.setFormat('png');
const attachment = await this.toBuffer(magik);
const attachment = await magikToBuffer(magik);
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
return msg.say({ files: [{ attachment, name: 'implode.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
toBuffer(magik) {
return new Promise((res, rej) => {
magik.toBuffer((err, buffer) => {
if (err) return rej(err);
return res(buffer);
});
});
}
};