Example #1
0
 private function set_boolean_option($parameter, $value)
 {
     if (strcmp($value, '0') === 0) {
         $this->chat->{$parameter} = false;
         return $this->chat->save($this->db);
     } elseif (strcmp($value, '1') === 0) {
         $this->chat->{$parameter} = true;
         return $this->chat->save($this->db);
     }
     return false;
 }
Example #2
0
 public static function constructFromTelegramUpdate($chat_update, \PDO $db)
 {
     $changed = false;
     $chatSQL = new \GroupBot\Database\Chat($db);
     if ($chat = $chatSQL->getChatById($chat_update['id'])) {
         if (isset($chat_update['title']) && strcmp($chat->title, $chat_update['title']) !== 0) {
             $chat->title = $chat_update['title'];
             $changed = true;
         }
         $chat->id = $chat->chat_id;
         unset($chat->chat_id);
     } else {
         $chat = new Chat();
         $chat->construct($chat_update['id'], $chat->determineChatType($chat_update), isset($chat_update['title']) ? $chat_update['title'] : NULL, 0);
         $changed = true;
     }
     if ($changed) {
         $chat->save($db);
     }
     return $chat;
 }
Example #3
0
 public function __construct($message, \PDO $db)
 {
     $this->db = $db;
     $this->User = User::constructFromTelegramUpdate($message['from'], $this->db);
     $this->Chat = Chat::constructFromTelegramUpdate($message['chat'], $this->db);
     $this->message_id = $message['message_id'];
     if (isset($message['callback'])) {
         $this->callback = $message['callback'];
     }
     $this->determineMessageContent($message);
     $this->determineMessageType($message);
     $this->determineMessageEntities($message);
     if ($this->MessageContent == MessageContent::Text) {
         $this->parseMessage($message);
     }
 }
Example #4
0
 public function dealer_done(Game $Game, Player $Dealer)
 {
     if ($Game->getNumberOfPlayers() > 1) {
         $this->addMessage('All players have stood or are bust. The dealer draws cards:');
         $this->addMessage($Dealer->Hand->getHandString() . " (" . $Dealer->Hand->Value . ")");
     } else {
         $this->addMessage('The dealer draws cards ' . $Dealer->Hand->getHandString() . " (" . $Dealer->Hand->Value . ")");
     }
     if ($Dealer->State == PlayerState::Bust) {
         $this->addMessage('The dealer is bust.');
     } elseif ($Dealer->State == PlayerState::Stand) {
         $this->addMessage('The dealer stands.');
     }
     if ($this->chat->isPrivate()) {
         $this->keyboard = [[['text' => emoji(0x1f4b5) . " Play again - default bet", 'callback_data' => '/bjstart'], ['text' => emoji(0x1f4b0) . " Play again - bet double", 'callback_data' => '/bjstart ' . 2 * $Game->getCurrentPlayer()->bet]], [['text' => emoji(0x1f4b0) . " Play again - bet half", 'callback_data' => '/bjstart all/2'], ['text' => emoji(0x1f4b0) . " Play again - bet all", 'callback_data' => '/bjstart all']], [['text' => emoji(0x1f3ae) . ' Back to games menu', 'callback_data' => '/help games'], ['text' => emoji(0x1f6aa) . ' Main menu', 'callback_data' => '/help']]];
     } else {
         $this->keyboard = [[['text' => emoji(0x1f4b5) . " New game - default bet", 'callback_data' => '/blackjack'], ['text' => emoji(0x1f4b0) . " Play again - bet double", 'callback_data' => '/blackjack ' . 2 * $Game->getCurrentPlayer()->bet]], [['text' => emoji(0x1f4b0) . " New game - bet half", 'callback_data' => '/blackjack all/2'], ['text' => emoji(0x1f4b0) . " New game - bet all", 'callback_data' => '/blackjack all']]];
     }
 }