コード例 #1
0
ファイル: TOPIC.php プロジェクト: nkreer/Fish
 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);
 }
コード例 #2
0
ファイル: QUIT.php プロジェクト: 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
     }
 }
コード例 #3
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);
         }
     }
 }
コード例 #4
0
ファイル: PART.php プロジェクト: 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
         }
     }
 }
コード例 #5
0
ファイル: NICK.php プロジェクト: 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
     }
 }
コード例 #6
0
ファイル: NOTICE.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]);
     $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
     }
 }
コード例 #7
0
ファイル: KICK.php プロジェクト: 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);
             }
         }
     }
 }
コード例 #8
0
ファイル: JOIN.php プロジェクト: 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
         }
     }
 }
コード例 #9
0
ファイル: MODE.php プロジェクト: 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);
     }
 }
コード例 #10
0
ファイル: INVITE.php プロジェクト: nkreer/Fish
 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));
 }