Advertisement
ignacy123

bot python: rock, paper, scizzors

Feb 26th, 2024 (edited)
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. import telebot
  2. from telebot import types
  3. import random
  4.  
  5. bot = telebot.TeleBot("TOKEN")
  6. # greetings = ["cześć", "siema", "cze", "witaj", "serwus", "dzien dobry"]
  7. answer_pool = ["Rock", "Paper", "Scissors"]
  8.  
  9.  
  10. @bot.message_handler(commands=['game'])
  11. def game_reply(message):
  12.  
  13.   # bot.send_message(message.chat.id, "GRAMYYY")
  14.   # bot.send_animation(message.chat.id, "https://i0.wp.com/www.printmag.com/wp-content/uploads/2021/02/4cbe8d_f1ed2800a49649848102c68fc5a66e53mv2.gif?fit=476%2C280&ssl=1")
  15.  
  16.   markup = types.InlineKeyboardMarkup()
  17.   itembtn1 = types.InlineKeyboardButton(text='Rock', callback_data='Rock')
  18.   itembtn2 = types.InlineKeyboardButton(text='Paper', callback_data='Paper')
  19.   itembtn3 = types.InlineKeyboardButton(text='Scissors', callback_data='Scissors')
  20.  
  21.   markup.add(itembtn1, itembtn2, itembtn3)
  22.   bot.send_message(message.chat.id, "Select an answer:", reply_markup=markup)
  23.  
  24. @bot.callback_query_handler(func=lambda call: True)
  25. def answering(call):
  26.   BOT = random.randint(0,2)
  27.   MY = 0
  28.   bot_answer = answer_pool[BOT]
  29.  
  30.   # CO WYBRAŁEM
  31.   if call.data == "Rock":
  32.     bot.send_message(call.message.chat.id, "You choose: Rock")
  33.     MY = 0
  34.   elif call.data == "Paper":
  35.     bot.send_message(call.message.chat.id, "You choose: Paper")
  36.     MY = 1
  37.   else:
  38.     MY = 2
  39.     bot.send_message(call.message.chat.id, "You choose: Scissors")
  40.  
  41.   # CO WYBRAŁ BOT
  42.   bot.send_message(call.message.chat.id, "My move: " + bot_answer)
  43.  
  44.   # KTO WYGRAŁ
  45.   WIN_LOOSE_DRAW = MY - BOT
  46.  
  47.   if WIN_LOOSE_DRAW == 0:
  48.     bot.send_message(call.message.chat.id, "DRAW")
  49.   elif WIN_LOOSE_DRAW == -1 or WIN_LOOSE_DRAW == 2:
  50.     bot.send_message(call.message.chat.id, "YOU LOOSE")
  51.   elif WIN_LOOSE_DRAW == 1 or WIN_LOOSE_DRAW == -2:
  52.     bot.send_message(call.message.chat.id, "YOU WIN")
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. # @bot.message_handler(func=lambda message: True)
  60. # def greeting(message):
  61. #   if(message.text in greetings):
  62. #     bot.reply_to(message, "Hello Human")
  63. #   else:
  64. #     bot.reply_to(message, message.text + " co ty do mnie rozmawiasz")
  65.  
  66. # @bot.message_handler(content_types=['photo'])
  67. # def photo_callback(message):
  68. #   bot.reply_to(message, "Nice pic! Send me more!!!")
  69.  
  70. bot.infinity_polling()
  71.  
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement