From 133538dbe9a33d59a31feca7519f43a1989d387a Mon Sep 17 00:00:00 2001
From: loicbersier <loic.bersier1@gmail.com>
Date: Sun, 3 May 2020 19:23:54 +0200
Subject: [PATCH 1/4] Use --rm-cache-dir when downloading a video

---
 commands/fun/ytp.js          | 6 +++---
 commands/utility/download.js | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/commands/fun/ytp.js b/commands/fun/ytp.js
index c0675e1..fa60e3c 100644
--- a/commands/fun/ytp.js
+++ b/commands/fun/ytp.js
@@ -3,6 +3,8 @@ const YTPGenerator = require('ytpplus-node');
 const os = require('os');
 const fs = require('fs');
 const youtubedl = require('youtube-dl');
+const MAX_CLIPS = 20;
+
 
 class ytpCommand extends Command {
 	constructor() {
@@ -100,8 +102,6 @@ class ytpCommand extends Command {
 	}
 
 	async exec(message, args) {
-		let MAX_CLIPS = 20;
-
 		if (args.pool) {
 			let mp4 = [];
 			fs.readdirSync('./asset/ytp/userVid/').forEach(file => {
@@ -123,7 +123,7 @@ class ytpCommand extends Command {
 			}
 			
 			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);
 					if (err) {
 						console.error(err);
diff --git a/commands/utility/download.js b/commands/utility/download.js
index 7c7cf46..56a365d 100644
--- a/commands/utility/download.js
+++ b/commands/utility/download.js
@@ -69,10 +69,10 @@ class DownloadCommand extends Command {
 
 			if (fs.existsSync(`${os.tmpdir()}/${fileName}`)) {
 				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) {
 					console.error(err);
 					loadingmsg.delete();
@@ -84,7 +84,7 @@ class DownloadCommand extends Command {
 				if (fs.existsSync(`${os.tmpdir()}/${fileName}`)) {
 					ext = await filetype.fromFile(`${os.tmpdir()}/${fileName}`);
 					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}`);
 				} 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
@@ -125,7 +125,7 @@ class DownloadCommand extends Command {
 
 					// Every 5 seconds update the compress message with the %
 					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);
 					}, 5000);
 

From 8af6023267da7bd13fdb3e2e7b9004a893e45a65 Mon Sep 17 00:00:00 2001
From: loicbersier <loic.bersier1@gmail.com>
Date: Sun, 3 May 2020 19:24:03 +0200
Subject: [PATCH 2/4] Updated some packages

---
 package-lock.json | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index 2912fea..b0bca64 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -76,16 +76,6 @@
       "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.5.tgz",
       "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": {
       "version": "2.3.0",
       "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"
     },
     "discord.js": {
-      "version": "github:discordjs/discord.js#026691702da7d1fcf9a959f00082f07f1e14b13d",
+      "version": "github:discordjs/discord.js#5b9cdc5cd243b1588c285e22b90d92535a30b993",
       "from": "github:discordjs/discord.js#master",
       "requires": {
         "@discordjs/collection": "^0.1.5",
-        "@discordjs/form-data": "^3.0.1",
         "abort-controller": "^3.0.0",
+        "form-data": "^3.0.0",
         "node-fetch": "^2.6.0",
         "prism-media": "^1.2.0",
         "setimmediate": "^1.0.5",
         "tweetnacl": "^1.0.3",
         "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": {
@@ -2465,7 +2467,7 @@
       }
     },
     "erlpack": {
-      "version": "github:discordapp/erlpack#c514d36ec81a7a61ef90b75df261025ab046574d",
+      "version": "github:discordapp/erlpack#5d0064f9e106841e1eead711a6451f99b0d289fd",
       "from": "github:discordapp/erlpack",
       "requires": {
         "bindings": "^1.5.0",
@@ -7894,7 +7896,7 @@
       }
     },
     "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",
       "requires": {
         "ffmpeg-static": "^2.4.0",

From 7f0453b3a55cc35c3c4ce9492fb2ac68452130df Mon Sep 17 00:00:00 2001
From: loicbersier <loic.bersier1@gmail.com>
Date: Sun, 3 May 2020 22:41:54 +0200
Subject: [PATCH 3/4] Show execution time

---
 event/listeners/commandfinish.js  | 16 ++++++++++++++++
 event/listeners/commandstarted.js |  6 ++++--
 2 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 event/listeners/commandfinish.js

diff --git a/event/listeners/commandfinish.js b/event/listeners/commandfinish.js
new file mode 100644
index 0000000..0b9cbeb
--- /dev/null
+++ b/event/listeners/commandfinish.js
@@ -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;
\ No newline at end of file
diff --git a/event/listeners/commandstarted.js b/event/listeners/commandstarted.js
index 380eddc..36736fb 100644
--- a/event/listeners/commandstarted.js
+++ b/event/listeners/commandstarted.js
@@ -13,6 +13,8 @@ class commandStartedListener extends Listener {
 	}
 
 	async exec(message, command) {
+		console.time(command.id);
+
 		//This is for april fools
 		let today = new Date(), lastUpdate;
 		
@@ -27,7 +29,7 @@ class commandStartedListener extends Listener {
 		} 
 		let curDate = dd + '.' + mm;
 		//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;
 			if (count < 10) {
 				serverID.push(message.guild.id);
@@ -49,7 +51,7 @@ class commandStartedListener extends Listener {
 		}
 
 		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 = {
 				guild: message.guild.id,
 				command: command.id

From b123ceb58498266258c035e9dd540cd86f476793 Mon Sep 17 00:00:00 2001
From: loicbersier <loic.bersier1@gmail.com>
Date: Sun, 3 May 2020 22:42:05 +0200
Subject: [PATCH 4/4] uncaughtException

---
 event/listeners/uncaughtException.js | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 event/listeners/uncaughtException.js

diff --git a/event/listeners/uncaughtException.js b/event/listeners/uncaughtException.js
new file mode 100644
index 0000000..7f7f1f5
--- /dev/null
+++ b/event/listeners/uncaughtException.js
@@ -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;
\ No newline at end of file