yandex / YandexDriver

YandexDriver is a WebDriver implementation
Other
69 stars 14 forks source link

telegram bot does not respond to inlinebuttons #20

Open rghWoagh opened 1 year ago

rghWoagh commented 1 year ago

the bot responds as expected to /start, but nothing responds to button clicks in the message

`from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.ext import Updater, CommandHandler, CallbackContext, CallbackQueryHandler, Application import telegram.ext import random

current_number = 0 game_active = False

async def start(update: Update, context: CallbackContext) -> None: global current_number global game_active

current_number = random.randint(1, 100)
game_active = True

keyboard = [
    [InlineKeyboardButton("Больше", callback_data='more')],
     [InlineKeyboardButton("Меньше", callback_data='less')]
]

reply_markup = InlineKeyboardMarkup(keyboard)

await update.message.reply_text(f"Загадано число {current_number} Больше или меньше?", reply_markup=reply_markup)

async def check_guess(update: Update, context: CallbackContext) -> None: global current_number global game_active

query = update.callback_query
choice = query.data

new_number = random.randint(1, 100)

if (choice == 'more' and new_number > current_number) or (choice == 'less' and new_number < current_number):
    message = "Вы выиграли! Вот следующее число: {}".format(new_number)
else:
    message = "Вы проиграли. Попробуйте снова. Вот следующее число: {}".format(new_number)

current_number = new_number
game_active = False

await query.edit_message_text(text=message)

def main() -> None: application = Application.builder().token('token').build() application.add_handler(CommandHandler('start', start)) application.run_polling()

if name == 'main': import asyncio asyncio.run(main())`