diff --git a/index.js b/index.js index a1bba8be..1aac5234 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,15 @@ const cli = require(`./${buildDir}/ririkoCli`); const configFileExists = fs.existsSync("./config.js"); +process + .on("unhandledRejection", (reason, p) => { + console.error(reason, "Unhandled Rejection at Promise", p); + }) + .on("uncaughtException", (err) => { + console.error(err, "Uncaught Exception thrown"); + console.oLog(err); + }); + function createLogDirectory() { if (!fs.existsSync(logDirectory)) { fs.mkdirSync(logDirectory); diff --git a/package-lock.json b/package-lock.json index c4829f28..04ce590e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ririko", - "version": "0.14.1", + "version": "0.14.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ririko", - "version": "0.14.1", + "version": "0.14.2", "license": "MIT", "dependencies": { "@discordjs/builders": "^1.6.3", diff --git a/package.json b/package.json index 6b7a6a7a..e9fec947 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ririko", - "version": "0.14.1", + "version": "0.14.2", "description": "Ririko - A powerful AI-powered general Discord bot that you can call your companion", "author": "Earnest Angel", "email": "me@angel.net.my", diff --git a/src/app/RirikoAVC.js b/src/app/RirikoAVC.js index 64cb860b..8dc47133 100644 --- a/src/app/RirikoAVC.js +++ b/src/app/RirikoAVC.js @@ -94,38 +94,43 @@ class RirikoAVC { } checkAVC(client) { - //remove deleted channels from data - let updatePersistance = false; - this.#_content.primary.forEach((id) => { - if (client.channels.cache.get(id) == null) { - this.#_content.primary.splice(this.#_content.primary.indexOf(id), 1); - updatePersistance = true; - } - }); - this.#_content.children.forEach((id) => { - if (client.channels.cache.get(id) == null) { - this.#_content.children.splice(this.#_content.children.indexOf(id), 1); - updatePersistance = true; - } - }); - if (updatePersistance) this.#save(); + try { + //remove deleted channels from data + let updatePersistance = false; + this.#_content.primary.forEach((id) => { + if (client.channels.cache.get(id) == null) { + this.#_content.primary.splice(this.#_content.primary.indexOf(id), 1); + updatePersistance = true; + } + }); + this.#_content.children.forEach((id) => { + if (client.channels.cache.get(id) == null) { + this.#_content.children.splice( + this.#_content.children.indexOf(id), + 1 + ); + updatePersistance = true; + } + }); + if (updatePersistance) this.#save(); - // Check if channels need to be created - this.#_content.primary.forEach((id) => { - let primary = client.channels.cache.get(id); - if (primary?.members.first() != null) { - primary.members.every((member) => { - this.createChildVoice(primary, member); - }); - } - }); - //Check if channels need to be deleted - this.#_content.children.forEach((id) => { - let children = client.channels.cache.get(id); - if (children != null && children?.members.first() == null) { - this.deleteChildrenVoice(children); - } - }); + // Check if channels need to be created + this.#_content.primary.forEach((id) => { + let primary = client.channels.cache.get(id); + if (primary?.members.first() != null) { + primary.members.every((member) => { + this.createChildVoice(primary, member); + }); + } + }); + //Check if channels need to be deleted + this.#_content.children.forEach((id) => { + let children = client.channels.cache.get(id); + if (children != null && children?.members.first() == null) { + this.deleteChildrenVoice(children); + } + }); + } catch (e) {} } } diff --git a/src/ririkoBot.js b/src/ririkoBot.js index b55df141..8411101f 100644 --- a/src/ririkoBot.js +++ b/src/ririkoBot.js @@ -19,9 +19,14 @@ const { RirikoMusic } = require("app/RirikoMusic"); const { getLang } = require("./helpers/language"); const { RirikoAVC } = require("./app/RirikoAVC"); -process.on("uncaughtException", function (err) { - console.log("Caught exception: " + err); -}); +process + .on("unhandledRejection", (reason, p) => { + console.error(reason, "Unhandled Rejection at Promise", p); + }) + .on("uncaughtException", (err) => { + console.error(err, "Uncaught Exception thrown"); + console.oLog(err); + }); console.info("0------------------| Ririko AI (Bot):".brightCyan); @@ -166,7 +171,7 @@ module.exports = client; }) .on("uncaughtException", (err) => { console.error(err, "Uncaught Exception thrown"); - process.exit(1); + console.oLog(err); }); // Use this to remove commands list diff --git a/src/ririkoCli.js b/src/ririkoCli.js index aabf721d..2fde52ce 100644 --- a/src/ririkoCli.js +++ b/src/ririkoCli.js @@ -8,6 +8,15 @@ const NODE_ENV = process.env.NODE_ENV || "development"; let initialized = false; let showPrompt = false; // Flag to control prompt display +process + .on("unhandledRejection", (reason, p) => { + console.error(reason, "Unhandled Rejection at Promise", p); + }) + .on("uncaughtException", (err) => { + console.error(err, "Uncaught Exception thrown"); + console.oLog(err); + }); + const rl = readline.createInterface({ input: process.stdin, output: process.stdout, diff --git a/src/ririkoExpress.js b/src/ririkoExpress.js index 8633144d..4c2f1a45 100644 --- a/src/ririkoExpress.js +++ b/src/ririkoExpress.js @@ -16,6 +16,15 @@ const path = require("path"); const configFileExists = fs.existsSync("./config.js"); +process + .on("unhandledRejection", (reason, p) => { + console.error(reason, "Unhandled Rejection at Promise", p); + }) + .on("uncaughtException", (err) => { + console.error(err, "Uncaught Exception thrown"); + console.oLog(err); + }); + console.info("0------------------| Ririko Express (Web Server):".brightCyan); let Hostname, Port; diff --git a/src/ririkoQueueManager.js b/src/ririkoQueueManager.js index 5c0eaaf8..d0a26608 100644 --- a/src/ririkoQueueManager.js +++ b/src/ririkoQueueManager.js @@ -13,6 +13,15 @@ overrideLoggers(); console.info("[Ririko Queue Manager] Started".brightMagenta); +process + .on("unhandledRejection", (reason, p) => { + console.error(reason, "Unhandled Rejection at Promise", p); + }) + .on("uncaughtException", (err) => { + console.error(err, "Uncaught Exception thrown"); + console.oLog(err); + }); + const { Client, Intents, GatewayIntentBits } = require("discord.js"); const client = new Client({ diff --git a/src/ririkoStreamChecker.js b/src/ririkoStreamChecker.js index 6883d06f..c77de7b3 100644 --- a/src/ririkoStreamChecker.js +++ b/src/ririkoStreamChecker.js @@ -27,6 +27,15 @@ let retries = 0, max_retries = 5; let iteration = 1; +process + .on("unhandledRejection", (reason, p) => { + console.error(reason, "Unhandled Rejection at Promise", p); + }) + .on("uncaughtException", (err) => { + console.error(err, "Uncaught Exception thrown"); + console.oLog(err); + }); + (async function () { require("handlers/mongoose")(false, "Stream Checker", true); diff --git a/test.js b/test.js deleted file mode 100644 index e27d1596..00000000 --- a/test.js +++ /dev/null @@ -1,62 +0,0 @@ -switch (item.name) { - /** - * { name: 'application_id', value: 'a' } - * { name: 'bot_token', value: 'b' } - * { name: 'privileged_intents', value: 'on' } - * { name: 'enable_chatbot', value: 'on' } - * { name: 'ai_provider', value: 'OpenAI' } - * { name: 'ai_token', value: 'c' } - * { name: 'enable_stablediffusion', value: 'on' } - * { name: 'replicate_token', value: 'd' } - * { name: 'enable_twitch', value: 'on' } - * { name: 'twitch_client_id', value: 'e' } - * { name: 'twitch_client_secret', value: 'f' } - * { name: 'mongodb_uri' value: 'mongodb+srv://' } - * { name: 'accept_tos', value: 'true' } - * { name: 'accept_privacypolicy', value: 'true' } - */ - case "application_id": - console.log("application_id", item.value); - break; - case "bot_token": - console.log("bot_token", item.value); - break; - case "privileged_intents": - console.log("privileged_intents", item.value); - break; - case "enable_chatbot": - console.log("enable_chatbot", item.value); - break; - case "ai_provider": - console.log("ai_provider", item.value); - break; - case "ai_token": - console.log("ai_token", item.value); - break; - case "enable_stablediffusion": - console.log("enable_stablediffusion", item.value); - break; - case "replicate_token": - console.log("replicate_token", item.value); - break; - case "enable_twitch": - console.log("enable_twitch", item.value); - break; - case "twitch_client_id": - console.log("twitch_client_id", item.value); - break; - case "twitch_client_secret": - console.log("twitch_client_secret", item.value); - break; - case "mongodb_uri": - console.log("mongodb_uri", item.value); - break; - case "accept_tos": - console.log("accept_tos", item.value); - break; - case "accept_privacypolicy": - console.log("accept_privacypolicy", item.value); - break; - default: - break; -} diff --git a/vc.json b/vc.json deleted file mode 100644 index 9e26dfee..00000000 --- a/vc.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file