Merge pull request #6 from plane000/dev
Initialization sequence changed slightly
This commit is contained in:
2
index.js
2
index.js
@@ -3,4 +3,4 @@ require('babel-register')({
|
|||||||
presets: [ 'env' ]
|
presets: [ 'env' ]
|
||||||
});
|
});
|
||||||
|
|
||||||
require('./src/index');
|
require('./src/index').init();
|
||||||
|
|||||||
@@ -1,22 +1,57 @@
|
|||||||
import {Logger} from './logger';
|
import {Logger} from './logger';
|
||||||
import {Config} from './config';
|
import {Config} from './config';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
import { rejects } from 'assert';
|
||||||
|
|
||||||
export class Events {
|
export class Events { // extends rate limits
|
||||||
async init(client) {
|
async init(client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.client.login(Config.Token);
|
this.client.login(Config.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleEvents() {
|
async handleEvents() {
|
||||||
this.client.on('ready', () => {this.handleReady()});
|
this.client.on('ready', async () => {
|
||||||
this.client.on('message', async (message) => {this.handleMessage(message)});
|
this.handle(undefined,
|
||||||
|
[this.handleReady]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.client.on('message', async (message) => {
|
||||||
|
this.handle(message,
|
||||||
|
[this.handleMessage]
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleReady() {
|
async handle(obj = [null], callbacks = [undefined]) {
|
||||||
|
let doNext = false;
|
||||||
|
if (callbacks.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const next = function() {
|
||||||
|
doNext = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
await callbacks[0](obj, next);
|
||||||
|
callbacks.splice(0, 1);
|
||||||
|
|
||||||
|
if (doNext) {
|
||||||
|
this.handle(obj, callbacks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleReady(obj, next) {
|
||||||
this.client.user.setPresence('online');
|
this.client.user.setPresence('online');
|
||||||
this.client.user.setActivity(Config.NowPlaying);
|
this.client.user.setActivity(Config.NowPlaying);
|
||||||
Logger.info(`Discord client logged in as ${this.client.user.tag}`);
|
Logger.info(`Discord client logged in as ${this.client.user.tag}`);
|
||||||
Logger.ready();
|
Logger.ready();
|
||||||
|
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
setTimeout(resolve, 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleMessage(...args) {
|
async handleMessage(...args) {
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import {Config} from './config';
|
|||||||
import {Database} from './database/database';
|
import {Database} from './database/database';
|
||||||
import {Events} from './events';
|
import {Events} from './events';
|
||||||
|
|
||||||
init();
|
let client;
|
||||||
async function init() {
|
|
||||||
|
export async function init() {
|
||||||
Logger.init();
|
Logger.init();
|
||||||
Logger.SetLevel(Logger.VERBOSE_LOGS);
|
Logger.SetLevel(Logger.VERBOSE_LOGS);
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ async function init() {
|
|||||||
|
|
||||||
await Database.init();
|
await Database.init();
|
||||||
|
|
||||||
const client = new Discord.Client();
|
client = new Discord.Client();
|
||||||
|
|
||||||
const eventHandler = new Events();
|
const eventHandler = new Events();
|
||||||
await eventHandler.init(client);
|
await eventHandler.init(client);
|
||||||
|
|||||||
0
src/ratelimits.js
Normal file
0
src/ratelimits.js
Normal file
Reference in New Issue
Block a user