Example #1
0
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     $channel = Channel::getChannel($connection, $command->getArg(0));
     $user = User::getUser($connection, $command->getPrefix());
     $args = $command->getArgs();
     for ($a = 0; $a <= 0; $a++) {
         unset($args[$a]);
     }
     $topic = explode(":", implode(" ", $args), 2)[1];
     $ev = new TopicChangeEvent($topic, $channel, $user);
     $connection->getEventHandler()->callEvent($ev);
 }
Example #2
0
File: QUIT.php Project: nkreer/Fish
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     //Tell the plugins that a user has quit
     $user = User::getUser($connection, $command->getPrefix());
     $ev = new UserQuitEvent($user);
     $connection->getEventHandler()->callEvent($ev);
     if (!$ev->isCancelled()) {
         Logger::info($user->getNick() . " quit");
         User::removeUser($connection, $user->getHostmask());
         // Remove user
     }
 }
Example #3
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);
         }
     }
 }
Example #4
0
 /**
  * @param $cmd
  * @param User $user
  * @param Channel $channel
  * @param $args
  * @return bool
  */
 public function handleCommand($cmd, User $user, Channel $channel, $args) : bool
 {
     $cmd = $this->connection->getCommandMap()->getCommand($cmd);
     if ($cmd instanceof CommandInterface) {
         if ($user->hasPermission($cmd->getMinimumPermission())) {
             if ($this->isBlocked($user) === false) {
                 $result = $this->connection->getPluginManager()->command($cmd, $args[1], $user, $channel);
                 if ($result === false and $cmd->getUsage() !== "") {
                     $ev = new CommandSendUsageTextEvent($cmd, $user, $channel, $args[1]);
                     if (!$ev->isCancelled()) {
                         $user->sendNotice("Usage: " . $cmd->getUsage());
                     }
                 }
             } else {
                 $user->sendNotice($this->config["message"]);
             }
         } else {
             $user->sendNotice($this->invalidPermissionsMsg);
         }
         return true;
     }
     return false;
 }
Example #5
0
File: PART.php Project: nkreer/Fish
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     //Tell the plugins that a user has parted
     $channel = Channel::getChannel($connection, str_replace(":", "", $command->getArg(0)));
     $user = User::getUser($connection, $command->getPrefix());
     if ($user instanceof User) {
         $ev = new ChannelLeaveEvent($channel, $user);
         $connection->getEventHandler()->callEvent($ev);
         if (!$ev->isCancelled()) {
             Logger::info($user->getNick() . " left " . $channel->getName());
             User::removeUser($connection, $user->getHostmask());
             //Remove the user, don't care if they are in other channels the bot is in
         }
     }
 }
Example #6
0
File: _307.php Project: nkreer/Fish
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     $user = User::getUserByNick($connection, $command->getArg(1));
     if ($user instanceof User) {
         $ev = new UserIdentifyEvent($user);
         $connection->getEventHandler()->callEvent($ev);
         if (!$ev->isCancelled()) {
             $config = IRC::getInstance()->getConfig();
             if ($config->getData("authentication_message", ["enabled" => true, "message" => "You have been identified."])["enabled"] === true) {
                 $user->sendNotice($config->getData("authentication_message")["message"]);
             }
             $user->identified = AuthenticationStatus::IDENTIFIED;
         }
     }
 }
Example #7
0
File: NICK.php Project: nkreer/Fish
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     $user = User::getUser($connection, $command->getPrefix());
     $new = str_replace(":", "", $command->getArg(0));
     $ev = new UserChangeNickEvent($user->getNick(), $new);
     $connection->getEventHandler()->callEvent($ev);
     if (!$ev->isCancelled()) {
         Logger::info($user->getNick() . " is now known as " . $new);
         if ($user->getNick() === $connection->getNick()) {
             // Bot changed name
             $connection->nickname = $new;
         }
         User::removeUser($connection, $user->getHostmask());
         //Remove old authentication status, mainly
     }
 }
