Move inline game methods to InlineMessageManager.
This commit is contained in:
parent
580deda3e7
commit
03ca49f3a1
@ -12,11 +12,8 @@
|
|||||||
#include "td/telegram/DialogId.h"
|
#include "td/telegram/DialogId.h"
|
||||||
#include "td/telegram/DialogManager.h"
|
#include "td/telegram/DialogManager.h"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/InlineQueriesManager.h"
|
|
||||||
#include "td/telegram/MessageId.h"
|
#include "td/telegram/MessageId.h"
|
||||||
#include "td/telegram/MessagesManager.h"
|
#include "td/telegram/MessagesManager.h"
|
||||||
#include "td/telegram/net/DcId.h"
|
|
||||||
#include "td/telegram/net/NetQueryCreator.h"
|
|
||||||
#include "td/telegram/Td.h"
|
#include "td/telegram/Td.h"
|
||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
#include "td/telegram/UpdatesManager.h"
|
#include "td/telegram/UpdatesManager.h"
|
||||||
@ -78,50 +75,6 @@ class SetGameScoreQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetInlineGameScoreQuery final : public Td::ResultHandler {
|
|
||||||
Promise<Unit> promise_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit SetInlineGameScoreQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void send(tl_object_ptr<telegram_api::InputBotInlineMessageID> input_bot_inline_message_id, bool edit_message,
|
|
||||||
tl_object_ptr<telegram_api::InputUser> input_user, int32 score, bool force) {
|
|
||||||
CHECK(input_bot_inline_message_id != nullptr);
|
|
||||||
CHECK(input_user != nullptr);
|
|
||||||
|
|
||||||
int32 flags = 0;
|
|
||||||
if (edit_message) {
|
|
||||||
flags |= telegram_api::messages_setInlineGameScore::EDIT_MESSAGE_MASK;
|
|
||||||
}
|
|
||||||
if (force) {
|
|
||||||
flags |= telegram_api::messages_setInlineGameScore::FORCE_MASK;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto dc_id = DcId::internal(InlineQueriesManager::get_inline_message_dc_id(input_bot_inline_message_id));
|
|
||||||
send_query(G()->net_query_creator().create(
|
|
||||||
telegram_api::messages_setInlineGameScore(flags, false /*ignored*/, false /*ignored*/,
|
|
||||||
std::move(input_bot_inline_message_id), std::move(input_user), score),
|
|
||||||
{}, dc_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_result(BufferSlice packet) final {
|
|
||||||
auto result_ptr = fetch_result<telegram_api::messages_setInlineGameScore>(packet);
|
|
||||||
if (result_ptr.is_error()) {
|
|
||||||
return on_error(result_ptr.move_as_error());
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_IF(ERROR, !result_ptr.ok()) << "Receive false in result of setInlineGameScore";
|
|
||||||
|
|
||||||
promise_.set_value(Unit());
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_error(Status status) final {
|
|
||||||
LOG(INFO) << "Receive error for SetInlineGameScoreQuery: " << status;
|
|
||||||
promise_.set_error(std::move(status));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class GetGameHighScoresQuery final : public Td::ResultHandler {
|
class GetGameHighScoresQuery final : public Td::ResultHandler {
|
||||||
Promise<td_api::object_ptr<td_api::gameHighScores>> promise_;
|
Promise<td_api::object_ptr<td_api::gameHighScores>> promise_;
|
||||||
DialogId dialog_id_;
|
DialogId dialog_id_;
|
||||||
@ -157,39 +110,6 @@ class GetGameHighScoresQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class GetInlineGameHighScoresQuery final : public Td::ResultHandler {
|
|
||||||
Promise<td_api::object_ptr<td_api::gameHighScores>> promise_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit GetInlineGameHighScoresQuery(Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise)
|
|
||||||
: promise_(std::move(promise)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void send(tl_object_ptr<telegram_api::InputBotInlineMessageID> input_bot_inline_message_id,
|
|
||||||
tl_object_ptr<telegram_api::InputUser> input_user) {
|
|
||||||
CHECK(input_bot_inline_message_id != nullptr);
|
|
||||||
CHECK(input_user != nullptr);
|
|
||||||
|
|
||||||
auto dc_id = DcId::internal(InlineQueriesManager::get_inline_message_dc_id(input_bot_inline_message_id));
|
|
||||||
send_query(G()->net_query_creator().create(
|
|
||||||
telegram_api::messages_getInlineGameHighScores(std::move(input_bot_inline_message_id), std::move(input_user)),
|
|
||||||
{}, dc_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_result(BufferSlice packet) final {
|
|
||||||
auto result_ptr = fetch_result<telegram_api::messages_getInlineGameHighScores>(packet);
|
|
||||||
if (result_ptr.is_error()) {
|
|
||||||
return on_error(result_ptr.move_as_error());
|
|
||||||
}
|
|
||||||
|
|
||||||
promise_.set_value(td_->game_manager_->get_game_high_scores_object(result_ptr.move_as_ok()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_error(Status status) final {
|
|
||||||
promise_.set_error(std::move(status));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
GameManager::GameManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
GameManager::GameManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,21 +152,6 @@ void GameManager::on_set_game_score(MessageFullId message_full_id,
|
|||||||
promise.set_value(td_->messages_manager_->get_message_object(message_full_id, "on_set_game_score"));
|
promise.set_value(td_->messages_manager_->get_message_object(message_full_id, "on_set_game_score"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameManager::set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score,
|
|
||||||
bool force, Promise<Unit> &&promise) {
|
|
||||||
CHECK(td_->auth_manager_->is_bot());
|
|
||||||
|
|
||||||
auto input_bot_inline_message_id = td_->inline_queries_manager_->get_input_bot_inline_message_id(inline_message_id);
|
|
||||||
if (input_bot_inline_message_id == nullptr) {
|
|
||||||
return promise.set_error(Status::Error(400, "Invalid inline message identifier specified"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TRY_RESULT_PROMISE(promise, input_user, td_->user_manager_->get_input_user(user_id));
|
|
||||||
|
|
||||||
td_->create_handler<SetInlineGameScoreQuery>(std::move(promise))
|
|
||||||
->send(std::move(input_bot_inline_message_id), edit_message, std::move(input_user), score, force);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameManager::get_game_high_scores(MessageFullId message_full_id, UserId user_id,
|
void GameManager::get_game_high_scores(MessageFullId message_full_id, UserId user_id,
|
||||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise) {
|
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise) {
|
||||||
CHECK(td_->auth_manager_->is_bot());
|
CHECK(td_->auth_manager_->is_bot());
|
||||||
@ -269,21 +174,6 @@ void GameManager::get_game_high_scores(MessageFullId message_full_id, UserId use
|
|||||||
td_->create_handler<GetGameHighScoresQuery>(std::move(promise))->send(dialog_id, message_id, std::move(input_user));
|
td_->create_handler<GetGameHighScoresQuery>(std::move(promise))->send(dialog_id, message_id, std::move(input_user));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameManager::get_inline_game_high_scores(const string &inline_message_id, UserId user_id,
|
|
||||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise) {
|
|
||||||
CHECK(td_->auth_manager_->is_bot());
|
|
||||||
|
|
||||||
auto input_bot_inline_message_id = td_->inline_queries_manager_->get_input_bot_inline_message_id(inline_message_id);
|
|
||||||
if (input_bot_inline_message_id == nullptr) {
|
|
||||||
return promise.set_error(Status::Error(400, "Invalid inline message identifier specified"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TRY_RESULT_PROMISE(promise, input_user, td_->user_manager_->get_input_user(user_id));
|
|
||||||
|
|
||||||
td_->create_handler<GetInlineGameHighScoresQuery>(std::move(promise))
|
|
||||||
->send(std::move(input_bot_inline_message_id), std::move(input_user));
|
|
||||||
}
|
|
||||||
|
|
||||||
td_api::object_ptr<td_api::gameHighScores> GameManager::get_game_high_scores_object(
|
td_api::object_ptr<td_api::gameHighScores> GameManager::get_game_high_scores_object(
|
||||||
telegram_api::object_ptr<telegram_api::messages_highScores> &&high_scores) {
|
telegram_api::object_ptr<telegram_api::messages_highScores> &&high_scores) {
|
||||||
td_->user_manager_->on_get_users(std::move(high_scores->users_), "get_game_high_scores_object");
|
td_->user_manager_->on_get_users(std::move(high_scores->users_), "get_game_high_scores_object");
|
||||||
|
@ -32,15 +32,9 @@ class GameManager final : public Actor {
|
|||||||
void set_game_score(MessageFullId message_full_id, bool edit_message, UserId user_id, int32 score, bool force,
|
void set_game_score(MessageFullId message_full_id, bool edit_message, UserId user_id, int32 score, bool force,
|
||||||
Promise<td_api::object_ptr<td_api::message>> &&promise);
|
Promise<td_api::object_ptr<td_api::message>> &&promise);
|
||||||
|
|
||||||
void set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score,
|
|
||||||
bool force, Promise<Unit> &&promise);
|
|
||||||
|
|
||||||
void get_game_high_scores(MessageFullId message_full_id, UserId user_id,
|
void get_game_high_scores(MessageFullId message_full_id, UserId user_id,
|
||||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise);
|
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise);
|
||||||
|
|
||||||
void get_inline_game_high_scores(const string &inline_message_id, UserId user_id,
|
|
||||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise);
|
|
||||||
|
|
||||||
td_api::object_ptr<td_api::gameHighScores> get_game_high_scores_object(
|
td_api::object_ptr<td_api::gameHighScores> get_game_high_scores_object(
|
||||||
telegram_api::object_ptr<telegram_api::messages_highScores> &&high_scores);
|
telegram_api::object_ptr<telegram_api::messages_highScores> &&high_scores);
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "td/telegram/AuthManager.h"
|
#include "td/telegram/AuthManager.h"
|
||||||
#include "td/telegram/DialogManager.h"
|
#include "td/telegram/DialogManager.h"
|
||||||
#include "td/telegram/files/FileManager.h"
|
#include "td/telegram/files/FileManager.h"
|
||||||
|
#include "td/telegram/GameManager.h"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/InlineQueriesManager.h"
|
#include "td/telegram/InlineQueriesManager.h"
|
||||||
#include "td/telegram/InputMessageText.h"
|
#include "td/telegram/InputMessageText.h"
|
||||||
@ -19,6 +20,7 @@
|
|||||||
#include "td/telegram/OptionManager.h"
|
#include "td/telegram/OptionManager.h"
|
||||||
#include "td/telegram/ReplyMarkup.h"
|
#include "td/telegram/ReplyMarkup.h"
|
||||||
#include "td/telegram/Td.h"
|
#include "td/telegram/Td.h"
|
||||||
|
#include "td/telegram/UserManager.h"
|
||||||
|
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
@ -89,6 +91,83 @@ class EditInlineMessageQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SetInlineGameScoreQuery final : public Td::ResultHandler {
|
||||||
|
Promise<Unit> promise_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit SetInlineGameScoreQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void send(tl_object_ptr<telegram_api::InputBotInlineMessageID> input_bot_inline_message_id, bool edit_message,
|
||||||
|
tl_object_ptr<telegram_api::InputUser> input_user, int32 score, bool force) {
|
||||||
|
CHECK(input_bot_inline_message_id != nullptr);
|
||||||
|
CHECK(input_user != nullptr);
|
||||||
|
|
||||||
|
int32 flags = 0;
|
||||||
|
if (edit_message) {
|
||||||
|
flags |= telegram_api::messages_setInlineGameScore::EDIT_MESSAGE_MASK;
|
||||||
|
}
|
||||||
|
if (force) {
|
||||||
|
flags |= telegram_api::messages_setInlineGameScore::FORCE_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dc_id = DcId::internal(InlineQueriesManager::get_inline_message_dc_id(input_bot_inline_message_id));
|
||||||
|
send_query(G()->net_query_creator().create(
|
||||||
|
telegram_api::messages_setInlineGameScore(flags, false /*ignored*/, false /*ignored*/,
|
||||||
|
std::move(input_bot_inline_message_id), std::move(input_user), score),
|
||||||
|
{}, dc_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(BufferSlice packet) final {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::messages_setInlineGameScore>(packet);
|
||||||
|
if (result_ptr.is_error()) {
|
||||||
|
return on_error(result_ptr.move_as_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_IF(ERROR, !result_ptr.ok()) << "Receive false in result of setInlineGameScore";
|
||||||
|
|
||||||
|
promise_.set_value(Unit());
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_error(Status status) final {
|
||||||
|
LOG(INFO) << "Receive error for SetInlineGameScoreQuery: " << status;
|
||||||
|
promise_.set_error(std::move(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class GetInlineGameHighScoresQuery final : public Td::ResultHandler {
|
||||||
|
Promise<td_api::object_ptr<td_api::gameHighScores>> promise_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GetInlineGameHighScoresQuery(Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise)
|
||||||
|
: promise_(std::move(promise)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void send(tl_object_ptr<telegram_api::InputBotInlineMessageID> input_bot_inline_message_id,
|
||||||
|
tl_object_ptr<telegram_api::InputUser> input_user) {
|
||||||
|
CHECK(input_bot_inline_message_id != nullptr);
|
||||||
|
CHECK(input_user != nullptr);
|
||||||
|
|
||||||
|
auto dc_id = DcId::internal(InlineQueriesManager::get_inline_message_dc_id(input_bot_inline_message_id));
|
||||||
|
send_query(G()->net_query_creator().create(
|
||||||
|
telegram_api::messages_getInlineGameHighScores(std::move(input_bot_inline_message_id), std::move(input_user)),
|
||||||
|
{}, dc_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(BufferSlice packet) final {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::messages_getInlineGameHighScores>(packet);
|
||||||
|
if (result_ptr.is_error()) {
|
||||||
|
return on_error(result_ptr.move_as_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
promise_.set_value(td_->game_manager_->get_game_high_scores_object(result_ptr.move_as_ok()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_error(Status status) final {
|
||||||
|
promise_.set_error(std::move(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
InlineMessageManager::InlineMessageManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
InlineMessageManager::InlineMessageManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,4 +333,34 @@ void InlineMessageManager::edit_inline_message_reply_markup(const string &inline
|
|||||||
get_input_reply_markup(td_->user_manager_.get(), new_reply_markup));
|
get_input_reply_markup(td_->user_manager_.get(), new_reply_markup));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InlineMessageManager::set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id,
|
||||||
|
int32 score, bool force, Promise<Unit> &&promise) {
|
||||||
|
CHECK(td_->auth_manager_->is_bot());
|
||||||
|
|
||||||
|
auto input_bot_inline_message_id = td_->inline_queries_manager_->get_input_bot_inline_message_id(inline_message_id);
|
||||||
|
if (input_bot_inline_message_id == nullptr) {
|
||||||
|
return promise.set_error(Status::Error(400, "Invalid inline message identifier specified"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TRY_RESULT_PROMISE(promise, input_user, td_->user_manager_->get_input_user(user_id));
|
||||||
|
|
||||||
|
td_->create_handler<SetInlineGameScoreQuery>(std::move(promise))
|
||||||
|
->send(std::move(input_bot_inline_message_id), edit_message, std::move(input_user), score, force);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InlineMessageManager::get_inline_game_high_scores(const string &inline_message_id, UserId user_id,
|
||||||
|
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise) {
|
||||||
|
CHECK(td_->auth_manager_->is_bot());
|
||||||
|
|
||||||
|
auto input_bot_inline_message_id = td_->inline_queries_manager_->get_input_bot_inline_message_id(inline_message_id);
|
||||||
|
if (input_bot_inline_message_id == nullptr) {
|
||||||
|
return promise.set_error(Status::Error(400, "Invalid inline message identifier specified"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TRY_RESULT_PROMISE(promise, input_user, td_->user_manager_->get_input_user(user_id));
|
||||||
|
|
||||||
|
td_->create_handler<GetInlineGameHighScoresQuery>(std::move(promise))
|
||||||
|
->send(std::move(input_bot_inline_message_id), std::move(input_user));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "td/telegram/td_api.h"
|
#include "td/telegram/td_api.h"
|
||||||
|
#include "td/telegram/UserId.h"
|
||||||
|
|
||||||
#include "td/actor/actor.h"
|
#include "td/actor/actor.h"
|
||||||
|
|
||||||
@ -44,6 +45,12 @@ class InlineMessageManager final : public Actor {
|
|||||||
td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
|
td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score,
|
||||||
|
bool force, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void get_inline_game_high_scores(const string &inline_message_id, UserId user_id,
|
||||||
|
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void tear_down() final;
|
void tear_down() final;
|
||||||
|
|
||||||
|
@ -6075,8 +6075,9 @@ void Td::on_request(uint64 id, td_api::setInlineGameScore &request) {
|
|||||||
CHECK_IS_BOT();
|
CHECK_IS_BOT();
|
||||||
CLEAN_INPUT_STRING(request.inline_message_id_);
|
CLEAN_INPUT_STRING(request.inline_message_id_);
|
||||||
CREATE_OK_REQUEST_PROMISE();
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
game_manager_->set_inline_game_score(request.inline_message_id_, request.edit_message_, UserId(request.user_id_),
|
inline_message_manager_->set_inline_game_score(request.inline_message_id_, request.edit_message_,
|
||||||
request.score_, request.force_, std::move(promise));
|
UserId(request.user_id_), request.score_, request.force_,
|
||||||
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::getGameHighScores &request) {
|
void Td::on_request(uint64 id, td_api::getGameHighScores &request) {
|
||||||
@ -6090,7 +6091,8 @@ void Td::on_request(uint64 id, td_api::getInlineGameHighScores &request) {
|
|||||||
CHECK_IS_BOT();
|
CHECK_IS_BOT();
|
||||||
CLEAN_INPUT_STRING(request.inline_message_id_);
|
CLEAN_INPUT_STRING(request.inline_message_id_);
|
||||||
CREATE_REQUEST_PROMISE();
|
CREATE_REQUEST_PROMISE();
|
||||||
game_manager_->get_inline_game_high_scores(request.inline_message_id_, UserId(request.user_id_), std::move(promise));
|
inline_message_manager_->get_inline_game_high_scores(request.inline_message_id_, UserId(request.user_id_),
|
||||||
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::deleteChatReplyMarkup &request) {
|
void Td::on_request(uint64 id, const td_api::deleteChatReplyMarkup &request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user