replace sayd and downloadspoiler with flag

This commit is contained in:
loicbersier 2019-07-11 00:31:15 +02:00
parent b6e4387c73
commit 4a169b3dae
4 changed files with 58 additions and 198 deletions

View file

@ -15,10 +15,15 @@ class SayCommand extends Command {
start: 'Write something so i can say it back',
},
match: 'rest'
},
{
id: 'delete',
match: 'flag',
flag: ['--del', '--delete', '-d']
}
],
description: {
content: 'Repeat what you say, [Click here to see the complete list of "tag"](https://cdn.discordapp.com/attachments/502198809355354133/561043193949585418/unknown.png)',
content: 'Repeat what you say, (Use "-d" to delete the message you sent) [Click here to see the complete list of "tag"](https://cdn.discordapp.com/attachments/502198809355354133/561043193949585418/unknown.png)',
usage: '[text]',
examples: ['[member] is a big [adverbs] [verbs]']
}
@ -134,16 +139,24 @@ class SayCommand extends Command {
.setTimestamp();
if (attach) {
if (args.delete)
message.delete();
return message.channel.send(embed, {files: [attach]});
} else {
if (args.delete)
message.delete();
return message.channel.send(embed);
}
}
// Send the final text
if (attach) {
if (args.delete)
message.delete();
return message.channel.send(text, {files: [attach]});
} else {
if (args.delete)
message.delete();
return message.channel.send(text);
}
}

View file

@ -1,44 +0,0 @@
const { Command } = require('discord-akairo');
const rand = require('../../rand.js');
class SaydCommand extends Command {
constructor() {
super('sayd', {
aliases: ['sayd'],
category: 'general',
clientPermissions: 'MANAGE_MESSAGES',
args: [
{
id: 'text',
type: 'string',
prompt: {
start: 'Write something so i can say it back',
},
match: 'rest'
}
],
description: {
content: 'Repeat what you say but delete the text you sent, [Click here to see the complete list of "tag"](https://cdn.discordapp.com/attachments/502198809355354133/561043193949585418/unknown.png)',
usage: '[text]',
examples: ['[member] is a big [adverbs] [verbs]']
}
});
}
async exec(message, args) {
let text = args.text;
if (!text)
return;
text = rand.random(text, message);
// Send the final text
message.delete();
return message.util.send('===ANTI-SNIPE MESSAGE===')
.then(() => {
message.util.edit(text);
});
}
}
module.exports = SaydCommand;

View file

