mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-12 15:57:43 +02:00
Begin migrating away from stupid "Oh no, an error occurred!"
This commit is contained in:
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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}` }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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}` }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user