/
utils.py
82 lines (69 loc) · 2.63 KB
/
utils.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
import config
import telebot
from views import register
from views import get_points
from telebot import types
entered = False
gaming = False
answered = True
user = 0
iteration = 0
bot = telebot.TeleBot(config.token)
def parsing(message):
global entered
global answered
global gaming
global user
global iteration
if not gaming:
if message.text == "/signup" and not entered:
user = register(message.chat.id, message.date) # message.from_user.username
entered = True
bot.send_message(message.chat.id, "Вы залогинены!")
# что-то там с юзернеймом
elif message.text == "/game" and entered:
gaming = True
answered = True
iteration = 0
elif message.text == "/exit" and entered:
user.save()
entered = False
gaming = False
bot.send_message(message.chat.id,
str(user.username) + ", Вы завершили игру c " + str(user.score) + " очками!")
if gaming and iteration < 4:
points = get_points()
if answered:
bot.send_message(message.chat.id, points[iteration].question,
reply_markup=generate_markup(points, iteration))
answered = False
else:
if message.text == points[iteration].r_answ:
bot.send_message(message.chat.id,
"Правильно!" + " Вы получаете " + str(points[iteration].score) + " очков",
reply_markup=next_markup())
user.score += points[iteration].score
else:
bot.send_message(message.chat.id, "Неравильно:(", reply_markup=next_markup())
answered = True
iteration += 1
elif gaming and iteration > 3:
user.save()
entered = False
gaming = False
bot.send_message(message.chat.id,
message.from_user.username + ", Вы завершили игру c " + str(user.score) + " очками!")
def generate_markup(answers, i):
markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
list_items = []
for item in answers[i].wr_answ.split(','):
list_items.append(item)
print(item)
list_items.append(answers[i].r_answ)
for item in list_items:
markup.add(item)
return markup
def next_markup():
markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
markup.add("Далее >>")
return markup