mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Whiteboard Command
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 584 KiB |
@@ -0,0 +1,86 @@
|
|||||||
|
const Command = require('../../structures/Command');
|
||||||
|
const { createCanvas, loadImage } = require('canvas');
|
||||||
|
const path = require('path');
|
||||||
|
const { wrapText } = require('../../util/Canvas');
|
||||||
|
|
||||||
|
module.exports = class WhiteboardCommand extends Command {
|
||||||
|
constructor(client) {
|
||||||
|
super(client, {
|
||||||
|
name: 'whiteboard',
|
||||||
|
group: 'edit-meme',
|
||||||
|
memberName: 'whiteboard',
|
||||||
|
description: 'Sends a "Jim Halpert point to whiteboard" meme with the text of your choice.',
|
||||||
|
throttling: {
|
||||||
|
usages: 2,
|
||||||
|
duration: 10
|
||||||
|
},
|
||||||
|
clientPermissions: ['ATTACH_FILES'],
|
||||||
|
credit: [
|
||||||
|
{
|
||||||
|
name: 'NBC',
|
||||||
|
url: 'https://www.nbc.com/',
|
||||||
|
reason: 'Image, Original "The Office" TV Series',
|
||||||
|
reasonURL: 'https://www.nbc.com/the-office'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Google',
|
||||||
|
url: 'https://www.google.com/',
|
||||||
|
reason: 'Noto Font',
|
||||||
|
reasonURL: 'https://www.google.com/get/noto/'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
key: 'initial',
|
||||||
|
prompt: 'What text should be on the first panel?',
|
||||||
|
type: 'string',
|
||||||
|
max: 500
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'resolved',
|
||||||
|
prompt: 'What text should be on the second panel?',
|
||||||
|
type: 'string',
|
||||||
|
max: 500
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(msg, { initial, resolved }) {
|
||||||
|
try {
|
||||||
|
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'whiteboard.png'));
|
||||||
|
const canvas = createCanvas(base.width, base.height);
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
ctx.drawImage(base, 0, 0);
|
||||||
|
ctx.textAlign = 'center';
|
||||||
|
ctx.textBaseline = 'top';
|
||||||
|
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(46);
|
||||||
|
let fontSize = 46;
|
||||||
|
while (ctx.measureText(nah).width > 608) {
|
||||||
|
fontSize--;
|
||||||
|
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
|
||||||
|
}
|
||||||
|
const initialLines = await wrapText(ctx, initial, 405);
|
||||||
|
const initialTopMost = 48 - (((fontSize * initialLines.length) / 2) + ((10 * (initialLines.length - 1)) / 2));
|
||||||
|
for (let i = 0; i < initialLines.length; i++) {
|
||||||
|
const height = initialTopMost + ((fontSize + 10) * i);
|
||||||
|
ctx.fillText(initialLines[i], 24, height);
|
||||||
|
}
|
||||||
|
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(40);
|
||||||
|
fontSize = 40;
|
||||||
|
while (ctx.measureText(yeah).width > 551) {
|
||||||
|
fontSize--;
|
||||||
|
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(fontSize);
|
||||||
|
}
|
||||||
|
const resolveLines = await wrapText(ctx, resolved, 367);
|
||||||
|
const resolveTopMost = 443 - (((fontSize * resolveLines.length) / 2) + ((10 * (resolveLines.length - 1)) / 2));
|
||||||
|
for (let i = 0; i < resolveLines.length; i++) {
|
||||||
|
const height = resolveTopMost + ((fontSize + 10) * i);
|
||||||
|
ctx.fillText(resolveLines[i], 14, height);
|
||||||
|
}
|
||||||
|
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'whiteboard.png' }] });
|
||||||
|
} catch (err) {
|
||||||
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "139.4.1",
|
"version": "139.5.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user