1 //
2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 #pragma once
8 
9 #include "td/telegram/td_api.h"
10 #include "td/telegram/telegram_api.h"
11 #include "td/telegram/UserId.h"
12 
13 #include "td/actor/PromiseFuture.h"
14 
15 #include "td/utils/common.h"
16 #include "td/utils/tl_helpers.h"
17 
18 namespace td {
19 
20 class Td;
21 
22 class BotCommand {
23   string command_;
24   string description_;
25 
26   friend bool operator==(const BotCommand &lhs, const BotCommand &rhs);
27 
28  public:
29   BotCommand() = default;
BotCommand(string command,string description)30   BotCommand(string command, string description) : command_(std::move(command)), description_(std::move(description)) {
31   }
32   explicit BotCommand(telegram_api::object_ptr<telegram_api::botCommand> &&bot_command);
33 
34   td_api::object_ptr<td_api::botCommand> get_bot_command_object() const;
35 
36   telegram_api::object_ptr<telegram_api::botCommand> get_input_bot_command() const;
37 
38   template <class StorerT>
store(StorerT & storer)39   void store(StorerT &storer) const {
40     td::store(command_, storer);
41     td::store(description_, storer);
42   }
43 
44   template <class ParserT>
parse(ParserT & parser)45   void parse(ParserT &parser) {
46     td::parse(command_, parser);
47     td::parse(description_, parser);
48   }
49 };
50 
51 bool operator==(const BotCommand &lhs, const BotCommand &rhs);
52 
53 inline bool operator!=(const BotCommand &lhs, const BotCommand &rhs) {
54   return !(lhs == rhs);
55 }
56 
57 class BotCommands {
58   UserId bot_user_id_;
59   vector<BotCommand> commands_;
60 
61   friend bool operator==(const BotCommands &lhs, const BotCommands &rhs);
62 
63  public:
64   BotCommands() = default;
65   BotCommands(UserId bot_user_id, vector<telegram_api::object_ptr<telegram_api::botCommand>> &&bot_commands);
66 
67   td_api::object_ptr<td_api::botCommands> get_bot_commands_object(Td *td) const;
68 
get_bot_user_id()69   UserId get_bot_user_id() const {
70     return bot_user_id_;
71   }
72 
73   template <class StorerT>
store(StorerT & storer)74   void store(StorerT &storer) const {
75     td::store(bot_user_id_, storer);
76     td::store(commands_, storer);
77   }
78 
79   template <class ParserT>
parse(ParserT & parser)80   void parse(ParserT &parser) {
81     td::parse(bot_user_id_, parser);
82     td::parse(commands_, parser);
83   }
84 };
85 
86 bool operator==(const BotCommands &lhs, const BotCommands &rhs);
87 
88 inline bool operator!=(const BotCommands &lhs, const BotCommands &rhs) {
89   return !(lhs == rhs);
90 }
91 
92 void set_commands(Td *td, td_api::object_ptr<td_api::BotCommandScope> &&scope_ptr, string &&language_code,
93                   vector<td_api::object_ptr<td_api::botCommand>> &&commands, Promise<Unit> &&promise);
94 
95 void delete_commands(Td *td, td_api::object_ptr<td_api::BotCommandScope> &&scope_ptr, string &&language_code,
96                      Promise<Unit> &&promise);
97 
98 void get_commands(Td *td, td_api::object_ptr<td_api::BotCommandScope> &&scope_ptr, string &&language_code,
99                   Promise<td_api::object_ptr<td_api::botCommands>> &&promise);
100 
101 }  // namespace td
102