mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-07 14:55:40 +02:00
80 lines
2.4 KiB
JavaScript
80 lines
2.4 KiB
JavaScript
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', 'Noto-Regular.ttf'), { family: 'Noto' });
|
|
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-CJK.otf'), { family: 'Noto' });
|
|
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Emoji.ttf'), { family: 'Noto' });
|
|
|
|
module.exports = class TwoButtonsCommand extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: 'two-buttons',
|
|
aliases: ['buttons'],
|
|
group: 'edit-meme',
|
|
memberName: 'two-buttons',
|
|
description: 'Sends a "Two Buttons" meme with the buttons of your choice.',
|
|
throttling: {
|
|
usages: 1,
|
|
duration: 10
|
|
},
|
|
clientPermissions: ['ATTACH_FILES'],
|
|
credit: [
|
|
{
|
|
name: 'Google',
|
|
url: 'https://www.google.com/',
|
|
reason: 'Noto Font',
|
|
reasonURL: 'https://www.google.com/get/noto/'
|
|
},
|
|
{
|
|
name: 'Jake Clark',
|
|
url: 'https://jake-clark.tumblr.com/',
|
|
reason: 'Image',
|
|
reasonURL: 'https://twitter.com/jakeclarkdude/status/689141113584619524'
|
|
}
|
|
],
|
|
args: [
|
|
{
|
|
key: 'first',
|
|
prompt: 'What should the text of the first button be?',
|
|
type: 'string',
|
|
max: 50
|
|
},
|
|
{
|
|
key: 'second',
|
|
prompt: 'What should the text of the second button be?',
|
|
type: 'string',
|
|
max: 50
|
|
}
|
|
]
|
|
});
|
|
}
|
|
|
|
async run(msg, { first, second }) {
|
|
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'two-buttons.png'));
|
|
const canvas = createCanvas(base.width, base.height);
|
|
const ctx = canvas.getContext('2d');
|
|
ctx.textBaseline = 'top';
|
|
ctx.drawImage(base, 0, 0);
|
|
ctx.rotate(-12 * (Math.PI / 180));
|
|
ctx.font = '34px Noto';
|
|
let fontSize = 34;
|
|
while (ctx.measureText(first).width > 244) {
|
|
fontSize -= 1;
|
|
ctx.font = `${fontSize}px Noto`;
|
|
}
|
|
const firstLines = await wrapText(ctx, first, 183);
|
|
ctx.fillText(firstLines.join('\n'), 20, 111);
|
|
ctx.font = '34px Noto';
|
|
fontSize = 34;
|
|
while (ctx.measureText(second).width > 163) {
|
|
fontSize -= 1;
|
|
ctx.font = `${fontSize}px Noto`;
|
|
}
|
|
const secondLines = await wrapText(ctx, second, 122);
|
|
ctx.fillText(secondLines.join('\n'), 249, 120);
|
|
ctx.rotate(12 * (Math.PI / 180));
|
|
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'two-buttons.png' }] });
|
|
}
|
|
};
|