diff --git a/commands/analyze/aspect-ratio.js b/commands/analyze/aspect-ratio.js
index f29b03f2..78497e24 100644
--- a/commands/analyze/aspect-ratio.js
+++ b/commands/analyze/aspect-ratio.js
@@ -26,13 +26,9 @@ module.exports = class AspectRatioCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const common = gcd(data.width, data.height);
- return msg.reply(`This image has an aspect ratio of **${data.width / common}:${data.height / common}**.`);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const common = gcd(data.width, data.height);
+ return msg.reply(`This image has an aspect ratio of **${data.width / common}:${data.height / common}**.`);
}
};
diff --git a/commands/analyze/dominant-color.js b/commands/analyze/dominant-color.js
index 567fd506..e29dca98 100644
--- a/commands/analyze/dominant-color.js
+++ b/commands/analyze/dominant-color.js
@@ -27,22 +27,18 @@ module.exports = class DominantColorCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(250, 250);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0, 1, 1);
- const imgData = ctx.getImageData(0, 0, 1, 1).data;
- const hexColor = `#${rgbToHex(imgData[0], imgData[1], imgData[2]).padStart(6, '0')}`;
- ctx.fillStyle = hexColor;
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- const name = ntc.name(hexColor);
- return msg.say(`${hexColor.toUpperCase()} - ${name[1]}`, {
- files: [{ attachment: canvas.toBuffer(), name: 'dominant-color.png' }]
- });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(250, 250);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0, 1, 1);
+ const imgData = ctx.getImageData(0, 0, 1, 1).data;
+ const hexColor = `#${rgbToHex(imgData[0], imgData[1], imgData[2]).padStart(6, '0')}`;
+ ctx.fillStyle = hexColor;
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
+ const name = ntc.name(hexColor);
+ return msg.say(`${hexColor.toUpperCase()} - ${name[1]}`, {
+ files: [{ attachment: canvas.toBuffer(), name: 'dominant-color.png' }]
+ });
}
};
diff --git a/commands/analyze/gender.js b/commands/analyze/gender.js
index 28237e64..b57a3ceb 100644
--- a/commands/analyze/gender.js
+++ b/commands/analyze/gender.js
@@ -28,14 +28,10 @@ module.exports = class GenderCommand extends Command {
}
async run(msg, { name }) {
- try {
- const { body } = await request
- .get(`https://api.genderize.io/`)
- .query({ name });
- if (!body.gender) return msg.say(`I have no idea what gender ${body.name} is.`);
- return msg.say(`I'm ${Math.round(body.probability * 100)}% sure ${body.name} is a ${body.gender} name.`);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request
+ .get(`https://api.genderize.io/`)
+ .query({ name });
+ if (!body.gender) return msg.say(`I have no idea what gender ${body.name} is.`);
+ return msg.say(`I'm ${Math.round(body.probability * 100)}% sure ${body.name} is a ${body.gender} name.`);
}
};
diff --git a/commands/analyze/image-size.js b/commands/analyze/image-size.js
index 69c992e4..50d51460 100644
--- a/commands/analyze/image-size.js
+++ b/commands/analyze/image-size.js
@@ -25,12 +25,8 @@ module.exports = class ImageSizeCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- return msg.reply(`This image is ${data.width}x${data.height}.`);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ return msg.reply(`This image is ${data.width}x${data.height}.`);
}
};
diff --git a/commands/analyze/is-it-down.js b/commands/analyze/is-it-down.js
index 51922c1a..d69b6bf5 100644
--- a/commands/analyze/is-it-down.js
+++ b/commands/analyze/is-it-down.js
@@ -29,15 +29,11 @@ module.exports = class IsItDownCommand extends Command {
async run(msg, { url }) {
const { type, domain, topLevelDomains } = this.client.parseDomain(url.hostname);
if (type !== this.client.ParseResultType.Listed) return msg.reply('This domain is not supported.');
- try {
- const { text } = await request
- .post('https://www.isitdownrightnow.com/check.php')
- .query({ domain: `${domain}.${topLevelDomains.join('.')}` });
- const down = text.includes('div class="statusdown"');
- if (!down) return msg.reply('👍 This site is up and running.');
- return msg.reply('👎 Looks like this site is down for everyone...');
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { text } = await request
+ .post('https://www.isitdownrightnow.com/check.php')
+ .query({ domain: `${domain}.${topLevelDomains.join('.')}` });
+ const down = text.includes('div class="statusdown"');
+ if (!down) return msg.reply('👍 This site is up and running.');
+ return msg.reply('👎 Looks like this site is down for everyone...');
}
};
diff --git a/commands/analyze/nsfw-image.js b/commands/analyze/nsfw-image.js
index a9449a88..7a379943 100644
--- a/commands/analyze/nsfw-image.js
+++ b/commands/analyze/nsfw-image.js
@@ -33,19 +33,15 @@ module.exports = class NsfwImageCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const predictions = await isImageNSFW(this.client.nsfwModel, body, false);
- const formatted = predictions.map(result => {
- const percentage = Math.round(result.probability * 100);
- return `${percentage}% ${displayNames[result.className]}`;
- });
- return msg.reply(stripIndents`
- **This image gives the following results:**
- ${formatted.join('\n')}
- `);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const predictions = await isImageNSFW(this.client.nsfwModel, body, false);
+ const formatted = predictions.map(result => {
+ const percentage = Math.round(result.probability * 100);
+ return `${percentage}% ${displayNames[result.className]}`;
+ });
+ return msg.reply(stripIndents`
+ **This image gives the following results:**
+ ${formatted.join('\n')}
+ `);
}
};
diff --git a/commands/analyze/read-qr-code.js b/commands/analyze/read-qr-code.js
index 16fc818c..493afdaa 100644
--- a/commands/analyze/read-qr-code.js
+++ b/commands/analyze/read-qr-code.js
@@ -29,15 +29,11 @@ module.exports = class ReadQRCodeCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request
- .get('https://api.qrserver.com/v1/read-qr-code/')
- .query({ fileurl: image });
- const data = body[0].symbol[0];
- if (!data.data) return msg.reply(`Could not read QR Code: ${data.error}.`);
- return msg.reply(shorten(data.data, 2000 - (msg.author.toString().length + 2)));
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request
+ .get('https://api.qrserver.com/v1/read-qr-code/')
+ .query({ fileurl: image });
+ const data = body[0].symbol[0];
+ if (!data.data) return msg.reply(`Could not read QR Code: ${data.error}.`);
+ return msg.reply(shorten(data.data, 2000 - (msg.author.toString().length + 2)));
}
};
diff --git a/commands/analyze/screenshot.js b/commands/analyze/screenshot.js
index c16e81a4..455fcc13 100644
--- a/commands/analyze/screenshot.js
+++ b/commands/analyze/screenshot.js
@@ -47,7 +47,7 @@ module.exports = class ScreenshotCommand extends Command {
return msg.say({ files: [{ attachment: body, name: 'screenshot.png' }] });
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results. Invalid URL?');
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ throw err;
}
}
};
diff --git a/commands/code/github.js b/commands/code/github.js
index 4fad6773..4f8d2601 100644
--- a/commands/code/github.js
+++ b/commands/code/github.js
@@ -60,7 +60,7 @@ module.exports = class GithubCommand extends Command {
return msg.embed(embed);
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results.');
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ throw err;
}
}
};
diff --git a/commands/code/npm.js b/commands/code/npm.js
index b794ed88..849009d4 100644
--- a/commands/code/npm.js
+++ b/commands/code/npm.js
@@ -55,7 +55,7 @@ module.exports = class NPMCommand extends Command {
return msg.embed(embed);
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results.');
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ throw err;
}
}
};
diff --git a/commands/edit-avatar/avatar-fusion.js b/commands/edit-avatar/avatar-fusion.js
index 8e71e8a1..00f18476 100644
--- a/commands/edit-avatar/avatar-fusion.js
+++ b/commands/edit-avatar/avatar-fusion.js
@@ -34,19 +34,15 @@ module.exports = class AvatarFusionCommand extends Command {
async run(msg, { overlay, base }) {
const baseAvatarURL = base.displayAvatarURL({ format: 'png', size: 512 });
const overlayAvatarURL = overlay.displayAvatarURL({ format: 'png', size: 512 });
- try {
- const baseAvatarData = await request.get(baseAvatarURL);
- const baseAvatar = await loadImage(baseAvatarData.body);
- const overlayAvatarData = await request.get(overlayAvatarURL);
- const overlayAvatar = await loadImage(overlayAvatarData.body);
- const canvas = createCanvas(baseAvatar.width, baseAvatar.height);
- const ctx = canvas.getContext('2d');
- ctx.globalAlpha = 0.5;
- ctx.drawImage(baseAvatar, 0, 0);
- ctx.drawImage(overlayAvatar, 0, 0, baseAvatar.width, baseAvatar.height);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'avatar-fusion.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const baseAvatarData = await request.get(baseAvatarURL);
+ const baseAvatar = await loadImage(baseAvatarData.body);
+ const overlayAvatarData = await request.get(overlayAvatarURL);
+ const overlayAvatar = await loadImage(overlayAvatarData.body);
+ const canvas = createCanvas(baseAvatar.width, baseAvatar.height);
+ const ctx = canvas.getContext('2d');
+ ctx.globalAlpha = 0.5;
+ ctx.drawImage(baseAvatar, 0, 0);
+ ctx.drawImage(overlayAvatar, 0, 0, baseAvatar.width, baseAvatar.height);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'avatar-fusion.png' }] });
}
};
diff --git a/commands/edit-avatar/eject.js b/commands/edit-avatar/eject.js
index d83efb02..b6d159dd 100644
--- a/commands/edit-avatar/eject.js
+++ b/commands/edit-avatar/eject.js
@@ -58,61 +58,57 @@ module.exports = class EjectCommand extends Command {
async run(msg, { user, imposter }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
- try {
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- if (imposter === '') {
- const random = MersenneTwister19937.seed(user.id);
- imposter = bool()(random);
- }
- const text = `${user.username} was${imposter ? ' ' : ' not '}An Imposter.`;
- const encoder = new GIFEncoder(320, 180);
- const canvas = createCanvas(320, 180);
- const ctx = canvas.getContext('2d');
- ctx.textAlign = 'center';
- ctx.textBaseline = 'middle';
- ctx.fillStyle = 'white';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(18);
- const stream = encoder.createReadStream();
- encoder.start();
- encoder.setRepeat(0);
- encoder.setDelay(100);
- encoder.setQuality(200);
- for (let i = 0; i < frameCount; i++) {
- const frameID = `frame_${i.toString().padStart(2, '0')}.gif`;
- const frame = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'eject', frameID));
- ctx.drawImage(frame, 0, 0);
- if (i <= 17) {
- const x = ((320 / 15) * i) - 50;
- const y = (frame.height / 2) - 25;
- const rotation = (360 / 15) * i;
- const angle = rotation * (Math.PI / 180);
- const originX = x + 25;
- const originY = y + 25;
- ctx.translate(originX, originY);
- ctx.rotate(-angle);
- ctx.translate(-originX, -originY);
- ctx.drawImage(avatar, x, y, 50, 50);
- ctx.translate(originX, originY);
- ctx.rotate(angle);
- ctx.translate(-originX, -originY);
- }
- if (i > 17) {
- if (i <= 27) {
- const letters = Math.ceil(((text.length / 10) * (i - 17)) + 1);
- const toDraw = text.slice(0, letters + 1);
- ctx.fillText(toDraw, frame.width / 2, frame.height / 2, 300);
- } else {
- ctx.fillText(text, frame.width / 2, frame.height / 2, 300);
- }
- }
- encoder.addFrame(ctx);
- }
- encoder.finish();
- const buffer = await streamToArray(stream);
- return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'eject.gif' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ if (imposter === '') {
+ const random = MersenneTwister19937.seed(user.id);
+ imposter = bool()(random);
}
+ const text = `${user.username} was${imposter ? ' ' : ' not '}An Imposter.`;
+ const encoder = new GIFEncoder(320, 180);
+ const canvas = createCanvas(320, 180);
+ const ctx = canvas.getContext('2d');
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'middle';
+ ctx.fillStyle = 'white';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(18);
+ const stream = encoder.createReadStream();
+ encoder.start();
+ encoder.setRepeat(0);
+ encoder.setDelay(100);
+ encoder.setQuality(200);
+ for (let i = 0; i < frameCount; i++) {
+ const frameID = `frame_${i.toString().padStart(2, '0')}.gif`;
+ const frame = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'eject', frameID));
+ ctx.drawImage(frame, 0, 0);
+ if (i <= 17) {
+ const x = ((320 / 15) * i) - 50;
+ const y = (frame.height / 2) - 25;
+ const rotation = (360 / 15) * i;
+ const angle = rotation * (Math.PI / 180);
+ const originX = x + 25;
+ const originY = y + 25;
+ ctx.translate(originX, originY);
+ ctx.rotate(-angle);
+ ctx.translate(-originX, -originY);
+ ctx.drawImage(avatar, x, y, 50, 50);
+ ctx.translate(originX, originY);
+ ctx.rotate(angle);
+ ctx.translate(-originX, -originY);
+ }
+ if (i > 17) {
+ if (i <= 27) {
+ const letters = Math.ceil(((text.length / 10) * (i - 17)) + 1);
+ const toDraw = text.slice(0, letters + 1);
+ ctx.fillText(toDraw, frame.width / 2, frame.height / 2, 300);
+ } else {
+ ctx.fillText(text, frame.width / 2, frame.height / 2, 300);
+ }
+ }
+ encoder.addFrame(ctx);
+ }
+ encoder.finish();
+ const buffer = await streamToArray(stream);
+ return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'eject.gif' }] });
}
};
diff --git a/commands/edit-avatar/fire.js b/commands/edit-avatar/fire.js
index d9edcd3a..3c85ead9 100644
--- a/commands/edit-avatar/fire.js
+++ b/commands/edit-avatar/fire.js
@@ -41,30 +41,26 @@ module.exports = class FireCommand extends Command {
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
- try {
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- const encoder = new GIFEncoder(avatar.width, avatar.height);
- const canvas = createCanvas(avatar.width, avatar.height);
- const ctx = canvas.getContext('2d');
- const stream = encoder.createReadStream();
- encoder.start();
- encoder.setRepeat(0);
- encoder.setDelay(0);
- encoder.setQuality(200);
- for (let i = 0; i < frameCount; i++) {
- const frame = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'fire', `frame-${i}.gif`));
- const ratio = frame.width / frame.height;
- const height = Math.round(avatar.width / ratio);
- drawImageWithTint(ctx, avatar, '#fc671e', 0, 0, avatar.width, avatar.height);
- ctx.drawImage(frame, 0, avatar.height - height, avatar.width, height);
- encoder.addFrame(ctx);
- }
- encoder.finish();
- const buffer = await streamToArray(stream);
- return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'fire.gif' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ const encoder = new GIFEncoder(avatar.width, avatar.height);
+ const canvas = createCanvas(avatar.width, avatar.height);
+ const ctx = canvas.getContext('2d');
+ const stream = encoder.createReadStream();
+ encoder.start();
+ encoder.setRepeat(0);
+ encoder.setDelay(0);
+ encoder.setQuality(200);
+ for (let i = 0; i < frameCount; i++) {
+ const frame = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'fire', `frame-${i}.gif`));
+ const ratio = frame.width / frame.height;
+ const height = Math.round(avatar.width / ratio);
+ drawImageWithTint(ctx, avatar, '#fc671e', 0, 0, avatar.width, avatar.height);
+ ctx.drawImage(frame, 0, avatar.height - height, avatar.width, height);
+ encoder.addFrame(ctx);
}
+ encoder.finish();
+ const buffer = await streamToArray(stream);
+ return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'fire.gif' }] });
}
};
diff --git a/commands/edit-avatar/hat.js b/commands/edit-avatar/hat.js
index 1b850e26..5f1fd0c9 100644
--- a/commands/edit-avatar/hat.js
+++ b/commands/edit-avatar/hat.js
@@ -142,17 +142,13 @@ module.exports = class HatCommand extends Command {
async run(msg, { type, user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'hat', `${type}.png`));
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- const canvas = createCanvas(avatar.width, avatar.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(avatar, 0, 0);
- ctx.drawImage(base, 0, 0, avatar.width, avatar.height);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: `${type}-hat.png` }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'hat', `${type}.png`));
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ const canvas = createCanvas(avatar.width, avatar.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(avatar, 0, 0);
+ ctx.drawImage(base, 0, 0, avatar.width, avatar.height);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: `${type}-hat.png` }] });
}
};
diff --git a/commands/edit-avatar/he-lives-in-you.js b/commands/edit-avatar/he-lives-in-you.js
index 3706d514..6d0ea859 100644
--- a/commands/edit-avatar/he-lives-in-you.js
+++ b/commands/edit-avatar/he-lives-in-you.js
@@ -38,19 +38,15 @@ module.exports = class HeLivesInYouCommand extends Command {
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 256 });
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'he-lives-in-you.png'));
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.rotate(-24 * (Math.PI / 180));
- drawImageWithTint(ctx, avatar, '#00115d', 75, 160, 130, 150);
- ctx.rotate(24 * (Math.PI / 180));
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'he-lives-in-you.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'he-lives-in-you.png'));
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.rotate(-24 * (Math.PI / 180));
+ drawImageWithTint(ctx, avatar, '#00115d', 75, 160, 130, 150);
+ ctx.rotate(24 * (Math.PI / 180));
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'he-lives-in-you.png' }] });
}
};
diff --git a/commands/edit-avatar/hearts.js b/commands/edit-avatar/hearts.js
index bcc656dd..04bc248e 100644
--- a/commands/edit-avatar/hearts.js
+++ b/commands/edit-avatar/hearts.js
@@ -38,17 +38,13 @@ module.exports = class HeartsCommand extends Command {
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'hearts.png'));
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- const canvas = createCanvas(avatar.width, avatar.height);
- const ctx = canvas.getContext('2d');
- drawImageWithTint(ctx, avatar, 'deeppink', 0, 0, avatar.width, avatar.height);
- ctx.drawImage(base, 0, 0, avatar.width, avatar.height);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'hearts.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'hearts.png'));
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ const canvas = createCanvas(avatar.width, avatar.height);
+ const ctx = canvas.getContext('2d');
+ drawImageWithTint(ctx, avatar, 'deeppink', 0, 0, avatar.width, avatar.height);
+ ctx.drawImage(base, 0, 0, avatar.width, avatar.height);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'hearts.png' }] });
}
};
diff --git a/commands/edit-avatar/i-have-the-power.js b/commands/edit-avatar/i-have-the-power.js
index 77ee2e87..e439b901 100644
--- a/commands/edit-avatar/i-have-the-power.js
+++ b/commands/edit-avatar/i-have-the-power.js
@@ -36,19 +36,15 @@ module.exports = class IHaveThePowerCommand extends Command {
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 256 });
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'i-have-the-power.png'));
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.rotate(18.3 * (Math.PI / 180));
- ctx.drawImage(avatar, 332, -125, 175, 175);
- ctx.rotate(-18.3 * (Math.PI / 180));
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'i-have-the-power.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'i-have-the-power.png'));
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.rotate(18.3 * (Math.PI / 180));
+ ctx.drawImage(avatar, 332, -125, 175, 175);
+ ctx.rotate(-18.3 * (Math.PI / 180));
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'i-have-the-power.png' }] });
}
};
diff --git a/commands/edit-avatar/rip.js b/commands/edit-avatar/rip.js
index 15914a15..528da703 100644
--- a/commands/edit-avatar/rip.js
+++ b/commands/edit-avatar/rip.js
@@ -51,27 +51,23 @@ module.exports = class RipCommand extends Command {
async run(msg, { user, cause }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'rip.png'));
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.drawImage(avatar, 194, 399, 500, 500);
- greyscale(ctx, 194, 399, 500, 500);
- ctx.textBaseline = 'top';
- ctx.textAlign = 'center';
- ctx.font = this.client.fonts.get('CoffinStone.otf').toCanvasString(62);
- ctx.fillStyle = 'black';
- ctx.fillText(user.username, 438, 330, 500);
- ctx.fillStyle = 'white';
- if (cause) ctx.fillText(cause, 438, 910, 500);
- ctx.font = this.client.fonts.get('CoffinStone.otf').toCanvasString(37);
- ctx.fillText('In Loving Memory of', 438, 292);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'rip.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'rip.png'));
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.drawImage(avatar, 194, 399, 500, 500);
+ greyscale(ctx, 194, 399, 500, 500);
+ ctx.textBaseline = 'top';
+ ctx.textAlign = 'center';
+ ctx.font = this.client.fonts.get('CoffinStone.otf').toCanvasString(62);
+ ctx.fillStyle = 'black';
+ ctx.fillText(user.username, 438, 330, 500);
+ ctx.fillStyle = 'white';
+ if (cause) ctx.fillText(cause, 438, 910, 500);
+ ctx.font = this.client.fonts.get('CoffinStone.otf').toCanvasString(37);
+ ctx.fillText('In Loving Memory of', 438, 292);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'rip.png' }] });
}
};
diff --git a/commands/edit-avatar/steam-now-playing.js b/commands/edit-avatar/steam-now-playing.js
index 6e045ad5..cda0866c 100644
--- a/commands/edit-avatar/steam-now-playing.js
+++ b/commands/edit-avatar/steam-now-playing.js
@@ -48,21 +48,17 @@ module.exports = class SteamNowPlayingCommand extends Command {
async run(msg, { game, user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 64 });
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'steam-now-playing.png'));
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.drawImage(avatar, 26, 26, 41, 42);
- ctx.fillStyle = '#90b93c';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(14);
- ctx.fillText(user.username, 80, 34);
- ctx.fillText(shortenText(ctx, game, 200), 80, 70);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'steam-now-playing.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'steam-now-playing.png'));
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.drawImage(avatar, 26, 26, 41, 42);
+ ctx.fillStyle = '#90b93c';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(14);
+ ctx.fillText(user.username, 80, 34);
+ ctx.fillText(shortenText(ctx, game, 200), 80, 70);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'steam-now-playing.png' }] });
}
};
diff --git a/commands/edit-avatar/triggered.js b/commands/edit-avatar/triggered.js
index 8fc3f5f8..37ab877f 100644
--- a/commands/edit-avatar/triggered.js
+++ b/commands/edit-avatar/triggered.js
@@ -43,30 +43,26 @@ module.exports = class TriggeredCommand extends Command {
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'triggered.png'));
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- const encoder = new GIFEncoder(base.width, base.width);
- const canvas = createCanvas(base.width, base.width);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'white';
- ctx.fillRect(0, 0, base.width, base.width);
- const stream = encoder.createReadStream();
- encoder.start();
- encoder.setRepeat(0);
- encoder.setDelay(50);
- encoder.setQuality(200);
- for (let i = 0; i < 4; i++) {
- drawImageWithTint(ctx, avatar, 'red', coord1[i], coord2[i], 300, 300);
- ctx.drawImage(base, 0, 218, 256, 38);
- encoder.addFrame(ctx);
- }
- encoder.finish();
- const buffer = await streamToArray(stream);
- return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'triggered.gif' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'triggered.png'));
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ const encoder = new GIFEncoder(base.width, base.width);
+ const canvas = createCanvas(base.width, base.width);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'white';
+ ctx.fillRect(0, 0, base.width, base.width);
+ const stream = encoder.createReadStream();
+ encoder.start();
+ encoder.setRepeat(0);
+ encoder.setDelay(50);
+ encoder.setQuality(200);
+ for (let i = 0; i < 4; i++) {
+ drawImageWithTint(ctx, avatar, 'red', coord1[i], coord2[i], 300, 300);
+ ctx.drawImage(base, 0, 218, 256, 38);
+ encoder.addFrame(ctx);
}
+ encoder.finish();
+ const buffer = await streamToArray(stream);
+ return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'triggered.gif' }] });
}
};
diff --git a/commands/edit-image-text/tweet.js b/commands/edit-image-text/tweet.js
index 98f6b073..0ae12027 100644
--- a/commands/edit-image-text/tweet.js
+++ b/commands/edit-image-text/tweet.js
@@ -55,98 +55,94 @@ module.exports = class TweetCommand extends Command {
}
async run(msg, { user, text }) {
- try {
- if (!this.guestClient) this.guestClient = await api.getGuestClient();
- const userData = await this.fetchUser(msg, user);
- const avatar = await loadImage(userData.avatar);
- const base1 = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'tweet', 'bg-1.png'));
- const base2 = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'tweet', 'bg-2.png'));
- const canvas = createCanvas(base1.width, base1.height + base2.height);
- const ctx = canvas.getContext('2d');
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(23);
- const lines = await wrapText(ctx, text, 710);
- const lineBreakLen = text.split('\n').length;
- const linesLen = (23 * lines.length)
+ if (!this.guestClient) this.guestClient = await api.getGuestClient();
+ const userData = await this.fetchUser(msg, user);
+ const avatar = await loadImage(userData.avatar);
+ const base1 = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'tweet', 'bg-1.png'));
+ const base2 = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'tweet', 'bg-2.png'));
+ const canvas = createCanvas(base1.width, base1.height + base2.height);
+ const ctx = canvas.getContext('2d');
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(23);
+ const lines = await wrapText(ctx, text, 710);
+ const lineBreakLen = text.split('\n').length;
+ const linesLen = (23 * lines.length)
+ (23 * (lineBreakLen - 1))
+ (9 * (lines.length - 1))
+ (9 * (lineBreakLen - 1));
- canvas.height += linesLen;
- const likes = randomRange(Math.ceil(userData.followers * 0.0015), Math.ceil(userData.followers * 0.002));
- const retweets = randomRange(Math.ceil(userData.followers * 0.00015), Math.ceil(userData.followers * 0.0002));
- const quotTweets = randomRange(Math.ceil(userData.followers * 0.000015), Math.ceil(userData.followers * 0.00002));
- const replies = randomRange(Math.ceil(userData.followers * 0.000015), Math.ceil(userData.followers * 0.00002));
- ctx.fillStyle = '#15202b';
- ctx.fillRect(0, base1.height, canvas.width, linesLen);
- ctx.drawImage(base1, 0, 0);
- const base2StartY = base1.height + linesLen;
- ctx.drawImage(base2, 0, base2StartY);
- ctx.textBaseline = 'top';
- ctx.font = this.client.fonts.get('Noto-Bold.ttf').toCanvasString(18);
- ctx.fillStyle = 'white';
- ctx.fillText(userData.name, 105, 84);
- if (userData.verified) {
- const verified = await loadImage(
- path.join(__dirname, '..', '..', 'assets', 'images', 'tweet', 'verified.png')
- );
- const nameLen = ctx.measureText(userData.name).width;
- ctx.drawImage(verified, 105 + nameLen + 4, 88, 18, 18);
- }
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(17);
- ctx.fillStyle = '#8899a6';
- ctx.fillText(`@${userData.screenName}`, 106, 111);
- ctx.fillStyle = 'white';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(23);
- ctx.fillText(lines.join('\n'), 32, 164);
- ctx.fillStyle = '#8899a6';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(18);
- const time = moment().format('h:mm A ∙ MMMM D, YYYY ∙');
- ctx.fillText(time, 31, base2StartY + 16);
- const timeLen = ctx.measureText(time).width;
- ctx.fillStyle = '#1b95e0';
- ctx.fillText('Twitter for Xiao', 31 + timeLen + 6, base2StartY + 16);
- ctx.fillStyle = '#8899a6';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(16);
- ctx.fillText(formatNumberK(replies), 87, base2StartY + 139);
- ctx.fillText(formatNumberK(likes), 509, base2StartY + 139);
- ctx.fillText(formatNumberK(retweets + quotTweets), 300, base2StartY + 139);
- let currentLen = 31;
- ctx.fillStyle = 'white';
- ctx.font = this.client.fonts.get('Noto-Bold.ttf').toCanvasString(18);
- ctx.fillText(formatNumberK(retweets), currentLen, base2StartY + 77);
- currentLen += ctx.measureText(formatNumberK(retweets)).width;
- currentLen += 5;
- ctx.fillStyle = '#8899a6';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(18);
- ctx.fillText('Retweets', currentLen, base2StartY + 77);
- currentLen += ctx.measureText('Retweets').width;
- currentLen += 10;
- ctx.fillStyle = 'white';
- ctx.font = this.client.fonts.get('Noto-Bold.ttf').toCanvasString(18);
- ctx.fillText(formatNumberK(quotTweets), currentLen, base2StartY + 77);
- currentLen += ctx.measureText(formatNumberK(quotTweets)).width;
- currentLen += 5;
- ctx.fillStyle = '#8899a6';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(18);
- ctx.fillText('Quote Tweets', currentLen, base2StartY + 77);
- currentLen += ctx.measureText('Quote Tweets').width;
- currentLen += 10;
- ctx.fillStyle = 'white';
- ctx.font = this.client.fonts.get('Noto-Bold.ttf').toCanvasString(18);
- ctx.fillText(formatNumberK(likes), currentLen, base2StartY + 77);
- currentLen += ctx.measureText(formatNumberK(likes)).width;
- currentLen += 5;
- ctx.fillStyle = '#8899a6';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(18);
- ctx.fillText('Likes', currentLen, base2StartY + 77);
- ctx.beginPath();
- ctx.arc(30 + 32, 84 + 32, 32, 0, Math.PI * 2);
- ctx.closePath();
- ctx.clip();
- ctx.drawImage(avatar, 30, 84, 64, 64);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'tweet.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ canvas.height += linesLen;
+ const likes = randomRange(Math.ceil(userData.followers * 0.0015), Math.ceil(userData.followers * 0.002));
+ const retweets = randomRange(Math.ceil(userData.followers * 0.00015), Math.ceil(userData.followers * 0.0002));
+ const quotTweets = randomRange(Math.ceil(userData.followers * 0.000015), Math.ceil(userData.followers * 0.00002));
+ const replies = randomRange(Math.ceil(userData.followers * 0.000015), Math.ceil(userData.followers * 0.00002));
+ ctx.fillStyle = '#15202b';
+ ctx.fillRect(0, base1.height, canvas.width, linesLen);
+ ctx.drawImage(base1, 0, 0);
+ const base2StartY = base1.height + linesLen;
+ ctx.drawImage(base2, 0, base2StartY);
+ ctx.textBaseline = 'top';
+ ctx.font = this.client.fonts.get('Noto-Bold.ttf').toCanvasString(18);
+ ctx.fillStyle = 'white';
+ ctx.fillText(userData.name, 105, 84);
+ if (userData.verified) {
+ const verified = await loadImage(
+ path.join(__dirname, '..', '..', 'assets', 'images', 'tweet', 'verified.png')
+ );
+ const nameLen = ctx.measureText(userData.name).width;
+ ctx.drawImage(verified, 105 + nameLen + 4, 88, 18, 18);
}
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(17);
+ ctx.fillStyle = '#8899a6';
+ ctx.fillText(`@${userData.screenName}`, 106, 111);
+ ctx.fillStyle = 'white';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(23);
+ ctx.fillText(lines.join('\n'), 32, 164);
+ ctx.fillStyle = '#8899a6';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(18);
+ const time = moment().format('h:mm A ∙ MMMM D, YYYY ∙');
+ ctx.fillText(time, 31, base2StartY + 16);
+ const timeLen = ctx.measureText(time).width;
+ ctx.fillStyle = '#1b95e0';
+ ctx.fillText('Twitter for Xiao', 31 + timeLen + 6, base2StartY + 16);
+ ctx.fillStyle = '#8899a6';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(16);
+ ctx.fillText(formatNumberK(replies), 87, base2StartY + 139);
+ ctx.fillText(formatNumberK(likes), 509, base2StartY + 139);
+ ctx.fillText(formatNumberK(retweets + quotTweets), 300, base2StartY + 139);
+ let currentLen = 31;
+ ctx.fillStyle = 'white';
+ ctx.font = this.client.fonts.get('Noto-Bold.ttf').toCanvasString(18);
+ ctx.fillText(formatNumberK(retweets), currentLen, base2StartY + 77);
+ currentLen += ctx.measureText(formatNumberK(retweets)).width;
+ currentLen += 5;
+ ctx.fillStyle = '#8899a6';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(18);
+ ctx.fillText('Retweets', currentLen, base2StartY + 77);
+ currentLen += ctx.measureText('Retweets').width;
+ currentLen += 10;
+ ctx.fillStyle = 'white';
+ ctx.font = this.client.fonts.get('Noto-Bold.ttf').toCanvasString(18);
+ ctx.fillText(formatNumberK(quotTweets), currentLen, base2StartY + 77);
+ currentLen += ctx.measureText(formatNumberK(quotTweets)).width;
+ currentLen += 5;
+ ctx.fillStyle = '#8899a6';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(18);
+ ctx.fillText('Quote Tweets', currentLen, base2StartY + 77);
+ currentLen += ctx.measureText('Quote Tweets').width;
+ currentLen += 10;
+ ctx.fillStyle = 'white';
+ ctx.font = this.client.fonts.get('Noto-Bold.ttf').toCanvasString(18);
+ ctx.fillText(formatNumberK(likes), currentLen, base2StartY + 77);
+ currentLen += ctx.measureText(formatNumberK(likes)).width;
+ currentLen += 5;
+ ctx.fillStyle = '#8899a6';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(18);
+ ctx.fillText('Likes', currentLen, base2StartY + 77);
+ ctx.beginPath();
+ ctx.arc(30 + 32, 84 + 32, 32, 0, Math.PI * 2);
+ ctx.closePath();
+ ctx.clip();
+ ctx.drawImage(avatar, 30, 84, 64, 64);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'tweet.png' }] });
}
async fetchUser(msg, user) {
diff --git a/commands/edit-image/approved.js b/commands/edit-image/approved.js
index 301978f7..d2932ef8 100644
--- a/commands/edit-image/approved.js
+++ b/commands/edit-image/approved.js
@@ -37,20 +37,16 @@ module.exports = class ApprovedCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'approved.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- const { x, y, width, height } = centerImage(base, data);
- ctx.drawImage(base, x, y, width, height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'approved.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'approved.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ const { x, y, width, height } = centerImage(base, data);
+ ctx.drawImage(base, x, y, width, height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'approved.png' }] });
}
};
diff --git a/commands/edit-image/ascii.js b/commands/edit-image/ascii.js
index 7086c1fb..c32bf8f4 100644
--- a/commands/edit-image/ascii.js
+++ b/commands/edit-image/ascii.js
@@ -26,13 +26,9 @@ module.exports = class AsciiCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const asciiImg = await this.ascii(body);
- return msg.code(null, asciiImg);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const asciiImg = await this.ascii(body);
+ return msg.code(null, asciiImg);
}
async ascii(image) {
diff --git a/commands/edit-image/blur.js b/commands/edit-image/blur.js
index 769214aa..b1d20ecd 100644
--- a/commands/edit-image/blur.js
+++ b/commands/edit-image/blur.js
@@ -35,18 +35,14 @@ module.exports = class BlurCommand extends Command {
}
async run(msg, { radius, image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- stackBlur.canvasRGBA(canvas, 0, 0, canvas.width, canvas.height, radius);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'blur.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ stackBlur.canvasRGBA(canvas, 0, 0, canvas.width, canvas.height, radius);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'blur.png' }] });
}
};
diff --git a/commands/edit-image/bob-ross.js b/commands/edit-image/bob-ross.js
index 53149d04..6f72f361 100644
--- a/commands/edit-image/bob-ross.js
+++ b/commands/edit-image/bob-ross.js
@@ -42,20 +42,16 @@ module.exports = class BobRossCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'bob-ross.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'white';
- ctx.fillRect(0, 0, base.width, base.height);
- const { x, y, width, height } = centerImagePart(data, 440, 440, 15, 20);
- ctx.drawImage(data, x, y, width, height);
- ctx.drawImage(base, 0, 0);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'bob-ross.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'bob-ross.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'white';
+ ctx.fillRect(0, 0, base.width, base.height);
+ const { x, y, width, height } = centerImagePart(data, 440, 440, 15, 20);
+ ctx.drawImage(data, x, y, width, height);
+ ctx.drawImage(base, 0, 0);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'bob-ross.png' }] });
}
};
diff --git a/commands/edit-image/brazzers.js b/commands/edit-image/brazzers.js
index 9500fc1c..b3d5d6b5 100644
--- a/commands/edit-image/brazzers.js
+++ b/commands/edit-image/brazzers.js
@@ -35,22 +35,18 @@ module.exports = class BrazzersCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'brazzers.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- const ratio = base.width / base.height;
- const width = data.width / 3;
- const height = Math.round(width / ratio);
- ctx.drawImage(base, 0, data.height - height, width, height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'brazzers.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'brazzers.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ const ratio = base.width / base.height;
+ const width = data.width / 3;
+ const height = Math.round(width / ratio);
+ ctx.drawImage(base, 0, data.height - height, width, height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'brazzers.png' }] });
}
};
diff --git a/commands/edit-image/charcoal.js b/commands/edit-image/charcoal.js
index 636222cc..bb3821a7 100644
--- a/commands/edit-image/charcoal.js
+++ b/commands/edit-image/charcoal.js
@@ -34,16 +34,12 @@ module.exports = class CharcoalCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const magik = gm(body);
- magik.charcoal(1);
- magik.setFormat('png');
- 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!`);
- }
+ const { body } = await request.get(image);
+ const magik = gm(body);
+ magik.charcoal(1);
+ magik.setFormat('png');
+ 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: 'charcoal.png' }] });
}
};
diff --git a/commands/edit-image/chocolate-milk.js b/commands/edit-image/chocolate-milk.js
index 550ccecd..95eca7d0 100644
--- a/commands/edit-image/chocolate-milk.js
+++ b/commands/edit-image/chocolate-milk.js
@@ -36,27 +36,23 @@ module.exports = class ChocolateMilkCommand extends Command {
}
async run(msg, { image, direction }) {
- try {
- const overlay = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'chocolate-milk.png'));
- const { body } = await request.get(image);
- const base = await loadImage(body);
- const canvas = createCanvas(overlay.width, overlay.height);
- const scaleH = overlay.width / base.width;
- const height = Math.round(base.height * scaleH);
- const ctx = canvas.getContext('2d');
- ctx.fillRect(0, 0, overlay.width, overlay.height);
- if (direction === 'right') {
- ctx.translate(overlay.width, 0);
- ctx.scale(-1, 1);
- }
- ctx.drawImage(base, 0, 0, overlay.width, height);
- if (direction === 'right') ctx.setTransform(1, 0, 0, 1, 0, 0);
- ctx.drawImage(overlay, 0, 0);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'chocolate-milk.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const overlay = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'chocolate-milk.png'));
+ const { body } = await request.get(image);
+ const base = await loadImage(body);
+ const canvas = createCanvas(overlay.width, overlay.height);
+ const scaleH = overlay.width / base.width;
+ const height = Math.round(base.height * scaleH);
+ const ctx = canvas.getContext('2d');
+ ctx.fillRect(0, 0, overlay.width, overlay.height);
+ if (direction === 'right') {
+ ctx.translate(overlay.width, 0);
+ ctx.scale(-1, 1);
}
+ ctx.drawImage(base, 0, 0, overlay.width, height);
+ if (direction === 'right') ctx.setTransform(1, 0, 0, 1, 0, 0);
+ ctx.drawImage(overlay, 0, 0);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'chocolate-milk.png' }] });
}
};
diff --git a/commands/edit-image/circle.js b/commands/edit-image/circle.js
index c586e156..4ccb9627 100644
--- a/commands/edit-image/circle.js
+++ b/commands/edit-image/circle.js
@@ -27,20 +27,16 @@ module.exports = class CircleCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const dimensions = data.width <= data.height ? data.width : data.height;
- const canvas = createCanvas(dimensions, dimensions);
- const ctx = canvas.getContext('2d');
- ctx.beginPath();
- ctx.arc(canvas.width / 2, canvas.height / 2, canvas.height / 2, 0, Math.PI * 2);
- ctx.closePath();
- ctx.clip();
- ctx.drawImage(data, (canvas.width / 2) - (data.width / 2), (canvas.height / 2) - (data.height / 2));
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'circle.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const dimensions = data.width <= data.height ? data.width : data.height;
+ const canvas = createCanvas(dimensions, dimensions);
+ const ctx = canvas.getContext('2d');
+ ctx.beginPath();
+ ctx.arc(canvas.width / 2, canvas.height / 2, canvas.height / 2, 0, Math.PI * 2);
+ ctx.closePath();
+ ctx.clip();
+ ctx.drawImage(data, (canvas.width / 2) - (data.width / 2), (canvas.height / 2) - (data.height / 2));
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'circle.png' }] });
}
};
diff --git a/commands/edit-image/communist.js b/commands/edit-image/communist.js
index 6241fbe1..14d40d71 100644
--- a/commands/edit-image/communist.js
+++ b/commands/edit-image/communist.js
@@ -37,22 +37,18 @@ module.exports = class CommunistCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'communist.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- drawImageWithTint(ctx, data, 'red', 0, 0, data.width, data.height);
- const { x, y, width, height } = centerImage(base, data);
- ctx.globalAlpha = 0.5;
- ctx.drawImage(base, x + (width / 20), y + (height / 20), width * 0.9, height * 0.9);
- ctx.globalAlpha = 1;
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'communist.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'communist.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ drawImageWithTint(ctx, data, 'red', 0, 0, data.width, data.height);
+ const { x, y, width, height } = centerImage(base, data);
+ ctx.globalAlpha = 0.5;
+ ctx.drawImage(base, x + (width / 20), y + (height / 20), width * 0.9, height * 0.9);
+ ctx.globalAlpha = 1;
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'communist.png' }] });
}
};
diff --git a/commands/edit-image/contrast.js b/commands/edit-image/contrast.js
index 6befe85d..0da4567c 100644
--- a/commands/edit-image/contrast.js
+++ b/commands/edit-image/contrast.js
@@ -27,18 +27,14 @@ module.exports = class ContrastCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- contrast(ctx, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'contrast.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ contrast(ctx, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'contrast.png' }] });
}
};
diff --git a/commands/edit-image/convert-image.js b/commands/edit-image/convert-image.js
index 0f9581ad..d8a6cab4 100644
--- a/commands/edit-image/convert-image.js
+++ b/commands/edit-image/convert-image.js
@@ -40,15 +40,13 @@ module.exports = class ConvertImageCommand extends Command {
}
async run(msg, { format, image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- return msg.say({ files: [{ attachment: canvas.toBuffer(formats[format]), name: `convert-image.${format}` }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ const attachment = canvas.toBuffer(formats[format]);
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: `convert-image.${format}` }] });
}
};
diff --git a/commands/edit-image/create-qr-code.js b/commands/edit-image/create-qr-code.js
index 6c2f47b4..0a0c4d08 100644
--- a/commands/edit-image/create-qr-code.js
+++ b/commands/edit-image/create-qr-code.js
@@ -28,13 +28,9 @@ module.exports = class CreateQRCodeCommand extends Command {
}
async run(msg, { text }) {
- try {
- const { body } = await request
- .get('https://api.qrserver.com/v1/create-qr-code/')
- .query({ data: text });
- return msg.say({ files: [{ attachment: body, name: 'qr-code.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request
+ .get('https://api.qrserver.com/v1/create-qr-code/')
+ .query({ data: text });
+ return msg.say({ files: [{ attachment: body, name: 'qr-code.png' }] });
}
};
diff --git a/commands/edit-image/desaturate.js b/commands/edit-image/desaturate.js
index 1d2751d1..699a23c5 100644
--- a/commands/edit-image/desaturate.js
+++ b/commands/edit-image/desaturate.js
@@ -33,18 +33,14 @@ module.exports = class DesaturateCommand extends Command {
}
async run(msg, { level, image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- desaturate(ctx, level, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'desaturate.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ desaturate(ctx, level, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'desaturate.png' }] });
}
};
diff --git a/commands/edit-image/dexter.js b/commands/edit-image/dexter.js
index 52e52842..7d5be69b 100644
--- a/commands/edit-image/dexter.js
+++ b/commands/edit-image/dexter.js
@@ -35,20 +35,16 @@ module.exports = class DexterCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'dexter.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.rotate(-11 * (Math.PI / 180));
- const { x, y, width, height } = centerImagePart(data, 225, 225, 234, 274);
- ctx.drawImage(data, x, y, width, height);
- ctx.rotate(11 * (Math.PI / 180));
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'dexter.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'dexter.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.rotate(-11 * (Math.PI / 180));
+ const { x, y, width, height } = centerImagePart(data, 225, 225, 234, 274);
+ ctx.drawImage(data, x, y, width, height);
+ ctx.rotate(11 * (Math.PI / 180));
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'dexter.png' }] });
}
};
diff --git a/commands/edit-image/distort.js b/commands/edit-image/distort.js
index ab2bc916..f4c5a2dd 100644
--- a/commands/edit-image/distort.js
+++ b/commands/edit-image/distort.js
@@ -32,18 +32,14 @@ module.exports = class DistortCommand extends Command {
}
async run(msg, { level, image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- distort(ctx, level, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'distort.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ distort(ctx, level, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'distort.png' }] });
}
};
diff --git a/commands/edit-image/emboss.js b/commands/edit-image/emboss.js
index e922a45a..0800586c 100644
--- a/commands/edit-image/emboss.js
+++ b/commands/edit-image/emboss.js
@@ -34,16 +34,12 @@ module.exports = class EmbossCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const magik = gm(body);
- magik.emboss();
- magik.setFormat('png');
- 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!`);
- }
+ const { body } = await request.get(image);
+ const magik = gm(body);
+ magik.emboss();
+ magik.setFormat('png');
+ 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' }] });
}
};
diff --git a/commands/edit-image/fire-frame.js b/commands/edit-image/fire-frame.js
index 86656daa..31961e24 100644
--- a/commands/edit-image/fire-frame.js
+++ b/commands/edit-image/fire-frame.js
@@ -37,19 +37,15 @@ module.exports = class FireFrameCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'fire-frame.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- drawImageWithTint(ctx, data, '#fc671e', 0, 0, data.width, data.height);
- ctx.drawImage(base, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'fire-frame.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'fire-frame.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ drawImageWithTint(ctx, data, '#fc671e', 0, 0, data.width, data.height);
+ ctx.drawImage(base, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'fire-frame.png' }] });
}
};
diff --git a/commands/edit-image/fish-eye.js b/commands/edit-image/fish-eye.js
index a4e18f60..cd430151 100644
--- a/commands/edit-image/fish-eye.js
+++ b/commands/edit-image/fish-eye.js
@@ -42,18 +42,14 @@ module.exports = class FishEyeCommand extends Command {
}
async run(msg, { level, image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- fishEye(ctx, level, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'fish-eye.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ fishEye(ctx, level, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'fish-eye.png' }] });
}
};
diff --git a/commands/edit-image/frame.js b/commands/edit-image/frame.js
index 8d93bde4..1a5ff265 100644
--- a/commands/edit-image/frame.js
+++ b/commands/edit-image/frame.js
@@ -46,30 +46,26 @@ module.exports = class FrameCommand extends Command {
}
async run(msg, { frame, image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'frame', frame.file));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- let canvas;
- if (frame.stretch) {
- canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- ctx.drawImage(base, 0, 0, data.width, data.height);
- } else {
- canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'black';
- ctx.fillRect(frame.xStart, frame.yStart, frame.xSize, frame.ySize);
- const { x, y, width, height } = centerImagePart(data, frame.xSize, frame.ySize, frame.xStart, frame.yStart);
- ctx.drawImage(data, x, y, width, height);
- ctx.drawImage(base, 0, 0);
- }
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: `frame-${frame.file}` }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'frame', frame.file));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ let canvas;
+ if (frame.stretch) {
+ canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ ctx.drawImage(base, 0, 0, data.width, data.height);
+ } else {
+ canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'black';
+ ctx.fillRect(frame.xStart, frame.yStart, frame.xSize, frame.ySize);
+ const { x, y, width, height } = centerImagePart(data, frame.xSize, frame.ySize, frame.xStart, frame.yStart);
+ ctx.drawImage(data, x, y, width, height);
+ ctx.drawImage(base, 0, 0);
}
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: `frame-${frame.file}` }] });
}
};
diff --git a/commands/edit-image/ghost.js b/commands/edit-image/ghost.js
index fd8b80d5..7c8dabef 100644
--- a/commands/edit-image/ghost.js
+++ b/commands/edit-image/ghost.js
@@ -26,20 +26,16 @@ module.exports = class GhostCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'white';
- ctx.fillRect(0, 0, data.width, data.height);
- ctx.globalAlpha = 0.25;
- ctx.drawImage(data, 0, 0);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'ghost.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'white';
+ ctx.fillRect(0, 0, data.width, data.height);
+ ctx.globalAlpha = 0.25;
+ ctx.drawImage(data, 0, 0);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'ghost.png' }] });
}
};
diff --git a/commands/edit-image/glass-shatter.js b/commands/edit-image/glass-shatter.js
index 186128b0..56e095ae 100644
--- a/commands/edit-image/glass-shatter.js
+++ b/commands/edit-image/glass-shatter.js
@@ -36,19 +36,15 @@ module.exports = class GlassShatterCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'glass-shatter.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- ctx.drawImage(base, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'glass-shatter.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'glass-shatter.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ ctx.drawImage(base, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'glass-shatter.png' }] });
}
};
diff --git a/commands/edit-image/glitch.js b/commands/edit-image/glitch.js
index 8518df8b..5640a3a0 100644
--- a/commands/edit-image/glitch.js
+++ b/commands/edit-image/glitch.js
@@ -27,18 +27,14 @@ module.exports = class GlitchCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- distort(ctx, 20, 0, 0, data.width, data.height, 5);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'glitch.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ distort(ctx, 20, 0, 0, data.width, data.height, 5);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'glitch.png' }] });
}
};
diff --git a/commands/edit-image/greyscale.js b/commands/edit-image/greyscale.js
index 513780d5..41efb483 100644
--- a/commands/edit-image/greyscale.js
+++ b/commands/edit-image/greyscale.js
@@ -28,18 +28,14 @@ module.exports = class GreyscaleCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- greyscale(ctx, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'greyscale.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ greyscale(ctx, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'greyscale.png' }] });
}
};
diff --git a/commands/edit-image/gun.js b/commands/edit-image/gun.js
index 0e85e34a..a4e94207 100644
--- a/commands/edit-image/gun.js
+++ b/commands/edit-image/gun.js
@@ -35,21 +35,17 @@ module.exports = class GunCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'gun.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- const ratio = (data.height / 2) / base.height;
- const width = base.width * ratio;
- ctx.drawImage(base, data.width - width, data.height - (data.height / 2), width, data.height / 2);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'gun.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'gun.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ const ratio = (data.height / 2) / base.height;
+ const width = base.width * ratio;
+ ctx.drawImage(base, data.width - width, data.height - (data.height / 2), width, data.height / 2);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'gun.png' }] });
}
};
diff --git a/commands/edit-image/hands.js b/commands/edit-image/hands.js
index 0b005764..d49b4c27 100644
--- a/commands/edit-image/hands.js
+++ b/commands/edit-image/hands.js
@@ -36,21 +36,17 @@ module.exports = class HandsCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'hands.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- const ratio = data.width / base.width;
- const height = base.height * ratio;
- ctx.drawImage(base, 0, data.height - height, data.width, height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'hands.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'hands.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ const ratio = data.width / base.width;
+ const height = base.height * ratio;
+ ctx.drawImage(base, 0, data.height - height, data.width, height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'hands.png' }] });
}
};
diff --git a/commands/edit-image/ifunny.js b/commands/edit-image/ifunny.js
index 5ee5ba11..af690c4d 100644
--- a/commands/edit-image/ifunny.js
+++ b/commands/edit-image/ifunny.js
@@ -34,21 +34,17 @@ module.exports = class IfunnyCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'ifunny.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- ctx.fillStyle = '#181619';
- ctx.fillRect(0, canvas.height - base.height, canvas.width, base.height);
- ctx.drawImage(base, canvas.width - base.width, canvas.height - base.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'ifunny.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'ifunny.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ ctx.fillStyle = '#181619';
+ ctx.fillRect(0, canvas.height - base.height, canvas.width, base.height);
+ ctx.drawImage(base, canvas.width - base.width, canvas.height - base.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'ifunny.png' }] });
}
};
diff --git a/commands/edit-image/implode.js b/commands/edit-image/implode.js
index 0bb9bfd4..0e851bfc 100644
--- a/commands/edit-image/implode.js
+++ b/commands/edit-image/implode.js
@@ -41,16 +41,12 @@ module.exports = class ImplodeCommand extends Command {
}
async run(msg, { level, image }) {
- try {
- const { body } = await request.get(image);
- const magik = gm(body);
- magik.implode(level / 100);
- magik.setFormat('png');
- 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!`);
- }
+ const { body } = await request.get(image);
+ const magik = gm(body);
+ magik.implode(level / 100);
+ magik.setFormat('png');
+ 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' }] });
}
};
diff --git a/commands/edit-image/invert.js b/commands/edit-image/invert.js
index b774f2a7..1cc100ca 100644
--- a/commands/edit-image/invert.js
+++ b/commands/edit-image/invert.js
@@ -27,18 +27,14 @@ module.exports = class InvertCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- invert(ctx, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'invert.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ invert(ctx, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'invert.png' }] });
}
};
diff --git a/commands/edit-image/lego-icon.js b/commands/edit-image/lego-icon.js
index 4088305d..023ab594 100644
--- a/commands/edit-image/lego-icon.js
+++ b/commands/edit-image/lego-icon.js
@@ -42,22 +42,18 @@ module.exports = class LegoIconCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'lego-icon.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.beginPath();
- ctx.arc(base.width / 2, base.height / 2, 764 / 2, 0, Math.PI * 2);
- ctx.closePath();
- ctx.clip();
- const height = 764 / data.width;
- ctx.drawImage(data, (base.width / 2) - (764 / 2), (base.height / 2) - (764 / 2), 764, data.height * height);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'lego-icon.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'lego-icon.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.beginPath();
+ ctx.arc(base.width / 2, base.height / 2, 764 / 2, 0, Math.PI * 2);
+ ctx.closePath();
+ ctx.clip();
+ const height = 764 / data.width;
+ ctx.drawImage(data, (base.width / 2) - (764 / 2), (base.height / 2) - (764 / 2), 764, data.height * height);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'lego-icon.png' }] });
}
};
diff --git a/commands/edit-image/liquid-rescale.js b/commands/edit-image/liquid-rescale.js
index 9122ed1d..a2ccb00a 100644
--- a/commands/edit-image/liquid-rescale.js
+++ b/commands/edit-image/liquid-rescale.js
@@ -35,18 +35,14 @@ module.exports = class LiquidRescaleCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const magik = gm(body);
- magik.out('-liquid-rescale');
- magik.out('50%');
- magik.implode(0.25);
- magik.setFormat('png');
- 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!`);
- }
+ const { body } = await request.get(image);
+ const magik = gm(body);
+ magik.out('-liquid-rescale');
+ magik.out('50%');
+ magik.implode(0.25);
+ magik.setFormat('png');
+ 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' }] });
}
};
diff --git a/commands/edit-image/mirror.js b/commands/edit-image/mirror.js
index 3576b92c..c47d268e 100644
--- a/commands/edit-image/mirror.js
+++ b/commands/edit-image/mirror.js
@@ -35,27 +35,23 @@ module.exports = class MirrorCommand extends Command {
}
async run(msg, { type, image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- if (type === 'x') {
- ctx.translate(canvas.width, 0);
- ctx.scale(-1, 1);
- } else if (type === 'y') {
- ctx.translate(0, canvas.height);
- ctx.scale(1, -1);
- } else if (type === 'both') {
- ctx.translate(canvas.width, canvas.height);
- ctx.scale(-1, -1);
- }
- ctx.drawImage(data, 0, 0);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'mirror.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ if (type === 'x') {
+ ctx.translate(canvas.width, 0);
+ ctx.scale(-1, 1);
+ } else if (type === 'y') {
+ ctx.translate(0, canvas.height);
+ ctx.scale(1, -1);
+ } else if (type === 'both') {
+ ctx.translate(canvas.width, canvas.height);
+ ctx.scale(-1, -1);
}
+ ctx.drawImage(data, 0, 0);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'mirror.png' }] });
}
};
diff --git a/commands/edit-image/motion-blur.js b/commands/edit-image/motion-blur.js
index b269f1f7..9081ad24 100644
--- a/commands/edit-image/motion-blur.js
+++ b/commands/edit-image/motion-blur.js
@@ -28,17 +28,13 @@ module.exports = class MotionBlurCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- motionBlur(ctx, data, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'motion-blur.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ motionBlur(ctx, data, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'motion-blur.png' }] });
}
};
diff --git a/commands/edit-image/needs-more-jpeg.js b/commands/edit-image/needs-more-jpeg.js
index 41bbcf29..bf0d0317 100644
--- a/commands/edit-image/needs-more-jpeg.js
+++ b/commands/edit-image/needs-more-jpeg.js
@@ -35,17 +35,13 @@ module.exports = class NeedsMoreJpegCommand extends Command {
}
async run(msg, { image, quality }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- const attachment = canvas.toBuffer('image/jpeg', { quality: quality / 10 });
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'needs-more-jpeg.jpeg' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ const attachment = canvas.toBuffer('image/jpeg', { quality: quality / 10 });
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'needs-more-jpeg.jpeg' }] });
}
};
diff --git a/commands/edit-image/noise.js b/commands/edit-image/noise.js
index 8a2758d3..75a65a5b 100644
--- a/commands/edit-image/noise.js
+++ b/commands/edit-image/noise.js
@@ -43,16 +43,12 @@ module.exports = class NoiseCommand extends Command {
}
async run(msg, { type, image }) {
- try {
- const { body } = await request.get(image);
- const magik = gm(body);
- magik.noise(type);
- magik.setFormat('png');
- 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!`);
- }
+ const { body } = await request.get(image);
+ const magik = gm(body);
+ magik.noise(type);
+ magik.setFormat('png');
+ 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' }] });
}
};
diff --git a/commands/edit-image/oil-painting.js b/commands/edit-image/oil-painting.js
index dc0bcfd6..ab282aa2 100644
--- a/commands/edit-image/oil-painting.js
+++ b/commands/edit-image/oil-painting.js
@@ -35,16 +35,12 @@ module.exports = class OilPaintingCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const magik = gm(body);
- magik.paint(5);
- magik.setFormat('png');
- 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!`);
- }
+ const { body } = await request.get(image);
+ const magik = gm(body);
+ magik.paint(5);
+ magik.setFormat('png');
+ 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' }] });
}
};
diff --git a/commands/edit-image/pet.js b/commands/edit-image/pet.js
index 5cb0f32c..400c61b9 100644
--- a/commands/edit-image/pet.js
+++ b/commands/edit-image/pet.js
@@ -31,35 +31,31 @@ module.exports = class PetCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const encoder = new GIFEncoder(112, 112);
- const canvas = createCanvas(112, 112);
- const ctx = canvas.getContext('2d');
- const stream = encoder.createReadStream();
- encoder.start();
- encoder.setRepeat(0);
- encoder.setDelay(20);
- encoder.setQuality(200);
- encoder.setTransparent('#000000');
- let squish = 0;
- for (let i = 0; i < frameCount; i++) {
- const frameID = `frame_${i.toString().padStart(2, '0')}.png`;
- const frame = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'pet', frameID));
- const { x, y, width, height } = centerImagePart(data, 75, 75, 27, 38);
- ctx.drawImage(data, x - (squish / 2), y + squish, width + squish, height - squish);
- ctx.drawImage(frame, 0, 0);
- encoder.addFrame(ctx);
- ctx.clearRect(0, 0, canvas.width, canvas.height);
- if (i + 1 > frameCount / 2) squish -= 4;
- else squish += 4;
- }
- encoder.finish();
- const buffer = await streamToArray(stream);
- return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'pet.gif' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const encoder = new GIFEncoder(112, 112);
+ const canvas = createCanvas(112, 112);
+ const ctx = canvas.getContext('2d');
+ const stream = encoder.createReadStream();
+ encoder.start();
+ encoder.setRepeat(0);
+ encoder.setDelay(20);
+ encoder.setQuality(200);
+ encoder.setTransparent('#000000');
+ let squish = 0;
+ for (let i = 0; i < frameCount; i++) {
+ const frameID = `frame_${i.toString().padStart(2, '0')}.png`;
+ const frame = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'pet', frameID));
+ const { x, y, width, height } = centerImagePart(data, 75, 75, 27, 38);
+ ctx.drawImage(data, x - (squish / 2), y + squish, width + squish, height - squish);
+ ctx.drawImage(frame, 0, 0);
+ encoder.addFrame(ctx);
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+ if (i + 1 > frameCount / 2) squish -= 4;
+ else squish += 4;
}
+ encoder.finish();
+ const buffer = await streamToArray(stream);
+ return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'pet.gif' }] });
}
};
diff --git a/commands/edit-image/pixelize.js b/commands/edit-image/pixelize.js
index 921b86c3..38ef9556 100644
--- a/commands/edit-image/pixelize.js
+++ b/commands/edit-image/pixelize.js
@@ -28,17 +28,13 @@ module.exports = class PixelizeCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- pixelize(ctx, canvas, data, 0.15, 0, 0, canvas.width, canvas.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'pixelize.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ pixelize(ctx, canvas, data, 0.15, 0, 0, canvas.width, canvas.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'pixelize.png' }] });
}
};
diff --git a/commands/edit-image/police-tape.js b/commands/edit-image/police-tape.js
index 476577cb..0e547b0d 100644
--- a/commands/edit-image/police-tape.js
+++ b/commands/edit-image/police-tape.js
@@ -37,20 +37,16 @@ module.exports = class PoliceTapeCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'police-tape.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- const { x, y, width, height } = centerImage(base, data);
- ctx.drawImage(base, x, y, width, height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'police-tape.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'police-tape.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ const { x, y, width, height } = centerImage(base, data);
+ ctx.drawImage(base, x, y, width, height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'police-tape.png' }] });
}
};
diff --git a/commands/edit-image/rainbow.js b/commands/edit-image/rainbow.js
index d031a708..7e60a7db 100644
--- a/commands/edit-image/rainbow.js
+++ b/commands/edit-image/rainbow.js
@@ -28,19 +28,15 @@ module.exports = class RainbowCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'rainbow.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- ctx.drawImage(base, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'rainbow.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'rainbow.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ ctx.drawImage(base, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'rainbow.png' }] });
}
};
diff --git a/commands/edit-image/rejected.js b/commands/edit-image/rejected.js
index 7997986f..8c872807 100644
--- a/commands/edit-image/rejected.js
+++ b/commands/edit-image/rejected.js
@@ -37,20 +37,16 @@ module.exports = class RejctedCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'rejected.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- const { x, y, width, height } = centerImage(base, data);
- ctx.drawImage(base, x, y, width, height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'rejected.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'rejected.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ const { x, y, width, height } = centerImage(base, data);
+ ctx.drawImage(base, x, y, width, height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'rejected.png' }] });
}
};
diff --git a/commands/edit-image/resize.js b/commands/edit-image/resize.js
index 7d84a446..3bd4fb08 100644
--- a/commands/edit-image/resize.js
+++ b/commands/edit-image/resize.js
@@ -40,15 +40,11 @@ module.exports = class ResizeCommand extends Command {
}
async run(msg, { width, height, image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(width, height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0, width, height);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'resize.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(width, height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0, width, height);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'resize.png' }] });
}
};
diff --git a/commands/edit-image/rotate.js b/commands/edit-image/rotate.js
index 5424f255..99eb5451 100644
--- a/commands/edit-image/rotate.js
+++ b/commands/edit-image/rotate.js
@@ -33,24 +33,20 @@ module.exports = class RotateCommand extends Command {
}
async run(msg, { degrees, image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const newDims = this.adjustCanvasSize(data.width, data.height, degrees);
- const canvas = createCanvas(newDims.width, newDims.height);
- const ctx = canvas.getContext('2d');
- ctx.translate(canvas.width / 2, canvas.height / 2);
- ctx.rotate(degrees * (Math.PI / 180));
- ctx.translate(-(canvas.width / 2), -(canvas.height / 2));
- ctx.drawImage(data, (canvas.width / 2) - (data.width / 2), (canvas.height / 2) - (data.height / 2));
- ctx.translate(canvas.width / 2, canvas.height / 2);
- ctx.rotate(-degrees * (Math.PI / 180));
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'rotate.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const newDims = this.adjustCanvasSize(data.width, data.height, degrees);
+ const canvas = createCanvas(newDims.width, newDims.height);
+ const ctx = canvas.getContext('2d');
+ ctx.translate(canvas.width / 2, canvas.height / 2);
+ ctx.rotate(degrees * (Math.PI / 180));
+ ctx.translate(-(canvas.width / 2), -(canvas.height / 2));
+ ctx.drawImage(data, (canvas.width / 2) - (data.width / 2), (canvas.height / 2) - (data.height / 2));
+ ctx.translate(canvas.width / 2, canvas.height / 2);
+ ctx.rotate(-degrees * (Math.PI / 180));
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'rotate.png' }] });
}
adjustCanvasSize(width, height, angle) {
diff --git a/commands/edit-image/sepia.js b/commands/edit-image/sepia.js
index da97de0c..16b1bd6c 100644
--- a/commands/edit-image/sepia.js
+++ b/commands/edit-image/sepia.js
@@ -27,18 +27,14 @@ module.exports = class SepiaCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- sepia(ctx, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'sepia.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ sepia(ctx, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'sepia.png' }] });
}
};
diff --git a/commands/edit-image/shake.js b/commands/edit-image/shake.js
index b5eb61b3..8237c0e6 100644
--- a/commands/edit-image/shake.js
+++ b/commands/edit-image/shake.js
@@ -36,31 +36,27 @@ module.exports = class ShakeCommand extends Command {
}
async run(msg, { amount, image }) {
- try {
- const { body } = await request.get(image);
- const base = await loadImage(body);
- const ratio = base.width / base.height;
- const height = 512 / ratio;
- const encoder = new GIFEncoder(512, height);
- const canvas = createCanvas(512, height);
- const ctx = canvas.getContext('2d');
- const stream = encoder.createReadStream();
- encoder.start();
- encoder.setRepeat(0);
- encoder.setDelay(20);
- encoder.setQuality(200);
- const frames = this.generateFrames(amount);
- for (const { x, y } of frames) {
- ctx.clearRect(0, 0, canvas.width, canvas.height);
- ctx.drawImage(base, x, y, 512, height);
- encoder.addFrame(ctx);
- }
- encoder.finish();
- const buffer = await streamToArray(stream);
- return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'shake.gif' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const { body } = await request.get(image);
+ const base = await loadImage(body);
+ const ratio = base.width / base.height;
+ const height = 512 / ratio;
+ const encoder = new GIFEncoder(512, height);
+ const canvas = createCanvas(512, height);
+ const ctx = canvas.getContext('2d');
+ const stream = encoder.createReadStream();
+ encoder.start();
+ encoder.setRepeat(0);
+ encoder.setDelay(20);
+ encoder.setQuality(200);
+ const frames = this.generateFrames(amount);
+ for (const { x, y } of frames) {
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+ ctx.drawImage(base, x, y, 512, height);
+ encoder.addFrame(ctx);
}
+ encoder.finish();
+ const buffer = await streamToArray(stream);
+ return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'shake.gif' }] });
}
generateFrames(amount) {
diff --git a/commands/edit-image/silhouette.js b/commands/edit-image/silhouette.js
index 2bd10656..e47906aa 100644
--- a/commands/edit-image/silhouette.js
+++ b/commands/edit-image/silhouette.js
@@ -27,18 +27,14 @@ module.exports = class SilhouetteCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- silhouette(ctx, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'silhouette.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ silhouette(ctx, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'silhouette.png' }] });
}
};
diff --git a/commands/edit-image/sip.js b/commands/edit-image/sip.js
index 05b29188..d3d314a9 100644
--- a/commands/edit-image/sip.js
+++ b/commands/edit-image/sip.js
@@ -44,27 +44,23 @@ module.exports = class SipCommand extends Command {
}
async run(msg, { image, direction }) {
- try {
- const overlay = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'sip.png'));
- const { body } = await request.get(image);
- const base = await loadImage(body);
- const canvas = createCanvas(overlay.width, overlay.height);
- const scaleH = overlay.width / base.width;
- const height = Math.round(base.height * scaleH);
- const ctx = canvas.getContext('2d');
- ctx.fillRect(0, 0, overlay.width, overlay.height);
- if (direction === 'right') {
- ctx.translate(overlay.width, 0);
- ctx.scale(-1, 1);
- }
- ctx.drawImage(base, 0, 0, overlay.width, height);
- if (direction === 'right') ctx.setTransform(1, 0, 0, 1, 0, 0);
- ctx.drawImage(overlay, 0, 0);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'sip.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const overlay = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'sip.png'));
+ const { body } = await request.get(image);
+ const base = await loadImage(body);
+ const canvas = createCanvas(overlay.width, overlay.height);
+ const scaleH = overlay.width / base.width;
+ const height = Math.round(base.height * scaleH);
+ const ctx = canvas.getContext('2d');
+ ctx.fillRect(0, 0, overlay.width, overlay.height);
+ if (direction === 'right') {
+ ctx.translate(overlay.width, 0);
+ ctx.scale(-1, 1);
}
+ ctx.drawImage(base, 0, 0, overlay.width, height);
+ if (direction === 'right') ctx.setTransform(1, 0, 0, 1, 0, 0);
+ ctx.drawImage(overlay, 0, 0);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'sip.png' }] });
}
};
diff --git a/commands/edit-image/sketch.js b/commands/edit-image/sketch.js
index 935acf67..5bf1dfb0 100644
--- a/commands/edit-image/sketch.js
+++ b/commands/edit-image/sketch.js
@@ -36,20 +36,16 @@ module.exports = class SketchCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- await reactIfAble(msg, msg.author, LOADING_EMOJI_ID, '💬');
- const magik = gm(body);
- magik.colorspace('gray');
- magik.out('-sketch');
- magik.out('0x20+120');
- magik.setFormat('png');
- const attachment = await magikToBuffer(magik);
- reactIfAble(msg, msg.author, SUCCESS_EMOJI_ID, '✅');
- 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!`);
- }
+ const { body } = await request.get(image);
+ await reactIfAble(msg, msg.author, LOADING_EMOJI_ID, '💬');
+ const magik = gm(body);
+ magik.colorspace('gray');
+ magik.out('-sketch');
+ magik.out('0x20+120');
+ magik.setFormat('png');
+ const attachment = await magikToBuffer(magik);
+ reactIfAble(msg, msg.author, SUCCESS_EMOJI_ID, '✅');
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'sketch.png' }] });
}
};
diff --git a/commands/edit-image/spotify-now-playing.js b/commands/edit-image/spotify-now-playing.js
index 60a49844..b5c82502 100644
--- a/commands/edit-image/spotify-now-playing.js
+++ b/commands/edit-image/spotify-now-playing.js
@@ -59,29 +59,25 @@ module.exports = class SpotifyNowPlayingCommand extends Command {
}
async run(msg, { name, artist, image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'spotify-now-playing.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'white';
- ctx.fillRect(0, 0, base.width, base.height);
- const height = 504 / data.width;
- ctx.drawImage(data, 66, 132, 504, height * data.height);
- ctx.drawImage(base, 0, 0);
- ctx.textBaseline = 'top';
- ctx.textAlign = 'center';
- ctx.font = this.client.fonts.get('Noto-Bold.ttf').toCanvasString(25);
- ctx.fillStyle = 'white';
- ctx.fillText(name, base.width / 2, 685);
- ctx.fillStyle = '#bdbec2';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(20);
- ctx.fillText(artist, base.width / 2, 720);
- ctx.fillText('Xiao\'s Picks', base.width / 2, 65);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'spotify-now-playing.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'spotify-now-playing.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'white';
+ ctx.fillRect(0, 0, base.width, base.height);
+ const height = 504 / data.width;
+ ctx.drawImage(data, 66, 132, 504, height * data.height);
+ ctx.drawImage(base, 0, 0);
+ ctx.textBaseline = 'top';
+ ctx.textAlign = 'center';
+ ctx.font = this.client.fonts.get('Noto-Bold.ttf').toCanvasString(25);
+ ctx.fillStyle = 'white';
+ ctx.fillText(name, base.width / 2, 685);
+ ctx.fillStyle = '#bdbec2';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(20);
+ ctx.fillText(artist, base.width / 2, 720);
+ ctx.fillText('Xiao\'s Picks', base.width / 2, 65);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'spotify-now-playing.png' }] });
}
};
diff --git a/commands/edit-image/square.js b/commands/edit-image/square.js
index 043aff77..426513d2 100644
--- a/commands/edit-image/square.js
+++ b/commands/edit-image/square.js
@@ -26,16 +26,12 @@ module.exports = class SquareCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const dimensions = data.width <= data.height ? data.width : data.height;
- const canvas = createCanvas(dimensions, dimensions);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, (canvas.width / 2) - (data.width / 2), (canvas.height / 2) - (data.height / 2));
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'square.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const dimensions = data.width <= data.height ? data.width : data.height;
+ const canvas = createCanvas(dimensions, dimensions);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, (canvas.width / 2) - (data.width / 2), (canvas.height / 2) - (data.height / 2));
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'square.png' }] });
}
};
diff --git a/commands/edit-image/squish.js b/commands/edit-image/squish.js
index f5742ab5..7753f682 100644
--- a/commands/edit-image/squish.js
+++ b/commands/edit-image/squish.js
@@ -45,17 +45,13 @@ module.exports = class SquishCommand extends Command {
let command;
if (axis === 'x') command = '15%x100%';
if (axis === 'y') command = '100%x15%';
- try {
- const { body } = await request.get(image);
- const magik = gm(body);
- magik.out('-liquid-rescale');
- magik.out(command);
- magik.setFormat('png');
- 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!`);
- }
+ const { body } = await request.get(image);
+ const magik = gm(body);
+ magik.out('-liquid-rescale');
+ magik.out(command);
+ magik.setFormat('png');
+ 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' }] });
}
};
diff --git a/commands/edit-image/steam-card.js b/commands/edit-image/steam-card.js
index e4e7850b..d417759c 100644
--- a/commands/edit-image/steam-card.js
+++ b/commands/edit-image/steam-card.js
@@ -54,25 +54,21 @@ module.exports = class SteamCardCommand extends Command {
}
async run(msg, { name, image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'steam-card.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = '#feb2c1';
- ctx.fillRect(0, 0, base.width, base.height);
- const height = 205 / data.width;
- ctx.drawImage(data, 12, 19, 205, height * data.height);
- ctx.drawImage(base, 0, 0);
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(14);
- ctx.fillStyle = 'black';
- ctx.fillText(name, 16, 25);
- ctx.fillStyle = 'white';
- ctx.fillText(name, 15, 24);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'steam-card.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'steam-card.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = '#feb2c1';
+ ctx.fillRect(0, 0, base.width, base.height);
+ const height = 205 / data.width;
+ ctx.drawImage(data, 12, 19, 205, height * data.height);
+ ctx.drawImage(base, 0, 0);
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(14);
+ ctx.fillStyle = 'black';
+ ctx.fillText(name, 16, 25);
+ ctx.fillStyle = 'white';
+ ctx.fillText(name, 15, 24);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'steam-card.png' }] });
}
};
diff --git a/commands/edit-image/subtitle.js b/commands/edit-image/subtitle.js
index 4808bd39..2a6d6b5d 100644
--- a/commands/edit-image/subtitle.js
+++ b/commands/edit-image/subtitle.js
@@ -42,34 +42,30 @@ module.exports = class SubtitleCommand extends Command {
}
async run(msg, { text, image }) {
- try {
- const { body } = await request.get(image);
- const base = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- const fontSize = Math.round(base.height / 15);
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
+ const { body } = await request.get(image);
+ const base = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ const fontSize = Math.round(base.height / 15);
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
+ ctx.fillStyle = 'yellow';
+ ctx.textAlign = 'center';
+ const lines = await wrapText(ctx, text, base.width - 10);
+ if (!lines) return msg.reply('There\'s not enough width to subtitle this image.');
+ ctx.textBaseline = 'bottom';
+ const initial = base.height - ((lines.length - 1) * fontSize) - (fontSize / 2) - ((lines.length - 1) * 10);
+ for (let i = 0; i < lines.length; i++) {
+ const textHeight = initial + (i * fontSize) + (i * 10);
+ ctx.strokeStyle = 'black';
+ const rounded = Math.round(base.height / 100);
+ ctx.lineWidth = rounded < 1 ? 1 : rounded;
+ ctx.strokeText(lines[i], base.width / 2, textHeight);
ctx.fillStyle = 'yellow';
- ctx.textAlign = 'center';
- const lines = await wrapText(ctx, text, base.width - 10);
- if (!lines) return msg.reply('There\'s not enough width to subtitle this image.');
- ctx.textBaseline = 'bottom';
- const initial = base.height - ((lines.length - 1) * fontSize) - (fontSize / 2) - ((lines.length - 1) * 10);
- for (let i = 0; i < lines.length; i++) {
- const textHeight = initial + (i * fontSize) + (i * 10);
- ctx.strokeStyle = 'black';
- const rounded = Math.round(base.height / 100);
- ctx.lineWidth = rounded < 1 ? 1 : rounded;
- ctx.strokeText(lines[i], base.width / 2, textHeight);
- ctx.fillStyle = 'yellow';
- ctx.fillText(lines[i], base.width / 2, textHeight);
- }
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'subtitle.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ ctx.fillText(lines[i], base.width / 2, textHeight);
}
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'subtitle.png' }] });
}
};
diff --git a/commands/edit-image/swirl.js b/commands/edit-image/swirl.js
index bacfd3a9..bd642e23 100644
--- a/commands/edit-image/swirl.js
+++ b/commands/edit-image/swirl.js
@@ -41,16 +41,12 @@ module.exports = class SwirlCommand extends Command {
}
async run(msg, { degrees, image }) {
- try {
- const { body } = await request.get(image);
- const magik = gm(body);
- magik.swirl(degrees);
- magik.setFormat('png');
- 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!`);
- }
+ const { body } = await request.get(image);
+ const magik = gm(body);
+ magik.swirl(degrees);
+ magik.setFormat('png');
+ 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' }] });
}
};
diff --git a/commands/edit-image/tint.js b/commands/edit-image/tint.js
index e998cc9e..9219d325 100644
--- a/commands/edit-image/tint.js
+++ b/commands/edit-image/tint.js
@@ -33,17 +33,13 @@ module.exports = class TintCommand extends Command {
}
async run(msg, { color, image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- drawImageWithTint(ctx, data, color, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'tint.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ drawImageWithTint(ctx, data, color, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'tint.png' }] });
}
};
diff --git a/commands/edit-image/vignette.js b/commands/edit-image/vignette.js
index 6b81d2e6..72e3f50c 100644
--- a/commands/edit-image/vignette.js
+++ b/commands/edit-image/vignette.js
@@ -27,18 +27,14 @@ module.exports = class VignetteCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- vignette(ctx, data.width, data.height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'vignette.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ vignette(ctx, data.width, data.height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'vignette.png' }] });
}
};
diff --git a/commands/edit-image/wanted.js b/commands/edit-image/wanted.js
index e86a5252..3d183263 100644
--- a/commands/edit-image/wanted.js
+++ b/commands/edit-image/wanted.js
@@ -37,19 +37,15 @@ module.exports = class WantedCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'wanted.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- const { x, y, width, height } = centerImagePart(data, 430, 430, 150, 360);
- ctx.drawImage(data, x, y, width, height);
- sepia(ctx, x, y, width, height);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'wanted.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'wanted.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ const { x, y, width, height } = centerImagePart(data, 430, 430, 150, 360);
+ ctx.drawImage(data, x, y, width, height);
+ sepia(ctx, x, y, width, height);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'wanted.png' }] });
}
};
diff --git a/commands/edit-image/wild-pokemon.js b/commands/edit-image/wild-pokemon.js
index b790bd41..b27e8d64 100644
--- a/commands/edit-image/wild-pokemon.js
+++ b/commands/edit-image/wild-pokemon.js
@@ -48,22 +48,18 @@ module.exports = class WildPokemonCommand extends Command {
}
async run(msg, { name, image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'wild-pokemon.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- const { x, y, width, height } = centerImagePart(data, 100, 100, 227, 11);
- pixelize(ctx, canvas, data, 0.30, x, y, width, height);
- greyscale(ctx, x, y, width, height);
- ctx.textBaseline = 'top';
- ctx.font = this.client.fonts.get('PokemonGb.ttf').toCanvasString(16);
- ctx.fillText(name.toUpperCase(), 110, 203, 215);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'wild-pokemon.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'wild-pokemon.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ const { x, y, width, height } = centerImagePart(data, 100, 100, 227, 11);
+ pixelize(ctx, canvas, data, 0.30, x, y, width, height);
+ greyscale(ctx, x, y, width, height);
+ ctx.textBaseline = 'top';
+ ctx.font = this.client.fonts.get('PokemonGb.ttf').toCanvasString(16);
+ ctx.fillText(name.toUpperCase(), 110, 203, 215);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'wild-pokemon.png' }] });
}
};
diff --git a/commands/edit-image/you-died.js b/commands/edit-image/you-died.js
index 5b9cc01b..e7e7d936 100644
--- a/commands/edit-image/you-died.js
+++ b/commands/edit-image/you-died.js
@@ -36,21 +36,17 @@ module.exports = class YouDiedCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'you-died.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- drawImageWithTint(ctx, data, 'black', 0, 0, data.width, data.height);
- greyscale(ctx, 0, 0, data.width, data.height);
- const { x, y, width, height } = centerImage(base, data);
- ctx.drawImage(base, x, y, width, height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'you-died.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'you-died.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ drawImageWithTint(ctx, data, 'black', 0, 0, data.width, data.height);
+ greyscale(ctx, 0, 0, data.width, data.height);
+ const { x, y, width, height } = centerImage(base, data);
+ ctx.drawImage(base, x, y, width, height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'you-died.png' }] });
}
};
diff --git a/commands/edit-image/yu-gi-oh-gen.js b/commands/edit-image/yu-gi-oh-gen.js
index 11b35859..38988db6 100644
--- a/commands/edit-image/yu-gi-oh-gen.js
+++ b/commands/edit-image/yu-gi-oh-gen.js
@@ -70,87 +70,83 @@ module.exports = class YuGiOhGenCommand extends Command {
async run(msg, { type, image }) {
const id = Math.floor(Math.random() * 100000000);
const setID = Math.floor(Math.random() * 1000);
- try {
- const monsterType = await this.determineMonsterType(msg, type);
- if (!monsterType) return msg.say('Aborted card creation.');
- const name = await this.determineName(msg);
- if (!name) return msg.say('Aborted card creation.');
- const attribute = await this.determineAttribute(msg, type);
- if (!attribute) return msg.say('Aborted card creation.');
- const species = await this.determineType(msg, type);
- if (!species) return msg.say('Aborted card creation.');
- const effect = await this.determineEffect(msg, monsterType);
- if (!effect) return msg.say('Aborted card creation.');
- const level = await this.determineLevel(msg, type, monsterType);
- if (!level) return msg.say('Aborted card creation.');
- const atk = await this.determineAttack(msg, type);
- if (!atk) return msg.say('Aborted card creation.');
- const def = await this.determineDefense(msg, type, monsterType);
- if (!def) return msg.say('Aborted card creation.');
- const base = await loadImage(
- path.join(__dirname, '..', '..', 'assets', 'images', 'yu-gi-oh-gen', 'bases', `${monsterType}.png`)
+ const monsterType = await this.determineMonsterType(msg, type);
+ if (!monsterType) return msg.say('Aborted card creation.');
+ const name = await this.determineName(msg);
+ if (!name) return msg.say('Aborted card creation.');
+ const attribute = await this.determineAttribute(msg, type);
+ if (!attribute) return msg.say('Aborted card creation.');
+ const species = await this.determineType(msg, type);
+ if (!species) return msg.say('Aborted card creation.');
+ const effect = await this.determineEffect(msg, monsterType);
+ if (!effect) return msg.say('Aborted card creation.');
+ const level = await this.determineLevel(msg, type, monsterType);
+ if (!level) return msg.say('Aborted card creation.');
+ const atk = await this.determineAttack(msg, type);
+ if (!atk) return msg.say('Aborted card creation.');
+ const def = await this.determineDefense(msg, type, monsterType);
+ if (!def) return msg.say('Aborted card creation.');
+ const base = await loadImage(
+ path.join(__dirname, '..', '..', 'assets', 'images', 'yu-gi-oh-gen', 'bases', `${monsterType}.png`)
+ );
+ const atr = await loadImage(
+ path.join(__dirname, '..', '..', 'assets', 'images', 'yu-gi-oh-gen', 'atrs', `${attribute}.png`)
+ );
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'white';
+ ctx.fillRect(0, 0, base.width, base.height);
+ ctx.drawImage(this.squareImage(data), 98, 217, 617, 617);
+ ctx.drawImage(base, 0, 0);
+ ctx.drawImage(atr, 686, 55 + (monsterType === 'link' ? 4 : 0), 70, 70);
+ if (level > 0) {
+ const levelToUse = monsterType === 'xyz' ? 'rank' : 'level';
+ const levelI = await loadImage(
+ path.join(__dirname, '..', '..', 'assets', 'images', 'yu-gi-oh-gen', `${levelToUse}.png`)
);
- const atr = await loadImage(
- path.join(__dirname, '..', '..', 'assets', 'images', 'yu-gi-oh-gen', 'atrs', `${attribute}.png`)
- );
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'white';
- ctx.fillRect(0, 0, base.width, base.height);
- ctx.drawImage(this.squareImage(data), 98, 217, 617, 617);
- ctx.drawImage(base, 0, 0);
- ctx.drawImage(atr, 686, 55 + (monsterType === 'link' ? 4 : 0), 70, 70);
- if (level > 0) {
- const levelToUse = monsterType === 'xyz' ? 'rank' : 'level';
- const levelI = await loadImage(
- path.join(__dirname, '..', '..', 'assets', 'images', 'yu-gi-oh-gen', `${levelToUse}.png`)
- );
- for (let i = 0; i < level; i++) {
- let levelX;
- if (monsterType === 'xyz') levelX = 76 + (50 * i) + (5 * i);
- else levelX = 686 - (50 * i) - (5 * i);
- ctx.drawImage(levelI, levelX, 141, 50, 50);
- }
+ for (let i = 0; i < level; i++) {
+ let levelX;
+ if (monsterType === 'xyz') levelX = 76 + (50 * i) + (5 * i);
+ else levelX = 686 - (50 * i) - (5 * i);
+ ctx.drawImage(levelI, levelX, 141, 50, 50);
}
- ctx.fillStyle = monsterType === 'xyz' || monsterType === 'link' ? 'white' : 'black';
- ctx.textBaseline = 'top';
- ctx.font = this.client.fonts.get('Matrix Small Caps.ttf').toCanvasString(87);
- ctx.fillText(name, 60, 57, 620);
- ctx.fillStyle = 'black';
- if (type === 'monster') {
- ctx.font = this.client.fonts.get('Stone Serif Small Caps.ttf').toCanvasString(31);
- let typeStr = `[ ${firstUpperCase(species)} / ${firstUpperCase(monsterType)}`;
- if (monsterType !== 'normal' && monsterType !== 'effect' && monsterType !== 'token') {
- typeStr += ' / Effect';
- }
- typeStr += ' ]';
- ctx.fillText(typeStr, 60, 894);
- ctx.font = this.client.fonts.get('Stone Serif.ttf').toCanvasString(29);
- ctx.fillText(atk.padStart(4, ' '), 514, 1079);
- if (monsterType === 'link') ctx.fillText(def, 722, 1079);
- else ctx.fillText(def.padStart(4, ' '), 675, 1079);
- } else if (type === 'spell') {
- ctx.font = this.client.fonts.get('Stone Serif Small Caps.ttf').toCanvasString(35);
- ctx.fillText('[ Spell Card ]', 479, 141);
- } else if (type === 'trap') {
- ctx.font = this.client.fonts.get('Stone Serif Small Caps.ttf').toCanvasString(35);
- ctx.fillText('[ Trap Card ]', 489, 141);
- }
- const font = monsterType === 'normal' ? 'Stone Serif LT Italic.ttf' : 'Matrix Book.ttf';
- ctx.font = this.client.fonts.get(font).toCanvasString(27);
- const wrappedEffect = await wrapText(ctx, effect, 690);
- const trimmed = wrappedEffect.slice(0, type === 'monster' ? 4 : 6);
- ctx.fillText(trimmed.join('\n'), 63, 933 - (type === 'monster' ? 0 : 34));
- ctx.font = this.client.fonts.get('Stone Serif.ttf').toCanvasString(22);
- ctx.fillStyle = monsterType === 'xyz' ? 'white' : 'black';
- ctx.fillText(id.toString().padStart(8, '0'), 43, 1128);
- ctx.fillText(`XIAO-EN${setID.toString().padStart(3, '0')}`, 589 - (monsterType === 'link' ? 58 : 0), 849);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'yu-gi-oh-gen.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
+ ctx.fillStyle = monsterType === 'xyz' || monsterType === 'link' ? 'white' : 'black';
+ ctx.textBaseline = 'top';
+ ctx.font = this.client.fonts.get('Matrix Small Caps.ttf').toCanvasString(87);
+ ctx.fillText(name, 60, 57, 620);
+ ctx.fillStyle = 'black';
+ if (type === 'monster') {
+ ctx.font = this.client.fonts.get('Stone Serif Small Caps.ttf').toCanvasString(31);
+ let typeStr = `[ ${firstUpperCase(species)} / ${firstUpperCase(monsterType)}`;
+ if (monsterType !== 'normal' && monsterType !== 'effect' && monsterType !== 'token') {
+ typeStr += ' / Effect';
+ }
+ typeStr += ' ]';
+ ctx.fillText(typeStr, 60, 894);
+ ctx.font = this.client.fonts.get('Stone Serif.ttf').toCanvasString(29);
+ ctx.fillText(atk.padStart(4, ' '), 514, 1079);
+ if (monsterType === 'link') ctx.fillText(def, 722, 1079);
+ else ctx.fillText(def.padStart(4, ' '), 675, 1079);
+ } else if (type === 'spell') {
+ ctx.font = this.client.fonts.get('Stone Serif Small Caps.ttf').toCanvasString(35);
+ ctx.fillText('[ Spell Card ]', 479, 141);
+ } else if (type === 'trap') {
+ ctx.font = this.client.fonts.get('Stone Serif Small Caps.ttf').toCanvasString(35);
+ ctx.fillText('[ Trap Card ]', 489, 141);
+ }
+ const font = monsterType === 'normal' ? 'Stone Serif LT Italic.ttf' : 'Matrix Book.ttf';
+ ctx.font = this.client.fonts.get(font).toCanvasString(27);
+ const wrappedEffect = await wrapText(ctx, effect, 690);
+ const trimmed = wrappedEffect.slice(0, type === 'monster' ? 4 : 6);
+ ctx.fillText(trimmed.join('\n'), 63, 933 - (type === 'monster' ? 0 : 34));
+ ctx.font = this.client.fonts.get('Stone Serif.ttf').toCanvasString(22);
+ ctx.fillStyle = monsterType === 'xyz' ? 'white' : 'black';
+ ctx.fillText(id.toString().padStart(8, '0'), 43, 1128);
+ ctx.fillText(`XIAO-EN${setID.toString().padStart(3, '0')}`, 589 - (monsterType === 'link' ? 58 : 0), 849);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'yu-gi-oh-gen.png' }] });
}
squareImage(image) {
diff --git a/commands/edit-meme/3000-years.js b/commands/edit-meme/3000-years.js
index 177c4542..c09963be 100644
--- a/commands/edit-meme/3000-years.js
+++ b/commands/edit-meme/3000-years.js
@@ -36,18 +36,14 @@ module.exports = class ThreeThousandYearsCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', '3000-years.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- const { x, y, width, height } = centerImagePart(data, 200, 200, 461, 127);
- ctx.drawImage(data, x, y, width, height);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: '3000-years.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', '3000-years.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ const { x, y, width, height } = centerImagePart(data, 200, 200, 461, 127);
+ ctx.drawImage(data, x, y, width, height);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: '3000-years.png' }] });
}
};
diff --git a/commands/edit-meme/beautiful.js b/commands/edit-meme/beautiful.js
index 1805a4b1..59485cb9 100644
--- a/commands/edit-meme/beautiful.js
+++ b/commands/edit-meme/beautiful.js
@@ -42,20 +42,16 @@ module.exports = class BeautifulCommand extends Command {
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 128 });
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'beautiful.png'));
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'white';
- ctx.fillRect(0, 0, base.width, base.height);
- ctx.drawImage(avatar, 249, 24, 105, 105);
- ctx.drawImage(avatar, 249, 223, 105, 105);
- ctx.drawImage(base, 0, 0);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'beautiful.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'beautiful.png'));
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'white';
+ ctx.fillRect(0, 0, base.width, base.height);
+ ctx.drawImage(avatar, 249, 24, 105, 105);
+ ctx.drawImage(avatar, 249, 223, 105, 105);
+ ctx.drawImage(base, 0, 0);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'beautiful.png' }] });
}
};
diff --git a/commands/edit-meme/challenger.js b/commands/edit-meme/challenger.js
index a9d1205d..44a6088a 100644
--- a/commands/edit-meme/challenger.js
+++ b/commands/edit-meme/challenger.js
@@ -49,19 +49,15 @@ module.exports = class ChallengerCommand extends Command {
}
async run(msg, { image, silhouetted }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'challenger.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- const { x, y, width, height } = centerImagePart(data, 256, 256, 484, 98);
- ctx.drawImage(silhouetted ? this.silhouetteImage(data) : data, x, y, width, height);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'challenger.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'challenger.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ const { x, y, width, height } = centerImagePart(data, 256, 256, 484, 98);
+ ctx.drawImage(silhouetted ? this.silhouetteImage(data) : data, x, y, width, height);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'challenger.png' }] });
}
silhouetteImage(image) {
diff --git a/commands/edit-meme/crush.js b/commands/edit-meme/crush.js
index 4c6d0e71..b1488565 100644
--- a/commands/edit-meme/crush.js
+++ b/commands/edit-meme/crush.js
@@ -37,22 +37,18 @@ module.exports = class CrushCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'crush.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'white';
- ctx.fillRect(0, 0, base.width, base.height);
- ctx.rotate(-3.79 * (Math.PI / 180));
- const { x, y, width, height } = centerImagePart(data, 400, 400, 79, 472);
- ctx.drawImage(data, x, y, width, height);
- ctx.rotate(3.79 * (Math.PI / 180));
- ctx.drawImage(base, 0, 0);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'crush.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'crush.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'white';
+ ctx.fillRect(0, 0, base.width, base.height);
+ ctx.rotate(-3.79 * (Math.PI / 180));
+ const { x, y, width, height } = centerImagePart(data, 400, 400, 79, 472);
+ ctx.drawImage(data, x, y, width, height);
+ ctx.rotate(3.79 * (Math.PI / 180));
+ ctx.drawImage(base, 0, 0);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'crush.png' }] });
}
};
diff --git a/commands/edit-meme/deep-fry.js b/commands/edit-meme/deep-fry.js
index fa2e521a..700e6a32 100644
--- a/commands/edit-meme/deep-fry.js
+++ b/commands/edit-meme/deep-fry.js
@@ -27,19 +27,15 @@ module.exports = class DeepFryCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- desaturate(ctx, -20, 0, 0, data.width, data.height);
- contrast(ctx, 0, 0, data.width, data.height);
- const attachment = canvas.toBuffer('image/jpeg', { quality: 0.2 });
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'deep-fry.jpeg' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ desaturate(ctx, -20, 0, 0, data.width, data.height);
+ contrast(ctx, 0, 0, data.width, data.height);
+ const attachment = canvas.toBuffer('image/jpeg', { quality: 0.2 });
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'deep-fry.jpeg' }] });
}
};
diff --git a/commands/edit-meme/demotivational.js b/commands/edit-meme/demotivational.js
index f7170f25..4932078a 100644
--- a/commands/edit-meme/demotivational.js
+++ b/commands/edit-meme/demotivational.js
@@ -49,32 +49,28 @@ module.exports = class DemotivationalCommand extends Command {
}
async run(msg, { title, text, image }) {
- try {
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(750, 600);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'black';
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- const { y, width, height } = centerImagePart(data, 602, 402, 0, 44);
- const x = (canvas.width / 2) - (width / 2);
- ctx.fillStyle = 'white';
- ctx.fillRect(x - 4, y - 4, width + 8, height + 8);
- ctx.fillStyle = 'black';
- ctx.fillRect(x - 2, y - 2, width + 4, height + 4);
- ctx.fillStyle = 'white';
- ctx.fillRect(x, y, width, height);
- ctx.drawImage(data, x, y, width, height);
- ctx.textAlign = 'center';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(60);
- ctx.fillStyle = 'aquamarine';
- ctx.fillText(shortenText(ctx, title, 610), 375, 518);
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(27);
- ctx.fillStyle = 'white';
- ctx.fillText(shortenText(ctx, text, 610), 375, 565);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'demotivational-poster.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(750, 600);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'black';
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
+ const { y, width, height } = centerImagePart(data, 602, 402, 0, 44);
+ const x = (canvas.width / 2) - (width / 2);
+ ctx.fillStyle = 'white';
+ ctx.fillRect(x - 4, y - 4, width + 8, height + 8);
+ ctx.fillStyle = 'black';
+ ctx.fillRect(x - 2, y - 2, width + 4, height + 4);
+ ctx.fillStyle = 'white';
+ ctx.fillRect(x, y, width, height);
+ ctx.drawImage(data, x, y, width, height);
+ ctx.textAlign = 'center';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(60);
+ ctx.fillStyle = 'aquamarine';
+ ctx.fillText(shortenText(ctx, title, 610), 375, 518);
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(27);
+ ctx.fillStyle = 'white';
+ ctx.fillText(shortenText(ctx, text, 610), 375, 565);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'demotivational-poster.png' }] });
}
};
diff --git a/commands/edit-meme/dislike.js b/commands/edit-meme/dislike.js
index 7b98b553..10221d6c 100644
--- a/commands/edit-meme/dislike.js
+++ b/commands/edit-meme/dislike.js
@@ -36,21 +36,17 @@ module.exports = class DislikeCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const base = await loadImage(body);
- const plate = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'dislike.png'));
- const scaleH = plate.width / base.width;
- const height = Math.round(base.height * scaleH);
- const canvas = createCanvas(plate.width, plate.height + height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0, plate.width, height);
- ctx.drawImage(plate, 0, height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'dislike.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const base = await loadImage(body);
+ const plate = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'dislike.png'));
+ const scaleH = plate.width / base.width;
+ const height = Math.round(base.height * scaleH);
+ const canvas = createCanvas(plate.width, plate.height + height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0, plate.width, height);
+ ctx.drawImage(plate, 0, height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'dislike.png' }] });
}
};
diff --git a/commands/edit-meme/distracted-boyfriend.js b/commands/edit-meme/distracted-boyfriend.js
index 538efa8c..56b8051c 100644
--- a/commands/edit-meme/distracted-boyfriend.js
+++ b/commands/edit-meme/distracted-boyfriend.js
@@ -49,27 +49,23 @@ module.exports = class DistractedBoyfriendCommand extends Command {
const boyfriendAvatarURL = boyfriend.displayAvatarURL({ format: 'png', size: 256 });
const girlfriendAvatarURL = girlfriend.displayAvatarURL({ format: 'png', size: 256 });
const otherGirlAvatarURL = otherGirl.displayAvatarURL({ format: 'png', size: 256 });
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'distracted-boyfriend.png'));
- const boyfriendAvatarData = await request.get(boyfriendAvatarURL);
- const boyfriendAvatar = await loadImage(boyfriendAvatarData.body);
- const girlfriendAvatarData = await request.get(girlfriendAvatarURL);
- const girlfriendAvatar = await loadImage(girlfriendAvatarData.body);
- const otherGirlAvatarData = await request.get(otherGirlAvatarURL);
- const otherGirlAvatar = await loadImage(otherGirlAvatarData.body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.rotate(-18.06 * (Math.PI / 180));
- ctx.drawImage(boyfriendAvatar, 290, 165, 125, 125);
- ctx.rotate(18.06 * (Math.PI / 180));
- ctx.rotate(3.11 * (Math.PI / 180));
- ctx.drawImage(girlfriendAvatar, 539, 67, 100, 125);
- ctx.rotate(-3.11 * (Math.PI / 180));
- ctx.drawImage(otherGirlAvatar, 120, 96, 175, 175);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'distracted-boyfriend.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'distracted-boyfriend.png'));
+ const boyfriendAvatarData = await request.get(boyfriendAvatarURL);
+ const boyfriendAvatar = await loadImage(boyfriendAvatarData.body);
+ const girlfriendAvatarData = await request.get(girlfriendAvatarURL);
+ const girlfriendAvatar = await loadImage(girlfriendAvatarData.body);
+ const otherGirlAvatarData = await request.get(otherGirlAvatarURL);
+ const otherGirlAvatar = await loadImage(otherGirlAvatarData.body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.rotate(-18.06 * (Math.PI / 180));
+ ctx.drawImage(boyfriendAvatar, 290, 165, 125, 125);
+ ctx.rotate(18.06 * (Math.PI / 180));
+ ctx.rotate(3.11 * (Math.PI / 180));
+ ctx.drawImage(girlfriendAvatar, 539, 67, 100, 125);
+ ctx.rotate(-3.11 * (Math.PI / 180));
+ ctx.drawImage(otherGirlAvatar, 120, 96, 175, 175);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'distracted-boyfriend.png' }] });
}
};
diff --git a/commands/edit-meme/drakeposting.js b/commands/edit-meme/drakeposting.js
index 1a2bb831..a863d97d 100644
--- a/commands/edit-meme/drakeposting.js
+++ b/commands/edit-meme/drakeposting.js
@@ -48,40 +48,36 @@ module.exports = class DrakepostingCommand extends Command {
}
async run(msg, { nah, yeah }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'drakeposting.png'));
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.textAlign = 'center';
- ctx.textBaseline = 'top';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
- let fontSize = 50;
- while (ctx.measureText(nah).width > 3003) {
- fontSize--;
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
- }
- const nahLines = await wrapText(ctx, nah, 462);
- const nahTopMost = 256 - (((fontSize * nahLines.length) / 2) + ((10 * (nahLines.length - 1)) / 2));
- for (let i = 0; i < nahLines.length; i++) {
- const height = nahTopMost + ((fontSize + 10) * i);
- ctx.fillText(nahLines[i], 768, height);
- }
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
- fontSize = 50;
- while (ctx.measureText(yeah).width > 3003) {
- fontSize--;
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
- }
- const yeahLines = await wrapText(ctx, yeah, 462);
- const yeahTopMost = 768 - (((fontSize * yeahLines.length) / 2) + ((10 * (yeahLines.length - 1)) / 2));
- for (let i = 0; i < yeahLines.length; i++) {
- const height = yeahTopMost + ((fontSize + 10) * i);
- ctx.fillText(yeahLines[i], 768, height);
- }
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'drakeposting.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'drakeposting.png'));
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'top';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
+ let fontSize = 50;
+ while (ctx.measureText(nah).width > 3003) {
+ fontSize--;
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
}
+ const nahLines = await wrapText(ctx, nah, 462);
+ const nahTopMost = 256 - (((fontSize * nahLines.length) / 2) + ((10 * (nahLines.length - 1)) / 2));
+ for (let i = 0; i < nahLines.length; i++) {
+ const height = nahTopMost + ((fontSize + 10) * i);
+ ctx.fillText(nahLines[i], 768, height);
+ }
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
+ fontSize = 50;
+ while (ctx.measureText(yeah).width > 3003) {
+ fontSize--;
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
+ }
+ const yeahLines = await wrapText(ctx, yeah, 462);
+ const yeahTopMost = 768 - (((fontSize * yeahLines.length) / 2) + ((10 * (yeahLines.length - 1)) / 2));
+ for (let i = 0; i < yeahLines.length; i++) {
+ const height = yeahTopMost + ((fontSize + 10) * i);
+ ctx.fillText(yeahLines[i], 768, height);
+ }
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'drakeposting.png' }] });
}
};
diff --git a/commands/edit-meme/enslaved.js b/commands/edit-meme/enslaved.js
index fc86b243..c9c09d15 100644
--- a/commands/edit-meme/enslaved.js
+++ b/commands/edit-meme/enslaved.js
@@ -43,23 +43,19 @@ module.exports = class EnslavedCommand extends Command {
}
async run(msg, { name, image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'enslaved.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- const { x, y, width, height } = centerImagePart(data, 200, 200, 254, 145);
- ctx.drawImage(data, x, y, width, height);
- ctx.textBaseline = 'top';
- ctx.textAlign = 'center';
- ctx.fillStyle = 'white';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
- ctx.fillText(name.toLowerCase(), 365, 400, 240);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'enslaved.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'enslaved.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ const { x, y, width, height } = centerImagePart(data, 200, 200, 254, 145);
+ ctx.drawImage(data, x, y, width, height);
+ ctx.textBaseline = 'top';
+ ctx.textAlign = 'center';
+ ctx.fillStyle = 'white';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
+ ctx.fillText(name.toLowerCase(), 365, 400, 240);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'enslaved.png' }] });
}
};
diff --git a/commands/edit-meme/food-broke.js b/commands/edit-meme/food-broke.js
index 964dda68..c7e83a88 100644
--- a/commands/edit-meme/food-broke.js
+++ b/commands/edit-meme/food-broke.js
@@ -38,20 +38,16 @@ module.exports = class FoodBrokeCommand extends Command {
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 128 });
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'food-broke.png'));
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.drawImage(avatar, 23, 9, 125, 125);
- contrast(ctx, 23, 9, 125, 125);
- ctx.drawImage(avatar, 117, 382, 75, 75);
- contrast(ctx, 117, 382, 75, 75);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'food-broke.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'food-broke.png'));
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.drawImage(avatar, 23, 9, 125, 125);
+ contrast(ctx, 23, 9, 125, 125);
+ ctx.drawImage(avatar, 117, 382, 75, 75);
+ contrast(ctx, 117, 382, 75, 75);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'food-broke.png' }] });
}
};
diff --git a/commands/edit-meme/for-five-hours.js b/commands/edit-meme/for-five-hours.js
index 16ac7790..b3c99808 100644
--- a/commands/edit-meme/for-five-hours.js
+++ b/commands/edit-meme/for-five-hours.js
@@ -36,21 +36,17 @@ module.exports = class ForFiveHoursCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const base = await loadImage(body);
- const plate = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'for-five-hours.png'));
- const scaleH = plate.width / base.width;
- const height = Math.round(base.height * scaleH);
- const canvas = createCanvas(plate.width, plate.height + height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0, plate.width, height);
- ctx.drawImage(plate, 0, height + 1);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'for-five-hours.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const base = await loadImage(body);
+ const plate = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'for-five-hours.png'));
+ const scaleH = plate.width / base.width;
+ const height = Math.round(base.height * scaleH);
+ const canvas = createCanvas(plate.width, plate.height + height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0, plate.width, height);
+ ctx.drawImage(plate, 0, height + 1);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'for-five-hours.png' }] });
}
};
diff --git a/commands/edit-meme/girl-worth-fighting-for.js b/commands/edit-meme/girl-worth-fighting-for.js
index 08f4b47b..83752afd 100644
--- a/commands/edit-meme/girl-worth-fighting-for.js
+++ b/commands/edit-meme/girl-worth-fighting-for.js
@@ -43,18 +43,14 @@ module.exports = class GirlWorthFightingForCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'girl-worth-fighting-for.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- const { x, y, width, height } = centerImagePart(data, 150, 150, 380, 511);
- ctx.drawImage(data, x, y, width, height);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'girl-worth-fighting-for.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'girl-worth-fighting-for.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ const { x, y, width, height } = centerImagePart(data, 150, 150, 380, 511);
+ ctx.drawImage(data, x, y, width, height);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'girl-worth-fighting-for.png' }] });
}
};
diff --git a/commands/edit-meme/i-fear-no-man.js b/commands/edit-meme/i-fear-no-man.js
index fe365a54..70287c09 100644
--- a/commands/edit-meme/i-fear-no-man.js
+++ b/commands/edit-meme/i-fear-no-man.js
@@ -37,18 +37,14 @@ module.exports = class IFearNoManCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'i-fear-no-man.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- const { x, y, width, height } = centerImagePart(data, 169, 169, 167, 330);
- ctx.drawImage(data, x, y, width, height);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'i-fear-no-man.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'i-fear-no-man.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ const { x, y, width, height } = centerImagePart(data, 169, 169, 167, 330);
+ ctx.drawImage(data, x, y, width, height);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'i-fear-no-man.png' }] });
}
};
diff --git a/commands/edit-meme/kyon-gun.js b/commands/edit-meme/kyon-gun.js
index 0747fe9f..929953be 100644
--- a/commands/edit-meme/kyon-gun.js
+++ b/commands/edit-meme/kyon-gun.js
@@ -41,21 +41,17 @@ module.exports = class KyonGunCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'kyon-gun.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'black';
- ctx.fillRect(0, 0, base.width, base.height);
- const ratio = data.width / data.height;
- const width = Math.round(base.height * ratio);
- ctx.drawImage(data, (base.width / 2) - (width / 2), 0, width, base.height);
- ctx.drawImage(base, 0, 0);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'kyon-gun.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'kyon-gun.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'black';
+ ctx.fillRect(0, 0, base.width, base.height);
+ const ratio = data.width / data.height;
+ const width = Math.round(base.height * ratio);
+ ctx.drawImage(data, (base.width / 2) - (width / 2), 0, width, base.height);
+ ctx.drawImage(base, 0, 0);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'kyon-gun.png' }] });
}
};
diff --git a/commands/edit-meme/like.js b/commands/edit-meme/like.js
index b64f6861..48fd2e7b 100644
--- a/commands/edit-meme/like.js
+++ b/commands/edit-meme/like.js
@@ -36,21 +36,17 @@ module.exports = class LikeCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const base = await loadImage(body);
- const plate = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'like.png'));
- const scaleH = plate.width / base.width;
- const height = Math.round(base.height * scaleH);
- const canvas = createCanvas(plate.width, plate.height + height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0, plate.width, height);
- ctx.drawImage(plate, 0, height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'like.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const base = await loadImage(body);
+ const plate = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'like.png'));
+ const scaleH = plate.width / base.width;
+ const height = Math.round(base.height * scaleH);
+ const canvas = createCanvas(plate.width, plate.height + height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0, plate.width, height);
+ ctx.drawImage(plate, 0, height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'like.png' }] });
}
};
diff --git a/commands/edit-meme/look-at-this-photograph.js b/commands/edit-meme/look-at-this-photograph.js
index d648f33f..0c276ab8 100644
--- a/commands/edit-meme/look-at-this-photograph.js
+++ b/commands/edit-meme/look-at-this-photograph.js
@@ -36,19 +36,15 @@ module.exports = class LookAtThisPhotographCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'look-at-this-photograph.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.rotate(-13.5 * (Math.PI / 180));
- ctx.drawImage(data, 280, 218, 175, 125);
- ctx.rotate(13.5 * (Math.PI / 180));
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'look-at-this-photograph.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'look-at-this-photograph.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.rotate(-13.5 * (Math.PI / 180));
+ ctx.drawImage(data, 280, 218, 175, 125);
+ ctx.rotate(13.5 * (Math.PI / 180));
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'look-at-this-photograph.png' }] });
}
};
diff --git a/commands/edit-meme/look-what-karen-have.js b/commands/edit-meme/look-what-karen-have.js
index 0d6c8a9c..1de222e1 100644
--- a/commands/edit-meme/look-what-karen-have.js
+++ b/commands/edit-meme/look-what-karen-have.js
@@ -42,22 +42,18 @@ module.exports = class LookWhatKarenHaveCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'look-what-karen-have.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'white';
- ctx.fillRect(0, 0, base.width, base.height);
- ctx.rotate(-6.5 * (Math.PI / 180));
- const { x, y, width, height } = centerImagePart(data, 512, 512, 514, 50);
- ctx.drawImage(data, x, y, width, height);
- ctx.rotate(6.5 * (Math.PI / 180));
- ctx.drawImage(base, 0, 0);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'look-what-karen-have.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'look-what-karen-have.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'white';
+ ctx.fillRect(0, 0, base.width, base.height);
+ ctx.rotate(-6.5 * (Math.PI / 180));
+ const { x, y, width, height } = centerImagePart(data, 512, 512, 514, 50);
+ ctx.drawImage(data, x, y, width, height);
+ ctx.rotate(6.5 * (Math.PI / 180));
+ ctx.drawImage(base, 0, 0);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'look-what-karen-have.png' }] });
}
};
diff --git a/commands/edit-meme/meme-gen.js b/commands/edit-meme/meme-gen.js
index 72e2c128..8e68d9fb 100644
--- a/commands/edit-meme/meme-gen.js
+++ b/commands/edit-meme/meme-gen.js
@@ -50,44 +50,40 @@ module.exports = class MemeGenCommand extends Command {
}
async run(msg, { top, bottom, image }) {
- try {
- const { body } = await request.get(image);
- const base = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- const fontSize = Math.round(base.height / 10);
- ctx.font = this.client.fonts.get('Impact.ttf').toCanvasString(fontSize);
+ const { body } = await request.get(image);
+ const base = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ const fontSize = Math.round(base.height / 10);
+ ctx.font = this.client.fonts.get('Impact.ttf').toCanvasString(fontSize);
+ ctx.fillStyle = 'white';
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'top';
+ const topLines = await wrapText(ctx, top, base.width - 10);
+ if (!topLines) return msg.reply('There\'s not enough width to make a meme with this image.');
+ for (let i = 0; i < topLines.length; i++) {
+ const textHeight = (i * fontSize) + (i * 10);
+ ctx.strokeStyle = 'black';
+ ctx.lineWidth = 5;
+ ctx.strokeText(topLines[i], base.width / 2, textHeight);
ctx.fillStyle = 'white';
- ctx.textAlign = 'center';
- ctx.textBaseline = 'top';
- const topLines = await wrapText(ctx, top, base.width - 10);
- if (!topLines) return msg.reply('There\'s not enough width to make a meme with this image.');
- for (let i = 0; i < topLines.length; i++) {
- const textHeight = (i * fontSize) + (i * 10);
- ctx.strokeStyle = 'black';
- ctx.lineWidth = 5;
- ctx.strokeText(topLines[i], base.width / 2, textHeight);
- ctx.fillStyle = 'white';
- ctx.fillText(topLines[i], base.width / 2, textHeight);
- }
- const bottomLines = await wrapText(ctx, bottom, base.width - 10);
- if (!bottomLines) return msg.reply('There\'s not enough width to make a meme with this image.');
- ctx.textBaseline = 'bottom';
- const initial = base.height - ((bottomLines.length - 1) * fontSize) - ((bottomLines.length - 1) * 10);
- for (let i = 0; i < bottomLines.length; i++) {
- const textHeight = initial + (i * fontSize) + (i * 10);
- ctx.strokeStyle = 'black';
- ctx.lineWidth = 5;
- ctx.strokeText(bottomLines[i], base.width / 2, textHeight);
- ctx.fillStyle = 'white';
- ctx.fillText(bottomLines[i], base.width / 2, textHeight);
- }
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'meme-gen.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ ctx.fillText(topLines[i], base.width / 2, textHeight);
}
+ const bottomLines = await wrapText(ctx, bottom, base.width - 10);
+ if (!bottomLines) return msg.reply('There\'s not enough width to make a meme with this image.');
+ ctx.textBaseline = 'bottom';
+ const initial = base.height - ((bottomLines.length - 1) * fontSize) - ((bottomLines.length - 1) * 10);
+ for (let i = 0; i < bottomLines.length; i++) {
+ const textHeight = initial + (i * fontSize) + (i * 10);
+ ctx.strokeStyle = 'black';
+ ctx.lineWidth = 5;
+ ctx.strokeText(bottomLines[i], base.width / 2, textHeight);
+ ctx.fillStyle = 'white';
+ ctx.fillText(bottomLines[i], base.width / 2, textHeight);
+ }
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'meme-gen.png' }] });
}
};
diff --git a/commands/edit-meme/metamorphosis.js b/commands/edit-meme/metamorphosis.js
index 9648d354..05fd889b 100644
--- a/commands/edit-meme/metamorphosis.js
+++ b/commands/edit-meme/metamorphosis.js
@@ -49,21 +49,17 @@ module.exports = class MetamorphosisCommand extends Command {
}
async run(msg, { name, image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'metamorphosis.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- const { x, y, width, height } = centerImagePart(data, 200, 200, 412, 257);
- ctx.drawImage(data, x, y, width, height);
- ctx.textBaseline = 'top';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(20);
- ctx.fillText(`le ${name.toLowerCase()}`, 345, 466, 330);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'metamorphosis.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'metamorphosis.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ const { x, y, width, height } = centerImagePart(data, 200, 200, 412, 257);
+ ctx.drawImage(data, x, y, width, height);
+ ctx.textBaseline = 'top';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(20);
+ ctx.fillText(`le ${name.toLowerCase()}`, 345, 466, 330);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'metamorphosis.png' }] });
}
};
diff --git a/commands/edit-meme/my-collection-grows.js b/commands/edit-meme/my-collection-grows.js
index f8d3e666..16116611 100644
--- a/commands/edit-meme/my-collection-grows.js
+++ b/commands/edit-meme/my-collection-grows.js
@@ -37,22 +37,18 @@ module.exports = class MyCollectionGrowsCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'my-collection-grows.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'white';
- ctx.fillRect(0, 0, base.width, base.height);
- ctx.rotate(-14 * (Math.PI / 180));
- const { x, y, width, height } = centerImagePart(data, 425, 425, 145, 179);
- ctx.drawImage(data, x, y, width, height);
- ctx.rotate(14 * (Math.PI / 180));
- ctx.drawImage(base, 0, 0);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'my-collection-grows.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'my-collection-grows.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'white';
+ ctx.fillRect(0, 0, base.width, base.height);
+ ctx.rotate(-14 * (Math.PI / 180));
+ const { x, y, width, height } = centerImagePart(data, 425, 425, 145, 179);
+ ctx.drawImage(data, x, y, width, height);
+ ctx.rotate(14 * (Math.PI / 180));
+ ctx.drawImage(base, 0, 0);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'my-collection-grows.png' }] });
}
};
diff --git a/commands/edit-meme/nike-ad.js b/commands/edit-meme/nike-ad.js
index ca9d5ace..ef28f876 100644
--- a/commands/edit-meme/nike-ad.js
+++ b/commands/edit-meme/nike-ad.js
@@ -54,34 +54,30 @@ module.exports = class NikeAdCommand extends Command {
}
async run(msg, { image, something, sacrifice }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'nike-ad.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- drawImageWithTint(ctx, data, 'black', 0, 0, data.width, data.height);
- greyscale(ctx, 0, 0, data.width, data.height);
- const ratio = base.width / base.height;
- const width = data.width / 3;
- const height = Math.round(width / ratio);
- ctx.drawImage(base, (data.width / 2) - (width / 2), data.height - height, width, height);
- const fontSize = Math.round(data.height / 25);
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
- ctx.fillStyle = 'white';
- ctx.textAlign = 'center';
- const lines = await wrapText(ctx, `Believe in ${something}. Even if it means ${sacrifice}.`, data.width - 20);
- if (!lines) return msg.reply('There\'s not enough width to make a Nike ad with this image.');
- const initial = data.height / 2;
- for (let i = 0; i < lines.length; i++) {
- const textHeight = initial + (i * fontSize) + (i * 10);
- ctx.fillText(lines[i], data.width / 2, textHeight);
- }
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'nike-ad.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'nike-ad.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ drawImageWithTint(ctx, data, 'black', 0, 0, data.width, data.height);
+ greyscale(ctx, 0, 0, data.width, data.height);
+ const ratio = base.width / base.height;
+ const width = data.width / 3;
+ const height = Math.round(width / ratio);
+ ctx.drawImage(base, (data.width / 2) - (width / 2), data.height - height, width, height);
+ const fontSize = Math.round(data.height / 25);
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
+ ctx.fillStyle = 'white';
+ ctx.textAlign = 'center';
+ const lines = await wrapText(ctx, `Believe in ${something}. Even if it means ${sacrifice}.`, data.width - 20);
+ if (!lines) return msg.reply('There\'s not enough width to make a Nike ad with this image.');
+ const initial = data.height / 2;
+ for (let i = 0; i < lines.length; i++) {
+ const textHeight = initial + (i * fontSize) + (i * 10);
+ ctx.fillText(lines[i], data.width / 2, textHeight);
}
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'nike-ad.png' }] });
}
};
diff --git a/commands/edit-meme/panik-kalm-panik.js b/commands/edit-meme/panik-kalm-panik.js
index 0358814b..eec0bd46 100644
--- a/commands/edit-meme/panik-kalm-panik.js
+++ b/commands/edit-meme/panik-kalm-panik.js
@@ -49,52 +49,48 @@ module.exports = class PanikKalmPanikCommand extends Command {
}
async run(msg, { panik, kalm, panik2 }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'panik-kalm-panik.png'));
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.textAlign = 'center';
- ctx.textBaseline = 'top';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
- let fontSize = 40;
- while (ctx.measureText(panik).width > 1136) {
- fontSize--;
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
- }
- const panikLines = await wrapText(ctx, panik, 284);
- const panikTopMost = 130 - (((fontSize * panikLines.length) / 2) + ((10 * (panikLines.length - 1)) / 2));
- for (let i = 0; i < panikLines.length; i++) {
- const height = panikTopMost + ((fontSize + 10) * i);
- ctx.fillText(panikLines[i], 150, height);
- }
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
- fontSize = 40;
- while (ctx.measureText(kalm).width > 1136) {
- fontSize--;
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
- }
- const kalmLines = await wrapText(ctx, kalm, 284);
- const kalmTopMost = 430 - (((fontSize * kalmLines.length) / 2) + ((10 * (kalmLines.length - 1)) / 2));
- for (let i = 0; i < kalmLines.length; i++) {
- const height = kalmTopMost + ((fontSize + 10) * i);
- ctx.fillText(kalmLines[i], 150, height);
- }
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
- fontSize = 40;
- while (ctx.measureText(panik2).width > 1136) {
- fontSize--;
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
- }
- const panik2Lines = await wrapText(ctx, panik2, 284);
- const panik2TopMost = 730 - (((fontSize * panik2Lines.length) / 2) + ((10 * (panik2Lines.length - 1)) / 2));
- for (let i = 0; i < panik2Lines.length; i++) {
- const height = panik2TopMost + ((fontSize + 10) * i);
- ctx.fillText(panik2Lines[i], 150, height);
- }
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'panik-kalm-panik.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'panik-kalm-panik.png'));
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'top';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
+ let fontSize = 40;
+ while (ctx.measureText(panik).width > 1136) {
+ fontSize--;
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
}
+ const panikLines = await wrapText(ctx, panik, 284);
+ const panikTopMost = 130 - (((fontSize * panikLines.length) / 2) + ((10 * (panikLines.length - 1)) / 2));
+ for (let i = 0; i < panikLines.length; i++) {
+ const height = panikTopMost + ((fontSize + 10) * i);
+ ctx.fillText(panikLines[i], 150, height);
+ }
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
+ fontSize = 40;
+ while (ctx.measureText(kalm).width > 1136) {
+ fontSize--;
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
+ }
+ const kalmLines = await wrapText(ctx, kalm, 284);
+ const kalmTopMost = 430 - (((fontSize * kalmLines.length) / 2) + ((10 * (kalmLines.length - 1)) / 2));
+ for (let i = 0; i < kalmLines.length; i++) {
+ const height = kalmTopMost + ((fontSize + 10) * i);
+ ctx.fillText(kalmLines[i], 150, height);
+ }
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
+ fontSize = 40;
+ while (ctx.measureText(panik2).width > 1136) {
+ fontSize--;
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
+ }
+ const panik2Lines = await wrapText(ctx, panik2, 284);
+ const panik2TopMost = 730 - (((fontSize * panik2Lines.length) / 2) + ((10 * (panik2Lines.length - 1)) / 2));
+ for (let i = 0; i < panik2Lines.length; i++) {
+ const height = panik2TopMost + ((fontSize + 10) * i);
+ ctx.fillText(panik2Lines[i], 150, height);
+ }
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'panik-kalm-panik.png' }] });
}
};
diff --git a/commands/edit-meme/reaction-meme.js b/commands/edit-meme/reaction-meme.js
index 20dcf469..b7d329f1 100644
--- a/commands/edit-meme/reaction-meme.js
+++ b/commands/edit-meme/reaction-meme.js
@@ -41,32 +41,28 @@ module.exports = class ReactionMemeCommand extends Command {
}
async run(msg, { text, image }) {
- try {
- const { body } = await request.get(image);
- const base = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
- const lines = await wrapText(ctx, text, base.width - 10);
- const lineBreakLen = text.split('\n').length;
- const linesLen = (40 * lines.length)
- + (40 * (lineBreakLen - 1))
- + (14 * lines.length)
- + (14 * (lineBreakLen - 1))
- + 14;
- canvas.height += linesLen;
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
- ctx.textBaseline = 'top';
- ctx.fillStyle = 'white';
- ctx.fillRect(0, 0, base.width, linesLen);
- ctx.fillStyle = 'black';
- ctx.fillText(lines.join('\n'), 5, 5);
- ctx.drawImage(base, 0, linesLen);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'meme-gen-modern.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const base = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
+ const lines = await wrapText(ctx, text, base.width - 10);
+ const lineBreakLen = text.split('\n').length;
+ const linesLen = (40 * lines.length)
+ + (40 * (lineBreakLen - 1))
+ + (14 * lines.length)
+ + (14 * (lineBreakLen - 1))
+ + 14;
+ canvas.height += linesLen;
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
+ ctx.textBaseline = 'top';
+ ctx.fillStyle = 'white';
+ ctx.fillRect(0, 0, base.width, linesLen);
+ ctx.fillStyle = 'black';
+ ctx.fillText(lines.join('\n'), 5, 5);
+ ctx.drawImage(base, 0, linesLen);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'meme-gen-modern.png' }] });
}
};
diff --git a/commands/edit-meme/sexy-singles.js b/commands/edit-meme/sexy-singles.js
index 0d620544..4463b565 100644
--- a/commands/edit-meme/sexy-singles.js
+++ b/commands/edit-meme/sexy-singles.js
@@ -30,24 +30,20 @@ module.exports = class SexySinglesCommand extends Command {
}
async run(msg, { image }) {
- try {
- const { body } = await request.get(image);
- const base = await loadImage(body);
- const choice = Math.floor(Math.random() * count);
- const plate = await loadImage(
- path.join(__dirname, '..', '..', 'assets', 'images', 'sexy-singles', `${choice}.png`)
- );
- const scaleW = plate.height / base.height;
- const width = Math.round(base.width * scaleW);
- const canvas = createCanvas(plate.width + width, plate.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, plate.width, 0, width, plate.height);
- ctx.drawImage(plate, 0, 0);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'sexy-singles.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const base = await loadImage(body);
+ const choice = Math.floor(Math.random() * count);
+ const plate = await loadImage(
+ path.join(__dirname, '..', '..', 'assets', 'images', 'sexy-singles', `${choice}.png`)
+ );
+ const scaleW = plate.height / base.height;
+ const width = Math.round(base.width * scaleW);
+ const canvas = createCanvas(plate.width + width, plate.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, plate.width, 0, width, plate.height);
+ ctx.drawImage(plate, 0, 0);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'sexy-singles.png' }] });
}
};
diff --git a/commands/edit-meme/skyrim-skill.js b/commands/edit-meme/skyrim-skill.js
index f587a627..dfff4c49 100644
--- a/commands/edit-meme/skyrim-skill.js
+++ b/commands/edit-meme/skyrim-skill.js
@@ -49,28 +49,24 @@ module.exports = class SkyrimSkillCommand extends Command {
}
async run(msg, { skill, image }) {
- try {
- const { body } = await request.get(image);
- const base = await loadImage(body);
- const plate = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'skyrim-skill.png'));
- const scaleH = plate.width / base.width;
- const height = Math.round(base.height * scaleH);
- const canvas = createCanvas(plate.width, plate.height + height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0, plate.width, height);
- ctx.drawImage(plate, 0, height + 1);
- ctx.font = this.client.fonts.get('Futura Condensed.ttf').toCanvasString(77);
- ctx.textAlign = 'center';
- ctx.textBaseline = 'top';
- ctx.fillStyle = 'black';
- ctx.fillText(skill, 189 + 5, height + 75 + 3, 300);
- ctx.fillStyle = 'white';
- ctx.fillText(skill, 189, height + 75, 300);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'skyrim-skill.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(image);
+ const base = await loadImage(body);
+ const plate = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'skyrim-skill.png'));
+ const scaleH = plate.width / base.width;
+ const height = Math.round(base.height * scaleH);
+ const canvas = createCanvas(plate.width, plate.height + height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0, plate.width, height);
+ ctx.drawImage(plate, 0, height + 1);
+ ctx.font = this.client.fonts.get('Futura Condensed.ttf').toCanvasString(77);
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'top';
+ ctx.fillStyle = 'black';
+ ctx.fillText(skill, 189 + 5, height + 75 + 3, 300);
+ ctx.fillStyle = 'white';
+ ctx.fillText(skill, 189, height + 75, 300);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'skyrim-skill.png' }] });
}
};
diff --git a/commands/edit-meme/sora-selfie.js b/commands/edit-meme/sora-selfie.js
index a5e76b88..67047a2e 100644
--- a/commands/edit-meme/sora-selfie.js
+++ b/commands/edit-meme/sora-selfie.js
@@ -42,21 +42,17 @@ module.exports = class SoraSelfieCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'sora-selfie.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = 'black';
- ctx.fillRect(0, 0, base.width, base.height);
- const ratio = data.width / data.height;
- const width = Math.round(base.height * ratio);
- ctx.drawImage(data, (base.width / 2) - (width / 2), 0, width, base.height);
- ctx.drawImage(base, 0, 0);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'sora-selfie.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'sora-selfie.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.fillStyle = 'black';
+ ctx.fillRect(0, 0, base.width, base.height);
+ const ratio = data.width / data.height;
+ const width = Math.round(base.height * ratio);
+ ctx.drawImage(data, (base.width / 2) - (width / 2), 0, width, base.height);
+ ctx.drawImage(base, 0, 0);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'sora-selfie.png' }] });
}
};
diff --git a/commands/edit-meme/this-guy.js b/commands/edit-meme/this-guy.js
index 8184e3d6..72322cc2 100644
--- a/commands/edit-meme/this-guy.js
+++ b/commands/edit-meme/this-guy.js
@@ -37,18 +37,14 @@ module.exports = class ThisGuyCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'this-guy.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- const { x, y, width, height } = centerImagePart(data, 361, 361, 76, 62);
- ctx.drawImage(data, x, y, width, height);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'this-guy.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'this-guy.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ const { x, y, width, height } = centerImagePart(data, 361, 361, 76, 62);
+ ctx.drawImage(data, x, y, width, height);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'this-guy.png' }] });
}
};
diff --git a/commands/edit-meme/thug-life.js b/commands/edit-meme/thug-life.js
index 1ceea3a0..bba77512 100644
--- a/commands/edit-meme/thug-life.js
+++ b/commands/edit-meme/thug-life.js
@@ -37,23 +37,19 @@ module.exports = class ThugLifeCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'thug-life.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(data, 0, 0);
- greyscale(ctx, 0, 0, data.width, data.height);
- const ratio = base.width / base.height;
- const width = data.width / 2;
- const height = Math.round(width / ratio);
- ctx.drawImage(base, (data.width / 2) - (width / 2), data.height - height, width, height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'thug-life.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'thug-life.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(data, 0, 0);
+ greyscale(ctx, 0, 0, data.width, data.height);
+ const ratio = base.width / base.height;
+ const width = data.width / 2;
+ const height = Math.round(width / ratio);
+ ctx.drawImage(base, (data.width / 2) - (width / 2), data.height - height, width, height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'thug-life.png' }] });
}
};
diff --git a/commands/edit-meme/to-be-continued.js b/commands/edit-meme/to-be-continued.js
index b98c3857..10617877 100644
--- a/commands/edit-meme/to-be-continued.js
+++ b/commands/edit-meme/to-be-continued.js
@@ -36,22 +36,18 @@ module.exports = class ToBeContinuedCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'to-be-continued.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- drawImageWithTint(ctx, data, '#704214', 0, 0, data.width, data.height);
- const ratio = base.width / base.height;
- const width = canvas.width / 2;
- const height = Math.round(width / ratio);
- ctx.drawImage(base, 0, canvas.height - height, width, height);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'to-be-continued.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'to-be-continued.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ drawImageWithTint(ctx, data, '#704214', 0, 0, data.width, data.height);
+ const ratio = base.width / base.height;
+ const width = canvas.width / 2;
+ const height = Math.round(width / ratio);
+ ctx.drawImage(base, 0, canvas.height - height, width, height);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'to-be-continued.png' }] });
}
};
diff --git a/commands/edit-meme/tuxedo-pooh.js b/commands/edit-meme/tuxedo-pooh.js
index 7e2e27db..0e7453d8 100644
--- a/commands/edit-meme/tuxedo-pooh.js
+++ b/commands/edit-meme/tuxedo-pooh.js
@@ -48,40 +48,36 @@ module.exports = class TuxedoPoohCommand extends Command {
}
async run(msg, { normal, tuxedo }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'tuxedo-pooh.png'));
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.textAlign = 'center';
- ctx.textBaseline = 'top';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
- let fontSize = 50;
- while (ctx.measureText(normal).width > 1320) {
- fontSize--;
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
- }
- const normalLines = await wrapText(ctx, normal, 440);
- const normalTopMost = 145 - (((fontSize * normalLines.length) / 2) + ((10 * (normalLines.length - 1)) / 2));
- for (let i = 0; i < normalLines.length; i++) {
- const height = normalTopMost + ((fontSize + 10) * i);
- ctx.fillText(normalLines[i], 570, height);
- }
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
- fontSize = 50;
- while (ctx.measureText(tuxedo).width > 1320) {
- fontSize--;
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
- }
- const tuxedoLines = await wrapText(ctx, tuxedo, 440);
- const tuxedoTopMost = 436 - (((fontSize * tuxedoLines.length) / 2) + ((10 * (tuxedoLines.length - 1)) / 2));
- for (let i = 0; i < tuxedoLines.length; i++) {
- const height = tuxedoTopMost + ((fontSize + 10) * i);
- ctx.fillText(tuxedoLines[i], 570, height);
- }
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'tuxedo-pooh.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'tuxedo-pooh.png'));
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'top';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
+ let fontSize = 50;
+ while (ctx.measureText(normal).width > 1320) {
+ fontSize--;
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
}
+ const normalLines = await wrapText(ctx, normal, 440);
+ const normalTopMost = 145 - (((fontSize * normalLines.length) / 2) + ((10 * (normalLines.length - 1)) / 2));
+ for (let i = 0; i < normalLines.length; i++) {
+ const height = normalTopMost + ((fontSize + 10) * i);
+ ctx.fillText(normalLines[i], 570, height);
+ }
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(50);
+ fontSize = 50;
+ while (ctx.measureText(tuxedo).width > 1320) {
+ fontSize--;
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
+ }
+ const tuxedoLines = await wrapText(ctx, tuxedo, 440);
+ const tuxedoTopMost = 436 - (((fontSize * tuxedoLines.length) / 2) + ((10 * (tuxedoLines.length - 1)) / 2));
+ for (let i = 0; i < tuxedoLines.length; i++) {
+ const height = tuxedoTopMost + ((fontSize + 10) * i);
+ ctx.fillText(tuxedoLines[i], 570, height);
+ }
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'tuxedo-pooh.png' }] });
}
};
diff --git a/commands/edit-meme/ugly.js b/commands/edit-meme/ugly.js
index b22acd1f..99997d96 100644
--- a/commands/edit-meme/ugly.js
+++ b/commands/edit-meme/ugly.js
@@ -37,18 +37,14 @@ module.exports = class UglyCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'ugly.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- const { x, y, width, height } = centerImagePart(data, 170, 170, 120, 52);
- ctx.drawImage(data, x, y, width, height);
- ctx.drawImage(base, 0, 0);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'ugly.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'ugly.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ const { x, y, width, height } = centerImagePart(data, 170, 170, 120, 52);
+ ctx.drawImage(data, x, y, width, height);
+ ctx.drawImage(base, 0, 0);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'ugly.png' }] });
}
};
diff --git a/commands/edit-meme/ultimate-tattoo.js b/commands/edit-meme/ultimate-tattoo.js
index 69aa311f..be260660 100644
--- a/commands/edit-meme/ultimate-tattoo.js
+++ b/commands/edit-meme/ultimate-tattoo.js
@@ -37,20 +37,16 @@ module.exports = class UltimateTattooCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'ultimate-tattoo.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.rotate(-10 * (Math.PI / 180));
- const { x, y, width, height } = centerImagePart(data, 300, 300, 84, 690);
- ctx.drawImage(data, x, y, width, height);
- ctx.rotate(10 * (Math.PI / 180));
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'ultimate-tattoo.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'ultimate-tattoo.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.rotate(-10 * (Math.PI / 180));
+ const { x, y, width, height } = centerImagePart(data, 300, 300, 84, 690);
+ ctx.drawImage(data, x, y, width, height);
+ ctx.rotate(10 * (Math.PI / 180));
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'ultimate-tattoo.png' }] });
}
};
diff --git a/commands/edit-meme/vietnam-flashbacks.js b/commands/edit-meme/vietnam-flashbacks.js
index 9992d9c6..45335bb6 100644
--- a/commands/edit-meme/vietnam-flashbacks.js
+++ b/commands/edit-meme/vietnam-flashbacks.js
@@ -35,22 +35,18 @@ module.exports = class VietnamFlashbacksCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'vietnam-flashbacks.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(data.width, data.height);
- const ctx = canvas.getContext('2d');
- const ratio = base.width / base.height;
- const width = Math.round(data.height * ratio);
- ctx.drawImage(base, (data.width / 2) - (width / 2), 0, width, data.height);
- ctx.globalAlpha = 0.675;
- ctx.drawImage(data, 0, 0);
- const attachment = canvas.toBuffer();
- if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
- return msg.say({ files: [{ attachment, name: 'vietnam-flashbacks.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'vietnam-flashbacks.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(data.width, data.height);
+ const ctx = canvas.getContext('2d');
+ const ratio = base.width / base.height;
+ const width = Math.round(data.height * ratio);
+ ctx.drawImage(base, (data.width / 2) - (width / 2), 0, width, data.height);
+ ctx.globalAlpha = 0.675;
+ ctx.drawImage(data, 0, 0);
+ const attachment = canvas.toBuffer();
+ if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
+ return msg.say({ files: [{ attachment, name: 'vietnam-flashbacks.png' }] });
}
};
diff --git a/commands/edit-meme/whiteboard.js b/commands/edit-meme/whiteboard.js
index 0e4a0853..a3c8d03d 100644
--- a/commands/edit-meme/whiteboard.js
+++ b/commands/edit-meme/whiteboard.js
@@ -47,40 +47,36 @@ module.exports = class WhiteboardCommand extends Command {
}
async run(msg, { initial, resolved }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'whiteboard.png'));
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.textAlign = 'center';
- ctx.textBaseline = 'top';
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(46);
- let fontSize = 46;
- while (ctx.measureText(initial).width > 608) {
- fontSize--;
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
- }
- const initialLines = await wrapText(ctx, initial, 405);
- const initialTopMost = 111 - (((fontSize * initialLines.length) / 2) + ((10 * (initialLines.length - 1)) / 2));
- for (let i = 0; i < initialLines.length; i++) {
- const height = initialTopMost + ((fontSize + 10) * i);
- ctx.fillText(initialLines[i], 210, height);
- }
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
- fontSize = 40;
- while (ctx.measureText(resolved).width > 551) {
- fontSize--;
- ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
- }
- const resolveLines = await wrapText(ctx, resolved, 367);
- const resolveTopMost = 500 - (((fontSize * resolveLines.length) / 2) + ((10 * (resolveLines.length - 1)) / 2));
- for (let i = 0; i < resolveLines.length; i++) {
- const height = resolveTopMost + ((fontSize + 10) * i);
- ctx.fillText(resolveLines[i], 195, height);
- }
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'whiteboard.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'whiteboard.png'));
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'top';
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(46);
+ let fontSize = 46;
+ while (ctx.measureText(initial).width > 608) {
+ fontSize--;
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
}
+ const initialLines = await wrapText(ctx, initial, 405);
+ const initialTopMost = 111 - (((fontSize * initialLines.length) / 2) + ((10 * (initialLines.length - 1)) / 2));
+ for (let i = 0; i < initialLines.length; i++) {
+ const height = initialTopMost + ((fontSize + 10) * i);
+ ctx.fillText(initialLines[i], 210, height);
+ }
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
+ fontSize = 40;
+ while (ctx.measureText(resolved).width > 551) {
+ fontSize--;
+ ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
+ }
+ const resolveLines = await wrapText(ctx, resolved, 367);
+ const resolveTopMost = 500 - (((fontSize * resolveLines.length) / 2) + ((10 * (resolveLines.length - 1)) / 2));
+ for (let i = 0; i < resolveLines.length; i++) {
+ const height = resolveTopMost + ((fontSize + 10) * i);
+ ctx.fillText(resolveLines[i], 195, height);
+ }
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'whiteboard.png' }] });
}
};
diff --git a/commands/edit-meme/worse-than-hitler.js b/commands/edit-meme/worse-than-hitler.js
index 6ed39c18..27b7612d 100644
--- a/commands/edit-meme/worse-than-hitler.js
+++ b/commands/edit-meme/worse-than-hitler.js
@@ -37,17 +37,13 @@ module.exports = class WorseThanHitlerCommand extends Command {
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 256 });
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'worse-than-hitler.png'));
- const { body } = await request.get(avatarURL);
- const avatar = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.drawImage(avatar, 47, 42, 140, 140);
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'worse-than-hitler.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'worse-than-hitler.png'));
+ const { body } = await request.get(avatarURL);
+ const avatar = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.drawImage(avatar, 47, 42, 140, 140);
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'worse-than-hitler.png' }] });
}
};
diff --git a/commands/edit-meme/worthless.js b/commands/edit-meme/worthless.js
index faed6ec5..6471770c 100644
--- a/commands/edit-meme/worthless.js
+++ b/commands/edit-meme/worthless.js
@@ -37,26 +37,22 @@ module.exports = class WorthlessCommand extends Command {
}
async run(msg, { image }) {
- try {
- const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'worthless.png'));
- const { body } = await request.get(image);
- const data = await loadImage(body);
- const canvas = createCanvas(base.width, base.height);
- const ctx = canvas.getContext('2d');
- ctx.drawImage(base, 0, 0);
- ctx.rotate(6 * (Math.PI / 180));
- const center1 = centerImagePart(data, 400, 400, 496, 183);
- ctx.drawImage(data, center1.x, center1.y, center1.width, center1.height);
- ctx.rotate(-6 * (Math.PI / 180));
- ctx.translate(canvas.width / 2, canvas.height / 2);
- ctx.rotate(160 * (Math.PI / 180));
- ctx.translate(-(canvas.width / 2), -(canvas.height / 2));
- const center2 = centerImagePart(data, 75, 75, 625, 55);
- ctx.drawImage(data, center2.x, center2.y, center2.width, center2.height);
- ctx.rotate(-160 * (Math.PI / 180));
- return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'worthless.png' }] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'worthless.png'));
+ const { body } = await request.get(image);
+ const data = await loadImage(body);
+ const canvas = createCanvas(base.width, base.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(base, 0, 0);
+ ctx.rotate(6 * (Math.PI / 180));
+ const center1 = centerImagePart(data, 400, 400, 496, 183);
+ ctx.drawImage(data, center1.x, center1.y, center1.width, center1.height);
+ ctx.rotate(-6 * (Math.PI / 180));
+ ctx.translate(canvas.width / 2, canvas.height / 2);
+ ctx.rotate(160 * (Math.PI / 180));
+ ctx.translate(-(canvas.width / 2), -(canvas.height / 2));
+ const center2 = centerImagePart(data, 75, 75, 625, 55);
+ ctx.drawImage(data, center2.x, center2.y, center2.width, center2.height);
+ ctx.rotate(-160 * (Math.PI / 180));
+ return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'worthless.png' }] });
}
};
diff --git a/commands/edit-number/currency.js b/commands/edit-number/currency.js
index 77f0d432..68313a42 100644
--- a/commands/edit-number/currency.js
+++ b/commands/edit-number/currency.js
@@ -49,14 +49,10 @@ module.exports = class CurrencyCommand extends Command {
if (!this.currencies[base]) return msg.say('You provided an invalid base currency code.');
if (!this.currencies[target]) return msg.say('You provided an invalid target currency code.');
if (base === target) return msg.say(`Converting ${base} to ${target} is the same value, dummy.`);
- try {
- const rate = await this.fetchRate(base, target);
- const baseName = this.currencies[base];
- const targetName = this.currencies[target];
- return msg.say(`${formatNumber(amount)} ${baseName} is ${formatNumber(amount * rate)} ${targetName}.`);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const rate = await this.fetchRate(base, target);
+ const baseName = this.currencies[base];
+ const targetName = this.currencies[target];
+ return msg.say(`${formatNumber(amount)} ${baseName} is ${formatNumber(amount * rate)} ${targetName}.`);
}
async fetchCurrencies() {
diff --git a/commands/edit-text/cow-say.js b/commands/edit-text/cow-say.js
index 8e4e1313..660cfe08 100644
--- a/commands/edit-text/cow-say.js
+++ b/commands/edit-text/cow-say.js
@@ -28,16 +28,12 @@ module.exports = class CowSayCommand extends Command {
}
async run(msg, { text }) {
- try {
- const { body } = await request
- .get('http://cowsay.morecode.org/say')
- .query({
- message: text,
- format: 'json'
- });
- return msg.code(null, body.cow);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request
+ .get('http://cowsay.morecode.org/say')
+ .query({
+ message: text,
+ format: 'json'
+ });
+ return msg.code(null, body.cow);
}
};
diff --git a/commands/edit-text/lolcat.js b/commands/edit-text/lolcat.js
index 2942f4fc..e575c837 100644
--- a/commands/edit-text/lolcat.js
+++ b/commands/edit-text/lolcat.js
@@ -29,15 +29,11 @@ module.exports = class LolcatCommand extends Command {
}
async run(msg, { from }) {
- try {
- const { text } = await request
- .get('https://speaklolcat.com/')
- .query({ from });
- const $ = cheerio.load(text);
- const translated = $('textarea[id="to"]').first().text();
- return msg.say(translated);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { text } = await request
+ .get('https://speaklolcat.com/')
+ .query({ from });
+ const $ = cheerio.load(text);
+ const translated = $('textarea[id="to"]').first().text();
+ return msg.say(translated);
}
};
diff --git a/commands/edit-text/shorten-url.js b/commands/edit-text/shorten-url.js
index 51b0cd12..4ed9d96f 100644
--- a/commands/edit-text/shorten-url.js
+++ b/commands/edit-text/shorten-url.js
@@ -41,7 +41,7 @@ module.exports = class ShortenUrlCommand extends Command {
return msg.say(body.link);
} catch (err) {
if (err.status === 400) return msg.reply('You provided an invalid URL. Please try again.');
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ throw err;
}
}
};
diff --git a/commands/edit-text/translate.js b/commands/edit-text/translate.js
index c7d49be6..729ac881 100644
--- a/commands/edit-text/translate.js
+++ b/commands/edit-text/translate.js
@@ -55,16 +55,12 @@ module.exports = class TranslateCommand extends Command {
}
async run(msg, { text, target, base }) {
- try {
- const { text: result, from } = await translate(text, { to: target, from: base });
- const embed = new MessageEmbed()
- .setColor(0x4285F4)
- .setFooter('Powered by Google Translate', 'https://i.imgur.com/h3RoHyp.png')
- .addField(`❯ From: ${translate.languages[from.language.iso]}`, from.text.value || text)
- .addField(`❯ To: ${translate.languages[target]}`, result);
- return msg.embed(embed);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { text: result, from } = await translate(text, { to: target, from: base });
+ const embed = new MessageEmbed()
+ .setColor(0x4285F4)
+ .setFooter('Powered by Google Translate', 'https://i.imgur.com/h3RoHyp.png')
+ .addField(`❯ From: ${translate.languages[from.language.iso]}`, from.text.value || text)
+ .addField(`❯ To: ${translate.languages[target]}`, result);
+ return msg.embed(embed);
}
};
diff --git a/commands/events/anime-airing.js b/commands/events/anime-airing.js
index d694aa13..03e20d4b 100644
--- a/commands/events/anime-airing.js
+++ b/commands/events/anime-airing.js
@@ -41,21 +41,17 @@ module.exports = class AnimeAiringCommand extends Command {
}
async run(msg) {
- try {
- const anime = await this.getList();
- if (!anime) return msg.say('No anime air today...');
- const mapped = anime.sort((a, b) => a.airingAt - b.airingAt).map(ani => {
- const title = ani.media.title.english || ani.media.title.romaji;
- const airingAt = moment(ani.airingAt * 1000).tz('Asia/Tokyo').format('h:mm A');
- return `• ${title} (@${airingAt} JST)`;
- });
- return msg.say(stripIndents`
- **Anime Airing on ${moment().tz('Asia/Tokyo').format('dddd, MMMM Do, YYYY')}**
- ${mapped.join('\n')}
- `);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const anime = await this.getList();
+ if (!anime) return msg.say('No anime air today...');
+ const mapped = anime.sort((a, b) => a.airingAt - b.airingAt).map(ani => {
+ const title = ani.media.title.english || ani.media.title.romaji;
+ const airingAt = moment(ani.airingAt * 1000).tz('Asia/Tokyo').format('h:mm A');
+ return `• ${title} (@${airingAt} JST)`;
+ });
+ return msg.say(stripIndents`
+ **Anime Airing on ${moment().tz('Asia/Tokyo').format('dddd, MMMM Do, YYYY')}**
+ ${mapped.join('\n')}
+ `);
}
async getList() {
diff --git a/commands/events/apod.js b/commands/events/apod.js
index c2ea3e5a..7711e472 100644
--- a/commands/events/apod.js
+++ b/commands/events/apod.js
@@ -25,26 +25,22 @@ module.exports = class ApodCommand extends Command {
}
async run(msg) {
- try {
- const { body } = await request
- .get('https://api.nasa.gov/planetary/apod')
- .query({ api_key: GOV_KEY });
- const embed = new MessageEmbed()
- .setTitle(body.title)
- .setDescription(shorten(body.explanation))
- .setColor(0x2E528E)
- .setAuthor(
- 'Astronomy Picture of the Day',
- 'https://i.imgur.com/Wh8jY9c.png',
- 'https://apod.nasa.gov/apod/astropix.html'
- )
- .setImage(body.media_type === 'image' ? body.url : null)
- .setURL(body.url)
- .setFooter(`Image Credits: ${body.copyright ? body.copyright.replaceAll('\n', '/') : 'Public Domain'}`)
- .setTimestamp();
- return msg.embed(embed);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request
+ .get('https://api.nasa.gov/planetary/apod')
+ .query({ api_key: GOV_KEY });
+ const embed = new MessageEmbed()
+ .setTitle(body.title)
+ .setDescription(shorten(body.explanation))
+ .setColor(0x2E528E)
+ .setAuthor(
+ 'Astronomy Picture of the Day',
+ 'https://i.imgur.com/Wh8jY9c.png',
+ 'https://apod.nasa.gov/apod/astropix.html'
+ )
+ .setImage(body.media_type === 'image' ? body.url : null)
+ .setURL(body.url)
+ .setFooter(`Image Credits: ${body.copyright ? body.copyright.replaceAll('\n', '/') : 'Public Domain'}`)
+ .setTimestamp();
+ return msg.embed(embed);
}
};
diff --git a/commands/events/google-doodle.js b/commands/events/google-doodle.js
index 89cfe2f7..92f6ab8d 100644
--- a/commands/events/google-doodle.js
+++ b/commands/events/google-doodle.js
@@ -40,14 +40,10 @@ module.exports = class GoogleDoodleCommand extends Command {
const now = new Date();
if (latest) month = now.getMonth() + 1;
if (!year) year = now.getFullYear();
- try {
- const { body } = await request.get(`https://www.google.com/doodles/json/${year}/${month}`);
- if (!body.length) return msg.say('Could not find any results.');
- const data = body[latest ? 0 : Math.floor(Math.random() * body.length)];
- const runDate = moment.utc(data.run_date_array.join('-')).format('MMMM Do, YYYY');
- return msg.say(`${runDate}: ${data.share_text}`, { files: [`https:${data.url}`] });
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const { body } = await request.get(`https://www.google.com/doodles/json/${year}/${month}`);
+ if (!body.length) return msg.say('Could not find any results.');
+ const data = body[latest ? 0 : Math.floor(Math.random() * body.length)];
+ const runDate = moment.utc(data.run_date_array.join('-')).format('MMMM Do, YYYY');
+ return msg.say(`${runDate}: ${data.share_text}`, { files: [`https:${data.url}`] });
}
};
diff --git a/commands/events/horoscope.js b/commands/events/horoscope.js
index 082d9188..262d79f1 100644
--- a/commands/events/horoscope.js
+++ b/commands/events/horoscope.js
@@ -35,20 +35,16 @@ module.exports = class HoroscopeCommand extends Command {
}
async run(msg, { sign }) {
- try {
- const horoscope = await this.fetchHoroscope(sign);
- const embed = new MessageEmbed()
- .setColor(0x9797FF)
- .setTitle(`Horoscope for ${firstUpperCase(sign)}...`)
- .setURL(`https://astrology.tv/horoscope/signs/${sign}/`)
- .setFooter('© Kelli Fox, The Astrologer')
- .setThumbnail(this.getImageURL(sign))
- .setTimestamp()
- .setDescription(horoscope);
- return msg.embed(embed);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ const horoscope = await this.fetchHoroscope(sign);
+ const embed = new MessageEmbed()
+ .setColor(0x9797FF)
+ .setTitle(`Horoscope for ${firstUpperCase(sign)}...`)
+ .setURL(`https://astrology.tv/horoscope/signs/${sign}/`)
+ .setFooter('© Kelli Fox, The Astrologer')
+ .setThumbnail(this.getImageURL(sign))
+ .setTimestamp()
+ .setDescription(horoscope);
+ return msg.embed(embed);
}
async fetchHoroscope(sign) {
diff --git a/commands/events/neko-atsume-password.js b/commands/events/neko-atsume-password.js
index ca9b81cf..cac9d141 100644
--- a/commands/events/neko-atsume-password.js
+++ b/commands/events/neko-atsume-password.js
@@ -43,17 +43,13 @@ module.exports = class NekoAtsumePasswordCommand extends Command {
}
async run(msg, { locale }) {
- try {
- const data = await this.fetchPassword(locale);
- return msg.say(stripIndents`
- The current Neko Atsume password is **${data.password}**.
- It will expire in **${moment.duration(data.expires - data.date).format('hh:mm:ss', { trim: false })}**.
+ const data = await this.fetchPassword(locale);
+ return msg.say(stripIndents`
+ The current Neko Atsume password is **${data.password}**.
+ It will expire in **${moment.duration(data.expires - data.date).format('hh:mm:ss', { trim: false })}**.
- ${data.gold} ${this.goldFishEmoji} ${data.silver} ${this.silverFishEmoji}
- `);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ ${data.gold} ${this.goldFishEmoji} ${data.silver} ${this.silverFishEmoji}
+ `);
}
async fetchPassword(locale) {
diff --git a/commands/events/today-in-history.js b/commands/events/today-in-history.js
index cf0b7ebc..ca069d73 100644
--- a/commands/events/today-in-history.js
+++ b/commands/events/today-in-history.js
@@ -56,7 +56,7 @@ module.exports = class TodayInHistoryCommand extends Command {
return msg.embed(embed);
} catch (err) {
if (err.status === 404 || err.status === 500) return msg.say('Invalid date.');
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ throw err;
}
}
};
diff --git a/commands/events/us-election.js b/commands/events/us-election.js
index adc1d8e5..5a2d7209 100644
--- a/commands/events/us-election.js
+++ b/commands/events/us-election.js
@@ -27,20 +27,16 @@ module.exports = class UsElectionCommand extends Command {
if (year !== currentYear) {
return msg.reply(`This command has not been updated to reflect the ${currentYear} election season.`);
}
- try {
- const canidates = await this.getList();
- const list = canidates.map(
- canidate => `**${canidate.name}:** ${canidate.score} (${canidate.percentChange} in last day)`
- );
- return msg.say(stripIndents`
- __**Chances of Winning the ${year} US Election:**__
- ${list.join('\n')}
+ const canidates = await this.getList();
+ const list = canidates.map(
+ canidate => `**${canidate.name}:** ${canidate.score} (${canidate.percentChange} in last day)`
+ );
+ return msg.say(stripIndents`
+ __**Chances of Winning the ${year} US Election:**__
+ ${list.join('\n')}
- _More detailed information is available at ._
- `);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
- }
+ _More detailed information is available at ._
+ `);
}
async getList() {
diff --git a/commands/events/word-of-the-day.js b/commands/events/word-of-the-day.js
index a1e39c3b..08a4b74a 100644
--- a/commands/events/word-of-the-day.js
+++ b/commands/events/word-of-the-day.js
@@ -26,25 +26,21 @@ module.exports = class WordOfTheDayCommand extends Command {
}
async run(msg) {
- try {
- const word = await this.fetchWordOfTheDay();
- let data;
- if (this.cache?.word === word) {
- data = this.cache.data;
- } else {
- const { body } = await request
- .get(`https://www.dictionaryapi.com/api/v3/references/collegiate/json/${word}`)
- .query({ key: WEBSTER_KEY });
- data = body[0];
- this.cache = { word, data };
- }
- return msg.say(stripIndents`
- **${data.meta.stems[0]}** (${data.fl})
- ${data.shortdef.map((definition, i) => `(${i + 1}) ${definition}`).join('\n')}
- `);
- } catch (err) {
- return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ const word = await this.fetchWordOfTheDay();
+ let data;
+ if (this.cache?.word === word) {
+ data = this.cache.data;
+ } else {
+ const { body } = await request
+ .get(`https://www.dictionaryapi.com/api/v3/references/collegiate/json/${word}`)
+ .query({ key: WEBSTER_KEY });
+ data = body[0];
+ this.cache = { word, data };
}
+ return msg.say(stripIndents`
+ **${data.meta.stems[0]}** (${data.fl})
+ ${data.shortdef.map((definition, i) => `(${i + 1}) ${definition}`).join('\n')}
+ `);
}
async fetchWordOfTheDay() {