import asyncio
from random import randint
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters, CallbackQueryHandler, ContextTypes
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
choices = ["камень", "ножницы", "бумага"]
scissors = InlineKeyboardButton("Ножницы", callback_data="Ножницы")
rock = InlineKeyboardButton("Камень", callback_data="Камень")
paper = InlineKeyboardButton("Бумага", callback_data="Бумага")
rockboard = InlineKeyboardMarkup([
[scissors, rock],
[paper]
])
TOKEN = ''
async def start_cmd(update: Update, context: ContextTypes.DEFAULT_TYPE):
print(update.effective_user.first_name)
print("Получена команда /game")
await update.message.reply_text(f'Привет, 🎮\nДавай сыграем в Камень, Ножницы, Бумага! Выбери свой вариант ниже ⬇️"', reply_markup=rockboard)
async def handle_choice(update: Update, context: ContextTypes.DEFAULT_TYPE):
bot_choice = randint.choice(["Камень", "Ножницы", "Бумага"])
result = determine_winner(update.message.text, bot_choice)
await update.message.reply_text(f"Вы выбрали: {update.message.text} Бот выбрал: {bot_choice} Результат: {result}")
def determine_winner(user, bot):
if user == bot:
return "Ничья!"
elif (user == "камень" and bot == "ножницы") or \
(user == "ножницы" and bot == "бумага") or \
(user == "бумага" and bot == "камень"):
return "Ты выиграл!"
else:
return "Я выиграл!"
def main():
application = Application.builder().token(TOKEN).build()
application.add_handler(CommandHandler("game", start_cmd))
print("Бот запущен!")
application.run_polling()
if __name__ == '__main__':
main()
主页
/
user-693761