Exemple #1
0
 private function select_game($message_id)
 {
     $sql = 'SELECT * FROM c2_games WHERE message_id = :message_id';
     $query = $this->db->prepare($sql);
     $query->bindParam(':message_id', $message_id);
     $query->execute();
     if ($query->rowCount()) {
         $results = $query->fetchAll();
         $out = [];
         $DbUser = new \GroupBot\Database\User($this->db);
         foreach ($results as $player) {
             if ($user = $DbUser->getUserFromId($player['user_id'])) {
                 $out[] = new c2player($user, $player['message_id'], $player['rank']);
             }
         }
         usort($out, function ($a, $b) {
             if ($a->rank == $b->rank) {
                 return 0;
             }
             if ($a->rank > $b->rank) {
                 return 1;
             }
             return -1;
         });
         return $out;
     }
     return false;
 }
Exemple #2
0
 /**
  * @param $include_bank
  * @return float
  */
 public function getTotalCoinExisting($include_bank)
 {
     $userSQL = new \GroupBot\Database\User($this->db);
     $users = $userSQL->getAllUsers($include_bank);
     $total_coin = 0.0;
     foreach ($users as $i) {
         $total_coin += $i->getBalance(true);
     }
     return $total_coin;
 }
Exemple #3
0
 public function addDealer(\PDO $db)
 {
     if (!$this->isGameStarted()) {
         $Player = new Player();
         //$Dealer = new User();
         //$Dealer->construct('-1', 'Dealer', '', 'Dealer');
         $DbUser = new \GroupBot\Database\User($db);
         $Dealer = $DbUser->getUserFromId('-1');
         $Player->construct($Dealer, new Hand(), new PlayerState(PlayerState::Dealer), -1, 0, false);
         $Player->Hand->addCard($this->Deck->dealCard());
         $this->Dealer = $Player;
         $this->SQL->insert_player($this->game_id, $Player);
         return true;
     }
     return false;
 }
Exemple #4
0
 /**
  * @param $chat_id
  * @return LeaderboardItem[]
  */
 public function getVoteLeaderboard($chat_id)
 {
     $DbUser = new \GroupBot\Database\User($this->db);
     if (isset($chat_id)) {
         $users = $DbUser->getAllUsersInChat($chat_id);
     } else {
         $users = $DbUser->getAllUsers(true);
     }
     $votes = $this->SQL->get_all_votes();
     $tallies = array();
     if ($votes) {
         foreach ($votes as $vote) {
             if ($this->in_array_field($vote->voter->user_id, 'user_id', $users)) {
                 if (isset($tallies[$vote->voted_for->user_id])) {
                     $tallies[$vote->voted_for->user_id] += $vote->vote;
                 } else {
                     $tallies[$vote->voted_for->user_id] = $vote->vote;
                 }
             }
         }
     }
     $leaderboard = array();
     foreach ($users as $user) {
         $tally = array_key_exists($user->user_id, $tallies) ? $tallies[$user->user_id] : 0;
         $leaderboard[] = new LeaderboardItem($user, $tally);
     }
     usort($leaderboard, function ($a, $b) {
         if ($a->vote_total == $b->vote_total) {
             return 0;
         }
         return $a->vote_total > $b->vote_total ? -1 : 1;
     });
     return $leaderboard;
 }
 public function set_option($parameter, $value)
 {
     $DbUser = new \GroupBot\Database\User($this->db);
     $admin = $DbUser->getUserFromId($this->chat->admin_user_id);
     if ($admin->user_id == $this->Message->User->user_id) {
         switch ($parameter) {
             case 'no_spam_mode':
                 return $this->set_boolean_option('no_spam_mode', $value);
                 break;
             case 'bot_kick_mode':
                 return $this->set_boolean_option('bot_kick_mode', $value);
                 break;
             case 'yandex_enabled':
                 return $this->set_boolean_option('yandex_enabled', $value);
                 break;
         }
     }
     return false;
 }
Exemple #6
0
 public function save(\PDO $db)
 {
     $userSQL = new \GroupBot\Database\User($db);
     return $userSQL->updateUser($this);
 }
Exemple #7
0
 private function keyboard()
 {
     $DbUser = new \GroupBot\Database\User($this->db);
     $chats = $DbUser->getActiveChatsByUser($this->Message->User);
     $keyboard = [[['text' => 'Global', 'callback_data' => '/vote']], [['text' => emoji(0x1f4bc) . ' Back to business menu', 'callback_data' => '/help business'], ['text' => emoji(0x1f6aa) . ' Back to main menu', 'callback_data' => '/help']]];
     $index = 0;
     foreach ($chats as $chat) {
         if ($index++ > 3) {
             break;
         }
         $keyboard[0][] = ['text' => $chat->title, 'callback_data' => '/vote _view_chat ' . $chat->id];
     }
     return $keyboard;
 }