@@ -83,6 +83,21 @@ class Core : public Http {
8383 _poll_offset++;
8484 }
8585
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+
86101 // id последнего отправленного сообщения от бота
87102 uint32_t lastBotMessage () {
88103 return _last_bot;
@@ -262,8 +277,11 @@ class Core : public Http {
262277 uint8_t _poll_limit = 3 ;
263278 bool _poll_wait = 0 ;
264279 bool _query_answ = 0 ;
280+ bool _query_auto = true ;
265281 bool _state = true ;
266282 bool _online = true ;
283+ bool _incr_auto = true ;
284+ bool _exit_f = false ;
267285 int32_t _poll_offset = 0 ;
268286 uint32_t _last_bot = 0 ;
269287 uint32_t _last_send = 0 ;
@@ -311,33 +329,40 @@ class Core : public Http {
311329#endif
312330 return ;
313331 }
332+ _exit_f = false ;
314333 uint8_t len = result.length ();
315- if (len) _poll_offset = result[0 ][tg_apih::update_id].toInt32 ();
316334
317335 for (uint8_t i = 0 ; i < len; i++) {
318336 FB_ESP_YIELD ();
319- _poll_offset++;
320337 gson::Entry upd = result[i][1 ];
321338 if (!upd) continue ;
322339
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+
323344 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 ;
326347
327348 if (_cbUpdate) _cbUpdate (update);
328349 FB_ESP_YIELD ();
329350
330351 if (typeHash == tg_apih::callback_query && !_query_answ) {
331352 _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+ }
335358 }
336359
337360 if (_reboot == Fetcher::Reboot::Triggered) {
338361 _reboot = Fetcher::Reboot::WaitUpdate;
339362 return ;
340363 }
364+
365+ if (_exit_f) break ;
341366 }
342367 }
343368};
0 commit comments