From d5486433e54ea4b91d65abd0da217e8dcac00c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Fri, 15 Jul 2016 01:46:27 +0200 Subject: [PATCH] use job context for timerbot example --- examples/timerbot.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/timerbot.py b/examples/timerbot.py index 8473a543a..a5f0207f8 100644 --- a/examples/timerbot.py +++ b/examples/timerbot.py @@ -34,6 +34,11 @@ def start(bot, update): bot.sendMessage(update.message.chat_id, text='Hi! Use /set to ' 'set a timer') +def alarm(bot, job): + """Function to send the alarm message""" + bot.sendMessage(job.context, text='Beep!') + + def set(bot, update, args, job_queue): """Adds a job to the queue""" chat_id = update.message.chat_id @@ -43,12 +48,8 @@ def set(bot, update, args, job_queue): if due < 0: bot.sendMessage(chat_id, text='Sorry we can not go back to future!') - def alarm(bot, job): - """Inner function to send the alarm message""" - bot.sendMessage(chat_id, text='Beep!') - # Add job to queue - job = Job(alarm, due, repeat=False) + job = Job(alarm, due, repeat=False, context=chat_id) timers[chat_id] = job job_queue.put(job) @@ -68,6 +69,8 @@ def unset(bot, update): job = timers[chat_id] job.schedule_removal() + del timers[chat_id] + bot.sendMessage(chat_id, text='Timer successfully unset!')