Compare commits

...

3 Commits

  1. 4
      .gitignore
  2. 9
      bot.js
  3. 5980
      package-lock.json
  4. 7
      src/db/connect.js
  5. 19
      src/handle/startup/run/login.js
  6. 12
      src/json/config.json

4
.gitignore vendored

@ -6,4 +6,6 @@ test.js
api/**/*
api/
.idea/**/*
/man.js
/man.js
.history/
.history/**/*

@ -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"});
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:

5980
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -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`)}.`);
};

@ -3,12 +3,12 @@
"suffix": ">>",
"defaultLevel": 1,
"colors": {
"error": "",
"warn": "",
"success": "",
"notice": "",
"primary": "",
"secondary": "",
"error": "redBright",
"warn": "yellowBright",
"success": "greenBright",
"notice": "#8521a0",
"primary": "blueBright",
"secondary": "white",
"altprimary": "",
"altsecondary": ""
}

Loading…
Cancel
Save