login + connect

v2
Kit Kasune 2 years ago
parent 53a3e5c839
commit 3182903c77
  1. 9
      bot.js
  2. 7
      src/db/connect.js
  3. 19
      src/handle/startup/run/login.js

@ -21,9 +21,14 @@ const startBot = async () => {
const loggers = log(client);
Object.keys(loggers).forEach(logger => client[logger] = loggers[logger]);
client.log(client.utils.gr(client.config.randResp.clistart), {color: "#78d9f8", source: "NATS"}, true); //natsuki's wakeup log
client.log(client.utils.gr(client.config.randResp.clistart), {color: "#78d9f8", source: "NATS"}, true, true); //natsuki's wakeup log
await require('./src/handle/startup/run/login')(client); //log in to discord
await require('./src/db/connect')(client); //connect to database
};
startBot();
startBot().catch(() => {
console.log("\nWell this is awkward.\n");
}); // TODO add a .catch() and flag to recover the process
// feels like there isn't a function name to do this justice :joy:
// to do list:

@ -7,17 +7,16 @@ const ora = require('../util/log/ora');
module.exports = async client => {
const auth = client.auth;
const t = Date.now();
client.misc = {};
client.misc.dbconnected = false;
await ora(chalk.blueBright.bold.underline("Connecting to MongoDB..."),
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))
).catch((e) => 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);
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`)}.`);
return client.success(`Connected to Mongo Database in ${chalk.white(`${Date.now() - t}ms`)}.`);
};

@ -0,0 +1,19 @@
const chalk = require('chalk');
const ora = require('../../../util/log/ora');
module.exports = async (client) => {
const t = Date.now();
client.misc = {};
client.misc.dscconnected = false;
await ora(`Waking up Natsuki... ${chalk.blueBright.bold.underline("(Connecting to Discord...)")}`,
client.login(client.auth.token)
).catch((e) => client.error("Failed to connect to Discord!! Error below.", 0, true, true, e))
.then(() => {client.misc.dscconnected = true;});
if (!client.misc.dscconnected) {
client.warn("Discord not connected, considering runtime to be unusable and exiting.", 0, true, true);
throw new Error();
}
return client.success(`Connected to Discord in ${chalk.white(`${Date.now() - t}ms`)}.`);
};
Loading…
Cancel
Save