Merge pull request #5 from plane000/dev
Merge stable branch dev to master
This commit is contained in:
@@ -15,9 +15,8 @@
|
|||||||
"body-parser": "^1.18.3",
|
"body-parser": "^1.18.3",
|
||||||
"colors": "^1.3.2",
|
"colors": "^1.3.2",
|
||||||
"discord.js": "^11.4.2",
|
"discord.js": "^11.4.2",
|
||||||
"express": "^4.16.4",
|
"moment": "^2.22.2",
|
||||||
"regenerator-runtime": "^0.12.1",
|
"regenerator-runtime": "^0.12.1",
|
||||||
"request": "^2.88.0",
|
|
||||||
"sequelize": "^4.39.1",
|
"sequelize": "^4.39.1",
|
||||||
"sqlite3": "^4.0.2"
|
"sqlite3": "^4.0.2"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,31 @@ import fs from 'fs';
|
|||||||
|
|
||||||
import {Logger} from './logger';
|
import {Logger} from './logger';
|
||||||
|
|
||||||
|
let file;
|
||||||
|
let path;
|
||||||
|
let Configuration;
|
||||||
|
|
||||||
export class Config {
|
export class Config {
|
||||||
constructor(path) {
|
static get Configuration() {return Configuration;}
|
||||||
this.file = './resources/config/config.json';
|
static get Token() {return Configuration.Token;}
|
||||||
this.path = [ './resources/', './resources/config' ]
|
static get NowPlaying() {return Configuration.NowPlaying;}
|
||||||
this.Config = {
|
|
||||||
token: 'YOUR TOKEN HERE'
|
static init() {
|
||||||
|
file = './resources/config/config.json';
|
||||||
|
path = [ './resources/', './resources/config' ]
|
||||||
|
Configuration = {
|
||||||
|
Token: 'BOT TOKEN HERE',
|
||||||
|
NowPlaying: 'PLAYING GAME HERE'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
load() {
|
static load() {
|
||||||
Logger.info('Loading config');
|
Logger.info('Loading config');
|
||||||
if (fs.existsSync(this.file)) {
|
if (fs.existsSync(file)) {
|
||||||
try {
|
try {
|
||||||
this.Config = JSON.parse(fs.readFileSync(this.file));
|
Configuration = JSON.parse(fs.readFileSync(file));
|
||||||
if (!this.Config.token);
|
if (!Configuration.Token) Logger.panic('Token is missing from config file');
|
||||||
|
if (!Configuration.NowPlaying) Logger.panic('NowPlaying is missing from config file');
|
||||||
|
|
||||||
Logger.info('Config loaded successfully');
|
Logger.info('Config loaded successfully');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -25,11 +35,11 @@ export class Config {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Logger.error('No config found');
|
Logger.error('No config found');
|
||||||
for (let folder of this.path) {
|
for (let folder of path) {
|
||||||
fs.mkdirSync(folder);
|
fs.mkdirSync(folder);
|
||||||
}
|
}
|
||||||
fs.writeFileSync(this.file, JSON.stringify(this.Config, null, 4));
|
fs.writeFileSync(file, JSON.stringify(Configuration, null, 4));
|
||||||
Logger.warn(`Created config at: ${this.path}`);
|
Logger.warn(`Created config at: ${path}`);
|
||||||
Logger.panic('Config required to be complete');
|
Logger.panic('Config required to be complete');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.panic(`Could not create config: ${e}`);
|
Logger.panic(`Could not create config: ${e}`);
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import {Logger} from './logger';
|
||||||
|
import {Config} from './config';
|
||||||
|
|
||||||
|
export class Events {
|
||||||
|
async init(client) {
|
||||||
|
this.client = client;
|
||||||
|
this.client.login(Config.Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEvents() {
|
||||||
|
this.client.on('ready', () => {this.handleReady()});
|
||||||
|
this.client.on('message', async (message) => {this.handleMessage(message)});
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleReady() {
|
||||||
|
this.client.user.setPresence('online');
|
||||||
|
this.client.user.setActivity(Config.NowPlaying);
|
||||||
|
Logger.info(`Discord client logged in as ${this.client.user.tag}`);
|
||||||
|
Logger.ready();
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleMessage(...args) {
|
||||||
|
Logger.info(args[0]);
|
||||||
|
args[0].channel.send('lol u homo')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
15
src/index.js
15
src/index.js
@@ -3,20 +3,21 @@ import Discord from 'discord.js';
|
|||||||
import {Logger} from './logger';
|
import {Logger} from './logger';
|
||||||
import {Config} from './config';
|
import {Config} from './config';
|
||||||
import {Database} from './database/database';
|
import {Database} from './database/database';
|
||||||
|
import {Events} from './events';
|
||||||
let client;
|
|
||||||
|
|
||||||
init();
|
init();
|
||||||
async function init() {
|
async function init() {
|
||||||
Logger.init();
|
Logger.init();
|
||||||
Logger.SetLevel(Logger.VERBOSE_LOGS);
|
Logger.SetLevel(Logger.VERBOSE_LOGS);
|
||||||
|
|
||||||
const config = new Config();
|
Config.init();
|
||||||
config.load();
|
Config.load();
|
||||||
|
|
||||||
await Database.init();
|
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));
|
|
||||||
|
|
||||||
client = new Discord.Client();
|
const client = new Discord.Client();
|
||||||
|
|
||||||
|
const eventHandler = new Events();
|
||||||
|
await eventHandler.init(client);
|
||||||
|
eventHandler.handleEvents();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import colours from 'colors/safe';
|
import colours from 'colors/safe';
|
||||||
|
import moment from 'moment';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
let LogLevel = 1;
|
let LogLevel = 1;
|
||||||
let Dialect = 'SQLITE';
|
let Dialect = 'SQLITE';
|
||||||
let logPath = 'logs.log';
|
let logPath = 'logs.log';
|
||||||
|
let dateFormat = 'DD-MM-YY HH:MM:ss'
|
||||||
|
|
||||||
export class Logger {
|
export class Logger {
|
||||||
static init(path) {
|
static init(path) {
|
||||||
@@ -34,6 +36,10 @@ export class Logger {
|
|||||||
Dialect = dialect;
|
Dialect = dialect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SetDateFormat(format) {
|
||||||
|
dateFormat = format;
|
||||||
|
}
|
||||||
|
|
||||||
static get VERBOSE_LOGS() {return 0;}
|
static get VERBOSE_LOGS() {return 0;}
|
||||||
static get DEBUG_LOGS() {return 1;}
|
static get DEBUG_LOGS() {return 1;}
|
||||||
static get INFO_LOGS() {return 2;}
|
static get INFO_LOGS() {return 2;}
|
||||||
@@ -41,7 +47,7 @@ export class Logger {
|
|||||||
|
|
||||||
static database(message) {
|
static database(message) {
|
||||||
if (LogLevel > 0) return;
|
if (LogLevel > 0) return;
|
||||||
let d = new Date();
|
let d = moment().format(dateFormat);
|
||||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [${Dialect}] ${message} \n`);
|
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [${Dialect}] ${message} \n`);
|
||||||
console.log('[' + d.toLocaleString() + '] ['
|
console.log('[' + d.toLocaleString() + '] ['
|
||||||
+ colours.magenta(Dialect) + '] ' + message);
|
+ colours.magenta(Dialect) + '] ' + message);
|
||||||
@@ -49,7 +55,7 @@ export class Logger {
|
|||||||
|
|
||||||
static middleware(message) {
|
static middleware(message) {
|
||||||
if (LogLevel > 0) return;
|
if (LogLevel > 0) return;
|
||||||
let d = new Date();
|
let d = moment().format(dateFormat);
|
||||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [HTTP-MIDDLEWARE] ${message} \n`);
|
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [HTTP-MIDDLEWARE] ${message} \n`);
|
||||||
console.log('[' + d.toLocaleString() + '] ['
|
console.log('[' + d.toLocaleString() + '] ['
|
||||||
+ colours.blue('HTTP-MIDDLEWARE') + '] ' + message);
|
+ colours.blue('HTTP-MIDDLEWARE') + '] ' + message);
|
||||||
@@ -57,22 +63,22 @@ export class Logger {
|
|||||||
|
|
||||||
static debug(message) {
|
static debug(message) {
|
||||||
if (LogLevel > 1) return;
|
if (LogLevel > 1) return;
|
||||||
let d = new Date();
|
let d = moment().format(dateFormat);
|
||||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [DEBUG] ${message} \n`);
|
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [DEBUG] ${message} \n`);
|
||||||
console.log('[' + d.toLocaleString() + '] ['
|
console.log('[' + d.toLocaleString() + '] ['
|
||||||
+ colours.cyan('DEBUG') + '] ' + message);
|
+ colours.cyan('DEBUG') + '] ' + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ready() {
|
static ready() {
|
||||||
let d = new Date();
|
let d = moment().format(dateFormat);
|
||||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [READY] \n`);
|
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [READY] \n`);
|
||||||
console.log('[' + d.toLocaleString() + '] ['
|
console.log('[' + d.toLocaleString() + '] ['
|
||||||
+ colours.rainbow('READY') + ']');
|
+ colours.rainbow('READY') + ']');
|
||||||
}
|
}
|
||||||
|
|
||||||
static info(message) {
|
static info(message) {
|
||||||
if (LogLevel > 2) return;
|
if (LogLevel > 2) return;
|
||||||
let d = new Date();
|
let d = moment().format(dateFormat);
|
||||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [INFO] ${message} \n`);
|
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [INFO] ${message} \n`);
|
||||||
console.log('[' + d.toLocaleString() + '] ['
|
console.log('[' + d.toLocaleString() + '] ['
|
||||||
+ colours.green('INFO') + '] ' + message);
|
+ colours.green('INFO') + '] ' + message);
|
||||||
@@ -80,21 +86,21 @@ export class Logger {
|
|||||||
|
|
||||||
static warn(message) {
|
static warn(message) {
|
||||||
if (LogLevel > 3) return;
|
if (LogLevel > 3) return;
|
||||||
let d = new Date();
|
let d = moment().format(dateFormat);
|
||||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [WARN] ${message} \n`);
|
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [WARN] ${message} \n`);
|
||||||
console.log('[' + d.toLocaleString() + '] ['
|
console.log('[' + d.toLocaleString() + '] ['
|
||||||
+ colours.yellow('WARN') + '] ' + message);
|
+ colours.yellow('WARN') + '] ' + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static error(message) {
|
static error(message) {
|
||||||
let d = new Date();
|
let d = moment().format(dateFormat);
|
||||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [ERROR] ${message} \n`);
|
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [ERROR] ${message} \n`);
|
||||||
console.log('[' + d.toLocaleString() + '] ['
|
console.log('[' + d.toLocaleString() + '] ['
|
||||||
+ colours.red('ERROR') + '] ' + message);
|
+ colours.red('ERROR') + '] ' + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static panic(message) {
|
static panic(message) {
|
||||||
let d = new Date();
|
let d = moment().format(dateFormat);
|
||||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [PANIC] ${message} \n`);
|
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [PANIC] ${message} \n`);
|
||||||
console.log('[' + d.toLocaleString() + '] ['
|
console.log('[' + d.toLocaleString() + '] ['
|
||||||
+ colours.red('PANIC') + '] ' + message);
|
+ colours.red('PANIC') + '] ' + message);
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// Logger.debug(JSON.stringify(await Database.Guilds.newGuild(1234, "Hello"), null, 4));
|
||||||
|
// Logger.debug(JSON.stringify(await Database.Guilds.deleteGuild(1234), null, 4));
|
||||||
|
|
||||||
Reference in New Issue
Block a user