public function __construct(string $name, array $json, Connection $connection) { if (file_exists("phar://plugins" . DIRECTORY_SEPARATOR . $name . ".phar" . DIRECTORY_SEPARATOR . "plugin.json")) { Logger::info(BashColor::GREEN . "Loading plugin " . BashColor::BLUE . $name); $this->name = $json["name"]; $this->description = $json["description"]; $this->apiVersion = $json["api"]; $this->version = $json["version"]; $this->author = $json["author"]; $this->main = $json["main"]; //Instantiating plugins $info = new \SplFileInfo("phar://plugins" . DIRECTORY_SEPARATOR . $name . ".phar" . DIRECTORY_SEPARATOR . $this->main); $class = new \ReflectionClass("\\" . $name . "\\" . $info->getBasename(".php")); //Taking care of using the correct namespace $this->class = $class->newInstanceWithoutConstructor(); $this->reflectionClass = $class; $this->class->connection = $connection; $this->class->plugin = $this; //Registering commands if (isset($json["commands"])) { $this->commands = $json["commands"]; foreach ($this->commands as $command => $settings) { // Set description $description = !empty($settings["description"]) ? $settings["description"] : ""; // Set usage help $usage = !empty($settings["usage"]) ? $settings["usage"] : $command; // Set required permission $permission = !empty($settings["permission"]) ? $settings["permission"] : false; //Default permission is false $command = new Command($command, $this->class, $permission, $description, $usage); // Add aliases if (isset($settings["aliases"]) && is_array($settings["aliases"])) { foreach ($settings["aliases"] as $alias) { $command->addAlias($alias); } } $connection->getCommandMap()->registerCommand($command, $this); } } } }
public function __construct(Connection $connection) { $connection->getCommandMap()->registerCommand(new JoinCommand($connection)); $connection->getCommandMap()->registerCommand(new PartCommand($connection)); $connection->getCommandMap()->registerCommand(new HelpCommand($connection)); $connection->getCommandMap()->registerCommand(new PluginLoadCommand($connection)); $connection->getCommandMap()->registerCommand(new PluginUnloadCommand($connection)); $connection->getCommandMap()->registerCommand(new PluginsListCommand($connection)); $connection->getCommandMap()->registerCommand(new WhoamiCommand($connection)); $connection->getCommandMap()->registerCommand(new RawCommand($connection)); $connection->getCommandMap()->registerCommand(new SayCommand($connection)); $connection->getCommandMap()->registerCommand(new NickCommand($connection)); $connection->getCommandMap()->registerCommand(new ReloadCommand($connection)); $connection->getCommandMap()->registerCommand(new StopCommand($connection)); }