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 attachment = require('../../utils/attachment');
const os = require('os');
const fs = require('fs');
const asciify = require('asciify-image');
let options = {
@ -14,6 +17,12 @@ class asciifyCommand extends Command {
aliases: ['asciify'],
category: 'fun',
clientPermissions: ['SEND_MESSAGES'],
args: [
{
id: 'link',
type: 'url',
}
],
cooldown: 600000,
ratelimit: 2,
description: {
@ -24,14 +33,25 @@ class asciifyCommand extends Command {
});
}
async exec(message) {
let Attachment = (message.attachments).array();
async exec(message, args) {
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;
// 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 attachment = require('../../utils/attachment');
const ffmpeg = require('fluent-ffmpeg');
const fetch = require('node-fetch');
const fs = require('fs');
@ -19,7 +20,7 @@ class audio2imageCommand extends Command {
},
{
id: 'link',
type: 'string',
type: 'url',
}
],
description: {
@ -31,12 +32,12 @@ class audio2imageCommand extends Command {
}
async exec(message, args) {
let Attachment = (message.attachments).array();
let url = args.link;
// Get attachment link
if (Attachment[0] && !args.link) {
url = Attachment[0].url;
}
let url;
if (args.link)
url = args.link.href;
else
url = await attachment(message);
let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>');

View file

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

View file

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

View file

@ -2,6 +2,7 @@ const { Command } = require('discord-akairo');
const YTPGenerator = require('ytpplus-node');
const os = require('os');
const fs = require('fs');
const attachment = require('../../utils/attachment');
const downloader = require('../../utils/download');
const md5File = require('md5-file');
const ytpHash = require('../../models').ytpHash;
@ -99,11 +100,18 @@ class ytpCommand extends Command {
},
{
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',
type: 'string'
type: 'string',
unordered: true
}
],
description: {
@ -128,12 +136,12 @@ class ytpCommand extends Command {
if (args.add) {
let loadingmsg = await message.channel.send('Downloading <a:loadingmin:527579785212329984>');
let Attachment = (message.attachments).array();
let url = args.link;
// Get attachment link
if (Attachment[0] && !args.link) {
url = Attachment[0].url;
}
let url;
if (args.link)
url = args.link.href;
else
url = await attachment(message);
if (url) {
return downloader(url, ['--format=mp4'], `./asset/ytp/userVid/${message.id}.mp4`)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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