コード例 #1
0
ファイル: PRIVMSG.php プロジェクト: nkreer/Fish
 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);
         }
     }
 }
コード例 #2
0
ファイル: IRC.php プロジェクト: 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
     }
 }
コード例 #3
0
ファイル: _323.php プロジェクト: 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
 }
コード例 #4
0
ファイル: PluginManager.php プロジェクト: nkreer/Fish
 /**
  * @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;
 }