示例#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
 }