Beispiel #1
0
 public static function constructFromTelegramUpdate($user_update, \PDO $db)
 {
     if (isset($user_update['username']) && strcmp($user_update['username'], BOT_FULL_USER_NAME) === 0) {
         $user = new User();
         $user->user_name = BOT_FULL_USER_NAME;
         $user->welcome_sent = true;
         return $user;
     }
     $changed = false;
     $userSQL = new \GroupBot\Database\User($db);
     if ($user = $userSQL->getUserFromId($user_update['id'])) {
         if (isset($user_update['first_name']) && strcmp($user->first_name, $user_update['first_name']) !== 0) {
             $user->first_name = $user_update['first_name'];
             $changed = true;
         }
         if (isset($user_update['username']) && strcmp($user->user_name, $user_update['username']) !== 0) {
             $user->user_name = $user_update['username'];
             $changed = true;
         }
         if (isset($user_update['last_name']) && strcmp($user->last_name, $user_update['last_name']) !== 0) {
             $user->last_name = $user_update['last_name'];
             $changed = true;
         }
     } else {
         $user = new User();
         $last_name = isset($user_update['last_name']) ? $user_update['last_name'] : NULL;
         $username = isset($user_update['username']) ? $user_update['username'] : NULL;
         $user->construct($user_update['id'], $user_update['first_name'], $last_name, $username);
         $changed = true;
     }
     if ($changed) {
         $user->save($db);
     }
     return $user;
 }
Beispiel #2
0
 public static function buyLevel(User $user, \PDO $db)
 {
     $price = Level::getLevelPrice($user->level + 1);
     if ($user->getBalance() >= $price) {
         $Transact = new Transact($db);
         if ($Transact->transactToBank(new BankTransaction($user, $price, new TransactionType(TransactionType::LevelPurchase)))) {
             $user->level++;
             $user->save($db);
             return true;
         }
     }
     return false;
 }
Beispiel #3
0
 /**
  * @param Game $game
  * @param User $user
  * @param User $bank
  * @param $bet
  * @return bool
  */
 public function checkPlayerBet(Game $game, User $user, User $bank, $bet)
 {
     switch ($game->GameType) {
         case GameType::Blackjack:
             $max_bet_factor = 1.5;
             break;
         case GameType::Casinowar:
             $max_bet_factor = 1.0;
             break;
         default:
             $max_bet_factor = 2.0;
             break;
     }
     $this->bet = $bet;
     if (!(is_numeric($this->bet) && $this->bet >= 0 && $this->bet == round($this->bet, 2))) {
         if (stripos($this->bet, "all") !== false) {
             try {
                 $value = Parser::solve($this->bet, array('all' => $user->getBalance(true)));
                 $value = round($value, 4);
                 if ($value >= 0 && $value <= $user->getBalance(true)) {
                     $this->bet = $value;
                     $this->Talk->bet_calculation(round($value, 2));
                 } else {
                     $this->Talk->bet_invalid_calculation();
                     return false;
                 }
             } catch (\Exception $e) {
                 $this->Talk->bet_invalid_notation();
                 return false;
             }
         } else {
             $this->Talk->bet_invalid();
             return false;
         }
     }
     if ($this->bet > CASINO_BETTING_MAX) {
         $this->bet = CASINO_BETTING_MAX;
         $this->Talk->bet_limit();
     }
     if ($user->getBalance(true) < 1 && $this->bet <= 1) {
         if ($bank->getBalance() > $game->betting_pool + $max_bet_factor) {
             if ($user->free_bets_today < CASINO_DAILY_FREE_BETS) {
                 $this->Talk->bet_free($user->free_bets_today);
                 $this->bet = 1;
                 $this->free_bet = true;
                 $user->free_bets_today++;
                 $user->save($this->db);
             } else {
                 $this->Talk->bet_free_too_many();
                 return false;
             }
         } else {
             $this->Talk->bet_free_failed();
             return false;
         }
     } elseif ($this->bet < 1) {
         if ($bank->getBalance() > $game->betting_pool + $max_bet_factor) {
             $this->bet = 1;
             $this->Talk->bet_mandatory();
         } else {
             $this->bet = 0;
             $this->Talk->bet_mandatory_failed();
         }
         return true;
     } elseif ($this->bet > $user->getBalance(true)) {
         $this->Talk->bet_too_high($user->getBalance(true));
         return false;
     }
     if ($bank->getBalance() < $game->betting_pool + $max_bet_factor * $this->bet) {
         $this->Talk->bet_too_high_for_dealer();
         return false;
     }
     $game->betting_pool += $this->bet;
     return true;
 }
Beispiel #4
0
 private function updateTimeZone(\GroupBot\Types\User $user, $timezone)
 {
     if (in_array($timezone, timezone_identifiers_list())) {
         $user->timezone = $this->getParam();
         return $user->save($this->db);
     }
     return false;
 }