Add "giveaway_country_count_max" option.

This commit is contained in:
levlam 2023-10-13 14:06:05 +03:00
parent e24f68a4ff
commit a6f0260cf2
5 changed files with 12 additions and 2 deletions

View File

@ -2303,7 +2303,7 @@ messageExtendedMediaUnsupported caption:formattedText = MessageExtendedMedia;
//@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
//@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. If empty, then all users can participate in the giveaway. There can be up to getOption("giveaway_country_count_max") chosen countries
premiumGiveawayParameters boosted_chat_id:int53 additional_chat_ids:vector<int53> winners_selection_date:int32 only_new_subscribers:Bool country_codes:vector<string> = PremiumGiveawayParameters;

View File

@ -1922,6 +1922,10 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
get_json_value_int(std::move(key_value->value_), key));
continue;
}
if (key == "giveaway_countries_max") {
G()->set_option_integer("giveaway_country_count_max", get_json_value_int(std::move(key_value->value_), key));
continue;
}
new_values.push_back(std::move(key_value));
}

View File

@ -102,7 +102,7 @@ class ConfigManager final : public NetQueryCallback {
private:
struct AppConfig {
static constexpr int32 CURRENT_VERSION = 15;
static constexpr int32 CURRENT_VERSION = 16;
int32 version_ = 0;
int32 hash_ = 0;
telegram_api::object_ptr<telegram_api::JSONValue> config_;

View File

@ -56,6 +56,9 @@ Result<GiveawayParameters> GiveawayParameters::get_giveaway_parameters(
return Status::Error(400, "Invalid country code specified");
}
}
if (parameters->country_codes_.size() > td->option_manager_->get_option_integer("giveaway_country_count_max")) {
return Status::Error(400, "Too many countries specified");
}
return GiveawayParameters(boosted_channel_id, std::move(additional_channel_ids), parameters->only_new_subscribers_,
parameters->winners_selection_date_, vector<string>(parameters->country_codes_));
}

View File

@ -131,6 +131,9 @@ OptionManager::OptionManager(Td *td)
if (!have_option("giveaway_additional_chat_count_max")) {
set_option_integer("giveaway_additional_chat_count_max", G()->is_test_dc() ? 3 : 10);
}
if (!have_option("giveaway_country_count_max")) {
set_option_integer("giveaway_country_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");