0
0 комментариев

У нас есть телеграм бот с методами

@asyncio.coroutine
def on_chat_message(msg):
    chat_id = msg['chat']['id']
    command = msg['text']
    full_name = msg['chat']['first_name'] + ' ' + msg['chat']['last_name']
    username = msg['chat']['username']
    print('User:', full_name, '\nNickname:', username, '\nGot command:', command)
    markup = ReplyKeyboardMarkup(keyboard=[
        ['Check once'],
        ['Start autoinformer', 'Stop autoinformer']
    ])
    if command == '/start':
        yield from bot.sendMessage(chat_id, 'Choose option:', reply_markup=markup)
    elif command == 'Check once':
        yield from bot.sendMessage(chat_id, latest_build_number)
    elif command == 'Start autoinformer':
        stop_markup = ReplyKeyboardMarkup(keyboard=[['Stop autoinformer']], resize_keyboard=True)
        yield from bot.sendMessage(chat_id, //TODO, reply_markup=stop_markup)
    elif command == 'Stop autoinformer':
        yield from bot.sendMessage(chat_id, 'Got you.'//TODO, reply_markup=markup)
 
def check_always(chat_id):
    global latest_build_number
    latest_build_number = check_build()
    print(latest_build_number)
    while 1:
        build_new = check_build()
        if latest_build_number == build_new:
            time.sleep(10)
        else:
            latest_build_number = build_new
            bot.sendMessage(chat_id, latest_build_number)

Как мне реализовать возможность принимать новые сообщения методу on_chat_message(msg) и при этом, если получена команда Start autoinformer, начать крутить метод check_always(chat_id) до тех пор, пока не будет получена команда Stop autoinformer?


Добавить комментарий