From 5fb88a0a0998ce6c308645ab912c1887bc3c4555 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Sun, 17 Nov 2024 09:13:02 -0800 Subject: [PATCH] fix/handle failed mongo connection --- package.json | 2 +- src/DayzRBot.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index aa72efd..fefd4d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "13.3.13", + "version": "13.3.14", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "main": "index.js", "nodemonConfig": { diff --git a/src/DayzRBot.js b/src/DayzRBot.js index 8750a4d..bc62120 100644 --- a/src/DayzRBot.js +++ b/src/DayzRBot.js @@ -384,8 +384,10 @@ class DayzRBot extends Client { databaselogs.attempts = 0; // reset attempts this.databaseConnected = true; } catch (err) { - databaselogs.attempts++; - let db = (mongoURI.includes("@") ? mongoURI.split("@")[1] : mongoURI.split("//")[1]).endsWith("/") ? mongoURI.slice(0, -1) : mongoURI; + databaselogs.attempts++; + databaselogs.connected = false; + let db = mongoURI.includes("@") ? mongoURI.split("@")[1] : mongoURI.split("//")[1]; + db = db.includes("/") ? db.split("/")[0] : db; this.error(`Failed to connect to mongodb (mongodb://${db}/${dbo}): attempt ${databaselogs.attempts} - ${err}`); failed = true; } @@ -399,7 +401,8 @@ class DayzRBot extends Client { async initialize() { // Wait for MongoDB to connect await this.connectMongo(this.config.mongoURI, this.config.dbo); - + + if (!this.databaseConnected) return; let guilds = await this.dbo.collection("guilds").find({}).toArray(); /*