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 -11
View File
@@ -1,7 +1,7 @@
const Command = require('../../structures/Command');
const gm = require('gm').subClass({ imageMagick: true });
const request = require('node-superfetch');
const { list } = require('../../util/Util');
const { list, magikToBuffer } = require('../../util/Util');
const types = ['uniform', 'gaussian', 'multiplicative', 'impulse', 'laplacian', 'poisson'];
module.exports = class NoiseCommand extends Command {
@@ -48,20 +48,11 @@ module.exports = class NoiseCommand extends Command {
const magik = gm(body);
magik.noise(type);
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: 'noise.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);
});
});
}
};