@@ -83,6 +83,21 @@ class Core : public Http {
83
83
_poll_offset++;
84
84
}
85
85
86
+ // авто-инкремент update offset (умолч. true). Если отключен - нужно вызывать skipNextMessage() в update
87
+ void autoIncrement (bool incr) {
88
+ _incr_auto = incr;
89
+ }
90
+
91
+ // автоматически отвечать на query, если юзер не ответил в update (умолч. true)
92
+ void autoQuery (bool query) {
93
+ _query_auto = query;
94
+ }
95
+
96
+ // покинуть цикл разбора updates, вызывать в обработичке update
97
+ void exitUpdates () {
98
+ _exit_f = true ;
99
+ }
100
+
86
101
// id последнего отправленного сообщения от бота
87
102
uint32_t lastBotMessage () {
88
103
return _last_bot;
@@ -262,8 +277,11 @@ class Core : public Http {
262
277
uint8_t _poll_limit = 3 ;
263
278
bool _poll_wait = 0 ;
264
279
bool _query_answ = 0 ;
280
+ bool _query_auto = true ;
265
281
bool _state = true ;
266
282
bool _online = true ;
283
+ bool _incr_auto = true ;
284
+ bool _exit_f = false ;
267
285
int32_t _poll_offset = 0 ;
268
286
uint32_t _last_bot = 0 ;
269
287
uint32_t _last_send = 0 ;
@@ -311,33 +329,40 @@ class Core : public Http {
311
329
#endif
312
330
return ;
313
331
}
332
+ _exit_f = false ;
314
333
uint8_t len = result.length ();
315
- if (len) _poll_offset = result[0 ][tg_apih::update_id].toInt32 ();
316
334
317
335
for (uint8_t i = 0 ; i < len; i++) {
318
336
FB_ESP_YIELD ();
319
- _poll_offset++;
320
337
gson::Entry upd = result[i][1 ];
321
338
if (!upd) continue ;
322
339
340
+ uint32_t offset = result[i][tg_apih::update_id].toInt32 ();
341
+ if (!_poll_offset) _poll_offset = offset;
342
+ if (_incr_auto) _poll_offset = offset + 1 ;
343
+
323
344
size_t typeHash = upd.keyHash ();
324
- Update update (upd, typeHash);
325
- if (typeHash == tg_apih::callback_query) _query_answ = 0 ;
345
+ Update update (upd, typeHash, offset );
346
+ if (typeHash == tg_apih::callback_query) _query_answ = false ;
326
347
327
348
if (_cbUpdate) _cbUpdate (update);
328
349
FB_ESP_YIELD ();
329
350
330
351
if (typeHash == tg_apih::callback_query && !_query_answ) {
331
352
_query_answ = true ;
332
- fb::Packet p (tg_cmd::answerCallbackQuery, _token);
333
- p[tg_api::callback_query_id] = update.query ().id ();
334
- sendPacket (p, false );
353
+ if (_query_auto) {
354
+ fb::Packet p (tg_cmd::answerCallbackQuery, _token);
355
+ p[tg_api::callback_query_id] = update.query ().id ();
356
+ sendPacket (p, false );
357
+ }
335
358
}
336
359
337
360
if (_reboot == Fetcher::Reboot::Triggered) {
338
361
_reboot = Fetcher::Reboot::WaitUpdate;
339
362
return ;
340
363
}
364
+
365
+ if (_exit_f) break ;
341
366
}
342
367
}
343
368
};
0 commit comments