Merge remote-tracking branch 'origin/master'

This commit is contained in:
loicbersier 2020-05-08 01:26:16 +02:00
commit f0d9b853c5
6 changed files with 59 additions and 23 deletions

View file

@ -3,6 +3,8 @@ const YTPGenerator = require('ytpplus-node');
const os = require('os'); const os = require('os');
const fs = require('fs'); const fs = require('fs');
const youtubedl = require('youtube-dl'); const youtubedl = require('youtube-dl');
const MAX_CLIPS = 20;
class ytpCommand extends Command { class ytpCommand extends Command {
constructor() { constructor() {
@ -100,8 +102,6 @@ class ytpCommand extends Command {
} }
async exec(message, args) { async exec(message, args) {
let MAX_CLIPS = 20;
if (args.pool) { if (args.pool) {
let mp4 = []; let mp4 = [];
fs.readdirSync('./asset/ytp/userVid/').forEach(file => { fs.readdirSync('./asset/ytp/userVid/').forEach(file => {
@ -123,7 +123,7 @@ class ytpCommand extends Command {
} }
if (url) { if (url) {
return youtubedl.exec(url, ['--no-playlist','--max-filesize', '50m', '--format=mp4', '-o', `./asset/ytp/userVid/${message.id}.mp4`], {}, function(err, output) { return youtubedl.exec(url, ['--rm-cache-dir', '--no-playlist', '--max-filesize', '50m', '--format=mp4', '-o', `./asset/ytp/userVid/${message.id}.mp4`], {}, function(err, output) {
console.log(output); console.log(output);
if (err) { if (err) {
console.error(err); console.error(err);

View file

@ -69,10 +69,10 @@ class DownloadCommand extends Command {
if (fs.existsSync(`${os.tmpdir()}/${fileName}`)) { if (fs.existsSync(`${os.tmpdir()}/${fileName}`)) {
fs.unlink(`${os.tmpdir()}/${fileName}`, (err) => { fs.unlink(`${os.tmpdir()}/${fileName}`, (err) => {
if (err); if (err) console.error(err);
}); });
} }
return youtubedl.exec(link, ['-o', `${os.tmpdir()}/${fileName}`], {}, async function(err) { return youtubedl.exec(link, ['--rm-cache-dir', '-o', `${os.tmpdir()}/${fileName}`], {}, async function(err) {
if (err) { if (err) {
console.error(err); console.error(err);
loadingmsg.delete(); loadingmsg.delete();
@ -84,7 +84,7 @@ class DownloadCommand extends Command {
if (fs.existsSync(`${os.tmpdir()}/${fileName}`)) { if (fs.existsSync(`${os.tmpdir()}/${fileName}`)) {
ext = await filetype.fromFile(`${os.tmpdir()}/${fileName}`); ext = await filetype.fromFile(`${os.tmpdir()}/${fileName}`);
ext = ext.ext; // This look stupid but hey, it work ext = ext.ext; // This look stupid but hey, it work
if (ext == '3gp') ext = 'mp4'; // Change 3gp file extension to mp4 so discord show the video ( and to stop people from complaining ) if (ext === '3gp') ext = 'mp4'; // Change 3gp file extension to mp4 so discord show the video ( and to stop people from complaining )
fs.renameSync(`${os.tmpdir()}/${fileName}`, `${os.tmpdir()}/${fileName}.${ext}`); fs.renameSync(`${os.tmpdir()}/${fileName}`, `${os.tmpdir()}/${fileName}.${ext}`);
} else if (fs.existsSync(`${os.tmpdir()}/${fileName}.mkv`)) { // If it can't find the video assume it got merged and end with mkv } else if (fs.existsSync(`${os.tmpdir()}/${fileName}.mkv`)) { // If it can't find the video assume it got merged and end with mkv
fs.renameSync(`${os.tmpdir()}/${fileName}.mkv`, `${os.tmpdir()}/${fileName}.mp4`); // Discord play mkv just fine but it need to end with mp4 fs.renameSync(`${os.tmpdir()}/${fileName}.mkv`, `${os.tmpdir()}/${fileName}.mp4`); // Discord play mkv just fine but it need to end with mp4
@ -125,7 +125,7 @@ class DownloadCommand extends Command {
// Every 5 seconds update the compress message with the % // Every 5 seconds update the compress message with the %
let editmsg = setInterval(() => { let editmsg = setInterval(() => {
compressEmbed.setDescription(`Ready in ${eta == '' ? 'soon enough' : eta}. ${percentComplete}% complete.`); compressEmbed.setDescription(`Ready in ${eta === '' ? 'soon enough' : eta}. ${percentComplete}% complete.`);
compressmsg.edit(compressEmbed); compressmsg.edit(compressEmbed);
}, 5000); }, 5000);

View file

@ -0,0 +1,16 @@
const { Listener } = require('discord-akairo');
class commandFinishedListener extends Listener {
constructor() {
super('commandFinished', {
emitter: 'commandHandler',
event: 'commandFinished'
});
}
async exec(message, command) {
console.timeEnd(command.id);
}
}
module.exports = commandFinishedListener;

View file

@ -13,6 +13,8 @@ class commandStartedListener extends Listener {
} }
async exec(message, command) { async exec(message, command) {
console.time(command.id);
//This is for april fools //This is for april fools
let today = new Date(), lastUpdate; let today = new Date(), lastUpdate;
@ -27,7 +29,7 @@ class commandStartedListener extends Listener {
} }
let curDate = dd + '.' + mm; let curDate = dd + '.' + mm;
//Only execute when its april first //Only execute when its april first
if (curDate == '01.04' && !serverID.includes(message.guild.id)) { if (curDate === '01.04' && !serverID.includes(message.guild.id)) {
let count = Math.random() * 100; let count = Math.random() * 100;
if (count < 10) { if (count < 10) {
serverID.push(message.guild.id); serverID.push(message.guild.id);
@ -49,7 +51,7 @@ class commandStartedListener extends Listener {
} }
if (dailyStats) { if (dailyStats) {
if (command.category.id == 'owner') return; // Don't count owner command if (command.category.id === 'owner') return; // Don't count owner command
let obj = { let obj = {
guild: message.guild.id, guild: message.guild.id,
command: command.id command: command.id

View file

@ -0,0 +1,16 @@
const { Listener } = require('discord-akairo');
class unhandledRejectionListener extends Listener {
constructor() {
super('uncaughtException', {
emitter: 'process',
event: 'uncaughtException'
});
}
async exec(error) {
return console.error(`\x1b[31mUncaughtException: ${error}\x1b[37m`);
}
}
module.exports = unhandledRejectionListener;

30
package-lock.json generated
View file

@ -76,16 +76,6 @@
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.5.tgz", "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.5.tgz",
"integrity": "sha512-CU1q0UXQUpFNzNB7gufgoisDHP7n+T3tkqTsp3MNUkVJ5+hS3BCvME8uCXAUFlz+6T2FbTCu75A+yQ7HMKqRKw==" "integrity": "sha512-CU1q0UXQUpFNzNB7gufgoisDHP7n+T3tkqTsp3MNUkVJ5+hS3BCvME8uCXAUFlz+6T2FbTCu75A+yQ7HMKqRKw=="
}, },
"@discordjs/form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"@google-cloud/text-to-speech": { "@google-cloud/text-to-speech": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/@google-cloud/text-to-speech/-/text-to-speech-2.3.0.tgz", "resolved": "https://registry.npmjs.org/@google-cloud/text-to-speech/-/text-to-speech-2.3.0.tgz",
@ -2295,17 +2285,29 @@
"from": "github:1Computer1/discord-akairo#master" "from": "github:1Computer1/discord-akairo#master"
}, },
"discord.js": { "discord.js": {
"version": "github:discordjs/discord.js#026691702da7d1fcf9a959f00082f07f1e14b13d", "version": "github:discordjs/discord.js#5b9cdc5cd243b1588c285e22b90d92535a30b993",
"from": "github:discordjs/discord.js#master", "from": "github:discordjs/discord.js#master",
"requires": { "requires": {
"@discordjs/collection": "^0.1.5", "@discordjs/collection": "^0.1.5",
"@discordjs/form-data": "^3.0.1",
"abort-controller": "^3.0.0", "abort-controller": "^3.0.0",
"form-data": "^3.0.0",
"node-fetch": "^2.6.0", "node-fetch": "^2.6.0",
"prism-media": "^1.2.0", "prism-media": "^1.2.0",
"setimmediate": "^1.0.5", "setimmediate": "^1.0.5",
"tweetnacl": "^1.0.3", "tweetnacl": "^1.0.3",
"ws": "^7.2.1" "ws": "^7.2.1"
},
"dependencies": {
"form-data": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
"integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
}
} }
}, },
"doctrine": { "doctrine": {
@ -2465,7 +2467,7 @@
} }
}, },
"erlpack": { "erlpack": {
"version": "github:discordapp/erlpack#c514d36ec81a7a61ef90b75df261025ab046574d", "version": "github:discordapp/erlpack#5d0064f9e106841e1eead711a6451f99b0d289fd",
"from": "github:discordapp/erlpack", "from": "github:discordapp/erlpack",
"requires": { "requires": {
"bindings": "^1.5.0", "bindings": "^1.5.0",
@ -7894,7 +7896,7 @@
} }
}, },
"ytpplus-node": { "ytpplus-node": {
"version": "git+https://git@github.com/loicbersier/ytpplus-node.git#6ebaa924f8e49b016f57610193517e65b7cce87d", "version": "git+https://git@github.com/loicbersier/ytpplus-node.git#a9edb7a9596734d0b518cb32e1581f06ce5f7ad7",
"from": "git+https://git@github.com/loicbersier/ytpplus-node.git", "from": "git+https://git@github.com/loicbersier/ytpplus-node.git",
"requires": { "requires": {
"ffmpeg-static": "^2.4.0", "ffmpeg-static": "^2.4.0",