function registerCommandsIn(string $path, $ignoreSameLevelFiles = false) {
        $path = \realpath($path);
        if(!$path) {
            throw new \RuntimeException('Invalid path specified');
        }
        
        $this->addCommandsDirectory($path);
        $files = \CharlotteDunois\Livia\Utils\FileHelpers::recursiveFileSearch($path, '*.php');
        
        foreach($files as $file) {
            if($ignoreSameLevelFiles === true) {
                $filepath = \ltrim(\str_replace(array($path, '\\'), array('', '/'), $file), '/');
                if(\mb_substr_count($filepath, '/') === 0) {
                    continue;
                }
            } elseif(!empty($ignoreSameLevelFiles) && \mb_stripos($file, $ignoreSameLevelFiles) !== false) {
                continue;
            }
            
            $command = include $file;
            
            if(!\is_callable($command)) {
                throw new \RuntimeException('Command file '.\str_replace($path, '', $file).' does not return an anonymous function');
            }
            
            $cmd = $command($this->client);
            if(!($cmd instanceof \CharlotteDunois\Livia\Commands\Command)) {
                throw new \RuntimeException('Anonymous function in command file '.\str_replace($path, '', $file).' does not return an instance of Command');
            }
            
            if($this->commands->has($cmd->name)) {
                throw new \RuntimeException('Can not register another command with the name '.$cmd->name);
            }
            
            $this->commands->set($cmd->name, $cmd);
            
            $group = $this->resolveGroup($cmd->groupID);
            $group->commands->set($cmd->name, $cmd);
            
            $this->client->emit('debug', 'Registered command '.$cmd->groupID.':'.$cmd->name);
            $this->client->emit('commandRegister', $cmd, $this);
        }
        
        return $this;
    }
function registerCommandsIn(string $path, $ignoreSameLevelFiles = false) {
        $path = \realpath($path);
        if(!$path) {
            throw new \RuntimeException('Invalid path specified');
        }
        
        $this->addCommandsDirectory($path);
        $files = \CharlotteDunois\Livia\Utils\FileHelpers::recursiveFileSearch($path, '*.php');
        
        foreach($files as $file) {
            if($ignoreSameLevelFiles === true) {
                $filepath = \ltrim(\str_replace(array($path, '\\'), array('', '/'), $file), '/');
                if(\mb_substr_count($filepath, '/') === 0) {
                    continue;
                }
            } elseif(!empty($ignoreSameLevelFiles) && \mb_stripos($file, $ignoreSameLevelFiles) !== false) {
                continue;
            }
            
            $command = include $file;
            
            if(!\is_callable($command)) {
                throw new \RuntimeException('Command file '.\str_replace($path, '', $file).' does not return an anonymous function');
            }
            
            $cmd = $command($this->client);
            if(!($cmd instanceof \CharlotteDunois\Livia\Commands\Command)) {
                throw new \RuntimeException('Anonymous function in command file '.\str_replace($path, '', $file).' does not return an instance of Command');
            }
            
            if($this->commands->has($cmd->name)) {
                throw new \RuntimeException('Can not register another command with the name '.$cmd->name);
            }
            
            $this->commands->set($cmd->name, $cmd);
            
            $group = $this->resolveGroup($cmd->groupID);
            $group->commands->set($cmd->name, $cmd);
            
            $this->client->emit('debug', 'Registered command '.$cmd->groupID.':'.$cmd->name);
            $this->client->emit('commandRegister', $cmd, $this);
        }
        
        return $this;
    }
function registerCommandsIn ( string $ path , $ ignoreSameLevelFiles = false ) { $ path = \ realpath ( $ path ) ; if ( ! $ path ) { throw new \ RuntimeException ( 'Invalid path specified' ) ; } $ this -> addCommandsDirectory ( $ path ) ; $ files = \ CharlotteDunois \ Livia \ Utils \ FileHelpers :: recursiveFileSearch ( $ path , '*.php' ) ; foreach ( $ files as $ file ) { if ( $ ignoreSameLevelFiles === true ) { $ filepath = \ ltrim ( \ str_replace ( array ( $ path , '\\' ) , array ( '' , '/' ) , $ file ) , '/' ) ; if ( \ mb_substr_count ( $ filepath , '/' ) === 0 ) { continue ; } } elseif ( ! empty ( $ ignoreSameLevelFiles ) && \ mb_stripos ( $ file , $ ignoreSameLevelFiles ) !== false ) { continue ; } $ command = include $ file ; if ( ! \ is_callable ( $ command ) ) { throw new \ RuntimeException ( 'Command file ' . \ str_replace ( $ path , '' , $ file ) . ' does not return an anonymous function' ) ; } $ cmd = $ command ( $ this -> client ) ; if ( ! ( $ cmd instanceof \ CharlotteDunois \ Livia \ Commands \ Command ) ) { throw new \ RuntimeException ( 'Anonymous function in command file ' . \ str_replace ( $ path , '' , $ file ) . ' does not return an instance of Command' ) ; } if ( $ this -> commands -> has ( $ cmd -> name ) ) { throw new \ RuntimeException ( 'Can not register another command with the name ' . $ cmd -> name ) ; } $ this -> commands -> set ( $ cmd -> name , $ cmd ) ; $ group = $ this -> resolveGroup ( $ cmd -> groupID ) ; $ group -> commands -> set ( $ cmd -> name , $ cmd ) ; $ this -> client -> emit ( 'debug' , 'Registered command ' . $ cmd -> groupID . ':' . $ cmd -> name ) ; $ this -> client -> emit ( 'commandRegister' , $ cmd , $ this ) ; } return $ this ; }
Registers all commands in a directory. The path gets saved as commands path. Emits a commandRegister event for each command.
@param string        $path
@param bool|string   $ignoreSameLevelFiles  Ignores files in the specified directory and only includes files in sub directories. As string it will ignore the file if the filename matches with the string.
@return $this
@throws \RuntimeException
Registers all commands in a directory . The path gets saved as commands path . Emits a commandRegister event for each command .