/** * {@inheritdoc} * * Constructs a new Vote command. */ public function __construct(RealTimeClient $client, GameManager $gameManager, Message $message, array $args = null) { parent::__construct($client, $gameManager, $message, $args); if ($this->channel[0] == 'D') { throw new Exception("You may not !vote privately."); } if (count($this->args) < 1) { throw new InvalidArgumentException("Must specify a player"); } if (!$this->game) { throw new Exception("No game in progress."); } if ($this->game->getState() != GameState::DAY) { throw new Exception("Voting occurs only during the day."); } // Voter should be alive if (!$this->game->isPlayerAlive($this->userId)) { throw new Exception("Can't vote if dead."); } $this->args[0] = UserIdFormatter::format($this->args[0], $this->game->getOriginalPlayers()); // Person player is voting for should also be alive if (!$this->game->isPlayerAlive($this->args[0]) && $this->args[0] != 'noone' && $this->args[0] != 'clear') { echo 'not found'; throw new Exception("Voted player not found in game."); } }
public function init() { if ($this->channel[0] == 'D') { throw new Exception("Vous ne pouvez pas voter par message privé."); } if (count($this->args) < 1) { throw new InvalidArgumentException("Vous devez spécifier un joueur"); } $this->game = $this->gameManager->getGame($this->channel); if (!$this->game) { throw new Exception("Aucun jeu en cours"); } if ($this->game->getState() != GameState::DAY) { throw new Exception("Vous ne pouvez que voter pendant le jour."); } // Voter should be alive if (!$this->game->isPlayerAlive($this->userId)) { throw new Exception("Vous ne pouvez pas voter car vous êtes mort."); } $this->args[0] = UserIdFormatter::format($this->args[0], $this->game->getOriginalPlayers()); echo $this->args[0]; // Person player is voting for should also be alive if (!$this->game->isPlayerAlive($this->args[0]) && $this->args[0] != 'noone' && $this->args[0] != 'clear') { echo 'not found'; throw new Exception("Le joueur que vous avez voté n'est pas dans la partie."); } }
public function init() { if ($this->channel[0] == 'D') { throw new Exception("You may not !vote privately."); } if (count($this->args) < 1) { throw new InvalidArgumentException("Must specify a player"); } $this->args[0] = UserIdFormatter::format($this->args[0]); $this->game = $this->gameManager->getGame($this->channel); if (!$this->game) { throw new Exception("No game in progress."); } if ($this->game->getState() != GameState::DAY) { throw new Exception("Voting occurs only during the day."); } // Voter should be alive if (!$this->game->hasPlayer($this->userId)) { throw new Exception("Can't vote if dead."); } // Person player is voting for should also be alive if (!$this->game->hasPlayer($this->args[0])) { throw new Exception("Voted player not found in game."); } }
/** * @param \Slack\User[] $users */ private function filterChosen(&$users) { $chosenUsers = []; foreach ($this->args as $chosenUser) { $chosenUser = UserIdFormatter::format($chosenUser, $users); $chosenUsers[] = $chosenUser; } // Remove the bot from the player list foreach ($users as $key => $user) { if ($user->getUsername() == getenv('BOT_NAME')) { unset($users[$key]); } } // Remove players that weren't specified, if there were specified players if (count($chosenUsers) == 0 || $chosenUsers[0] != 'all') { foreach ($users as $key => $user) { $userFound = false; foreach ($chosenUsers as $chosenUser) { if (strpos($chosenUser, $user->getId()) !== false) { $userFound = true; } } if (!$userFound) { unset($users[$key]); } } } }
public function init() { if ($this->channel[0] == 'D') { throw new Exception("Больше двух говорят вслух. Нельзя головать (!vote) втихую."); } if (count($this->args) < 1) { throw new InvalidArgumentException("Выбери жертву."); } $this->game = $this->gameManager->getGame($this->channel); if (!$this->game) { throw new Exception("Что-то пошло не так. Кажется игра не началась."); } if ($this->game->getState() != GameState::DAY) { throw new Exception("Слишком темно для голования, дождись утра."); } // Voter should be alive if (!$this->game->isPlayerAlive($this->userId)) { throw new Exception("Мертвые лежат и не возникают."); } $this->args[0] = UserIdFormatter::format($this->args[0], $this->game->getOriginalPlayers()); echo $this->args[0]; // Person player is voting for should also be alive if (!$this->game->isPlayerAlive($this->args[0]) && $this->args[0] != 'noone' && $this->args[0] != 'clear') { echo 'not found'; throw new Exception("Не вижу такого чела, а он с какого района?"); } }
/** * {@inheritdoc} * * Constructs a new Kill command. */ public function __construct(RealTimeClient $client, GameManager $gameManager, Message $message, array $args = null) { parent::__construct($client, $gameManager, $message, $args); $client = $this->client; if ($this->channel[0] != 'D') { throw new Exception("You may only !kill privately."); } if (count($this->args) < 2) { $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) { $client->send(":warning: Invalid command. Usage: !kill #channel @user", $channel); }); throw new InvalidArgumentException("Not enough arguments"); } $client = $this->client; $channelId = null; $channelName = ""; if (strpos($this->args[0], '#C') !== false) { $channelId = ChannelIdFormatter::format($this->args[0]); } else { if (strpos($this->args[0], '#') !== false) { $channelName = substr($this->args[0], 1); } else { $channelName = $this->args[0]; } } if ($channelId != null) { $this->client->getChannelById($channelId)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getGroupByName($channelName)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Invalid channel specified. Usage: !kill #channel @user", $dmc); }); throw new InvalidArgumentException(); } $this->game = $this->gameManager->getGame($channelId); if (!$this->game) { $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) { $client->send(":warning: No game in progress.", $channel); }); throw new Exception("No game in progress."); } $this->args[1] = UserIdFormatter::format($this->args[1], $this->game->getOriginalPlayers()); }
public function init() { $client = $this->client; if ($this->channel[0] != 'D') { throw new Exception("Vous pouvez uniquement utiliser la commande !guard par message privé."); } if (count($this->args) < 2) { $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) { $client->send(":warning: Commande invalide. Utilisation: !guard #channel @joueur", $channel); }); throw new InvalidArgumentException("Pas assez d'arguments"); } $client = $this->client; $channelId = null; $channelName = ""; if (strpos($this->args[0], '#C') !== false) { $channelId = ChannelIdFormatter::format($this->args[0]); } else { if (strpos($this->args[0], '#') !== false) { $channelName = substr($this->args[0], 1); } else { $channelName = $this->args[0]; } } if ($channelId != null) { $this->client->getChannelById($channelId)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getGroupByName($channelName)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Commande invalide. Utilisation: !guard #channel @joueur", $dmc); }); throw new InvalidArgumentException(); } $this->game = $this->gameManager->getGame($channelId); if (!$this->game) { $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) { $client->send(":warning: Aucun jeu en cours", $channel); }); throw new Exception("Aucun jeu en cours"); } $this->args[1] = UserIdFormatter::format($this->args[1], $this->game->getOriginalPlayers()); }
public function init() { $client = $this->client; if ($this->channel[0] != 'D') { throw new Exception("Псс, пацан, если хочешь защищать (!guard) то пиши в личку."); } if (count($this->args) < 2) { $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) { $client->send(":warning: Ты что-то попутал. Смотри как надо: !guard #channel @user", $channel); }); throw new InvalidArgumentException("Ты что-то попутал."); } $client = $this->client; $channelId = null; $channelName = ""; if (strpos($this->args[0], '#C') !== false) { $channelId = ChannelIdFormatter::format($this->args[0]); } else { if (strpos($this->args[0], '#') !== false) { $channelName = substr($this->args[0], 1); } else { $channelName = $this->args[0]; } } if ($channelId != null) { $this->client->getChannelById($channelId)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getGroupByName($channelName)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Не в тот чат, милок. Смотри как надо: !guard #channel @user", $dmc); }); throw new InvalidArgumentException(); } $this->game = $this->gameManager->getGame($channelId); if (!$this->game) { $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) { $client->send(":warning: Что-то пошло не так. Кажется игра не началась.", $channel); }); throw new Exception("Что-то пошло не так. Кажется игра не началась."); } $this->args[1] = UserIdFormatter::format($this->args[1], $this->game->getOriginalPlayers()); }
public function init() { $client = $this->client; if ($this->channel[0] != 'D') { throw new Exception("You may only !kill privately."); } if (count($this->args) < 2) { $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $channel) use($client) { $client->send(":warning: Invalid command. Usage: !kill #channel @user", $channel); }); throw new InvalidArgumentException("Not enough arguments"); } $this->args[1] = UserIdFormatter::format($this->args[0]); $client = $this->client; $channelId = null; $channelName = ""; if (strpos($this->args[0], '#C') !== false) { $channelId = $this->args[0]; } elseif (strpos($this->args[0], '#') !== false) { $channelName = substr($this->args[0], 1); } else { $channelName = $this->args[0]; } if ($channelId == null) { $this->client->getChannelByName($channelName)->then(function (Channel $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getGroupByName($channelName)->then(function (Channel $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Invalid channel specified. Usage: !guard #channel @user", $dmc); }); throw new InvalidArgumentException(); } $this->game = $this->gameManager->getGame($channelId); if (!$this->game) { $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $channel) use($client) { $client->send(":warning: No game in progress.", $channel); }); throw new Exception("No game in progress."); } }
/** * {@inheritdoc} * * Constructs a new Shoot command. */ public function __construct(RealTimeClient $client, GameManager $gameManager, Message $message, array $args = null) { parent::__construct($client, $gameManager, $message, $args); $client = $this->client; if (!$this->game) { throw new Exception("No game in progress."); } if (!$this->game->hunterNeedsToShoot) { $this->gameManager->sendMessageToChannel($this->game, ":warning: Invalid !shoot command."); throw new Exception("Hunter cant shoot yet."); } if ($this->channel[0] == 'D') { $this->gameManager->sendMessageToChannel($this->game, "Please !shoot in the public channel."); throw new Exception("You may not !shoot privately."); } if (count($this->args) < 1) { $this->gameManager->sendMessageToChannel($this->game, "Please target a player using !shoot @player"); throw new InvalidArgumentException("Must specify a player"); } $this->args[0] = UserIdFormatter::format($this->args[0], $this->game->getOriginalPlayers()); }
public function init() { $client = $this->client; if ($this->channel[0] != 'D') { throw new Exception("You may only !see from a DM."); } if (count($this->args) < 2) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Not enough arguments. Usage: !see #channel @user", $dmc); }); throw new InvalidArgumentException(); } $channelId = null; $channelName = ""; if (strpos($this->args[0], '#C') !== false) { $channelId = ChannelIdFormatter::format($this->args[0]); } else { if (strpos($this->args[0], '#') !== false) { $channelName = substr($this->args[0], 1); } else { $channelName = $this->args[0]; } } if ($channelId != null) { $this->client->getChannelById($channelId)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getGroupByName($channelName)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Invalid channel specified. Usage: !see #channel @user", $dmc); }); throw new InvalidArgumentException(); } $this->game = $this->gameManager->getGame($channelId); $this->gameId = $channelId; if (!$this->game) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Could not find a running game on the specified channel.", $dmc); }); throw new InvalidArgumentException(); } $this->args[1] = UserIdFormatter::format($this->args[1], $this->game->getOriginalPlayers()); $this->chosenUserId = $this->args[1]; $player = $this->game->getPlayerById($this->userId); if (!$player) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Could not find you in the game you specified.", $dmc); }); throw new InvalidArgumentException(); } // Player should be alive if (!$this->game->isPlayerAlive($this->userId)) { $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) { $client->send(":warning: You aren't alive in the specified channel.", $channel); }); throw new Exception("Can't See if dead."); } if ($player->role != Role::SEER) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: You aren't a seer in the specified game.", $dmc); }); throw new Exception("Player is not the seer but is trying to see."); } if (!in_array($this->game->getState(), [GameState::FIRST_NIGHT, GameState::NIGHT])) { throw new Exception("Can only See at night."); } if ($this->game->seerSeen()) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: You may only see once each night.", $dmc); }); throw new Exception("You may only see once each night."); } }
public function init() { $client = $this->client; if ($this->channel[0] != 'D') { throw new Exception("Псс, пацан, если хочешь видеть (!see) то пиши в личку."); } if (count($this->args) < 2) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Ты что-то попутал. Смотри как надо: !see #channel @user", $dmc); }); throw new InvalidArgumentException(); } $channelId = null; $channelName = ""; if (strpos($this->args[0], '#C') !== false) { $channelId = ChannelIdFormatter::format($this->args[0]); } else { if (strpos($this->args[0], '#') !== false) { $channelName = substr($this->args[0], 1); } else { $channelName = $this->args[0]; } } if ($channelId != null) { $this->client->getChannelById($channelId)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getGroupByName($channelName)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Не в тот чат, милок. Смотри как надо: !see #channel @user", $dmc); }); throw new InvalidArgumentException(); } $this->game = $this->gameManager->getGame($channelId); $this->gameId = $channelId; if (!$this->game) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Что-то пошло не так. Кажется игра не началась.", $dmc); }); throw new InvalidArgumentException(); } $this->args[1] = UserIdFormatter::format($this->args[1], $this->game->getOriginalPlayers()); $this->chosenUserId = $this->args[1]; $player = $this->game->getPlayerById($this->userId); if (!$player) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Не вижу тебя в списке игроков.", $dmc); }); throw new InvalidArgumentException(); } // Player should be alive if (!$this->game->isPlayerAlive($this->userId)) { $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) { $client->send(":warning: Кажется тебя уже выпилили, наберись терпения и жди следующей игры.", $channel); }); throw new Exception("Кажется тебя уже выпилили, наберись терпения и жди следующей игры."); } if ($player->role != Role::SEER) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: А справка от окулиста у тебя есть?", $dmc); }); throw new Exception("А справка от окулиста у тебя есть?"); } if (!in_array($this->game->getState(), [GameState::FIRST_NIGHT, GameState::NIGHT])) { throw new Exception("Ночь утра мудренее. Дождись заката."); } if ($this->game->seerSeen()) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Глазки устали, иди поспи.", $dmc); }); throw new Exception("Глазки устали, иди поспи."); } }
public function init() { $client = $this->client; if ($this->channel[0] != 'D') { throw new Exception("Vous pouvez uniquement !see par message privé."); } if (count($this->args) < 2) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Pas assez d'arguments. Utilisation : !see #channel @joueur", $dmc); }); throw new InvalidArgumentException(); } $channelId = null; $channelName = ""; if (strpos($this->args[0], '#C') !== false) { $channelId = ChannelIdFormatter::format($this->args[0]); } else { if (strpos($this->args[0], '#') !== false) { $channelName = substr($this->args[0], 1); } else { $channelName = $this->args[0]; } } if ($channelId != null) { $this->client->getChannelById($channelId)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getGroupByName($channelName)->then(function (ChannelInterface $channel) use(&$channelId) { $channelId = $channel->getId(); }, function (Exception $e) { // Do nothing }); } if ($channelId == null) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Channel invalide. Utilisation : !see #channel @joueur", $dmc); }); throw new InvalidArgumentException(); } $this->game = $this->gameManager->getGame($channelId); $this->gameId = $channelId; if (!$this->game) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Impossible de trouver une partie en cours sur le channel spécifié", $dmc); }); throw new InvalidArgumentException(); } $this->args[1] = UserIdFormatter::format($this->args[1], $this->game->getOriginalPlayers()); $this->chosenUserId = $this->args[1]; $player = $this->game->getPlayerById($this->userId); if (!$player) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Vous n'êtes pas dans la partie spécifiée.", $dmc); }); throw new InvalidArgumentException(); } // Player should be alive if (!$this->game->isPlayerAlive($this->userId)) { $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) { $client->send(":warning: Vous n'êtes pas vivant dans la partie spécifiée.", $channel); }); throw new Exception("Impossible de sonder en étant mort."); } if ($player->role != Role::SEER) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Vous n'êtes pas la Voyante dans la partie spécifiée.", $dmc); }); throw new Exception("Le joueur n'est pas la Voyante mais essaie de sonder."); } if (!in_array($this->game->getState(), [GameState::FIRST_NIGHT, GameState::NIGHT])) { throw new Exception("Can only See at night."); } if ($this->game->seerSeen()) { $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) { $this->client->send(":warning: Vous ne pouvez sonder un joueur qu'une seule fois par nuit.", $dmc); }); throw new Exception("Vous ne pouvez sonder un joueur qu'une seule fois par nuit."); } }