mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
63 lines
2.0 KiB
JavaScript
63 lines
2.0 KiB
JavaScript
const Command = require('../../framework/Command');
|
|
const { PermissionFlagsBits } = require('discord.js');
|
|
const { createCanvas, loadImage } = require('@napi-rs/canvas');
|
|
const path = require('path');
|
|
const { shortenText, fillTextWithBreaks } = require('../../util/Canvas');
|
|
|
|
module.exports = class LisaPresentationCommand extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: 'bart-chalkboard',
|
|
aliases: ['bart', 'bart-chalk', 'bart-board'],
|
|
group: 'edit-meme',
|
|
description: 'Sends a "Bart Chalkboard" meme with the text of your choice.',
|
|
throttling: {
|
|
usages: 2,
|
|
duration: 10
|
|
},
|
|
clientPermissions: [PermissionFlagsBits.AttachFiles],
|
|
credit: [
|
|
{
|
|
name: '20th Century Fox',
|
|
url: 'https://www.foxmovies.com/',
|
|
reason: 'Image, Original "The Simpsons" Show',
|
|
reasonURL: 'http://www.simpsonsworld.com/'
|
|
},
|
|
{
|
|
name: 'Jon Bernhardt',
|
|
url: 'http://web.mit.edu/jonb/www/',
|
|
reason: 'Akbar Font',
|
|
reasonURL: 'https://www.wobblymusic.com/groening/akbar.html'
|
|
}
|
|
],
|
|
args: [
|
|
{
|
|
key: 'text',
|
|
type: 'string',
|
|
max: 50
|
|
}
|
|
]
|
|
});
|
|
}
|
|
|
|
async run(msg, { text }) {
|
|
const base = await loadImage(
|
|
path.join(__dirname, '..', '..', 'assets', 'images', 'bart-chalkboard', 'chalkboard.png')
|
|
);
|
|
const bart = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'bart-chalkboard', 'bart.png'));
|
|
const canvas = createCanvas(base.width, base.height);
|
|
const ctx = canvas.getContext('2d');
|
|
ctx.drawImage(base, 0, 0);
|
|
ctx.textBaseline = 'top';
|
|
ctx.font = this.client.fonts.get('akbar.ttf').toCanvasString(19);
|
|
ctx.fillStyle = 'white';
|
|
const shortened = shortenText(ctx, text.toUpperCase(), 500);
|
|
const len = ctx.measureText(shortened).width;
|
|
const arr = [];
|
|
for (let i = 0; i < 12; i++) arr.push(shortened);
|
|
fillTextWithBreaks(ctx, arr.join('\n'), 30, 27);
|
|
ctx.drawImage(bart, Math.min(522, 30 + len), 142, 103, 212);
|
|
return msg.say({ files: [{ attachment: canvas.toBuffer('image/png'), name: 'bart-chalkboard.png' }] });
|
|
}
|
|
};
|