@ -21,11 +21,16 @@ class DownloadCommand extends Command {
id: 'alt',
match: 'flag',
flag: '--alt'
},
{
id: 'spoiler',
match: 'flag',
flag: ['--spoil', '--spoiler', '-s']
}
],
clientPermissions: ['ATTACH_FILES'],
description: {
content: 'Download videos from different website from the link you provided',
content: 'Download videos from different website from the link you provided ( use "-s" to make the vid a spoiler )',
usage: '[link]',
examples: ['https://www.youtube.com/watch?v=6n3pFFPSlW4']
}
@ -35,25 +40,37 @@ class DownloadCommand extends Command {
async exec(message, args) {
let link = args.link;
let needCompress = false;
let fileName;
if (args.spoiler) {
fileName = 'SPOILER_video';
} else {
fileName = 'video';
}
if (link.includes('http') || link.includes('www')) {
if (args.alt) {
console.log('alt download!');
fs.unlink('./video.mp4', (err) => {
if (fs.existsSync(`./${fileName}.mp4`)) {
fs.unlink(`./${fileName}.mp4`, (err) => {
if (err);
});
return youtubedl.exec(args.link, ['-o', './video.mp4'], {}, function(err, output) {
}
return youtubedl.exec(args.link, ['-o', `./${fileName}.mp4`], {}, function(err, output) {
if (err) throw err;
console.log(output.join('\n'));
message.delete();
message.channel.send(`Downloaded by ${message.author.username}`, { files: ['./video.mp4'] })
.catch(() => message.channel.send('File too big'));
message.channel.send(`Downloaded by ${message.author.username}`, { files: [`./${fileName}.mp4`] })
.catch(err => {
console.error(err);
return message.channel.send('File too big');
});
});
}
let video = youtubedl(link, [`--username=${fbuser}`, `--password=${fbpasswd}`]);
video.pipe(fs.createWriteStream('./video.mp4'));
video.pipe(fs.createWriteStream(`./${fileName}.mp4`));
video.on('error', function error(err) {
console.log('error 2:', err);
message.channel.send('An error has occured, I can\'t download from the link you provided.');
@ -89,26 +106,31 @@ class DownloadCommand extends Command {
video.on('end', function () {
if (!needCompress) {
message.delete();
return message.channel.send(`Downloaded by ${message.author.username}`, { files: ['./video.mp4'] })
.catch(() => message.channel.send('File too big'));
return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`./${fileName}.mp4`] })
.catch(err => {
console.error(err);
return message.channel.send('File too big');
});
}
const options = {
input: 'video.mp4',
output: 'videoReady.mp4',
input: `${fileName}.mp4`,
output: `${fileName}Ready.mp4`,
preset: 'General/Gmail Small 10 Minutes 288p30'
};
//Compress vid if bigger than 8MB
let handbrake = hbjs.spawn(options);
handbrake.on('start', function() {
message.channel.send('Video bigger than 8MB compressing now <a:loadingmin:527579785212329984> (This can take a long time!)\nWant it to go faster? Donate to the dev with the donate command, so i can get a better server and do it faster!').then(msg => {
handbrake.on('end', function () {
msg.delete();
handbrake.on('end', async function () {
await msg.delete();
});
});
});
handbrake.on('error', err => {
message.channel.send('An error has occured while compressing the video');
console.error(err);
return message.channel.send('An error has occured while compressing the video');
});
handbrake.on('progress', progress => {
console.log(
@ -119,13 +141,15 @@ class DownloadCommand extends Command {
});
handbrake.on('end', function () {
message.delete();
message.channel.send(`Downloaded by ${message.author.username}`, { files: ['./videoReady.mp4'] })
.catch(() => message.channel.send('File too big'));
return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`./${fileName}Ready.mp4`] })
.catch(err => {
console.error(err);
return message.channel.send('File too big');
});
});
});
} else {
message.channel.send('You need to input a valid link');
return message.channel.send('You need to input a valid link');
}
}
}

View file

@ -1,133 +0,0 @@
const { Command } = require('discord-akairo');
const fs = require('fs');
const youtubedl = require('youtube-dl');
const hbjs = require('handbrake-js');
const { fbuser, fbpasswd } = require('../../config.json');
class DownloadspoilerCommand extends Command {
constructor() {
super('downloadspoiler', {
aliases: ['downloadspoiler', 'dls'],
category: 'utility',
args: [
{
id: 'link',
type: 'string',
prompt: {
start: 'Send the link of wich video you want to download',
}
},
{
id: 'alt',
match: 'flag',
flag: '--alt'
}
],
clientPermissions: ['ATTACH_FILES'],
description: {
content: 'Download videos from different website from the link you provided (The video will be in spoiler)',
usage: '[link]',
examples: ['https://www.youtube.com/watch?v=6n3pFFPSlW4']
}
});
}
async exec(message, args) {
let link = args.link;
let needCompress = false;
if (link.includes('http') || link.includes('www')) {
if (args.alt) {
console.log('alt download!');
fs.unlink('./SPOILER_video.mp4', (err) => {
if (err);
});
return youtubedl.exec(args.link, ['-o', './SPOILER_video.mp4'], {}, function(err, output) {
if (err) throw err;
console.log(output.join('\n'));
message.delete();
message.channel.send(`Downloaded by ${message.author.username}`, { files: ['./SPOILER_video.mp4'] })
.catch(() => message.channel.send('File too big'));
});
}
let video = youtubedl(link, [`--username=${fbuser}`, `--password=${fbpasswd}`]);
video.pipe(fs.createWriteStream('./SPOILER_video.mp4'));
video.on('error', function error(err) {
console.log('error 2:', err);
message.channel.send('An error has occured, I can\'t download from the link you provided.');
});
message.channel.send('Downloading <a:loadingmin:527579785212329984>').then(msg => {
video.on('end', function () {
msg.delete();
});
});
video.on('info', function(info) {
let duration = info.duration;
if (duration) {
duration = duration.replace(/:/g, '');
if (duration > 500) {
video.pause();
video.unpipe();
return message.channel.send('Can\'t download video longer than 5 minutes');
}
}
console.log('Download started');
console.log('filename: ' + info._filename);
console.log('size: ' + info.size);
if (info.size >= 8000000) {
needCompress = true;
}
});
video.on('end', function () {
if (!needCompress) {
message.delete();
return message.channel.send(`Downloaded by ${message.author.username}`, { files: ['./SPOILER_video.mp4'] })
.catch(() => message.channel.send('File too big'));
}
const options = {
input: 'SPOILER_video.mp4',
output: 'SPOILER_videoReady.mp4',
preset: 'General/Gmail Small 10 Minutes 288p30'
};
//Compress vid if bigger than 8MB
let handbrake = hbjs.spawn(options);
handbrake.on('start', function() {
message.channel.send('Video bigger than 8MB compressing now <a:loadingmin:527579785212329984> (This can take a long time!)\nWant it to go faster? Donate to the dev with the donate command, so i can get a better server and do it faster!').then(msg => {
handbrake.on('end', function () {
msg.delete();
});
});
});
handbrake.on('error', err => {
message.channel.send('An error has occured while compressing the video');
console.error(err);
});
handbrake.on('progress', progress => {
console.log(
'Percent complete: %s, ETA: %s',
progress.percentComplete,
progress.eta
);
});
handbrake.on('end', function () {
message.delete();
message.channel.send(`Downloaded by ${message.author.username}`, { files: ['./SPOILER_videoReady.mp4'] })
.catch(() => message.channel.send('File too big'));
});
});
} else {
message.channel.send('You need to input a valid link');
}
}
}
module.exports = DownloadspoilerCommand;