From 5e18aa5d676f6cb36874b1138cb3a46c4c4adb9d Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sun, 13 Oct 2019 21:59:17 +0200 Subject: [PATCH] if no image send message about it and catch error --- commands/images/autocrop.js | 9 +++++++++ commands/images/blur.js | 10 ++++++++++ commands/images/gaussian.js | 9 +++++++++ commands/images/jpegify.js | 9 +++++++++ commands/images/mirror.js | 8 ++++++++ commands/images/rotate.js | 9 +++++++++ 6 files changed, 54 insertions(+) diff --git a/commands/images/autocrop.js b/commands/images/autocrop.js index 657e0c41..d92a062a 100644 --- a/commands/images/autocrop.js +++ b/commands/images/autocrop.js @@ -32,6 +32,10 @@ class autocropCommand extends Command { url = Attachment[0].url; } + if (!url) { + return message.channel.send('You need an image to use this command!'); + } + let loadingmsg = await message.channel.send('Processing '); @@ -46,10 +50,15 @@ class autocropCommand extends Command { .then(() => { loadingmsg.delete(); return message.channel.send({files: [output]}); + }) + .catch(error => { + console.error(error); + return message.channel.send('Oh no, an error just occured! Maybe the format of your image don\'t work?'); }); + } } diff --git a/commands/images/blur.js b/commands/images/blur.js index d38904ec..66585332 100644 --- a/commands/images/blur.js +++ b/commands/images/blur.js @@ -11,6 +11,7 @@ class blurCommand extends Command { { id: 'link', type: 'string', + }, { id: 'radius', @@ -38,6 +39,10 @@ class blurCommand extends Command { url = Attachment[0].url; } + if (!url) { + return message.channel.send('You need an image to use this command!'); + } + let loadingmsg = await message.channel.send('Processing '); jimp.read({ @@ -51,10 +56,15 @@ class blurCommand extends Command { .then(() => { loadingmsg.delete(); return message.channel.send({files: [output]}); + }) + .catch(error => { + console.error(error); + return message.channel.send('Oh no, an error just occured! Maybe the format of your image don\'t work?'); }); + } } diff --git a/commands/images/gaussian.js b/commands/images/gaussian.js index 1ebb5d8d..7a2c811d 100644 --- a/commands/images/gaussian.js +++ b/commands/images/gaussian.js @@ -38,6 +38,10 @@ class gaussianCommand extends Command { url = Attachment[0].url; } + if (!url) { + return message.channel.send('You need an image to use this command!'); + } + let loadingmsg = await message.channel.send('Processing '); jimp.read({ @@ -51,10 +55,15 @@ class gaussianCommand extends Command { .then(() => { loadingmsg.delete(); return message.channel.send({files: [output]}); + }) + .catch(error => { + console.error(error); + return message.channel.send('Oh no, an error just occured! Maybe the format of your image don\'t work?'); }); + } } diff --git a/commands/images/jpegify.js b/commands/images/jpegify.js index 88d21263..66c3dbc0 100644 --- a/commands/images/jpegify.js +++ b/commands/images/jpegify.js @@ -32,6 +32,10 @@ class jpegifyCommand extends Command { url = Attachment[0].url; } + if (!url) { + return message.channel.send('You need an image to use this command!'); + } + let loadingmsg = await message.channel.send('Processing '); jimp.read({ @@ -45,9 +49,14 @@ class jpegifyCommand extends Command { .then(() => { loadingmsg.delete(); return message.channel.send({files: [output]}); + }) + .catch(error => { + console.error(error); + return message.channel.send('Oh no, an error just occured! Maybe the format of your image don\'t work?'); }); + } } diff --git a/commands/images/mirror.js b/commands/images/mirror.js index 864db411..f366cfa0 100644 --- a/commands/images/mirror.js +++ b/commands/images/mirror.js @@ -32,6 +32,10 @@ class mirrorCommand extends Command { url = Attachment[0].url; } + if (!url) { + return message.channel.send('You need an image to use this command!'); + } + let loadingmsg = await message.channel.send('Processing '); jimp.read({ @@ -45,6 +49,10 @@ class mirrorCommand extends Command { .then(() => { loadingmsg.delete(); return message.channel.send({files: [output]}); + }) + .catch(error => { + console.error(error); + return message.channel.send('Oh no, an error just occured! Maybe the format of your image don\'t work?'); }); diff --git a/commands/images/rotate.js b/commands/images/rotate.js index 07562bff..796c3960 100644 --- a/commands/images/rotate.js +++ b/commands/images/rotate.js @@ -36,6 +36,10 @@ class rotateCommand extends Command { url = Attachment[0].url; } + if (!url) { + return message.channel.send('You need an image to use this command!'); + } + let loadingmsg = await message.channel.send('Processing '); jimp.read({ @@ -49,10 +53,15 @@ class rotateCommand extends Command { .then(() => { loadingmsg.delete(); return message.channel.send({files: [output]}); + }) + .catch(error => { + console.error(error); + return message.channel.send('Oh no, an error just occured! Maybe the format of your image don\'t work?'); }); + } }