Compare commits

..

No commits in common. '762bdc17bd8edf9a40af241afd49b351fc1e8e0e' and 'd469ed39690b142d1fcbb43781e01a31d01fb3a5' have entirely different histories.

  1. 19
      bot.js
  2. 27
      src/db/connect.js
  3. 13
      src/util/log/log.js
  4. 18
      src/util/log/ora.js
  5. 20
      src/util/log/types.js
  6. 7
      src/util/misc/wait.js

@ -1,5 +1,14 @@
const dbConnect = require('./src/db/connect'); const logger = require('./src/util/log/log');
const r = async () => { const client = {test: 'e', config: {logLevel: 1}};
await dbConnect({auth: require('./src/json/auth.json'), config: {logLevel: 1}}); const log = logger(client);
}; log();
r(); 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'});

@ -1,23 +1,10 @@
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 auth = client.auth; const config = client.config;
const t = Date.now(); try {
client.misc = {}; await mongoose.connect(`mongodb+srv://${config.database.user}:${config.database.password}@${config.database.cluster}.3jpp4.mongodb.net/test`, {
client.misc.dbconnected = false; useFindAndModify: false, useNewUrlParser: true, dbName: 'Natsuki-Main', useUnifiedTopology: true, useCreateIndex: true
await ora(chalk.blueBright.bold.underline("Connecting to MongoDB..."), }).catch(() => {});
mongoose.connect(`mongodb+srv://${auth.database.user}:${auth.database.password}@${auth.database.cluster}.3jpp4.mongodb.net/test`, { } catch (e) {
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`)}.`);
}; };

@ -1,7 +1,6 @@
const chalk = require('chalk'); const chalk = require('chalk');
const getLevel = require('./getlevel'); const getLevel = require('./getlevel');
const types = require('./types');
const config = require('../../json/config.json'); const config = require('../../json/config.json');
@ -13,9 +12,9 @@ let defaultOptions = {
suffix: " >> " suffix: " >> "
}; };
const tlog = (client) => (message = "Test Log", options = {}, prenl = false, postnl = false, ...multcons) => { module.exports = (client) => {
return (message = "Test Log", options = {}, newLine = false, spacer = false) => {
let opt = {}; let opt = {};
if (typeof options !== 'object') {options = {};}
opt.color = options.color || defaultOptions.color; opt.color = options.color || defaultOptions.color;
opt.level = ['string', 'number'].includes(typeof options.level) ? options.level : defaultOptions.level; opt.level = ['string', 'number'].includes(typeof options.level) ? options.level : defaultOptions.level;
opt.suffix = typeof options.suffix === 'string' ? options.suffix : defaultOptions.suffix; opt.suffix = typeof options.suffix === 'string' ? options.suffix : defaultOptions.suffix;
@ -26,12 +25,6 @@ const tlog = (client) => (message = "Test Log", options = {}, prenl = false, pos
client.config.logLevel = getLevel(client.config.logLevel); client.config.logLevel = getLevel(client.config.logLevel);
if (client.config.logLevel < opt.level) {return;} if (client.config.logLevel < opt.level) {return;}
} }
console.log(`${prenl ? '\n' : ''}${(opt.sourceColor.startsWith('#') ? chalk.hex(opt.sourceColor) : chalk[opt.sourceColor])(`[${opt.source.toUpperCase()}]`)}${opt.suffix}${options.nc || options.noColor ? message : (opt.color.startsWith('#') ? chalk.hex(opt.color) : chalk[opt.color])(message)}${postnl ? '\n' : ''}`, ...multcons); console.log(`${spacer ? '\n' : ''}${(opt.sourceColor.startsWith('#') ? chalk.hex(opt.sourceColor) : chalk[opt.sourceColor])(`[${opt.source.toUpperCase()}]`)}${opt.suffix}${options.nc || options.noColor ? message : (opt.color.startsWith('#') ? chalk.hex(opt.color) : chalk[opt.color])(message)}${newLine ? '\n' : ''}`);
};
module.exports = (client) => {
return {
log: tlog(client),
...types(tlog(client))
}; };
}; };

@ -1,18 +0,0 @@
const ora = require('ora');
module.exports = async (text, promise, callback) => {
return new Promise(async (resolve, reject) => {
let spin = ora(text).start();
return await promise
.catch(e => {
spin.stop();
spin.clear();
return reject(e)
})
.then((...args) => {
spin.stop();
spin.clear();
return callback ? resolve(callback(spin, args)) : resolve(true);
});
});
};

@ -1,20 +0,0 @@
module.exports = (log) => { return {
error: (message, options, prenl, postnl, ...multcons) => log(message, {
color: 'redBright',
source: 'err!',
sourceColor: 'red',
level: 0
}, prenl, postnl, ...multcons),
warn: (message, options, prenl, postnl, ...multcons) => log(message, {
color: 'yellowBright',
source: 'warn',
sourceColor: 'yellow',
level: 1
}, prenl, postnl, ...multcons),
success: (message, options, prenl, postnl, ...multcons) => log(message, {
color: 'greenBright',
source: 'proc' || options && options.source,
sourceColor: 'green',
level: options && typeof options.level !== 'undefined' ? options.level : 0
}, prenl, postnl, ...multcons)
}};

@ -1,7 +0,0 @@
module.exports = (time) => {
return new Promise(function (resolve) {
setTimeout(function () {
resolve(null);
}, time);
});
};
Loading…
Cancel
Save