diff options
| author | levlam <levlam@telegram.org> | 2025-12-24 16:40:54 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2025-12-24 16:40:54 +0300 |
| commit | 6aa52b0f2fd8b7d55eb6ab9cbd039d5c3ed7f4c8 (patch) | |
| tree | c095f4c0c389b1f3d5d96095742cedaff21a0d9b | |
| parent | 029ba9ae67414fb1225bc51151c403056e5431ef (diff) | |
Add td_api::stakeDiceState.
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | td/generate/scheme/td_api.tl | 8 | ||||
| -rw-r--r-- | td/telegram/EmojiGameInfo.cpp | 58 | ||||
| -rw-r--r-- | td/telegram/EmojiGameInfo.h | 32 |
4 files changed, 100 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index dda3bae26..ad6da7d8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -430,6 +430,7 @@ set(TDLIB_SOURCE_PART1 td/telegram/DownloadManagerCallback.cpp td/telegram/DraftMessage.cpp td/telegram/EmailVerification.cpp + td/telegram/EmojiGameInfo.cpp td/telegram/EmojiGroup.cpp td/telegram/EmojiGroupType.cpp td/telegram/EmojiStatus.cpp @@ -792,6 +793,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/DownloadManagerCallback.h td/telegram/DraftMessage.h td/telegram/EmailVerification.h + td/telegram/EmojiGameInfo.h td/telegram/EmojiGroup.h td/telegram/EmojiGroupType.h td/telegram/EmojiStatus.h diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index e8f6c8a43..761304fc9 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -555,6 +555,14 @@ venue location:location title:string address:string provider:string id:string ty //@animation Game animation; may be null game id:int64 short_name:string title:string text:formattedText description:string photo:photo animation:animation = Game; +//@description Describes state of the stake dice +//@state_hash Hash of the state to use for sending the next dice; may be empty if the stake dice can't be sent by the current user +//@stake_toncoin_amount The amount of Toncoins that was staked in the previous roll; in the smallest units of the currency +//@current_streak The number of rolled sixes towards the streak; 0-2 +//@prize_per_mille The number of Toncoins received by the user for each 1000 Toncoins staked if the dice outcome is 1-6 correspondingly; may be empty if the stake dice can't be sent by the current user +//@streak_prize_per_mille The number of Toncoins received by the user for each 1000 Toncoins staked if the dice outcome is 6 three times in a row with the same stake +stakeDiceState state_hash:string stake_toncoin_amount:int53 current_streak:int32 prize_per_mille:vector<int32> streak_prize_per_mille:int32 = StakeDiceState; + //@description Describes a Web App. Use getInternalLink with internalLinkTypeWebApp to share the Web App //@short_name Web App short name //@title Web App title diff --git a/td/telegram/EmojiGameInfo.cpp b/td/telegram/EmojiGameInfo.cpp new file mode 100644 index 000000000..3dc171809 --- /dev/null +++ b/td/telegram/EmojiGameInfo.cpp @@ -0,0 +1,58 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#include "td/telegram/EmojiGameInfo.h" + +#include "td/telegram/TonAmount.h" + +#include "td/utils/logging.h" + +namespace td { + +EmojiGameInfo::EmojiGameInfo(telegram_api::object_ptr<telegram_api::messages_EmojiGameInfo> &&game_info) { + CHECK(game_info != nullptr); + switch (game_info->get_id()) { + case telegram_api::messages_emojiGameUnavailable::ID: + break; + case telegram_api::messages_emojiGameDiceInfo::ID: { + auto info = telegram_api::move_object_as<telegram_api::messages_emojiGameDiceInfo>(game_info); + auto is_bad = info->game_hash_.empty() || info->prev_stake_ < 0 || info->current_streak_ < 0 || + info->current_streak_ >= 3 || info->params_.size() != 7u; + for (auto param : info->params_) { + if (param < 0) { + is_bad = true; + } + } + if (is_bad) { + LOG(ERROR) << "Receive " << to_string(info); + break; + } + game_hash_ = std::move(info->game_hash_); + prev_stake_ = TonAmount::get_ton_count(info->prev_stake_, false); + current_streak_ = info->current_streak_; + params_ = std::move(info->params_); + break; + } + default: + UNREACHABLE(); + } +} + +td_api::object_ptr<td_api::stakeDiceState> EmojiGameInfo::get_stake_dice_state_object() const { + if (game_hash_.empty()) { + return td_api::make_object<td_api::stakeDiceState>(); + } + CHECK(params_.size() == 7u); + return td_api::make_object<td_api::stakeDiceState>(game_hash_, prev_stake_, current_streak_, + vector<int32>(params_.begin(), params_.begin() + 6), params_[6]); +} + +bool operator==(const EmojiGameInfo &lhs, const EmojiGameInfo &rhs) { + return lhs.game_hash_ == rhs.game_hash_ && lhs.prev_stake_ == rhs.prev_stake_ && + lhs.current_streak_ == rhs.current_streak_ && lhs.params_ == rhs.params_; +} + +} // namespace td diff --git a/td/telegram/EmojiGameInfo.h b/td/telegram/EmojiGameInfo.h new file mode 100644 index 000000000..c2af44022 --- /dev/null +++ b/td/telegram/EmojiGameInfo.h @@ -0,0 +1,32 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" + +namespace td { + +class EmojiGameInfo { + string game_hash_; + int64 prev_stake_ = 0; + int32 current_streak_ = 0; + vector<int32> params_; + + friend bool operator==(const EmojiGameInfo &lhs, const EmojiGameInfo &rhs); + + public: + explicit EmojiGameInfo(telegram_api::object_ptr<telegram_api::messages_EmojiGameInfo> &&game_info); + + td_api::object_ptr<td_api::stakeDiceState> get_stake_dice_state_object() const; +}; + +bool operator==(const EmojiGameInfo &lhs, const EmojiGameInfo &rhs); + +} // namespace td |
