Use new attachment utils

This commit is contained in:
loicbersier 2020-07-16 09:22:17 +02:00
parent 7d0ae36b63
commit 81a23658f9
13 changed files with 130 additions and 98 deletions

View file

@ -1,4 +1,7 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const os = require('os');
const fs = require('fs');
const asciify = require('asciify-image'); const asciify = require('asciify-image');
let options = { let options = {
@ -14,6 +17,12 @@ class asciifyCommand extends Command {
aliases: ['asciify'], aliases: ['asciify'],
category: 'fun', category: 'fun',
clientPermissions: ['SEND_MESSAGES'], clientPermissions: ['SEND_MESSAGES'],
args: [
{
id: 'link',
type: 'url',
}
],
cooldown: 600000, cooldown: 600000,
ratelimit: 2, ratelimit: 2,
description: { description: {
@ -24,14 +33,25 @@ class asciifyCommand extends Command {
}); });
} }
async exec(message) { async exec(message, args) {
let Attachment = (message.attachments).array(); let url;
if (args.link)
url = args.link.href;
else
url = await attachment(message);
return asciify(Attachment[0].url, options, function (err, asciified) { return asciify(url, options, function (err, asciified) {
if (err) throw err; if (err) throw err;
// Print to console // Print to console
return message.channel.send(asciified, { split: true, code: true }); fs.writeFile(`${os.tmpdir()}/${message.id}ascii.txt`, asciified, function (err) {
if (err) {
console.log(err);
}
return message.channel.send({files: [`${os.tmpdir()}/${message.id}ascii.txt`]});
});
//return message.channel.send(asciified, { split: true, code: true });
}); });
} }
} }

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const ffmpeg = require('fluent-ffmpeg'); const ffmpeg = require('fluent-ffmpeg');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const fs = require('fs'); const fs = require('fs');
@ -19,7 +20,7 @@ class audio2imageCommand extends Command {
}, },
{ {
id: 'link', id: 'link',
type: 'string', type: 'url',
} }
], ],
description: { description: {
@ -31,12 +32,12 @@ class audio2imageCommand extends Command {
} }
async exec(message, args) { async exec(message, args) {
let Attachment = (message.attachments).array(); let url;
let url = args.link;
// Get attachment link if (args.link)
if (Attachment[0] && !args.link) { url = args.link.href;
url = Attachment[0].url; else
} url = await attachment(message);
let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>'); let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>');

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const ffmpeg = require('fluent-ffmpeg'); const ffmpeg = require('fluent-ffmpeg');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const fs = require('fs'); const fs = require('fs');
@ -13,7 +14,7 @@ class image2audioCommand extends Command {
args: [ args: [
{ {
id: 'link', id: 'link',
type: 'string', type: 'url',
}, },
{ {
id: 'wav', id: 'wav',
@ -30,12 +31,12 @@ class image2audioCommand extends Command {
} }
async exec(message, args) { async exec(message, args) {
let Attachment = (message.attachments).array(); let url;
let url = args.link;
// Get attachment link if (args.link)
if (Attachment[0] && !args.link) { url = args.link.href;
url = Attachment[0].url; else
} url = await attachment(message);
let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>'); let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>');

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const util = require('util'); const util = require('util');
const exec = util.promisify(require('child_process').exec); const exec = util.promisify(require('child_process').exec);
const downloader = require('../../utils/download'); const downloader = require('../../utils/download');
@ -15,7 +16,7 @@ class midifyCommand extends Command {
args: [ args: [
{ {
id: 'link', id: 'link',
type: 'string', type: 'url',
match: 'rest' match: 'rest'
}, },
{ {
@ -43,12 +44,12 @@ class midifyCommand extends Command {
} }
async exec(message, args) { async exec(message, args) {
let Attachment = (message.attachments).array(); let url;
let url = args.link;
// Get attachment link if (args.link)
if (Attachment[0] && !args.link) { url = args.link.href;
url = Attachment[0].url; else
} url = await attachment(message);
let input = `${os.tmpdir()}/${message.id}`; let input = `${os.tmpdir()}/${message.id}`;
let input2 = `${os.tmpdir()}/${message.id}.wav`; let input2 = `${os.tmpdir()}/${message.id}.wav`;

View file

@ -2,6 +2,7 @@ const { Command } = require('discord-akairo');
const YTPGenerator = require('ytpplus-node'); const YTPGenerator = require('ytpplus-node');
const os = require('os'); const os = require('os');
const fs = require('fs'); const fs = require('fs');
const attachment = require('../../utils/attachment');
const downloader = require('../../utils/download'); const downloader = require('../../utils/download');
const md5File = require('md5-file'); const md5File = require('md5-file');
const ytpHash = require('../../models').ytpHash; const ytpHash = require('../../models').ytpHash;
@ -99,11 +100,18 @@ class ytpCommand extends Command {
}, },
{ {
id: 'link', id: 'link',
type: 'string' type: 'url',
prompt: {
start: 'Please send the URL of which video you want to download. Say `cancel` to stop the command',
retry: 'Please send a valid URL of the video you want to download. Say `cancel` to stop the command',
optional: true,
},
unordered: true
}, },
{ {
id: 'max', id: 'max',
type: 'string' type: 'string',
unordered: true
} }
], ],
description: { description: {
@ -128,12 +136,12 @@ class ytpCommand extends Command {
if (args.add) { if (args.add) {
let loadingmsg = await message.channel.send('Downloading <a:loadingmin:527579785212329984>'); let loadingmsg = await message.channel.send('Downloading <a:loadingmin:527579785212329984>');
let Attachment = (message.attachments).array(); let url;
let url = args.link;
// Get attachment link if (args.link)
if (Attachment[0] && !args.link) { url = args.link.href;
url = Attachment[0].url; else
} url = await attachment(message);
if (url) { if (url) {
return downloader(url, ['--format=mp4'], `./asset/ytp/userVid/${message.id}.mp4`) return downloader(url, ['--format=mp4'], `./asset/ytp/userVid/${message.id}.mp4`)

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const jimp = require('jimp'); const jimp = require('jimp');
const os = require('os'); const os = require('os');
@ -11,7 +12,7 @@ class autocropCommand extends Command {
args: [ args: [
{ {
id: 'link', id: 'link',
type: 'string', type: 'url',
} }
], ],
description: { description: {
@ -24,18 +25,12 @@ class autocropCommand extends Command {
async exec(message, args) { async exec(message, args) {
let output = `${os.tmpdir()}/cropped${message.id}.jpg`; let output = `${os.tmpdir()}/cropped${message.id}.jpg`;
let url;
if (args.link)
let Attachment = (message.attachments).array(); url = args.link.href;
let url = args.link; else
// Get attachment link url = await attachment(message);
if (Attachment[0] && !args.link) {
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 <a:loadingmin:527579785212329984>'); let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>');

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const jimp = require('jimp'); const jimp = require('jimp');
const os = require('os'); const os = require('os');
@ -11,12 +12,13 @@ class blurCommand extends Command {
args: [ args: [
{ {
id: 'link', id: 'link',
type: 'string', type: 'url',
unordered: true
}, },
{ {
id: 'radius', id: 'radius',
type: 'integer', type: 'integer',
unordered: true
} }
], ],
description: { description: {
@ -31,14 +33,12 @@ class blurCommand extends Command {
let output = `${os.tmpdir()}/blurred${message.id}.jpg`; let output = `${os.tmpdir()}/blurred${message.id}.jpg`;
if (!args.radius) args.radius = 10; if (!args.radius) args.radius = 10;
let url;
if (args.link)
let Attachment = (message.attachments).array(); url = args.link.href;
let url = args.link; else
// Get attachment link url = await attachment(message);
if (Attachment[0] && !args.link) {
url = Attachment[0].url;
}
if (!url) { if (!url) {
return message.channel.send('You need an image to use this command!'); return message.channel.send('You need an image to use this command!');

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const jimp = require('jimp'); const jimp = require('jimp');
const os = require('os'); const os = require('os');
@ -11,11 +12,13 @@ class gaussianCommand extends Command {
args: [ args: [
{ {
id: 'link', id: 'link',
type: 'string', type: 'url',
unordered: true
}, },
{ {
id: 'radius', id: 'radius',
type: 'integer', type: 'integer',
unordered: true
} }
], ],
description: { description: {
@ -31,13 +34,12 @@ class gaussianCommand extends Command {
if (!args.radius) args.radius = 10; if (!args.radius) args.radius = 10;
let url;
let Attachment = (message.attachments).array(); if (args.link)
let url = args.link; url = args.link.href;
// Get attachment link else
if (Attachment[0] && !args.link) { url = await attachment(message);
url = Attachment[0].url;
}
if (!url) { if (!url) {
return message.channel.send('You need an image to use this command!'); return message.channel.send('You need an image to use this command!');

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const jimp = require('jimp'); const jimp = require('jimp');
const os = require('os'); const os = require('os');
@ -11,7 +12,7 @@ class jpegifyCommand extends Command {
args: [ args: [
{ {
id: 'link', id: 'link',
type: 'string', type: 'url',
} }
], ],
description: { description: {
@ -24,14 +25,12 @@ class jpegifyCommand extends Command {
async exec(message, args) { async exec(message, args) {
let output = `${os.tmpdir()}/jpegified${message.id}.jpg`; let output = `${os.tmpdir()}/jpegified${message.id}.jpg`;
let url;
if (args.link)
let Attachment = (message.attachments).array(); url = args.link.href;
let url = args.link; else
// Get attachment link url = await attachment(message);
if (Attachment[0] && !args.link) {
url = Attachment[0].url;
}
if (!url) { if (!url) {
return message.channel.send('You need an image to use this command!'); return message.channel.send('You need an image to use this command!');

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const gm = require('gm').subClass({imageMagick: true}); const gm = require('gm').subClass({imageMagick: true});
const os = require('os'); const os = require('os');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
@ -13,10 +14,7 @@ class memeCommand extends Command {
args: [ args: [
{ {
id: 'link', id: 'link',
prompt: { type: 'url',
start: 'Please input a link to use, say `cancel` to stop the command'
},
type: 'string',
}, },
{ {
id: 'message', id: 'message',
@ -43,14 +41,18 @@ class memeCommand extends Command {
async exec(message, args) { async exec(message, args) {
let options = args.message.trim().split('|'); let options = args.message.trim().split('|');
let url;
if (args.link)
url = args.link.href;
else
url = await attachment(message);
if (options[0] == undefined) if (options[0] == undefined)
options[0] = ''; options[0] = '';
else if (options[1] == undefined) else if (options[1] == undefined)
options[1] = ''; options[1] = '';
let url = args.link;
if (!url) { if (!url) {
return message.channel.send('You need an image to use this command!'); return message.channel.send('You need an image to use this command!');
} }

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const jimp = require('jimp'); const jimp = require('jimp');
const os = require('os'); const os = require('os');
@ -11,7 +12,7 @@ class mirrorCommand extends Command {
args: [ args: [
{ {
id: 'link', id: 'link',
type: 'string', type: 'url',
} }
], ],
description: { description: {
@ -24,14 +25,12 @@ class mirrorCommand extends Command {
async exec(message, args) { async exec(message, args) {
let output = `${os.tmpdir()}/mirrored${message.id}.jpg`; let output = `${os.tmpdir()}/mirrored${message.id}.jpg`;
let url;
if (args.link)
let Attachment = (message.attachments).array(); url = args.link.href;
let url = args.link; else
// Get attachment link url = await attachment(message);
if (Attachment[0] && !args.link) {
url = Attachment[0].url;
}
if (!url) { if (!url) {
return message.channel.send('You need an image to use this command!'); return message.channel.send('You need an image to use this command!');

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const { createCanvas, loadImage } = require('canvas'); const { createCanvas, loadImage } = require('canvas');
const superagent = require('superagent'); const superagent = require('superagent');
@ -19,14 +20,14 @@ class paintCommand extends Command {
} }
async exec(message, args) { async exec(message, args) {
let Attachment = (message.attachments).array();
let image = args.image; let image = args.image;
if (!Attachment[0] && !image) if (!image)
image = message.author.displayAvatarURL().replace('webp', 'png'); image = await attachment(message);
else if(Attachment[0] && Attachment[0].url.endsWith('gif'))
return message.channel.send('Gif dosent work, sorry');
else if (!image) else if (!image)
image = Attachment[0].url; image = message.author.displayAvatarURL().replace('webp', 'png');
else if(image.endsWith('gif'))
return message.channel.send('Gif dosent work, sorry');
message.channel.send('Processing <a:loadingmin:527579785212329984>') message.channel.send('Processing <a:loadingmin:527579785212329984>')
.then(loadingmsg => loadingmsg.delete(1000)); .then(loadingmsg => loadingmsg.delete(1000));

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const attachment = require('../../utils/attachment');
const jimp = require('jimp'); const jimp = require('jimp');
const os = require('os'); const os = require('os');
@ -11,7 +12,8 @@ class rotateCommand extends Command {
args: [ args: [
{ {
id: 'link', id: 'link',
type: 'string', type: 'url',
unordered: true
}, },
{ {
id: 'rotate', id: 'rotate',
@ -19,7 +21,8 @@ class rotateCommand extends Command {
prompt: { prompt: {
start: 'Please enter the number of degrees you want to rotate.', start: 'Please enter the number of degrees you want to rotate.',
retry: 'This doesn\'t look like a number to me, please try again.' retry: 'This doesn\'t look like a number to me, please try again.'
} },
unordered: true
} }
], ],
description: { description: {
@ -34,12 +37,12 @@ class rotateCommand extends Command {
let output = `${os.tmpdir()}/rotated${message.id}.jpg`; let output = `${os.tmpdir()}/rotated${message.id}.jpg`;
let Attachment = (message.attachments).array(); let url;
let url = args.link; if (args.link)
// Get attachment link url = args.link.href;
if (Attachment[0] && !args.link) { else
url = Attachment[0].url; url = await attachment(message);
}
if (!url) { if (!url) {
return message.channel.send('You need an image to use this command!'); return message.channel.send('You need an image to use this command!');