protected function buildGameDm(SpymasterGame $game)
 {
     $text = '--- Target words ---' . PHP_EOL . implode(PHP_EOL, $game->getScorableWords());
     $text .= PHP_EOL . PHP_EOL;
     $text .= '--- Assassin ---' . PHP_EOL . implode(PHP_EOL, $game->getAssassinWords());
     $text .= PHP_EOL . PHP_EOL;
     $text .= '--- Other words ---' . PHP_EOL . implode(PHP_EOL, $game->getNeutralWords());
     $text .= PHP_EOL . PHP_EOL;
     $text .= 'Respond with a clue (word number) to begin the game. Your clue will be tweeted with an image of the board';
     return $text;
 }
 protected function getResponse(TwitterBot $bot, $tweet)
 {
     $id = $tweet->id_str;
     $sender = $tweet->user->screen_name;
     $targetId = $tweet->in_reply_to_status_id;
     $text = $tweet->text;
     $username = $bot->getUsername();
     if (strpos($text, '@' . $username) !== 0) {
         return null;
         // not a direct mention
     }
     $game = SpymasterGame::getByTweetId($targetId);
     if ($game === null) {
         return null;
         // Not in response to a game
     }
     if ($game->getFinished()) {
         return 'Sorry, this game has already finished. DM me "start" to start a new game of your own';
     }
     $text = substr($text, strlen($username) + 2);
     $text = preg_replace('/[^A-Za-z]+/', ' ', $text);
     $words = explode(' ', trim($text));
     // TODO: validate this shit
     $game->recordGuess($sender, $words);
 }
    public function behave(TwitterBot $bot)
    {
        $sql = <<<'SQL'
SELECT
*
FROM spymaster_game
WHERE finished = FALSE
AND end_timestamp <= NOW()
SQL;
        $result = Di::getDefault()->getDb()->query($sql);
        while ($game = SpymasterGame::createFromQueryResult($result)) {
            $game->finish($bot);
        }
    }
Пример #4
0
 public static function createFromQueryResult($result)
 {
     $row = $result->fetch();
     if (!$row) {
         return null;
     }
     $game = new SpymasterGame();
     $game->setId($row['id']);
     $game->setOwner($row['owner']);
     $game->setTweetId($row['tweet_id']);
     $game->setWords(explode(',', $row['words']));
     $game->setScorableWords(explode(',', $row['scorable_words']));
     $game->setAssassinWords(explode(',', $row['assassin_words']));
     $game->setClue($row['clue']);
     $game->setFinished((bool) $row['finished']);
     return $game;
 }