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; }
private function parseAmount(User $User, $amount) { if ($User->getBalance() - $amount == 0) { return $User->getBalance(true); } else { return $amount; } }
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; }
private function determineMessageType($message) { if (isset($message['reply_to_message'])) { $this->MessageType = new MessageType(MessageType::Reply); $this->reply_to_message = new Message($message['reply_to_message'], $this->db); } elseif (isset($message['forward_from'])) { $this->forward_from = new User(); $this->forward_from->constructFromTelegramUpdate($message['forward_from'], $this->db); $this->MessageType = new MessageType(MessageType::Forward); } elseif (isset($message['new_chat_participant'])) { $this->MessageType = new MessageType(MessageType::NewChatParticipant); $this->new_chat_participant = User::constructFromTelegramUpdate($message['new_chat_participant'], $this->db); } elseif (isset($message['left_chat_participant'])) { $this->MessageType = new MessageType(MessageType::LeftChatParticipant); } elseif (isset($message['new_chat_title'])) { $this->MessageType = new MessageType(MessageType::NewChatTitle); $this->new_chat_title = $message['new_chat_title']; } elseif (isset($message['new_chat_photo'])) { $this->MessageType = new MessageType(MessageType::NewChatPhoto); $this->new_chat_photo = $message['new_chat_photo']; } elseif (isset($message['delete_chat_photo'])) { $this->MessageType = new MessageType(MessageType::DeleteChatPhoto); } elseif (isset($message['group_chat_created'])) { $this->MessageType = new MessageType(MessageType::GroupChatCreated); } elseif (isset($message['supergroup_chat_created'])) { $this->MessageType = new MessageType(MessageType::SuperGroupChatCreated); } elseif (isset($message['channel_chat_created'])) { $this->MessageType = new MessageType(MessageType::ChannelChatCreated); } else { $this->MessageType = new MessageType(MessageType::Regular); } }
public function removeMoney(User $User, $amount) { $new_balance = $User->getBalance(true) - $amount; if ($new_balance >= 0) { $User->balance = $new_balance; return true; } else { $this->Feedback->addFeedbackCode(27); // You don't have enough Coin! return false; } }
/** * @param Player $player * @param User $bank * @param $multiplier */ public function payPlayer(Player $player, User $bank, $multiplier) { if ($multiplier > 0) { if ($bank->getBalance() > (1 + $multiplier) * $player->bet) { $this->taxationBodyTransact($player, (1 + $multiplier) * $player->bet); $player->bet_result = $multiplier * $player->bet; } elseif ($bank->getBalance() > abs($player->bet)) { $this->Talk->pay_bet_failed_return(); $this->taxationBodyTransact($player, abs($player->bet)); } else { $this->Talk->pay_bet_failed(); $player->bet_result = -1 * $player->bet; } $player->game_result = new GameResult(GameResult::Win); } elseif ($multiplier == 0) { if (!$player->free_bet) { if ($bank->getBalance() > abs($player->bet)) { $this->taxationBodyTransact($player, abs($player->bet)); } else { $this->Talk->pay_bet_failed_repay(); } } $player->game_result = new GameResult(GameResult::Draw); } else { if (!$player->free_bet) { $player->bet_result = $multiplier * $player->bet; } $player->game_result = new GameResult(GameResult::Loss); } $this->Talk->player_result($player, $multiplier); }
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; }