Slackwolf\Game\Command\Command::__construct PHP Method

__construct() public method

Command constructor.
public __construct ( RealTimeClient $client, GameManager $gameManager, Message $message, array $args = null )
$client Slack\RealTimeClient The Slack API client.
$gameManager Slackwolf\Game\GameManager The game manager.
$message Slackwolf\Message\Message The message object.
$args array
    public function __construct(RealTimeClient $client, GameManager $gameManager, Message $message, array $args = null)
    {
        $this->client = $client;
        $this->gameManager = $gameManager;
        $this->message = $message;
        $this->userId = $message->getUser();
        $this->channel = $message->getChannel();
        $this->args = $args;
        $this->game = $this->gameManager->getGame($this->channel);
        echo get_called_class() . " " . $this->userId . " " . $this->channel . "\r\n";
    }

Usage Example

Beispiel #1
0
 /**
  * {@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.");
     }
 }
All Usage Examples Of Slackwolf\Game\Command\Command::__construct