mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 02:15:10 +02:00
Fix
This commit is contained in:
@@ -10,6 +10,10 @@ module.exports = class FontCommand extends Command {
|
|||||||
group: 'edit-image',
|
group: 'edit-image',
|
||||||
memberName: 'font',
|
memberName: 'font',
|
||||||
description: 'Types text in a specific font.',
|
description: 'Types text in a specific font.',
|
||||||
|
throttling: {
|
||||||
|
uses: 1,
|
||||||
|
duration: 10
|
||||||
|
},
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
key: 'font',
|
key: 'font',
|
||||||
@@ -25,16 +29,17 @@ module.exports = class FontCommand extends Command {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
run(msg, { font, text }) {
|
async run(msg, { font, text }) {
|
||||||
return msg.say({ files: [{ attachment: this.generateImage(font, text), name: `${font.filenameNoExt}.png` }] });
|
const image = await this.generateImage(font, text);
|
||||||
|
return msg.say({ files: [{ attachment: image, name: `${font.filenameNoExt}.png` }] });
|
||||||
}
|
}
|
||||||
|
|
||||||
generateImage(font, text) {
|
async generateImage(font, text) {
|
||||||
const canvasPre = createCanvas(1, 1);
|
const canvasPre = createCanvas(1, 1);
|
||||||
const ctxPre = canvasPre.getContext('2d');
|
const ctxPre = canvasPre.getContext('2d');
|
||||||
ctxPre.font = this.client.fonts.get(font.filename).toCanvasString(75);
|
ctxPre.font = this.client.fonts.get(font.filename).toCanvasString(75);
|
||||||
const len = ctxPre.measureText(text);
|
const len = ctxPre.measureText(text);
|
||||||
const lines = wrapText(ctxPre, text, 450);
|
const lines = await wrapText(ctxPre, text, 450);
|
||||||
const canvas = createCanvas(Math.min(len, 500), 50 + (75 * lines.length));
|
const canvas = createCanvas(Math.min(len, 500), 50 + (75 * lines.length));
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
ctx.font = this.client.fonts.get(font.filename).toCanvasString(75);
|
ctx.font = this.client.fonts.get(font.filename).toCanvasString(75);
|
||||||
|
|||||||
Reference in New Issue
Block a user