Added discord methods in events.js and renamed some variables in config then adapted the code around that. Redid date structures in Logger

This commit is contained in:
plane000
2018-10-26 21:13:06 +01:00
parent c3a98599cd
commit 3f1a80e83b
5 changed files with 41 additions and 18 deletions

View File

@@ -6,8 +6,8 @@ export class Config {
constructor(path) {
this.file = './resources/config/config.json';
this.path = [ './resources/', './resources/config' ]
this.Config = {
token: 'YOUR TOKEN HERE'
this.Configuration = {
Token: 'YOUR TOKEN HERE'
};
}
@@ -15,8 +15,8 @@ export class Config {
Logger.info('Loading config');
if (fs.existsSync(this.file)) {
try {
this.Config = JSON.parse(fs.readFileSync(this.file));
if (!this.Config.token);
this.Configuration = JSON.parse(fs.readFileSync(this.file));
if (!this.Configuration.Token) Logger.panic('Token is missing from config file');
Logger.info('Config loaded successfully');
} catch (e) {

View File

@@ -0,0 +1,15 @@
import {Logger} from './logger';
import {Config} from './config';
export class Events {
async init(client) {
this.client = client;
this.client.login(Config.Configuration.Token);
}
async handle() {
this.client.on('ready', () => {
console.log('cx');
});
}
}

View File

@@ -3,8 +3,7 @@ import Discord from 'discord.js';
import {Logger} from './logger';
import {Config} from './config';
import {Database} from './database/database';
let client;
import {Events} from './events';
init();
async function init() {
@@ -15,8 +14,10 @@ async function init() {
config.load();
await Database.init();
Logger.debug(JSON.stringify(await Database.Guilds.newGuild(1234, "Hello"), null, 4));
Logger.debug(JSON.stringify(await Database.Guilds.deleteGuild(1234), null, 4));
// Logger.debug(JSON.stringify(await Database.Guilds.newGuild(1234, "Hello"), null, 4));
// Logger.debug(JSON.stringify(await Database.Guilds.deleteGuild(1234), null, 4));
client = new Discord.Client();
const client = new Discord.Client();
const eventHandler = new Events(client);
eventHandler.handle();
}

View File

@@ -1,9 +1,11 @@
import colours from 'colors/safe';
import moment from 'moment';
import fs from 'fs';
let LogLevel = 1;
let Dialect = 'SQLITE';
let logPath = 'logs.log';
let dateFormat = 'DD-MM-YY HH:MM:ss'
export class Logger {
static init(path) {
@@ -34,6 +36,10 @@ export class Logger {
Dialect = dialect;
}
static SetDateFormat(format) {
dateFormat = format;
}
static get VERBOSE_LOGS() {return 0;}
static get DEBUG_LOGS() {return 1;}
static get INFO_LOGS() {return 2;}
@@ -41,7 +47,7 @@ export class Logger {
static database(message) {
if (LogLevel > 0) return;
let d = new Date();
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [${Dialect}] ${message} \n`);
console.log('[' + d.toLocaleString() + '] ['
+ colours.magenta(Dialect) + '] ' + message);
@@ -49,7 +55,7 @@ export class Logger {
static middleware(message) {
if (LogLevel > 0) return;
let d = new Date();
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [HTTP-MIDDLEWARE] ${message} \n`);
console.log('[' + d.toLocaleString() + '] ['
+ colours.blue('HTTP-MIDDLEWARE') + '] ' + message);
@@ -57,22 +63,22 @@ export class Logger {
static debug(message) {
if (LogLevel > 1) return;
let d = new Date();
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [DEBUG] ${message} \n`);
console.log('[' + d.toLocaleString() + '] ['
+ colours.cyan('DEBUG') + '] ' + message);
}
static ready() {
let d = new Date();
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [READY] \n`);
console.log('[' + d.toLocaleString() + '] ['
+ colours.rainbow('READY') + ']');
}
static info(message) {
if (LogLevel > 2) return;
let d = new Date();
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [INFO] ${message} \n`);
console.log('[' + d.toLocaleString() + '] ['
+ colours.green('INFO') + '] ' + message);
@@ -80,21 +86,21 @@ export class Logger {
static warn(message) {
if (LogLevel > 3) return;
let d = new Date();
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [WARN] ${message} \n`);
console.log('[' + d.toLocaleString() + '] ['
+ colours.yellow('WARN') + '] ' + message);
}
static error(message) {
let d = new Date();
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [ERROR] ${message} \n`);
console.log('[' + d.toLocaleString() + '] ['
+ colours.red('ERROR') + '] ' + message);
}
static panic(message) {
let d = new Date();
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [PANIC] ${message} \n`);
console.log('[' + d.toLocaleString() + '] ['
+ colours.red('PANIC') + '] ' + message);