Begin migrating away from stupid "Oh no, an error occurred!"

This commit is contained in:
Dragon Fire
2024-03-29 23:57:49 -04:00
parent 067545b818
commit 0b807767d1
130 changed files with 1692 additions and 2190 deletions
+9 -13
View File
@@ -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' }] });
}
};
+11 -15
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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) {
+13 -17
View File
@@ -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' }] });
}
};
+10 -14
View File
@@ -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' }] });
}
};
+23 -27
View File
@@ -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' }] });
}
};
+12 -16
View File
@@ -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' }] });
}
};
+18 -22
View File
@@ -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' }] });
}
};
+30 -34
View File
@@ -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' }] });
}
};
+14 -18
View File
@@ -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' }] });
}
};
+11 -15
View File
@@ -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' }] });
}
};
+12 -16
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+12 -16
View File
@@ -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' }] });
}
};
+12 -16
View File
@@ -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' }] });
}
};
+10 -14
View File
@@ -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' }] });
}
};
+13 -17
View File
@@ -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' }] });
}
};
+33 -37
View File
@@ -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' }] });
}
};
+12 -16
View File
@@ -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' }] });
}
};
+13 -17
View File
@@ -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' }] });
}
};
+24 -28
View File
@@ -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' }] });
}
};
+42 -46
View File
@@ -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' }] });
}
};
+23 -27
View File
@@ -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' }] });
}
};
+15 -19
View File
@@ -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' }] });
}
};
+19 -23
View File
@@ -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' }] });
}
};
+12 -16
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+14 -18
View File
@@ -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' }] });
}
};
+13 -17
View File
@@ -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' }] });
}
};
+30 -34
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+11 -15
View File
@@ -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' }] });
}
};
+13 -17
View File
@@ -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' }] });
}
};
+30 -34
View File
@@ -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' }] });
}
};
+8 -12
View File
@@ -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' }] });
}
};
+17 -21
View File
@@ -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' }] });
}
};