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
+4 -8
View File
@@ -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}**.`);
}
};
+13 -17
View File
@@ -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' }]
});
}
};
+5 -9
View File
@@ -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.`);
}
};
+3 -7
View File
@@ -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}.`);
}
};
+6 -10
View File
@@ -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...');
}
};
+10 -14
View File
@@ -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')}
`);
}
};
+6 -10
View File
@@ -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)));
}
};
+1 -1
View File
@@ -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;
}
}
};
+1 -1
View File
@@ -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;
}
}
};
+1 -1
View File
@@ -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;
}
}
};
+10 -14
View File
@@ -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' }] });
}
};
+51 -55
View File
@@ -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' }] });
}
};
+20 -24
View File
@@ -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' }] });
}
};
+8 -12
View File
@@ -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` }] });
}
};
+10 -14
View File
@@ -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' }] });
}
};
+8 -12
View File
@@ -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' }] });
}
};
+10 -14
View File
@@ -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' }] });
}
};
+18 -22
View File
@@ -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' }] });
}
};
+12 -16
View File
@@ -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' }] });
}
};
+20 -24
View File
@@ -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' }] });
}
};
+84 -88
View File
@@ -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) {
+11 -15
View File
@@ -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' }] });
}
};
+3 -7
View File
@@ -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) {
+9 -13
View File
@@ -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' }] });
}
};
+11 -15
View File
@@ -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' }] });
}
};
+13 -17
View File
@@ -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' }] });
}
};
+7 -11
View File
@@ -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' }] });
}
};
+17 -21
View File
@@ -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' }] });
}
};
+11 -15
View File
@@ -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' }] });
}
};
+13 -17
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+8 -10
View File
@@ -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}` }] });
}
};
+4 -8
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+11 -15
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+7 -11
View File
@@ -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' }] });
}
};
+10 -14
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+20 -24
View File
@@ -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}` }] });
}
};
+11 -15
View File
@@ -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' }] });
}
};
+10 -14
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+12 -16
View File
@@ -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' }] });
}
};
+12 -16
View File
@@ -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' }] });
}
};
+12 -16
View File
@@ -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' }] });
}
};
+7 -11
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+13 -17
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+17 -21
View File
@@ -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' }] });
}
};
+8 -12
View File
@@ -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' }] });
}
};
+8 -12
View File
@@ -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' }] });
}
};
+7 -11
View File
@@ -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' }] });
}
};
+7 -11
View File
@@ -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' }] });
}
};
+25 -29
View File
@@ -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' }] });
}
};
+8 -12
View File
@@ -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' }] });
}
};
+11 -15
View File
@@ -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' }] });
}
};
+10 -14
View File
@@ -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' }] });
}
};
+11 -15
View File
@@ -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' }] });
}
};
+6 -10
View File
@@ -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' }] });
}
};
+14 -18
View File
@@ -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) {
+9 -13
View File
@@ -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' }] });
}
};
+20 -24
View File
@@ -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) {
+9 -13
View File
@@ -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' }] });
}
};
+17 -21
View File
@@ -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' }] });
}
};
+11 -15
View File
@@ -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' }] });
}
};
+20 -24
View File
@@ -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' }] });
}
};
+7 -11
View File
@@ -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' }] });
}
};
+8 -12
View File
@@ -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' }] });
}
};
+16 -20
View File
@@ -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' }] });
}
};
+23 -27
View File
@@ -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' }] });
}
};
+7 -11
View File
@@ -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' }] });
}
};
+8 -12
View File
@@ -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' }] });
}
};
+9 -13
View File
@@ -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' }] });
}
};
+10 -14
View File
@@ -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' }] });
}
};
+13 -17
View File
@@ -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' }] });
}
};
+12 -16
View File
@@ -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' }] });
}
};
+74 -78
View File
@@ -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) {
+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' }] });
}
};

Some files were not shown because too many files have changed in this diff Show More