Merge pull request #4 from SowinskiBraeden/test_failed_mongo

Catch Failed Mongo
This commit is contained in:
SowinskiBraeden authored and GitHub committed 2022-10-12 08:12:56 -07:00
commit eed9869976
2 files changed
+15 -24

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@ require('dotenv').config();
module.exports = { module.exports = {
Dev: "PROD.", Dev: "PROD.",
Version: "12.7.6", Version: "12.7.7",
Admins: ["362791661274660874", "329371697570381824"], // Admins of the bot Admins: ["362791661274660874", "329371697570381824"], // Admins of the bot
DefaultPrefix: "?", DefaultPrefix: "?",
ServerID: "955668596745461830", ServerID: "955668596745461830",
+14 -23
View File
@@ -6,6 +6,7 @@ const mongoose = require('mongoose');
const Logger = require("../util/Logger"); const Logger = require("../util/Logger");
const path = require("path"); const path = require("path");
const fs = require('fs'); const fs = require('fs');
const { exit } = require("process");
class QuarksBot extends Client { class QuarksBot extends Client {
@@ -69,12 +70,16 @@ class QuarksBot extends Client {
} }
async connectMongo(mongoURI, dbo) { async connectMongo(mongoURI, dbo) {
// Connect to MongoDB database. try {
this.db = await MongoClient.connect(mongoURI); // Connect to MongoDB database.
this.dbo = this.db.db(dbo); this.db = await MongoClient.connect(mongoURI, {connectTimeoutMS: 5000});
this.dbo = this.db.db(dbo);
mongoose.connect(`${mongoURI}/${dbo}`); mongoose.connect(`${mongoURI}/${dbo}`);
this.log('Successfully connected to mongoDB'); this.log('Successfully connected to mongoDB');
} catch (err) {
this.error('Failed to connect to mongodb');
process.exit(-1);
}
} }
exists(n) {return null != n && undefined != n && "" != n} exists(n) {return null != n && undefined != n && "" != n}
@@ -128,7 +133,7 @@ class QuarksBot extends Client {
sendTime(Channel, Error) { sendTime(Channel, Error) {
let embed = new EmbedBuilder() let embed = new EmbedBuilder()
.setColor(this.config.EmbedColor) .setColor(this.config.Red)
.setDescription(Error); .setDescription(Error);
Channel.send(embed); Channel.send(embed);
@@ -189,22 +194,8 @@ class QuarksBot extends Client {
return guildData; return guildData;
} }
log(Text) { log(Text) { this.logger.log(Text); }
this.logger.log(Text); error(Text) { this.logger.error(Text); }
}
error(Text) {
this.logger.error(Text);
}
sendError(Channel, Error) {
let embed = new EmbedBuilder()
.setTitle("An error occured")
.setColor(client.config.Colors.Red)
.setDescription(Error)
Channel.send(embed);
}
build() { build() {
this.login(this.config.Token); this.login(this.config.Token);