/**
 * @file Module Handler
 * @author Sankarsan Kampa (a.k.a k3rn31p4nic)
 * @license GPL-3.0
 */

const fs = require('fs');
const path = require('path');
const color = require('chalk');
const { Collection } = require('discord.js');
const commandInfo = require('../locales/en_us/command.json');

/* eslint-disable no-sync */
let Commands = new Collection();
let Aliases = new Collection();

let commandFiles = fs.readdirSync(path.resolve('./commands/')).
  filter(file => !fs.statSync(path.resolve('./commands/', file)).isDirectory()).
  filter(file => file.endsWith('.js'));

for (let file of commandFiles) {
  file = file.substr(0, file.length - 3);
  process.stdout.write(`${color.cyan('[Bastion]:')} Loading ${file} command...\n`);

  file = require(path.resolve(`./commands/${file}`));
  Commands.set(file.help.name.toLowerCase(), file);

  if (commandInfo[file.help.name]) {
    file.config.module = commandInfo[file.help.name].module;
  }
  else {
    throw new Error(`The \`${file.help.name}\` command has not been described in the default locale strings.`);
  }

  for (let alias of file.config.aliases) {
    Aliases.set(alias.toLowerCase(), file.help.name);
  }

  if (process.stdout.moveCursor && process.stdout.clearLine) {
    process.stdout.moveCursor(0, -1);
    process.stdout.clearLine();
  }
}

exports.commands = Commands;
exports.aliases = Aliases;

@@ -230,70 +230,8 @@
 s');
-%0Aconst commandInfo = require('../locales/en_us/command.json');
 %0A%0A/*
@@ -323,16 +323,254 @@
 ion();%0A%0A
+let modules = fs.readdirSync('./commands/').filter(file =%3E fs.statSync(path.join('./commands/', file)).isDirectory());%0A%0Afor (let module of modules) %7B%0A  process.stdout.write(%60$%7Bcolor.cyan('%5BBastion%5D:')%7D Loading $%7Bmodule%7D module...%5Cn%60);%0A%0A  
 let comm
@@ -600,33 +600,33 @@
 nc(path.resolve(
-'
+%60
 ./commands/')).%0A
@@ -624,13 +624,24 @@
 nds/
-'
+$%7Bmodule%7D%60
 )).%0A
+  
   fi
@@ -685,32 +685,40 @@
 e('./commands/',
+ module,
  file)).isDirect
@@ -725,16 +725,18 @@
 ory()).%0A
+  
   filter
@@ -764,24 +764,26 @@
 h('.js'));%0A%0A
+  
 for (let fil
@@ -803,16 +803,18 @@
 iles) %7B%0A
+  
   file =
@@ -847,16 +847,18 @@
 h - 3);%0A
+  
   proces
@@ -934,16 +934,18 @@
 .%5Cn%60);%0A%0A
+  
   file =
@@ -958,33 +958,33 @@
 re(path.resolve(
-%60
+'
 ./commands/$%7Bfil
@@ -982,20 +982,29 @@
 nds/
-$%7B
+', module, 
 file
-%7D%60
 ));%0A
+  
   Co
@@ -1058,234 +1058,42 @@
 %0A%0A  
-if (commandInfo%5Bfile.help.name%5D) %7B%0A    file.config.module = commandInfo%5Bfile.help.name%5D.module;%0A  %7D%0A  else %7B%0A    throw new Error(%60The %5C%60$%7Bfile.help.name%7D%5C%60 command has not been described in the default locale strings.%60);%0A  %7D%0A%0A
+  file.config.module = module;%0A%0A  
   fo
@@ -1127,24 +1127,26 @@
 .aliases) %7B%0A
+  
     Aliases.
@@ -1187,16 +1187,168 @@
 .name);%0A
+    %7D%0A%0A    if (process.stdout.moveCursor && process.stdout.clearLine) %7B%0A      process.stdout.moveCursor(0, -1);%0A      process.stdout.clearLine();%0A    %7D%0A
   %7D%0A%0A  i

rewrite module handler