Ejemplo n.º 1
0
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     $user = User::getUser($connection, $command->getPrefix());
     $arg = $command->getArgs();
     if ($command->getArg(0) === $connection->nickname) {
         $channel = Channel::getChannel($connection, $user->getNick());
     } else {
         $channel = Channel::getChannel($connection, $arg[0]);
     }
     unset($arg[0]);
     $args = explode(":", implode(" ", $arg), 2);
     if ($args[1][0] === chr(1)) {
         //Check whether the message is a ctcp, message or command
         $args[1] = explode(" ", $args[1], 2);
         $ctcp_command = str_replace(chr(1), "", $args[1][0]);
         unset($args[1][0]);
         $ev = new CTCPReceiveEvent($user, $ctcp_command);
         $connection->getEventHandler()->callEvent($ev);
         if (empty($args[1][1])) {
             if ($reply = IRC::getInstance()->getConfig()->getData("default_ctcp_replies", [])[$ctcp_command]) {
                 if ($reply !== null) {
                     $ev = new CTCPSendEvent($user, $ctcp_command, $reply);
                     $connection->getEventHandler()->callEvent($ev);
                     if (!$ev->isCancelled()) {
                         $user->sendNotice(chr(1) . $ctcp_command . " " . $ev->getMessage());
                     }
                 }
             }
         }
     } elseif (!in_array($args[1][0], $config->getData("command_prefix", [".", "!", "\\", "@"]))) {
         $ev = new MessageReceiveEvent($args[1], $user, $channel);
         $connection->getEventHandler()->callEvent($ev);
         if (!$ev->isCancelled()) {
             Logger::info(BashColor::GREEN . $ev->getChannel()->getName() . " " . $ev->getUser()->getNick() . ":" . BashColor::REMOVE . " " . $ev->getMessage());
             //Display the message to the console
         }
     } else {
         $args[1] = substr($args[1], 1);
         $args[1] = explode(" ", $args[1]);
         $cmd = strtolower($args[1][0]);
         //Command in lower case
         unset($args[1][0]);
         Logger::info(BashColor::CYAN . $user->getNick() . " > " . $cmd . " " . implode(" ", $args[1]));
         $ev = new CommandEvent($cmd, $args[1], $channel, $user);
         $connection->getEventHandler()->callEvent($ev);
         if (!$ev->isCancelled()) {
             $connection->getCommandHandler()->handleCommand($cmd, $user, $channel, $args);
         }
     }
 }
Ejemplo n.º 2
0
Archivo: IRC.php Proyecto: nkreer/Fish
 /**
  * Close a connection
  * @param Connection $connection
  * @param String $quitMessage
  * @return bool
  */
 public function removeConnection(Connection $connection, string $quitMessage = null) : bool
 {
     if ($this->isConnected($connection->getAddress())) {
         Logger::info(BashColor::RED . "Disconnecting " . $connection->getAddress() . ":" . $connection->getPort());
         if ($quitMessage === null) {
             $quitMessage = $this->config->getData("default_quitmsg", "Leaving");
         }
         $connection->disconnect($quitMessage);
         unset($this->connections[$connection->getAddress()]);
         return true;
     } else {
         unset($this->connections[$connection->getAddress()]);
         return true;
         //These statements are kept for reasons of backwards-compatibility
     }
 }
Ejemplo n.º 3
0
Archivo: _323.php Proyecto: nkreer/Fish
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     IRC::getInstance()->idleTime = $config->getData("cpu_idle", 10) * 1000;
     // Go back to regular performance
 }
Ejemplo n.º 4
0
 /**
  * @param $name
  * @return bool|int
  */
 public function loadPlugin(string $name, bool $force = false)
 {
     if (file_exists("phar://plugins" . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . "plugin.json") && !$this->hasPlugin($name)) {
         $json = new JsonConfig();
         $json->loadFile("phar://plugins" . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . "plugin.json");
         $json = $json->getConfig();
         if (isset($json["load"]) and $json["load"] !== false or $force == true) {
             if ($json["api"] != IRC::VERSION) {
                 Logger::info(BashColor::YELLOW . "Plugin " . $name . " was developed for Fish version " . $json["api"] . ", while you are running version " . IRC::VERSION . "! It might not be compatible!");
             }
             $success = true;
             if (isset($json["depend"])) {
                 foreach ($json["depend"] as $dependency) {
                     Logger::info(BashColor::YELLOW . "Loading dependency " . $dependency);
                     $success = $this->loadPlugin($dependency, true);
                     if ($success === false) {
                         Logger::info(BashColor::RED . "Couldn't find dependency " . $dependency);
                         break;
                     }
                 }
             }
             if ($success !== false) {
                 $this->getClassLoader()->addPsr4(basename($name, ".phar") . "\\", "phar://plugins" . DIRECTORY_SEPARATOR . $name);
                 $plugin = new Plugin(basename($name, ".phar"), $json, $this->getConnection());
                 $ev = new PluginLoadEvent($plugin);
                 $this->getConnection()->getEventHandler()->callEvent($ev);
                 if (!$ev->isCancelled()) {
                     $key = count($this->plugins);
                     $this->plugins[$plugin->name] = $plugin;
                     $plugin->load();
                     return $key;
                 } else {
                     unset($plugin);
                     // Don't keep it loaded
                 }
             }
         }
     }
     return false;
 }