From 0073d3c76d294ed7247294f46b4030ebcb3f1e42 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sun, 13 Oct 2019 18:15:46 +0200 Subject: [PATCH] some blur command --- commands/images/blur.js | 61 +++++++++++++++++++++++++++++++++++++ commands/images/gaussian.js | 61 +++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 commands/images/blur.js create mode 100644 commands/images/gaussian.js diff --git a/commands/images/blur.js b/commands/images/blur.js new file mode 100644 index 0000000..d38904e --- /dev/null +++ b/commands/images/blur.js @@ -0,0 +1,61 @@ +const { Command } = require('discord-akairo'); +const jimp = require('jimp'); +const os = require('os'); + +class blurCommand extends Command { + constructor() { + super('blur', { + aliases: ['blur'], + category: 'images', + args: [ + { + id: 'link', + type: 'string', + }, + { + id: 'radius', + type: 'integer', + } + ], + description: { + content: 'Make your vid shit quality.', + usage: '[link to image] [angle of rotation]', + examples: [''] + } + }); + } + + async exec(message, args) { + let output = `${os.tmpdir()}/blurred${message.id}.jpg`; + + if (!args.radius) args.radius = 10; + + + let Attachment = (message.attachments).array(); + let url = args.link; + // Get attachment link + if (Attachment[0] && !args.link) { + url = Attachment[0].url; + } + + let loadingmsg = await message.channel.send('Processing '); + + jimp.read({ + url: url + }) + .then(image => { + return image + .blur(args.radius) + .write(output); + }) + .then(() => { + loadingmsg.delete(); + return message.channel.send({files: [output]}); + }); + + + + } +} + +module.exports = blurCommand; \ No newline at end of file diff --git a/commands/images/gaussian.js b/commands/images/gaussian.js new file mode 100644 index 0000000..1ebb5d8 --- /dev/null +++ b/commands/images/gaussian.js @@ -0,0 +1,61 @@ +const { Command } = require('discord-akairo'); +const jimp = require('jimp'); +const os = require('os'); + +class gaussianCommand extends Command { + constructor() { + super('gaussian', { + aliases: ['gaussian'], + category: 'images', + args: [ + { + id: 'link', + type: 'string', + }, + { + id: 'radius', + type: 'integer', + } + ], + 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; + + + let Attachment = (message.attachments).array(); + let url = args.link; + // Get attachment link + if (Attachment[0] && !args.link) { + url = Attachment[0].url; + } + + let loadingmsg = await message.channel.send('Processing '); + + jimp.read({ + url: url + }) + .then(image => { + return image + .gaussian(args.radius) + .write(output); + }) + .then(() => { + loadingmsg.delete(); + return message.channel.send({files: [output]}); + }); + + + + } +} + +module.exports = gaussianCommand; \ No newline at end of file