1
Fork 0
mirror of https://github.com/Steffo99/greed.git synced 2024-10-16 13:47:27 +00:00

Configure long polling

This commit is contained in:
Steffo 2017-12-14 10:25:05 +01:00
parent edefc57147
commit aec1391b17
No known key found for this signature in database
GPG key ID: C27544372FBB445D
2 changed files with 5 additions and 6 deletions

View file

@ -3,7 +3,7 @@
# Config file parameters # Config file parameters
[Config] [Config]
; Config file version. DO NOT EDIT THIS! ; Config file version. DO NOT EDIT THIS!
version = 2 version = 3
; Set this to no when you are done editing the file ; Set this to no when you are done editing the file
is_template = yes is_template = yes
@ -13,4 +13,6 @@ is_template = yes
token = 123456789:YOUR_TOKEN_GOES_HERE_______________ token = 123456789:YOUR_TOKEN_GOES_HERE_______________
; Time in seconds before a conversation with no new messages expires ; Time in seconds before a conversation with no new messages expires
; A lower value reduces memory usage but can be inconvenient for the users ; A lower value reduces memory usage but can be inconvenient for the users
conversation_timeout = 7200 conversation_timeout = 7200
; Time to wait before sending another getUpdates request
long_polling_timeout = 30

View file

@ -33,7 +33,7 @@ def main():
while True: while True:
# Get a new batch of 100 updates and mark the last 100 parsed as read # Get a new batch of 100 updates and mark the last 100 parsed as read
# TODO: handle possible errors # TODO: handle possible errors
updates = bot.get_updates(offset=next_update) updates = bot.get_updates(offset=next_update, timeout=int(config["Telegram"]["long_polling_timeout"]))
# Parse all the updates # Parse all the updates
for update in updates: for update in updates:
# If the update is a message... # If the update is a message...
@ -85,9 +85,6 @@ def main():
if len(updates): if len(updates):
# Mark them as read by increasing the update_offset # Mark them as read by increasing the update_offset
next_update = updates[-1].update_id + 1 next_update = updates[-1].update_id + 1
# Temporarily prevent rate limits
# TODO: (remove this later)
time.sleep(5)
# Run the main function only in the main process # Run the main function only in the main process