The helper bot for LHT
https://lhtranslation.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
1.0 KiB
24 lines
1.0 KiB
const chalk = require('chalk');
|
|
const mongoose = require('mongoose');
|
|
|
|
const ora = require('../util/log/ora');
|
|
|
|
module.exports = async client => {
|
|
if (!client.misc) {client.misc = {};}
|
|
const auth = client.auth;
|
|
const t = Date.now();
|
|
client.misc.dbconnected = true;
|
|
await ora(chalk.blueBright.bold.underline("Connecting to MongoDB..."),
|
|
mongoose.connect(`mongodb+srv://${auth.database.user}:${auth.database.password}@${auth.database.cluster}.uqyvv.mongodb.net/test`, {
|
|
dbName: auth.database.name //TODO research mongo connect options
|
|
})
|
|
).catch((e) => {
|
|
client.error("Failed to connect to mongoose!! Error below.", 0, 0, true, e);
|
|
client.misc.dbconnected = false;
|
|
});
|
|
if (!client.misc.dbconnected) {
|
|
client.warn("Database not connected, considering runtime to be unusable and exiting.", 0, true, true);
|
|
throw new Error();
|
|
}
|
|
return client.success(`Connected to Mongo Database in ${chalk.white(`${Date.now() - t}ms`)}.`, 0, 0, 1);
|
|
}; |