2019-10-13 16:54:07 +02:00
|
|
|
const { Command } = require('discord-akairo');
|
2020-07-16 09:22:17 +02:00
|
|
|
const attachment = require('../../utils/attachment');
|
2019-10-13 16:54:07 +02:00
|
|
|
const jimp = require('jimp');
|
|
|
|
const os = require('os');
|
|
|
|
|
|
|
|
class mirrorCommand extends Command {
|
|
|
|
constructor() {
|
|
|
|
super('mirror', {
|
|
|
|
aliases: ['mirror', 'flip'],
|
|
|
|
category: 'images',
|
2019-11-09 12:04:01 +01:00
|
|
|
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
|
2019-10-13 16:54:07 +02:00
|
|
|
args: [
|
|
|
|
{
|
|
|
|
id: 'link',
|
2020-07-16 09:22:17 +02:00
|
|
|
type: 'url',
|
2019-10-13 16:54:07 +02:00
|
|
|
}
|
|
|
|
],
|
|
|
|
description: {
|
|
|
|
content: 'mirror the image.',
|
|
|
|
usage: '[link to image]',
|
|
|
|
examples: ['']
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async exec(message, args) {
|
|
|
|
let output = `${os.tmpdir()}/mirrored${message.id}.jpg`;
|
2020-07-16 09:22:17 +02:00
|
|
|
let url;
|
2019-10-13 16:54:07 +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 16:54:07 +02:00
|
|
|
|
2019-10-13 21:59:17 +02:00
|
|
|
if (!url) {
|
|
|
|
return message.channel.send('You need an image to use this command!');
|
|
|
|
}
|
|
|
|
|
2019-10-13 18:15:56 +02:00
|
|
|
let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>');
|
2019-10-13 16:54:07 +02:00
|
|
|
|
|
|
|
jimp.read({
|
|
|
|
url: url
|
|
|
|
})
|
|
|
|
.then(image => {
|
|
|
|
return image
|
|
|
|
.mirror(true, false)
|
|
|
|
.write(output);
|
|
|
|
})
|
|
|
|
.then(() => {
|
2019-10-13 18:15:56 +02:00
|
|
|
loadingmsg.delete();
|
2019-10-13 16:54:07 +02:00
|
|
|
return message.channel.send({files: [output]});
|
2019-10-13 21:59:17 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
2020-07-16 09:42:07 +02:00
|
|
|
return message.channel.send('Oh no, an error just occurredred! Maybe the format of your image don\'t work?');
|
2019-10-13 16:54:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = mirrorCommand;
|