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
+1 -7
View File
@@ -53,13 +53,7 @@ module.exports = class AceAttorneyCommand extends Command {
prompt: `What character do you want to use? Either ${list(Object.keys(characters), 'or')}.`,
type: 'string',
oneOf: Object.values(characters).reduce((a, b) => a.concat(b)),
parse: character => {
for (const [id, arr] of Object.entries(characters)) {
if (!arr.includes(character.toLowerCase())) continue;
return id;
}
return character.toLowerCase();
}
parse: character => character.toLowerCase()
},
{
key: 'quote',
+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 CharcoalCommand extends Command {
constructor(client) {
@@ -38,20 +39,11 @@ module.exports = class CharcoalCommand extends Command {
const magik = gm(body);
magik.charcoal(1);
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: 'sketch.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);
});
});
}
};
+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 EmbossCommand extends Command {
constructor(client) {
@@ -38,20 +39,11 @@ module.exports = class EmbossCommand extends Command {
const magik = gm(body);
magik.emboss();
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: 'emboss.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);
});
});
}
};
+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);
});
});
}
};
+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 LiquidRescaleCommand extends Command {
constructor(client) {
@@ -41,20 +42,11 @@ module.exports = class LiquidRescaleCommand extends Command {
magik.out('50%');
magik.implode(0.25);
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: 'liquid-rescale.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);
});
});
}
};
+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);
});
});
}
};
+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 OilPaintingCommand extends Command {
constructor(client) {
@@ -39,20 +40,11 @@ module.exports = class OilPaintingCommand extends Command {
const magik = gm(body);
magik.paint(5);
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: 'old-painting.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);
});
});
}
};
+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 SketchCommand extends Command {
constructor(client) {
@@ -41,20 +42,11 @@ module.exports = class SketchCommand extends Command {
magik.out('-sketch');
magik.out('0x20+120');
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: 'sketch.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);
});
});
}
};
+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 SquishCommand extends Command {
constructor(client) {
@@ -50,20 +51,11 @@ module.exports = class SquishCommand extends Command {
magik.out('-liquid-rescale');
magik.out(command);
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: 'squish.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);
});
});
}
};
+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 SwirlCommand extends Command {
constructor(client) {
@@ -45,20 +46,11 @@ module.exports = class SwirlCommand extends Command {
const magik = gm(body);
magik.swirl(degrees);
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: 'swirl.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);
});
});
}
};