From 0691b1e971e2daafdef448a0bb7a09bd81984874 Mon Sep 17 00:00:00 2001 From: rahiel Date: Thu, 20 Aug 2015 19:58:57 +0200 Subject: [PATCH] confirm processed message in examples --- examples/echobot.py | 21 ++++++++++----------- examples/roboed.py | 10 ++++------ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/examples/echobot.py b/examples/echobot.py index da4712361..10c98083c 100644 --- a/examples/echobot.py +++ b/examples/echobot.py @@ -49,20 +49,19 @@ def main(): def echo(bot): global LAST_UPDATE_ID - # Request updates from last updated_id + # Request updates after the last updated_id for update in bot.getUpdates(offset=LAST_UPDATE_ID): - if LAST_UPDATE_ID < update.update_id: - # chat_id is required to reply any message - chat_id = update.message.chat_id - message = update.message.text.encode('utf-8') + # chat_id is required to reply any message + chat_id = update.message.chat_id + message = update.message.text.encode('utf-8') - if (message): - # Reply the message - bot.sendMessage(chat_id=chat_id, - text=message) + if (message): + # Reply the message + bot.sendMessage(chat_id=chat_id, + text=message) - # Updates global offset to get the new updates - LAST_UPDATE_ID = update.update_id + # Updates global offset to get the new updates + LAST_UPDATE_ID = update.update_id + 1 if __name__ == '__main__': diff --git a/examples/roboed.py b/examples/roboed.py index 75dc096b2..7cf070988 100644 --- a/examples/roboed.py +++ b/examples/roboed.py @@ -38,12 +38,10 @@ def main(): chat_id = update.message.chat.id update_id = update.update_id - if LAST_UPDATE_ID < update_id: # If newer than the initial - # LAST_UPDATE_ID - if text: - roboed = ed(text) # Ask something to Robô Ed - bot.sendMessage(chat_id=chat_id, text=roboed) - LAST_UPDATE_ID = update_id + if text: + roboed = ed(text) # Ask something to Robô Ed + bot.sendMessage(chat_id=chat_id, text=roboed) + LAST_UPDATE_ID = update_id + 1 def ed(text):