From e24f68a4ff1a7d8f4374ff71ad7bc317e8babdfb Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 13 Oct 2023 13:39:14 +0300 Subject: [PATCH] Add "giveaway_additional_chat_count_max" option. --- td/generate/scheme/td_api.tl | 2 +- td/telegram/ConfigManager.cpp | 5 +++++ td/telegram/ConfigManager.h | 2 +- td/telegram/GiveawayParameters.cpp | 4 ++++ td/telegram/OptionManager.cpp | 3 +++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 2392982ff..0f30697a4 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2300,7 +2300,7 @@ messageExtendedMediaUnsupported caption:formattedText = MessageExtendedMedia; //@description Describes parameters of a Telegram Premium giveaway //@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by the winners of the giveaway for duration of the Premium subscription -//@additional_chat_ids Identifiers of other channel chats that must be subscribed by the users to be eligible for the giveaway +//@additional_chat_ids Identifiers of other channel chats that must be subscribed by the users to be eligible for the giveaway. There can be up to getOption("giveaway_additional_chat_count_max") additional chats //@winners_selection_date Point in time (Unix timestamp) when the giveaway is expected to be performed; must be from 1 minute to 365 days in the future in scheduled giveaways //@only_new_subscribers True, if only new subscribers of the chats will be eligible for the giveaway //@country_codes The list of two-letter ISO 3166-1 alpha-2 codes of countries, only users from which will be eligible for the giveaway diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 3027f944b..19bce5a98 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -1917,6 +1917,11 @@ void ConfigManager::process_app_config(tl_object_ptr &c get_json_value_int(std::move(key_value->value_), key)); continue; } + if (key == "giveaway_add_peers_max") { + G()->set_option_integer("giveaway_additional_chat_count_max", + get_json_value_int(std::move(key_value->value_), key)); + continue; + } new_values.push_back(std::move(key_value)); } diff --git a/td/telegram/ConfigManager.h b/td/telegram/ConfigManager.h index 4848703c8..2598e0edb 100644 --- a/td/telegram/ConfigManager.h +++ b/td/telegram/ConfigManager.h @@ -102,7 +102,7 @@ class ConfigManager final : public NetQueryCallback { private: struct AppConfig { - static constexpr int32 CURRENT_VERSION = 14; + static constexpr int32 CURRENT_VERSION = 15; int32 version_ = 0; int32 hash_ = 0; telegram_api::object_ptr config_; diff --git a/td/telegram/GiveawayParameters.cpp b/td/telegram/GiveawayParameters.cpp index 9269e4e78..1bf40833e 100644 --- a/td/telegram/GiveawayParameters.cpp +++ b/td/telegram/GiveawayParameters.cpp @@ -10,6 +10,7 @@ #include "td/telegram/Dependencies.h" #include "td/telegram/DialogId.h" #include "td/telegram/MessagesManager.h" +#include "td/telegram/OptionManager.h" #include "td/telegram/Td.h" #include "td/utils/Random.h" @@ -44,6 +45,9 @@ Result GiveawayParameters::get_giveaway_parameters( TRY_RESULT(channel_id, get_boosted_channel_id(td, DialogId(additional_chat_id))); additional_channel_ids.push_back(channel_id); } + if (additional_channel_ids.size() > td->option_manager_->get_option_integer("giveaway_additional_chat_count_max")) { + return Status::Error(400, "Too many additional chats specified"); + } if (parameters->winners_selection_date_ < G()->unix_time()) { return Status::Error(400, "Giveaway date is in the past"); } diff --git a/td/telegram/OptionManager.cpp b/td/telegram/OptionManager.cpp index d95a475bb..b19a001e8 100644 --- a/td/telegram/OptionManager.cpp +++ b/td/telegram/OptionManager.cpp @@ -128,6 +128,9 @@ OptionManager::OptionManager(Td *td) if (!have_option("story_stealth_mode_cooldown_period")) { set_option_integer("story_stealth_mode_cooldown_period", 3600); } + if (!have_option("giveaway_additional_chat_count_max")) { + set_option_integer("giveaway_additional_chat_count_max", G()->is_test_dc() ? 3 : 10); + } set_option_empty("archive_and_mute_new_chats_from_unknown_users"); set_option_empty("chat_filter_count_max");