Add td_api::deleteCommands.
This commit is contained in:
parent
7e543cf80b
commit
e8b32d9b05
@ -5023,6 +5023,10 @@ checkChangePhoneNumberCode code:string = Ok;
|
||||
//@commands List of the bot's commands
|
||||
setCommands scope:BotCommandScope language_code:string commands:vector<botCommand> = Ok;
|
||||
|
||||
//@description Deletes commands supported by the bot for the given user scope and language; for bots only @scope The scope to which the commands are applied
|
||||
//@language_code A two-letter ISO 639-1 country code or an empty string
|
||||
deleteCommands scope:BotCommandScope language_code:string = Ok;
|
||||
|
||||
//@description Returns the list of commands supported by the bot for the given user scope and language; for bots only @scope The scope to which the commands are applied
|
||||
//@language_code A two-letter ISO 639-1 country code or an empty string
|
||||
getCommands scope:BotCommandScope language_code:string = BotCommands;
|
||||
|
@ -1011,6 +1011,32 @@ class SetBotCommandsQuery : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class ResetBotCommandsQuery : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ResetBotCommandsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(BotCommandScope scope, const string &language_code) {
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::bots_resetBotCommands(scope.get_input_bot_command_scope(td), language_code)));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) override {
|
||||
auto result_ptr = fetch_result<telegram_api::bots_resetBotCommands>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) override {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetBotCommandsQuery : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::botCommands>> promise_;
|
||||
|
||||
@ -6340,6 +6366,21 @@ void ContactsManager::set_commands(td_api::object_ptr<td_api::BotCommandScope> &
|
||||
td_->create_handler<SetBotCommandsQuery>(std::move(promise))->send(scope, language_code, std::move(new_commands));
|
||||
}
|
||||
|
||||
void ContactsManager::delete_commands(td_api::object_ptr<td_api::BotCommandScope> &&scope_ptr, string &&language_code,
|
||||
Promise<Unit> &&promise) {
|
||||
TRY_RESULT_PROMISE(promise, scope, BotCommandScope::get_bot_command_scope(td_, std::move(scope_ptr)));
|
||||
|
||||
if (!language_code.empty() && (language_code.size() != 2 || language_code[0] < 'a' || language_code[0] > 'z' ||
|
||||
language_code[1] < 'a' || language_code[1] > 'z')) {
|
||||
return promise.set_error(Status::Error(400, "Invalid language code specified"));
|
||||
}
|
||||
if (!scope.have_input_bot_command_scope(td_)) {
|
||||
return promise.set_error(Status::Error(400, "Invalid scope specified"));
|
||||
}
|
||||
|
||||
td_->create_handler<ResetBotCommandsQuery>(std::move(promise))->send(scope, language_code);
|
||||
}
|
||||
|
||||
void ContactsManager::get_commands(td_api::object_ptr<td_api::BotCommandScope> &&scope_ptr, string &&language_code,
|
||||
Promise<td_api::object_ptr<td_api::botCommands>> &&promise) {
|
||||
TRY_RESULT_PROMISE(promise, scope, BotCommandScope::get_bot_command_scope(td_, std::move(scope_ptr)));
|
||||
|
@ -332,6 +332,9 @@ class ContactsManager : public Actor {
|
||||
void set_commands(td_api::object_ptr<td_api::BotCommandScope> &&scope_ptr, string &&language_code,
|
||||
vector<td_api::object_ptr<td_api::botCommand>> &&commands, Promise<Unit> &&promise);
|
||||
|
||||
void delete_commands(td_api::object_ptr<td_api::BotCommandScope> &&scope_ptr, string &&language_code,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void get_commands(td_api::object_ptr<td_api::BotCommandScope> &&scope_ptr, string &&language_code,
|
||||
Promise<td_api::object_ptr<td_api::botCommands>> &&promise);
|
||||
|
||||
|
@ -6878,6 +6878,12 @@ void Td::on_request(uint64 id, td_api::setCommands &request) {
|
||||
std::move(request.commands_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::deleteCommands &request) {
|
||||
CHECK_IS_BOT();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
contacts_manager_->delete_commands(std::move(request.scope_), std::move(request.language_code_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getCommands &request) {
|
||||
CHECK_IS_BOT();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
|
@ -920,6 +920,8 @@ class Td final : public NetQueryCallback {
|
||||
|
||||
void on_request(uint64 id, td_api::setCommands &request);
|
||||
|
||||
void on_request(uint64 id, td_api::deleteCommands &request);
|
||||
|
||||
void on_request(uint64 id, td_api::getCommands &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::setLocation &request);
|
||||
|
Loading…
Reference in New Issue
Block a user