mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-10 10:57:08 +02:00
Lisa Presentation Command
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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 LisaPresentationCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'lisa-presentation',
|
||||
aliases: ['lisa'],
|
||||
group: 'image-edit',
|
||||
memberName: 'lisa-presentation',
|
||||
description: 'Sends a "Lisa Presentation" meme with the presentation of your choice.',
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 10
|
||||
},
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
key: 'text',
|
||||
prompt: 'What should the text of the presentation be?',
|
||||
type: 'string',
|
||||
max: 280
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { text }) {
|
||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'lisa-presentation.png'));
|
||||
const canvas = createCanvas(base.width, base.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(base, 0, 0);
|
||||
ctx.font = '24px Noto';
|
||||
ctx.textAlign = 'center';
|
||||
const lines = await wrapText(ctx, text, 330);
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const textHeight = 95 + (i * 24) + (i * 10);
|
||||
ctx.fillText(lines[i], base.width / 2, textHeight);
|
||||
}
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'lisa-presentation.png' }] });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user