D
D
DuXter2020-12-18 16:59:16
Python
DuXter, 2020-12-18 16:59:16

How to make a win counter in db.bd in a rock paper scissors game and a certain user could press a button?

reviewed everything, found little useful ... It is necessary for the user to write

A game
and the bot started the game, it's already there
the code

@dp.message_handler(lambda message: message.text.lower() == 'игра')
async def process_command_1(message: types.Message):
    
    button1 = InlineKeyboardButton('Камень', callback_data = '1')
    button2 = InlineKeyboardButton('✂️Ножницы', callback_data = '2')
    button3 = InlineKeyboardButton('Бумага', callback_data = '3')
    buttons = InlineKeyboardMarkup().add(button1, button2, button3)
    await bot.send_message(message.chat.id, "Я готов!\nВыбери предмет, чтобы победить меня УАХАХА\n*зловещий смех*", reply_markup= buttons)



@dp.callback_query_handler(lambda c: c.data == '1')
async def process_callback_yes(callback: types.CallbackQuery):
    rand = random.choice(["Камень", "✂️Ножницы", "Бумага"])

    await bot.delete_message(callback.message.chat.id, callback.message.message_id)
    await callback.message.answer("Я выбрал " + rand + "\nА ты выбрал Камень")
    if rand == 'Камень':
        await callback.message.answer("⚔️НИЧЬЯ⚔️")
    elif rand == '✂️Ножницы':
        await callback.message.answer("ПОБЕДА ЗА ТОБОЙ✅")
    else:
        await callback.message.answer("☠️Я ПОБЕДИЛ☠️")

@dp.callback_query_handler(lambda c: c.data == '2')
async def process_callback_yes(callback: types.CallbackQuery):
    rand = random.choice(["Камень", "✂️Ножницы", "Бумага"])

    await bot.delete_message(callback.message.chat.id, callback.message.message_id)
    await callback.message.answer("Я выбрал " + rand + "\nА ты выбрал ✂️Ножницы")
    if rand == 'Камень':
        await callback.message.answer("☠️Я ПОБЕДИЛ☠️")
    elif rand == '✂️Ножницы':
        await callback.message.answer("⚔️НИЧЬЯ⚔️")
    else:
        await callback.message.answer("ПОБЕДА ЗА ТОБОЙ✅")

@dp.callback_query_handler(lambda c: c.data == '2')
async def process_callback_yes(callback: types.CallbackQuery):
    rand = random.choice(["Камень", "✂️Ножницы", "Бумага"])

    await bot.delete_message(callback.message.chat.id, callback.message.message_id)
    await callback.message.answer("Я выбрал " + rand + "\nА ты выбрал ✂️Ножницы")
    if rand == 'Камень':
        await callback.message.answer("☠️Я ПОБЕДИЛ☠️")
    elif rand == '✂️Ножницы':
        await callback.message.answer("⚔️НИЧЬЯ⚔️")
    else:
        await callback.message.answer("ПОБЕДА ЗА ТОБОЙ✅")

@dp.callback_query_handler(lambda c: c.data == '2')
async def process_callback_yes(callback: types.CallbackQuery):
    rand = random.choice(["Камень", "✂️Ножницы", "Бумага"])

    await bot.delete_message(callback.message.chat.id, callback.message.message_id)
    await callback.message.answer("Я выбрал " + rand + "\nА ты выбрал ✂️Ножницы")
    if rand == 'Камень':
        await callback.message.answer("☠️Я ПОБЕДИЛ☠️")
    elif rand == '✂️Ножницы':
        await callback.message.answer("⚔️НИЧЬЯ⚔️")
    else:
        await callback.message.answer("ПОБЕДА ЗА ТОБОЙ✅")

@dp.callback_query_handler(lambda c: c.data == '3')
async def process_callback_yes(callback: types.CallbackQuery):
    rand = random.choice(["Камень", "✂️Ножницы", "Бумага"])

    await bot.delete_message(callback.message.chat.id, callback.message.message_id)
    await callback.message.answer("Я выбрал " + rand + "\nА ты выбрал Бумага")
    if rand == 'Камень':
        await callback.message.answer("ПОБЕДА ЗА ТОБОЙ✅")
    elif rand == '✂️Ножницы':
        await callback.message.answer("☠️Я ПОБЕДИЛ☠️")
    else:
        await callback.message.answer("⚔️НИЧЬЯ⚔️")


And now it is necessary that a certain user who started the game can press the button, that is, make a check .. but how .. this is another question ...
And so that the score is recorded in the SQLite database and, upon request, the top displays the top 10 or then 5 here no longer matter

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question