Example #1
0
 public static function info(string $info)
 {
     if (!IRC::getInstance()->silent) {
         echo date("H:i:s") . "  " . $info . "\n" . BashColor::REMOVE;
         //Actual logging will be implemented later on
     }
 }
Example #2
0
 public function onRun()
 {
     $time = (int) IRC::getInstance()->getConfig()->getData("auto_reconnect_after_timeout", 500);
     $max_attempts = (int) IRC::getInstance()->getConfig()->getData("max_reconnect_attempts", 5);
     if ($time) {
         if ($this->connection->getLastPing() <= $time + time() and $this->connection->isConnected()) {
             // Possibly time-outed. Attempt a reconnect
             Logger::info(BashColor::RED . "Lost connection to " . $this->connection->getAddress() . " - Reconnecting...");
             $this->connection->disconnect();
             if ($this->connection->connect()) {
                 Logger::info(BashColor::GREEN . "Successfully reconnected.");
                 // Re-schedule this task
                 $this->reschedule($time);
                 $this->attempts = 0;
                 // Successfully reconnected, reset
             } else {
                 Logger::info(BashColor::RED . "Error while reconnecting.");
                 $this->attempts++;
                 if ($this->attempts > $max_attempts) {
                     // Remove the connection
                     Logger::info(BashColor::RED . "Terminating connection.");
                     IRC::getInstance()->removeConnection($this->connection);
                 } else {
                     Logger::info(BashColor::CYAN . "Next attempt in " . $time . "s");
                     $this->reschedule($time);
                 }
             }
         } else {
             $this->reschedule($time);
         }
     }
 }
Example #3
0
File: _433.php Project: nkreer/Fish
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     Logger::info(BashColor::HIGHLIGHT . "Nickname already in use.");
     $altNick = IRC::getInstance()->getConfig()->getData("alt_nickname", "FishIRC");
     if (!$connection->isConnected() and $connection->getNick() !== $altNick) {
         $connection->changeNick($altNick);
     }
 }
Example #4
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 #5
0
 public function onCommand(CommandInterface $command, CommandSender $sender, CommandSender $room, array $args)
 {
     if ($sender instanceof User) {
         if (isset($args[1])) {
             if (is_numeric($args[1]) and $args[1] > 0) {
                 $page = --$args[1];
             } elseif (is_string($args[1])) {
                 $page = strtolower($args[1]);
             } else {
                 $page = $args[1];
             }
         } else {
             $page = 0;
         }
         if (!is_numeric($page)) {
             $help = $this->connection->getCommandMap()->getCommand($page);
             if ($help instanceof Command) {
                 $sender->sendNotice(IRC::getInstance()->getCommandPrefix() . $help->getCommand() . " - " . $help->getDescription() . " (" . $help->getUsage() . ")");
             } else {
                 $sender->sendNotice("Command not found.");
             }
         } else {
             $commands = $this->connection->getCommandMap()->getCommands();
             foreach ($commands as $key => $help) {
                 if (!$sender->hasPermission($help->getMinimumPermission()) or $help->getCommand() !== $key) {
                     unset($commands[$key]);
                 }
             }
             ksort($commands);
             $list = ["Help page " . ($page + 1)];
             $min = $page * self::COMMANDS_PER_PAGE;
             $max = $page * self::COMMANDS_PER_PAGE + self::COMMANDS_PER_PAGE;
             $count = 1;
             foreach ($commands as $help) {
                 if ($count >= $min and $count < $max) {
                     $list[] = IRC::getInstance()->getCommandPrefix() . $help->getCommand() . " - " . $help->getDescription() . " (" . $help->getUsage() . ")";
                 }
                 $count++;
             }
             if (count($list) > 1) {
                 foreach ($list as $entry) {
                     $sender->sendNotice($entry);
                 }
             } else {
                 $sender->sendNotice("This help page is empty");
             }
         }
     }
 }
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: 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 #8
0
File: _376.php Project: nkreer/Fish
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     $ev = new ConnectionFinishedEvent($connection);
     $connection->getEventHandler()->callEvent($ev);
     if (!$ev->isCancelled()) {
         $config = IRC::getInstance()->getConfig()->getData("connections");
         if (!empty($config[$connection->getAddress()]["nickserv"])) {
             $connection->getNickServ()->identify($config[$connection->getAddress()]["nickserv"]);
             //Identify with NickServ
         }
         if (!empty($config[$connection->getAddress()]["channels"])) {
             $channels = $config[$connection->getAddress()]["channels"];
             foreach ($channels as $channel) {
                 $connection->joinChannel(Channel::getChannel($connection, $channel));
                 //Join these channels
             }
         }
     }
 }
Example #9
0
 public function listChannels(array $channels = [])
 {
     // We need full power for this.
     IRC::getInstance()->idleTime = false;
     $this->sendData("LIST" . (!empty($channels) ? " " . implode(" ", $channels) : ""));
 }
Example #10
0
File: _323.php Project: 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
 }
Example #11
0
 public function getClient() : IRC
 {
     return IRC::getInstance();
 }
Example #12
0
 public function onCommand(CommandInterface $command, CommandSender $sender, CommandSender $room, array $args)
 {
     IRC::getInstance()->stop();
 }
Example #13
0
 public function __construct(Connection $connection)
 {
     $this->connection = $connection;
     $this->config = IRC::getInstance()->getConfig()->getData("spam_protection", ["enabled" => true, "max_commands" => 10, "time" => 60, "message" => "You're currently blocked from using commands because you were using too many."]);
     $this->invalidPermissionsMsg = IRC::getInstance()->getConfig()->getData("invalid_permissions", "Sorry, you do not have the required permissions to use this command.");
 }
Example #14
0
 public function onCommand(CommandInterface $command, CommandSender $sender, CommandSender $room, array $args)
 {
     $sender->sendNotice("Reloading...");
     IRC::getInstance()->reload();
     $sender->sendNotice("Reload complete.");
 }