xxtelebot  1.4.1.0
A simple Telegram Bot implementation in C++
register_callback.h
1 #ifndef TGBOT_REGISTER_CB_H
2 #define TGBOT_REGISTER_CB_H
3 
4 #include "methods/api.h"
5 #include "types.h"
6 #include "utils/str_match.h"
7 
8 #include <functional>
9 #include <tuple>
10 #include <vector>
11 
12 namespace tgbot {
13 
17  template<typename __TypeUpdate>
18  using __T_UpdateCallback =
19  std::function<void(const __TypeUpdate, const methods::Api &)>;
20 
25  public:
26  using MessageCallback = __T_UpdateCallback<types::Message>;
27  using InlineQueryCallback = __T_UpdateCallback<types::InlineQuery>;
28  using ChosenInlineResultCallback =
30  using CallbackQueryCallback = __T_UpdateCallback<types::CallbackQuery>;
31  using ShippingQueryCallback = __T_UpdateCallback<types::ShippingQuery>;
32  using PreCheckoutQueryCallback = __T_UpdateCallback<types::PreCheckoutQuery>;
33 
34  protected:
35  using __Command_Tuple =
36  std::tuple<const char *,
37  std::function<bool(const std::string &, const char *)>,
38  const char,
39  std::function<void(const types::Message, const methods::Api &,
40  const std::vector<std::string>)> >;
41 
42  RegisterCallback() = default;
43 
44  MessageCallback messageCallback;
45  InlineQueryCallback inlineQueryCallback;
46  ChosenInlineResultCallback chosenInlineResultCallback;
47  CallbackQueryCallback callbackQueryCallback;
48  ShippingQueryCallback shippingQueryCallback;
49  PreCheckoutQueryCallback preCheckoutQueryCallback;
50  MessageCallback editedMessageCallback;
51  MessageCallback editedChannelPostCallback;
52  MessageCallback channelPostCallback;
53  std::vector<__Command_Tuple> commandCallback;
54 
55  public:
65  inline void callback(bool (&matcherCallback)(const std::string &,
66  const char *),
67  void (&callback)(const types::Message,
68  const methods::Api &,
69  const std::vector<std::string>),
70  const char *matchWord, const char sep = ' ') {
71  commandCallback.emplace_back(matchWord, matcherCallback, sep, callback);
72  }
73 
84  inline void callback(bool (&matcherCallback)(const std::string &, const char *),
85  std::function<void(const types::Message, const methods::Api &,
86  const std::vector<std::string>)>
87  callback,
88  const char *matchWord, const char sep = ' ') {
89  commandCallback.emplace_back(matchWord, matcherCallback, sep, callback);
90  }
91 
101  inline void callback(std::function<bool(const std::string &,
102  const char *)> matcherCallback,
103  void (&callback)(const types::Message,
104  const methods::Api &,
105  const std::vector<std::string>),
106  const char *matchWord, const char sep = ' ') {
107 
108  commandCallback.emplace_back(matchWord, matcherCallback, sep, callback);
109  }
110 
121  inline void callback(std::function<bool(const std::string &,
122  const char *)> matcherCallback,
123  std::function<void(const types::Message, const methods::Api &,
124  const std::vector<std::string>)> callback,
125  const char *matchWord, const char sep = ' ') {
126 
127  commandCallback.emplace_back(matchWord, matcherCallback, sep, callback);
128  }
129 
134  inline void callback(void (&callback)(const types::Message,
135  const methods::Api &)) {
136  messageCallback = callback;
137  }
138 
143  inline void callback(MessageCallback callback) { messageCallback = callback; }
144 
149  inline void callback(void (&callback)(const types::InlineQuery,
150  const methods::Api &)) {
151  inlineQueryCallback = callback;
152  }
153 
158  inline void callback(InlineQueryCallback callback) {
159  inlineQueryCallback = callback;
160  }
161 
166  inline void callback(void (&callback)(const types::ChosenInlineResult,
167  const methods::Api &)) {
168  chosenInlineResultCallback = callback;
169  }
170 
171  inline void callback(ChosenInlineResultCallback callback) {
176  chosenInlineResultCallback = callback;
177  }
178 
183  inline void callback(void (&callback)(const types::CallbackQuery,
184  const methods::Api &)) {
185  callbackQueryCallback = callback;
186  }
187 
192  inline void callback(CallbackQueryCallback callback) {
193  callbackQueryCallback = callback;
194  }
195 
200  inline void callback(void (&callback)(const types::ShippingQuery,
201  const methods::Api &)) {
202  shippingQueryCallback = callback;
203  }
204 
209  inline void callback(ShippingQueryCallback callback) {
210  shippingQueryCallback = callback;
211  }
212 
217  inline void callback(void (&callback)(const types::PreCheckoutQuery,
218  const methods::Api &)) {
219  preCheckoutQueryCallback = callback;
220  }
221 
226  inline void callback(PreCheckoutQueryCallback callback) {
227  preCheckoutQueryCallback = callback;
228  }
229 
236  inline void callback(void (&callback)(const types::Message,
237  const methods::Api &),
238  const types::UpdateType &which) {
239  if (which == types::UpdateType::EDITED_MESSAGE)
240  editedMessageCallback = callback;
241  else if (which == types::UpdateType::EDITED_CHANNEL_POST)
242  editedChannelPostCallback = callback;
243  else if (which == types::UpdateType::CHANNEL_POST)
244  channelPostCallback = callback;
245  }
246 
253  inline void callback(MessageCallback callback,
254  const types::UpdateType updateType) {
255  switch (updateType) {
256  case types::UpdateType::EDITED_MESSAGE:
257  editedMessageCallback = callback;
258  break;
259  case types::UpdateType::EDITED_CHANNEL_POST:
260  editedChannelPostCallback = callback;
261  break;
262  case types::UpdateType::CHANNEL_POST:
263  channelPostCallback = callback;
264  break;
265  default:
266  break;
267  }
268  }
269  };
270 
271 } // namespace tgbot
272 
273 #endif
void callback(CallbackQueryCallback callback)
Callback query update callback.
Definition: register_callback.h:192
void callback(void(&callback)(const types::Message, const methods::Api &), const types::UpdateType &which)
Multiple-options update callback.
Definition: register_callback.h:236
void callback(ShippingQueryCallback callback)
Shipping query update callback.
Definition: register_callback.h:209
registers and holds callbacks for each type of update
Definition: register_callback.h:24
void callback(MessageCallback callback)
Message update callback.
Definition: register_callback.h:143
Definition: types.h:395
void callback(bool(&matcherCallback)(const std::string &, const char *), std::function< void(const types::Message, const methods::Api &, const std::vector< std::string >)> callback, const char *matchWord, const char sep= ' ')
std::function wrapper callback overload, associate with command (ability to use lambdas ...
Definition: register_callback.h:84
void callback(bool(&matcherCallback)(const std::string &, const char *), void(&callback)(const types::Message, const methods::Api &, const std::vector< std::string >), const char *matchWord, const char sep= ' ')
C-style function pointer callback overload, associate with command.
Definition: register_callback.h:65
void callback(ChosenInlineResultCallback callback)
Definition: register_callback.h:171
void callback(void(&callback)(const types::Message, const methods::Api &))
Message update callback.
Definition: register_callback.h:134
Main tgbot namespace.
Definition: bot.h:13
void callback(MessageCallback callback, const types::UpdateType updateType)
Multiple-options update callback.
Definition: register_callback.h:253
void callback(PreCheckoutQueryCallback callback)
Pre checkout query update callback.
Definition: register_callback.h:226
void callback(void(&callback)(const types::ShippingQuery, const methods::Api &))
Shipping query update callback.
Definition: register_callback.h:200
Definition: types.h:430
void callback(std::function< bool(const std::string &, const char *)> matcherCallback, void(&callback)(const types::Message, const methods::Api &, const std::vector< std::string >), const char *matchWord, const char sep= ' ')
C-style function pointer callback overload, associate with command.
Definition: register_callback.h:101
Definition: types.h:345
void callback(void(&callback)(const types::ChosenInlineResult, const methods::Api &))
Chosen inline result update callback.
Definition: register_callback.h:166
void callback(void(&callback)(const types::CallbackQuery, const methods::Api &))
Callback query update callback.
Definition: register_callback.h:183
void callback(void(&callback)(const types::InlineQuery, const methods::Api &))
Inline query update callback.
Definition: register_callback.h:149
Definition: types.h:417
void callback(std::function< bool(const std::string &, const char *)> matcherCallback, std::function< void(const types::Message, const methods::Api &, const std::vector< std::string >)> callback, const char *matchWord, const char sep= ' ')
std::function wrapper callback overload, associate with command (ability to use lambdas ...
Definition: register_callback.h:121
Definition: types.h:440
std::function< void(const __TypeUpdate, const methods::Api &)> __T_UpdateCallback
refer to RegisterCallback::callback() function (overloads)
Definition: register_callback.h:19
void callback(InlineQueryCallback callback)
Inline query update callback.
Definition: register_callback.h:158
Contains Telegram bot API methods.
Definition: api.h:19
Definition: types.h:406
void callback(void(&callback)(const types::PreCheckoutQuery, const methods::Api &))
Pre checkout query update callback.
Definition: register_callback.h:217