mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-17 08:17:35 +02:00
Test
This commit is contained in:
@@ -0,0 +1,54 @@
|
|||||||
|
const { Command } = require('discord.js-commando');
|
||||||
|
const { createCanvas, loadImage } = require('canvas');
|
||||||
|
const snekfetch = require('snekfetch');
|
||||||
|
const { distort } = require('../../util/Canvas');
|
||||||
|
|
||||||
|
module.exports = class DistortTestCommand extends Command {
|
||||||
|
constructor(client) {
|
||||||
|
super(client, {
|
||||||
|
name: 'distort-test',
|
||||||
|
aliases: ['under-water-test'],
|
||||||
|
group: 'avatar-edit',
|
||||||
|
memberName: 'distort-test',
|
||||||
|
description: 'Draws an image or user\'s avatar but distorted.',
|
||||||
|
throttling: {
|
||||||
|
usages: 1,
|
||||||
|
duration: 15
|
||||||
|
},
|
||||||
|
clientPermissions: ['ATTACH_FILES'],
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
key: 'level',
|
||||||
|
prompt: 'What level of distortion would you like to use?',
|
||||||
|
type: 'integer'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'image',
|
||||||
|
prompt: 'What image would you like to edit?',
|
||||||
|
type: 'image',
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(msg, { level, image }) {
|
||||||
|
if (!image) {
|
||||||
|
image = msg.author.displayAvatarURL({
|
||||||
|
format: 'png',
|
||||||
|
size: 512
|
||||||
|
});
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const { body } = await snekfetch.get(image);
|
||||||
|
const imageData = await loadImage(body);
|
||||||
|
const canvas = createCanvas(imageData.width, imageData.height);
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
ctx.drawImage(imageData, 0, 0);
|
||||||
|
distort(ctx, level, 0, 0, imageData.width, imageData.height);
|
||||||
|
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'distort-test.png' }] });
|
||||||
|
} catch (err) {
|
||||||
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -7,6 +7,7 @@ class EmojiArgumentType extends ArgumentType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validate(value, msg) {
|
validate(value, msg) {
|
||||||
|
if (!value) return false;
|
||||||
const matches = value.match(/^(?:<:([a-zA-Z0-9_]+):)?([0-9]+)>?$/);
|
const matches = value.match(/^(?:<:([a-zA-Z0-9_]+):)?([0-9]+)>?$/);
|
||||||
if (matches && msg.client.emojis.has(matches[2])) return true;
|
if (matches && msg.client.emojis.has(matches[2])) return true;
|
||||||
if (!msg.guild) return false;
|
if (!msg.guild) return false;
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
const { ArgumentType } = require('discord.js-commando');
|
||||||
|
|
||||||
|
class ImageArgumentType extends ArgumentType {
|
||||||
|
constructor(client) {
|
||||||
|
super(client, 'image');
|
||||||
|
}
|
||||||
|
|
||||||
|
async validate(value, msg) {
|
||||||
|
const attachment = msg.attachments.first();
|
||||||
|
if (!attachment) {
|
||||||
|
const valid = await this.client.registry.types.get('user').validate(value, msg);
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
if (!attachment.height || !attachment.width) return false;
|
||||||
|
if (attachment.size > 8e+6) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
parse(value, msg) {
|
||||||
|
if (!msg.attachments.size) {
|
||||||
|
return this.client.registry.types.get('user').parse(value, msg).displayAvatarURL({
|
||||||
|
format: 'png',
|
||||||
|
size: 512
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return msg.attachments.first().url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ImageArgumentType;
|
||||||
Reference in New Issue
Block a user