Beispiel #1
0
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     $channelName = $command->getArg(1);
     $userCount = $command->getArg(2);
     $args = $command->getArgs();
     $topic = explode(":", implode(" ", $args), 2)[1];
     $event = new ChannelListEvent($channelName, $userCount, $topic);
     $connection->getEventHandler()->callEvent($event);
 }
Beispiel #2
0
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     $ev = new PingEvent();
     $connection->getEventHandler()->callEvent($ev);
     $ev = new PongEvent();
     $connection->getEventHandler()->callEvent($ev);
     if (!$ev->isCancelled()) {
         $connection->lastPing = time();
         $connection->sendData("PONG " . $command->getArgs()[0]);
         //Reply to Pings
     }
 }
Beispiel #3
0
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     $args = $command->getArgs();
     $channel = Channel::getChannel($connection, $args[1]);
     for ($a = 0; $a <= 1; $a++) {
         unset($args[$a]);
     }
     $topic = explode(":", implode(" ", $args), 2)[1];
     $channel->topic = $topic;
     $ev = new TopicReceiveEvent($topic, $channel);
     $connection->getEventHandler()->callEvent($ev);
 }
Beispiel #4
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);
 }
Beispiel #5
0
 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
     }
 }
Beispiel #6
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);
         }
     }
 }
Beispiel #7
0
 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
         }
     }
 }
Beispiel #8
0
 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;
         }
     }
 }
Beispiel #9
0
 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
     }
 }
Beispiel #10
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
     }
 }
Beispiel #11
0
 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);
             }
         }
     }
 }
Beispiel #12
0
 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
         }
     }
 }
Beispiel #13
0
 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);
     }
 }
Beispiel #14
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));
 }
Beispiel #15
0
 public function handle(Command $run, Connection $connection)
 {
     $ev = new ConnectionActivityEvent($connection, $run);
     $connection->getEventHandler()->callEvent($ev);
     if (!$ev->isCancelled()) {
         $command = $run->getCommand();
         if (is_numeric($command)) {
             $command = "_" . $command;
         }
         $function = '\\IRC\\Protocol\\' . strtoupper($command);
         if (method_exists($function, "run")) {
             // Most stupid hack ever, but it gets the job done
             call_user_func($function . "::run", $run, $connection, $this->getConfig());
         } else {
             // Handle unknown commands
             $unknownEvent = new ConnectionUnknownCommandEvent($connection, $run);
             $connection->getEventHandler()->callEvent($unknownEvent);
         }
     }
 }
Beispiel #16
0
 public static function run(Command $command, Connection $connection, JsonConfig $config)
 {
     $channel = Channel::getChannel($connection, $command->getArg(1));
     $time = $command->getArg(3);
     $channel->topicTime = $time;
 }