mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
const Command = require('../../framework/Command');
|
|
const { PermissionFlagsBits } = require('discord.js');
|
|
const gm = require('gm').subClass({ imageMagick: '7+' });
|
|
const request = require('node-superfetch');
|
|
const { magikToBuffer } = require('../../util/Util');
|
|
const types = ['uniform', 'gaussian', 'multiplicative', 'impulse', 'laplacian', 'poisson'];
|
|
|
|
module.exports = class NoiseCommand extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: 'noise',
|
|
group: 'edit-image',
|
|
memberName: 'noise',
|
|
description: 'Draws an image or a user\'s avatar but with noise.',
|
|
details: `**Types:** ${types.join(', ')}`,
|
|
throttling: {
|
|
usages: 2,
|
|
duration: 15
|
|
},
|
|
clientPermissions: [PermissionFlagsBits.AttachFiles],
|
|
credit: [
|
|
{
|
|
name: 'ImageMagick',
|
|
url: 'https://imagemagick.org/index.php',
|
|
reason: 'Image Manipulation'
|
|
}
|
|
],
|
|
args: [
|
|
{
|
|
key: 'type',
|
|
type: 'string',
|
|
oneOf: types,
|
|
default: 'poisson'
|
|
},
|
|
{
|
|
key: 'image',
|
|
type: 'image-or-avatar',
|
|
default: msg => msg.author.displayAvatarURL({ extension: 'png', size: 512 })
|
|
}
|
|
]
|
|
});
|
|
}
|
|
|
|
async run(msg, { type, image }) {
|
|
const { body } = await request.get(image);
|
|
const magik = gm(body);
|
|
magik.noise(type);
|
|
magik.setFormat('png');
|
|
const attachment = await magikToBuffer(magik);
|
|
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
|
return msg.say({ files: [{ attachment, name: 'noise.png' }] });
|
|
}
|
|
};
|