Compare commits

...

4 Commits

  1. 8
      bot.js
  2. 11
      src/db/connect.js
  3. 5
      src/handle/startup/collect/commands.js
  4. 1
      src/handle/startup/collect/events.js
  5. 8
      src/handle/startup/run/collect.js
  6. 10
      src/handle/startup/run/hello.js
  7. 8
      src/handle/startup/run/login.js
  8. 8
      src/util/log/errorhandler.js

@ -3,6 +3,7 @@ const Discord = require('discord.js');
const auth = require('./src/json/auth.json');
const config = require('./src/json/config.json');
const randresp = require('./src/json/randresp.json');
const errorhandler = require('./src/util/log/errorhandler');
const log = require('./src/util/log/log');
@ -18,6 +19,7 @@ const startBot = async () => {
client.config.randResp = randresp;
require('./src/util/misc/setutils')(client); // add some basic swiss army knife utils
const loggers = log(client);
Object.keys(loggers).forEach(logger => client[logger] = loggers[logger]);
@ -25,10 +27,10 @@ const startBot = async () => {
await require('./src/handle/startup/run/login')(client); //log in to discord
await require('./src/db/connect')(client); //connect to database
await require('./src/handle/startup/run/collect')(client);
};
startBot().catch(() => {
console.log("\nWell this is awkward.\n");
}); // TODO add a .catch() and flag to recover the process
startBot().catch(e => errorhandler(e)); // 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:

@ -1,22 +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 => {
const auth = client.auth;
const t = Date.now();
client.misc.dbconnected = false;
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}.3jpp4.mongodb.net/test`, {
useFindAndModify: false, useNewUrlParser: true, dbName: auth.database.name, useUnifiedTopology: true, useCreateIndex: true
})
).catch((e) => client.error("Failed to connect to mongoose!! Error below.", 0, true, true, e))
.then(() => {client.misc.dbconnected = true;});
).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`)}.`);
return client.success(`Connected to Mongo Database in ${chalk.white(`${Date.now() - t}ms`)}.`, 0, 0, 1);
};

@ -0,0 +1,5 @@
const fs = require('fs');
module.exports = async client => {
};

@ -0,0 +1 @@
module.exports = async client => {};

@ -0,0 +1,8 @@
const {Collection} = require("discord.js");
module.exports = async client => {
['commands', 'events'].forEach(x => {
client[x] = new Collection();
require(`../collect/${x}`)(client);
});
};

@ -0,0 +1,10 @@
const moment = require("moment");
const chalk = require('chalk');
const os = require('os');
module.exports = client => {
client.log(`Logged in as ${chalk.blueBright(client.user.username)}. ${chalk.greenBright(`[${chalk.grey(client.user.id)}]`)}`);
client.log(`Time: ${chalk.blueBright(moment().format('MMMM d, YYYY - HH:MM:SS'))}`);
client.log(`Running on ${chalk.blueBright(client.guilds.cache.size)} ${chalk.blue("servers")} and interacting with about ${chalk.blueBright(client.users.cache.size)} ${chalk.blue("users")}.`);
client.log(`This ${chalk.blue('heap')} has ${chalk.blueBright((process.memoryUsage().heapTotal / (1024 ** 2)).toFixed(2))}MB allocated; The ${chalk.blue('machine')} has ${chalk.blueBright((os.totalmem() / (1024 ** 3)).toFixed(2))}GB (${chalk.blueBright((os.freemem() / (1024 ** 3)).toFixed(2))}GB free)`);
};

@ -5,12 +5,14 @@ const ora = require('../../../util/log/ora');
module.exports = async (client) => {
const t = Date.now();
client.misc = {};
client.misc.dscconnected = false;
client.misc.dscconnected = true;
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;});
).catch((e) => {
client.error("Failed to connect to Discord!! Error below.", 0, 0, true, e);
client.misc.dscconnected = false;
});
if (!client.misc.dscconnected) {
client.warn("Discord not connected, considering runtime to be unusable and exiting.", 0, true, true);
throw new Error();

@ -0,0 +1,8 @@
const chalk = require('chalk');
module.exports = e => {
console.log(`#######################################\n\n${chalk.grey('[NATS]')} >> ${chalk.hex('#78d9f8')("Well this is awkward.")}\n`);
console.log(`${chalk.bold.redBright.underline("There was an error that killed Natsuki's process.")}\n${chalk.redBright("See available stack trace and error information below.")}\n`);
console.error(e);
console.log(`\n#######################################\n\n${chalk.grey('[NATS]')} >> ${chalk.hex('#78d9f8')("Back to sleepies...")}`);
};
Loading…
Cancel
Save