Discord login works and fixed config instance
This commit is contained in:
@@ -2,21 +2,28 @@ import fs from 'fs';
|
||||
|
||||
import {Logger} from './logger';
|
||||
|
||||
let file;
|
||||
let path;
|
||||
let Configuration;
|
||||
|
||||
export class Config {
|
||||
constructor(path) {
|
||||
this.file = './resources/config/config.json';
|
||||
this.path = [ './resources/', './resources/config' ]
|
||||
this.Configuration = {
|
||||
static get Configuration() {return Configuration;}
|
||||
static get Token() {return Configuration.Token;}
|
||||
|
||||
static init() {
|
||||
file = './resources/config/config.json';
|
||||
path = [ './resources/', './resources/config' ]
|
||||
Configuration = {
|
||||
Token: 'YOUR TOKEN HERE'
|
||||
};
|
||||
}
|
||||
|
||||
load() {
|
||||
static load() {
|
||||
Logger.info('Loading config');
|
||||
if (fs.existsSync(this.file)) {
|
||||
if (fs.existsSync(file)) {
|
||||
try {
|
||||
this.Configuration = JSON.parse(fs.readFileSync(this.file));
|
||||
if (!this.Configuration.Token) Logger.panic('Token is missing from config file');
|
||||
Configuration = JSON.parse(fs.readFileSync(file));
|
||||
if (!Configuration.Token) Logger.panic('Token is missing from config file');
|
||||
|
||||
Logger.info('Config loaded successfully');
|
||||
} catch (e) {
|
||||
@@ -25,11 +32,11 @@ export class Config {
|
||||
} else {
|
||||
try {
|
||||
Logger.error('No config found');
|
||||
for (let folder of this.path) {
|
||||
for (let folder of path) {
|
||||
fs.mkdirSync(folder);
|
||||
}
|
||||
fs.writeFileSync(this.file, JSON.stringify(this.Config, null, 4));
|
||||
Logger.warn(`Created config at: ${this.path}`);
|
||||
fs.writeFileSync(file, JSON.stringify(Configuration, null, 4));
|
||||
Logger.warn(`Created config at: ${path}`);
|
||||
Logger.panic('Config required to be complete');
|
||||
} catch (e) {
|
||||
Logger.panic(`Could not create config: ${e}`);
|
||||
|
||||
@@ -4,12 +4,13 @@ import {Config} from './config';
|
||||
export class Events {
|
||||
async init(client) {
|
||||
this.client = client;
|
||||
this.client.login(Config.Configuration.Token);
|
||||
this.client.login(Config.Token);
|
||||
}
|
||||
|
||||
async handle() {
|
||||
this.client.on('ready', () => {
|
||||
console.log('cx');
|
||||
Logger.info(`Discord client logged in as ${this.client.user.tag}`);
|
||||
Logger.ready();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ async function init() {
|
||||
Logger.init();
|
||||
Logger.SetLevel(Logger.VERBOSE_LOGS);
|
||||
|
||||
const config = new Config();
|
||||
config.load();
|
||||
Config.init();
|
||||
Config.load();
|
||||
|
||||
await Database.init();
|
||||
// Logger.debug(JSON.stringify(await Database.Guilds.newGuild(1234, "Hello"), null, 4));
|
||||
|
||||
Reference in New Issue
Block a user