Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
merged reorganise branch
  • Loading branch information
amritpandey23 committed Aug 19, 2019
1 parent d8a003d commit 6d33cc6
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 47 deletions.
44 changes: 26 additions & 18 deletions bot.js
@@ -1,24 +1,32 @@
require('colors');

const { Client } = require('discord.js');
const { events } = require('./configurations');
const { Auth, Utils } = require('./modules');
const events = require("./events/events.registry");
const EventHandler = require('./events/EventHandler');

const bot = new Client();
class Bot {

constructor(token) {
this._token = token;
this._client = new Client();
this._events = events;
this.load_events();
}

load_events() {
const eventHandler = new EventHandler(this._client);
eventHandler.load();
for (const e of Object.keys(events)) {
this._client.on(e, (...args) => {
eventHandler.onEvent(e, ...args);
eventHandler.logEvent(e);
});
}
}

/**
* event handler class is specifically made to handle commands
* i.e. run them, load them in cache etc. If you wish to add
* a command managing functionality checkout EventHandler file.
*/
const eventHandler = new EventHandler(bot);
// initialise and load all the available command in a cache store
eventHandler.load();
for (const e of Object.keys(events)) {
bot.on(e, (...args) => {
eventHandler.onEvent(e, ...args);
eventHandler.logEvent(e);
});
start() {
Utils.createLogFiles();
this._client.login(Auth.botToken);
}
}

module.exports = bot;
module.exports = Bot;
17 changes: 0 additions & 17 deletions configurations/events.js

This file was deleted.

3 changes: 1 addition & 2 deletions configurations/index.js
@@ -1,6 +1,5 @@
module.exports = {
api_keys: require('./api_keys.json'),
commands: require('./commands'),
config: require('./config.json'),
events: require('./events')
config: require('./config.json')
};
2 changes: 1 addition & 1 deletion events/EventHandler.js
@@ -1,4 +1,4 @@
const events = require('../configurations/events');
const events = require("./events.registry");
const fs = require('fs');

class EventHandler {
Expand Down
18 changes: 18 additions & 0 deletions events/events.registry.js
@@ -0,0 +1,18 @@
module.exports = {
disconnect: ['Bot.Disconnect'],
guildBandAdd: [],
guildBanRemove: [],
guildCreate: [],
guildDelete: [],
guildMemberAdd: ['Bot.GuildMemberAdd'],
guildMemberRemove: [],
guildUnavailable: [],
guildUpdate: [],
message: ['Bot.CommandHandler'],
rateLimit: [],
ready: ['Bot.Ready'],
reconnecting: [],
resume: [],
userUpdate: []
};

Empty file removed modules/utils/NotifyMaintainer.js
Empty file.
@@ -1,6 +1,6 @@
const fs = require('fs');

const checkLogFiles = () => {
const createLogFiles = () => {
// check, create blank log files for logging
const necessaryLogFiles = ['command-activity', 'event-activity', 'errors'];
// check if log files exist already
Expand All @@ -13,7 +13,7 @@ const checkLogFiles = () => {
process.stdout.write(
`log directory created at `.gray + `./logs`.bgYellow.black + `\n`
);
return checkLogFiles();
return createLogFiles();
}
necessaryLogFiles.forEach((fileName) => {
if (!files.includes(`${fileName}.txt`)) {
Expand All @@ -28,4 +28,4 @@ const checkLogFiles = () => {
});
};

module.exports = checkLogFiles;
module.exports = createLogFiles;
2 changes: 1 addition & 1 deletion modules/utils/index.js
@@ -1,7 +1,7 @@
module.exports = {
ErrorHandler: require('./ErrorHandler'),
NotifyMaintainer: require('./NotifyMaintainer'),
checkLogFiles: require('./checkLogFiles'),
createLogFiles: require('./createLogFiles'),
timeConversion: require('./timeConversion'),
slug: require('./slug')
};
7 changes: 2 additions & 5 deletions start.js
@@ -1,6 +1,3 @@
require('colors');
const bot = require('./bot');
const { Auth, Utils } = require('./modules');

Utils.checkLogFiles();
bot.login(Auth.botToken);
const bot = new (require('./bot'))();
bot.start();

0 comments on commit 6d33cc6

Please sign in to comment.