text: const Base = require('../Base/Base');
  const Discord = require('discord.js');
  const Path = require('path');
  
  class CommandManager extends Base {
  
      constructor(DisBot) {
  
          super(DisBot);
  
          this.aliases = new Discord.Collection();
          this.commands = new Discord.Collection();
  
      }
  
      async loadAllCommands() {
  
          const CommandDirectory = await this.DisBot.readDirectory('./Commands/');
  
          this.DisBot.logger.debug(`Loading ${CommandDirectory.length} command categorys...`);
      
          CommandDirectory.forEach(async CommandCategoryDirectory => {
              
              var Commands = (await this.DisBot.readDirectory(`./Commands/${CommandCategoryDirectory}/`)).filter(Command => Command.split('.').pop() === 'js');
      
              Commands.forEach(Command => {
      
                  this.loadCommand(Command, `../Commands/${CommandCategoryDirectory}`);
      
              });
      
          });
  
      }
  
      loadCommand(CommandName, CommandPath) {
  
          try {
  
              const CommandData = new (require(`${CommandPath}${Path.sep}${CommandName}`))(this.DisBot);
  
              CommandData.Config.Location = SlashCommandPath;
  
              if(CommandData.init) CommandData.init(this.DisBot);
  
              this.commands.set(CommandData.Help.Name, CommandData);
  
              CommandData.Help.Aliases.forEach(Alias => {
  
                  this.aliases.set(Alias, CommandData.Help.Name);
  
              })
  
              this.DisBot.logger.debug(`Loaded interaction ${CommandData.Help.Name}`);
  
          } catch (Error) {
  
              return this.DisBot.logger.error(`There was an error while loading interaction ${CommandName} : ${Error}`);
  
          }
      
      }
  
      async unloadAllCommands() {
  
          const CommandDirectory = await this.DisBot.readDirectory('./Commands/');
      
          CommandDirectory.forEach(async CommandCategoryDirectory => {
              
              var Commands = (await this.DisBot.readDirectory(`./Commands/${CommandCategoryDirectory}/`)).filter(Command => Command.split('.').pop() === 'js');
      
              Commands.forEach(Command => {
      
                  this.unloadCommand(Command, `../Commands/${CommandCategoryDirectory}`);
      
              });
      
          });
  
      }
  
      unloadCommand(CommandName, CommandPath) {
  
          delete require.cache[require.resolve(`${CommandPath}${Path.sep}${CommandName}`)];
  
          return this.DisBot.logger.debug(`Unloaded command ${SlashCommandName}`);
  
      }
  
  }
  
  module.exports = CommandManager;