mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 18:05:01 +02:00
Silhouette challenger support, adjust demotivational dimensions
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 9.7 KiB |
@@ -2,6 +2,7 @@ const Command = require('../../structures/Command');
|
|||||||
const { createCanvas, loadImage } = require('canvas');
|
const { createCanvas, loadImage } = require('canvas');
|
||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const { silhouette } = require('../../util/Canvas');
|
||||||
|
|
||||||
module.exports = class ChallengerCommand extends Command {
|
module.exports = class ChallengerCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -22,12 +23,18 @@ module.exports = class ChallengerCommand extends Command {
|
|||||||
prompt: 'Which user would you like to edit the avatar of?',
|
prompt: 'Which user would you like to edit the avatar of?',
|
||||||
type: 'user',
|
type: 'user',
|
||||||
default: msg => msg.author
|
default: msg => msg.author
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'silhouetted',
|
||||||
|
prompt: 'Should the image be silhouetted?',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { user }) {
|
async run(msg, { user, silhouetted }) {
|
||||||
const avatarURL = user.displayAvatarURL({ format: 'png', size: 256 });
|
const avatarURL = user.displayAvatarURL({ format: 'png', size: 256 });
|
||||||
try {
|
try {
|
||||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'challenger.png'));
|
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'challenger.png'));
|
||||||
@@ -36,10 +43,18 @@ module.exports = class ChallengerCommand extends Command {
|
|||||||
const canvas = createCanvas(base.width, base.height);
|
const canvas = createCanvas(base.width, base.height);
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
ctx.drawImage(base, 0, 0);
|
ctx.drawImage(base, 0, 0);
|
||||||
ctx.drawImage(avatar, 484, 98, 256, 256);
|
ctx.drawImage(silhouetted ? this.silhouetteImage(avatar) : avatar, 484, 98, 256, 256);
|
||||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'challenger.png' }] });
|
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'challenger.png' }] });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
silhouetteImage(image) {
|
||||||
|
const canvas = createCanvas(image.width, image.height);
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
ctx.drawImage(image, 0, 0);
|
||||||
|
silhouette(ctx, 0, 0, image.width, image.height);
|
||||||
|
return canvas;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,15 +44,22 @@ module.exports = class DemotivationalPosterCommand extends Command {
|
|||||||
|
|
||||||
async run(msg, { title, text, image }) {
|
async run(msg, { title, text, image }) {
|
||||||
try {
|
try {
|
||||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'demotivational-poster.png'));
|
|
||||||
const { body } = await request.get(image);
|
const { body } = await request.get(image);
|
||||||
const data = await loadImage(body);
|
const data = await loadImage(body);
|
||||||
const canvas = createCanvas(base.width, base.height);
|
const canvas = createCanvas(750, 600);
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
|
ctx.fillStyle = 'black';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
const ratio = data.width / data.height;
|
||||||
|
const width = Math.min(Math.round(402 / ratio), 602);
|
||||||
|
const x = (data.width / 2) - (width / 2);
|
||||||
ctx.fillStyle = 'white';
|
ctx.fillStyle = 'white';
|
||||||
ctx.fillRect(0, 0, base.width, base.height);
|
ctx.fillRect(x - 4, 40, width + 4, 406);
|
||||||
ctx.drawImage(data, 69, 44, 612, 412);
|
ctx.fillStyle = 'black';
|
||||||
ctx.drawImage(base, 0, 0);
|
ctx.fillRect(x - 2, 42, width + 2, 404);
|
||||||
|
ctx.fillStyle = 'white';
|
||||||
|
ctx.fillRect(x, 44, width, 402);
|
||||||
|
ctx.drawImage(data, x, 44, width, 402);
|
||||||
ctx.textAlign = 'center';
|
ctx.textAlign = 'center';
|
||||||
ctx.font = '60px Noto';
|
ctx.font = '60px Noto';
|
||||||
ctx.fillStyle = 'aquamarine';
|
ctx.fillStyle = 'aquamarine';
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "91.2.0",
|
"version": "91.2.1",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user