Chinese Restaurant Command

This commit is contained in:
Dragon Fire
2020-05-22 10:44:09 -04:00
parent 448d7b80c2
commit b405dc20e4
4 changed files with 80 additions and 2 deletions
+74
View File
@@ -0,0 +1,74 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage, registerFont } = require('canvas');
const path = require('path');
const { wrapText } = require('../../util/Canvas');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Futura Condensed.ttf'), {
family: 'Futura',
weight: 'bold'
});
module.exports = class ChineseRestaurantCommand extends Command {
constructor(client) {
super(client, {
name: 'chinese-restaurant',
aliases: ['chinese-restaurant-sign', 'chinese-food-sign', 'chinese-sign'],
group: 'edit-image',
memberName: 'chinese-restaurant',
description: 'Sends a Chinese restaurant sign with the text of your choice.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'ATOM.SMASHER.ORG',
url: 'http://atom.smasher.org/',
reason: 'Image',
reasonURL: 'http://atom.smasher.org/chinese/'
},
{
name: 'Fontsgeek',
url: 'http://fontsgeek.com/',
reason: 'Futura Condensed Font',
reasonURL: 'http://fontsgeek.com/fonts/Futura-Condensed-Bold'
}
],
args: [
{
key: 'text',
prompt: 'What should the text of the sign be?',
type: 'string'
}
]
});
}
async run(msg, { text }) {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'chinese-restaurant.png'));
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.fillStyle = 'black';
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.font = 'normal bold 28px Futura';
const lines = await wrapText(ctx, text.toUpperCase(), 340);
if (lines.length === 1) {
ctx.fillText(lines[0], base.width / 2, 294);
} else if (lines.length === 2) {
ctx.fillText(lines[0], base.width / 2, 294);
ctx.fillText(lines[1], base.width / 2, 323);
} else if (lines.length === 3) {
ctx.fillText(lines[0], base.width / 2, 269);
ctx.fillText(lines[1], base.width / 2, 294);
ctx.fillText(lines[2], base.width / 2, 323);
} else {
ctx.fillText(lines[0], base.width / 2, 269);
ctx.fillText(lines[1], base.width / 2, 294);
ctx.fillText(lines[2], base.width / 2, 323);
ctx.fillText(lines[4], base.width / 2, 350);
}
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'chinese-restaurant.png' }] });
}
};