Example #8
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]);
     $ev = new NoticeReceiveEvent(explode(":", implode(" ", $arg), 2)[1], $user, $channel);
     $connection->getEventHandler()->callEvent($ev);
     if (!$ev->isCancelled()) {
         Logger::info(BashColor::HIGHLIGHT . (!empty($ev->getUser()->getNick()) ? $ev->getUser()->getNick() . ": " : " ") . $ev->getNotice() . BashColor::REMOVE);
         //Display the notice to the console
     }
 }
Example #9
0
File: KICK.php Project: nkreer/Fish
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     //Tell the plugins that a user was kicked
     $channel = Channel::getChannel($connection, str_replace(":", "", $command->getArg(0)));
     $kicker = User::getUser($connection, $command->getPrefix());
     $user = $command->getArg(1);
     $ev = new KickEvent($user, $channel, $kicker);
     $connection->getEventHandler()->callEvent($ev);
     if (!$ev->isCancelled()) {
         Logger::info($user . " was kicked from " . $channel->getName());
         if ($user === $connection->getNick()) {
             if (IRC::getInstance()->getConfig()->getData("auto_rejoin_after_kick", false)) {
                 // Make the bot rejoin in 5 seconds
                 $connection->getScheduler()->scheduleDelayedTask(new RejoinChannelTask($connection, $channel), 5);
             }
         }
     }
 }
Example #10
0
File: JOIN.php Project: nkreer/Fish
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     //Tell the plugins that a user has joined
     $channel = Channel::getChannel($connection, str_replace(":", "", $command->getArg(0)));
     $user = User::getUser($connection, $command->getPrefix());
     if ($user->getNick() === $connection->getNick()) {
         $ev = new BotJoinChannelEvent($channel, $user);
     } else {
         $ev = new JoinChannelEvent($channel, $user);
     }
     $connection->getEventHandler()->callEvent($ev);
     if (!$ev->isCancelled()) {
         Logger::info($user->getNick() . " joined " . $channel->getName());
         if ($ev instanceof BotJoinChannelEvent) {
             $connection->addChannel($channel);
             // Add the channel
         }
     }
 }
Example #11
0
File: MODE.php Project: nkreer/Fish
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     $user = User::getUser($connection, $command->getPrefix());
     $channel = Channel::getChannel($connection, $command->getArg(0));
     $mode = $command->getArg(1);
     if ($channel->getName() === $connection->getNick()) {
         $ev = new MyModesChangeEvent($mode, $user, $channel);
         $connection->getEventHandler()->callEvent($ev);
     } elseif (empty($command->getArg(2))) {
         if ($mode === "+b") {
             $ev = new BanSetEvent($command->getArg(1), $user, $channel);
         } elseif ($mode === "-b") {
             $ev = new UnbanEvent($command->getArg(1), $user, $channel);
         } else {
             $ev = new ChannelModeChangeEvent($mode, $user, $channel);
         }
         $connection->getEventHandler()->callEvent($ev);
     } else {
         $nick = $command->getArg(2);
         $ev = new UserModeChangeEvent($mode, $user, $channel, $nick);
         $connection->getEventHandler()->callEvent($ev);
     }
 }
Example #12
0
 /**
  * @param User $user
  * @param String $reason
  */
 public function kick(User $user, string $reason = "Kicked.")
 {
     $this->connection->sendData("KICK " . $this->getName() . " " . $user->getNick() . " :" . $reason);
     User::removeUser($this->connection, $user->getHostmask());
     //Remove from connection
     $this->removeUser($user->getNick());
     // Remove from channel
 }
Example #13
0
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     $channel = Channel::getChannel($connection, explode(":", implode(" ", $command->getArgs()), 2)[1]);
     $user = User::getUser($connection, $command->getPrefix());
     $connection->getEventHandler()->callEvent(new InvitationReceiveEvent($channel, $user));
 }