-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknb.py
92 lines (92 loc) · 3.38 KB
/
knb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import random, telebot
from telebot import types
from time import sleep
bot = telebot.TeleBot("")#Токен
@bot.message_handler(commands=["start"])
def start(message):
markup = types.InlineKeyboardMarkup(row_width=3)
item = types.InlineKeyboardButton("✊", callback_data="stone")
item2 = types.InlineKeyboardButton("✌️", callback_data="scissors")
item3 = types.InlineKeyboardButton("✋", callback_data="paper")
markup.add(item, item2, item3)
bot.send_message(message.chat.id, f"Привет, {message.from_user.first_name}!\nВыбери:\nКамень✊\nНожницы✌️\nБумагу✋", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def button(call):
if call.message:
if call.data == "stone":
list = ["stone", "scissors", "paper"]
r = random.choice(list)
bot.send_message(call.message.chat.id, "Твой ход")
sleep(1)
bot.send_message(call.message.chat.id, "✊")
if r == "stone":
bot.send_message(call.message.chat.id,"Ход бота")
sleep(1)
bot.send_message(call.message.chat.id,"✊")
sleep(1)
bot.send_message(call.message.chat.id,"Ничья!")
if r == "scissors":
bot.send_message(call.message.chat.id,"Ход бота")
sleep(1)
bot.send_message(call.message.chat.id,"✌️")
sleep(1)
bot.send_message(call.message.chat.id,"Ты выиграл!")
if r == "paper":
bot.send_message(call.message.chat.id,"Ход бота")
sleep(1)
bot.send_message(call.message.chat.id,"✋")
sleep(1)
bot.send_message(call.message.chat.id,"Ты проиграл!")
if call.data == "scissors":
list2 = ["stone", "scissors", "paper"]
r2 = random.choice(list2)
bot.send_message(call.message.chat.id, "Твой ход")
sleep(1)
bot.send_message(call.message.chat.id, "✌️")
if r2 == "scissors":
bot.send_message(call.message.chat.id,"Ход бота")
sleep(1)
bot.send_message(call.message.chat.id,"✌️")
sleep(1)
bot.send_message(call.message.chat.id,"Ничья!")
if r2 == "paper":
bot.send_message(call.message.chat.id,"Ход бота")
sleep(1)
bot.send_message(call.message.chat.id,"✋")
sleep(1)
bot.send_message(call.message.chat.id,"Ты выиграл!")
if r2 == "stone":
bot.send_message(call.message.chat.id,"Ход бота")
sleep(1)
bot.send_message(call.message.chat.id,"✊")
sleep(1)
bot.send_message(call.message.chat.id,"Ты проиграл!")
if call.data == "paper":
list3 = ["stone", "scissors", "paper"]
r3 = random.choice(list3)
bot.send_message(call.message.chat.id, "Твой ход")
sleep(1)
bot.send_message(call.message.chat.id, "✋")
if r3 == "paper":
bot.send_message(call.message.chat.id,"Ход бота")
sleep(1)
bot.send_message(call.message.chat.id,"✋")
sleep(1)
bot.send_message(call.message.chat.id,"Ничья!")
if r3 == "stone":
bot.send_message(call.message.chat.id,"Ход бота")
sleep(1)
bot.send_message(call.message.chat.id,"✊")
sleep(1)
bot.send_message(call.message.chat.id,"Ты выиграл!")
if r3 == "scissors":
bot.send_message(call.message.chat.id,"Ход бота")
sleep(1)
bot.send_message(call.message.chat.id,"✌️")
sleep(1)
bot.send_message(call.message.chat.id,"Ты проиграл!")
while True:
try:
bot.polling(none_stop=True)
except Exception as e:
print(e)