Improve timer_bot.py example (#1440)

Fixes #1439
This commit is contained in:
René Filip 2019-08-23 21:09:46 +02:00 committed by Noam Meltzer
parent 179cf14bd8
commit 3afb0ae6c3

View file

@ -55,9 +55,12 @@ def set_timer(update, context):
update.message.reply_text('Sorry we can not go back to future!')
return
# Add job to queue
job = context.job_queue.run_once(alarm, due, context=chat_id)
context.chat_data['job'] = job
# Add job to queue and stop current one if there is a timer already
if 'job' in context.chat_data:
old_job = context.chat_data['job']
old_job.schedule_removal()
new_job = context.job_queue.run_once(alarm, due, context=chat_id)
context.chat_data['job'] = new_job
update.message.reply_text('Timer successfully set!')