mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-25 06:42:51 +02:00
Demotivational with image support
This commit is contained in:
@@ -8,7 +8,7 @@ module.exports = class PixelizeCommand extends Command {
|
|||||||
name: 'pixelize',
|
name: 'pixelize',
|
||||||
group: 'avatar-edit',
|
group: 'avatar-edit',
|
||||||
memberName: 'pixelize',
|
memberName: 'pixelize',
|
||||||
description: 'Draws a user\'s avatar but pixelized.',
|
description: 'Draws a user\'s avatar pixelized.',
|
||||||
throttling: {
|
throttling: {
|
||||||
usages: 1,
|
usages: 1,
|
||||||
duration: 15
|
duration: 15
|
||||||
|
|||||||
+17
-15
@@ -11,9 +11,9 @@ module.exports = class DemotivationalPosterCommand extends Command {
|
|||||||
super(client, {
|
super(client, {
|
||||||
name: 'demotivational-poster',
|
name: 'demotivational-poster',
|
||||||
aliases: ['demotivational'],
|
aliases: ['demotivational'],
|
||||||
group: 'avatar-edit',
|
group: 'image-edit',
|
||||||
memberName: 'demotivational-poster',
|
memberName: 'demotivational-poster',
|
||||||
description: 'Draws a user\'s avatar and the text you specify as a demotivational poster.',
|
description: 'Draws an image or a user\'s avatar and the text you specify as a demotivational poster.',
|
||||||
throttling: {
|
throttling: {
|
||||||
usages: 1,
|
usages: 1,
|
||||||
duration: 15
|
duration: 15
|
||||||
@@ -32,30 +32,32 @@ module.exports = class DemotivationalPosterCommand extends Command {
|
|||||||
type: 'string'
|
type: 'string'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'user',
|
key: 'image',
|
||||||
prompt: 'Which user would you like to edit the avatar of?',
|
prompt: 'What image would you like to edit?',
|
||||||
type: 'user',
|
type: 'image',
|
||||||
default: ''
|
default: '',
|
||||||
|
avatarSize: 1024
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { title, text, user }) {
|
async run(msg, { title, text, image }) {
|
||||||
if (!user) user = msg.author;
|
if (!image) {
|
||||||
const avatarURL = user.displayAvatarURL({
|
image = msg.author.displayAvatarURL({
|
||||||
format: 'png',
|
format: 'png',
|
||||||
size: 1024
|
size: 1024
|
||||||
});
|
});
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'demotivational-poster.png'));
|
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'demotivational-poster.png'));
|
||||||
const { body } = await snekfetch.get(avatarURL);
|
const { body } = await snekfetch.get(image);
|
||||||
const avatar = await loadImage(body);
|
const data = await loadImage(body);
|
||||||
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.fillStyle = 'white';
|
ctx.fillStyle = 'white';
|
||||||
ctx.fillRect(0, 0, base.width, base.height);
|
ctx.fillRect(0, 0, base.width, base.height);
|
||||||
ctx.drawImage(avatar, 68, -57, 612, 612);
|
ctx.drawImage(data, 69, 44, 612, data.height > 412 ? data.height : 412);
|
||||||
ctx.drawImage(base, 0, 0);
|
ctx.drawImage(base, 0, 0);
|
||||||
ctx.textAlign = 'center';
|
ctx.textAlign = 'center';
|
||||||
ctx.font = '60px Noto';
|
ctx.font = '60px Noto';
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiaobot",
|
"name": "xiaobot",
|
||||||
"version": "55.1.2",
|
"version": "55.1.3",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "XiaoBot.js",
|
"main": "XiaoBot.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+2
-2
@@ -16,11 +16,11 @@ class ImageArgumentType extends ArgumentType {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
parse(value, msg) {
|
parse(value, msg, arg) {
|
||||||
if (!msg.attachments.size) {
|
if (!msg.attachments.size) {
|
||||||
return this.client.registry.types.get('user').parse(value, msg).displayAvatarURL({
|
return this.client.registry.types.get('user').parse(value, msg).displayAvatarURL({
|
||||||
format: 'png',
|
format: 'png',
|
||||||
size: 512
|
size: arg.avatarSize || 512
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return msg.attachments.first().url;
|
return msg.attachments.first().url;
|
||||||
|
|||||||
Reference in New Issue
Block a user