Haha-Yes/commands/images/gaussian.js

73 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2019-10-13 18:15:46 +02:00
const { Command } = require('discord-akairo');
2020-07-16 09:22:17 +02:00
const attachment = require('../../utils/attachment');
2019-10-13 18:15:46 +02:00
const jimp = require('jimp');
const os = require('os');
class gaussianCommand extends Command {
constructor() {
super('gaussian', {
aliases: ['gaussian'],
category: 'images',
2019-11-09 12:04:01 +01:00
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
2019-10-13 18:15:46 +02:00
args: [
{
id: 'link',
2020-07-16 09:22:17 +02:00
type: 'url',
unordered: true
2019-10-13 18:15:46 +02:00
},
{
id: 'radius',
type: 'integer',
2020-07-16 09:22:17 +02:00
unordered: true
2019-10-13 18:15:46 +02:00
}
],
description: {
content: 'Make your vid shit quality.',
usage: '[link to image] [angle of rotation]',
examples: ['']
}
});
}
async exec(message, args) {
let output = `${os.tmpdir()}/gaussian${message.id}.jpg`;
if (!args.radius) args.radius = 10;
2020-07-16 09:22:17 +02:00
let url;
2019-10-13 18:15:46 +02:00
2020-07-16 09:22:17 +02:00
if (args.link)
url = args.link.href;
else
url = await attachment(message);
2019-10-13 18:15:46 +02:00
if (!url) {
return message.channel.send('You need an image to use this command!');
}
2019-10-13 18:15:46 +02:00
let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>');
jimp.read({
url: url
})
.then(image => {
return image
.gaussian(args.radius)
.write(output);
})
.then(() => {
loadingmsg.delete();
return message.channel.send({files: [output]});
})
.catch(error => {
console.error(error);
return message.channel.send('Oh no, an error just occurred! Maybe the format of your image don\'t work?');
2019-10-13 18:15:46 +02:00
});
2019-10-13 18:15:46 +02:00
}
}
module.exports = gaussianCommand;