parent
a5e1c4c1f9
commit
762bdc17bd
@ -1,29 +1,5 @@ |
|||||||
const logger = require('./src/util/log/log'); |
const dbConnect = require('./src/db/connect'); |
||||||
const ora = require('./src/util/log/ora'); |
|
||||||
const wait = require('./src/util/misc/wait'); |
|
||||||
const chalk = require('chalk'); |
|
||||||
|
|
||||||
const client = {test: 'e', config: {logLevel: 1}}; |
|
||||||
|
|
||||||
const loggers = logger(client); |
|
||||||
const log = loggers.log; |
|
||||||
|
|
||||||
log(); |
|
||||||
log("Hello World!") |
|
||||||
log("Hello in blue", {color: 'blue'}); |
|
||||||
log('A strange warning appears!', {color: 'yellowBright', source: 'warn', sourceColor: 'yellow'}); |
|
||||||
/*log('Extra line spacing before', {}, false, true); |
|
||||||
log('regular line'); |
|
||||||
log('extra line spacing after', {}, true); |
|
||||||
log('regular line'); |
|
||||||
log('both line spaces', {}, true, true); |
|
||||||
log('regular line'); |
|
||||||
log('a custom fancy pink color', {color: '#ff00ff', sourceColor: '#660066'});*/ |
|
||||||
loggers.warn("A warning appears!"); |
|
||||||
loggers.error("Something bad happened!"); |
|
||||||
loggers.success("Something good happened!"); |
|
||||||
const r = async () => { |
const r = async () => { |
||||||
await ora(chalk.yellowBright("Waiting for a slow connection..."), wait(2000), () => loggers.success("Connected!", 0, true)); |
await dbConnect({auth: require('./src/json/auth.json'), config: {logLevel: 1}}); |
||||||
log('after thingy'); |
|
||||||
}; |
}; |
||||||
r(); |
r(); |
@ -1,10 +1,23 @@ |
|||||||
|
const chalk = require('chalk'); |
||||||
|
const mongoose = require('mongoose'); |
||||||
|
|
||||||
|
const log = require('../util/log/log'); |
||||||
|
const ora = require('../util/log/ora'); |
||||||
|
|
||||||
module.exports = async client => { |
module.exports = async client => { |
||||||
const config = client.config; |
const auth = client.auth; |
||||||
try { |
const t = Date.now(); |
||||||
await mongoose.connect(`mongodb+srv://${config.database.user}:${config.database.password}@${config.database.cluster}.3jpp4.mongodb.net/test`, { |
client.misc = {}; |
||||||
useFindAndModify: false, useNewUrlParser: true, dbName: 'Natsuki-Main', useUnifiedTopology: true, useCreateIndex: true |
client.misc.dbconnected = false; |
||||||
}).catch(() => {}); |
await ora(chalk.blueBright.bold.underline("Connecting to MongoDB..."), |
||||||
} catch (e) { |
mongoose.connect(`mongodb+srv://${auth.database.user}:${auth.database.password}@${auth.database.cluster}.3jpp4.mongodb.net/test`, { |
||||||
|
useFindAndModify: false, useNewUrlParser: true, dbName: auth.database.name, useUnifiedTopology: true, useCreateIndex: true |
||||||
|
}) |
||||||
|
).catch((e) => log(client).error("Failed to connect to mongoose!! Error below.", 0, true, true, e)) |
||||||
|
.then(() => {client.misc.dbconnected = true;}); |
||||||
|
if (!client.misc.dbconnected) { |
||||||
|
log(client).warn("Database not connected, considering runtime to be unusable and exiting.", 0, true, true); |
||||||
|
throw new Error(); |
||||||
} |
} |
||||||
|
return log(client).success(`Connected to Mongo Database in ${chalk.white(`${Date.now() - t}ms`)}.`); |
||||||
}; |
}; |
Loading…
Reference in new issue