mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-04 10:11:31 +01:00
update timerbot example with pass_job_queue
This commit is contained in:
parent
bb165b6acf
commit
e7f4a07b7a
1 changed files with 2 additions and 6 deletions
|
@ -25,7 +25,6 @@ logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
||||||
level=logging.DEBUG)
|
level=logging.DEBUG)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
job_queue = None
|
|
||||||
timers = dict()
|
timers = dict()
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ def start(bot, update):
|
||||||
bot.sendMessage(update.message.chat_id, text='Hi! Use /set <seconds> to ' 'set a timer')
|
bot.sendMessage(update.message.chat_id, text='Hi! Use /set <seconds> to ' 'set a timer')
|
||||||
|
|
||||||
|
|
||||||
def set(bot, update, args):
|
def set(bot, update, args, job_queue):
|
||||||
"""Adds a job to the queue"""
|
"""Adds a job to the queue"""
|
||||||
chat_id = update.message.chat_id
|
chat_id = update.message.chat_id
|
||||||
try:
|
try:
|
||||||
|
@ -77,10 +76,7 @@ def error(bot, update, error):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global job_queue
|
|
||||||
|
|
||||||
updater = Updater("TOKEN")
|
updater = Updater("TOKEN")
|
||||||
job_queue = updater.job_queue
|
|
||||||
|
|
||||||
# Get the dispatcher to register handlers
|
# Get the dispatcher to register handlers
|
||||||
dp = updater.dispatcher
|
dp = updater.dispatcher
|
||||||
|
@ -88,7 +84,7 @@ def main():
|
||||||
# on different commands - answer in Telegram
|
# on different commands - answer in Telegram
|
||||||
dp.add_handler(CommandHandler("start", start))
|
dp.add_handler(CommandHandler("start", start))
|
||||||
dp.add_handler(CommandHandler("help", start))
|
dp.add_handler(CommandHandler("help", start))
|
||||||
dp.add_handler(CommandHandler("set", set, pass_args=True))
|
dp.add_handler(CommandHandler("set", set, pass_args=True, pass_job_queue=True))
|
||||||
dp.add_handler(CommandHandler("unset", unset))
|
dp.add_handler(CommandHandler("unset", unset))
|
||||||
|
|
||||||
# log all errors
|
# log all errors
|
||||||
|
|
Loading…
Reference in a new issue