@GameKi11er

Как сделать так чтобы переменная сохранялась для каждого пользователя telebot?

Имеется глобальная переменная lines2 и когда сразу несколько пользователей используют команду, то переменная меняется, как сделать чтобы она присваивалась к каждому пользователю, смотрел про классы, но не могу понять как, новичок тут, помогите(
def button_message(message):
    global lines2
    a = list(range(1, 105))
    x = random.choice(a)
    c = random.choice(a)
    j = random.choice(a)
    while c == j:
        j = random.choice(a)
    while x == c or x == j:
        x = random.choice(a)
    f = open('phrases.txt', encoding="utf8")
    lines = f.readlines()
    fp = open('phrases rus.txt', encoding="utf8")
    lines1 = fp.readlines()

    l1 = lines1[x]           # correct answer
    l2 = lines1[c]
    l3 = lines1[j]
    l4 = (l1, l2, l3)
    r = random.choice(l4)
    r1 = random.choice(l4)
    r2 = random.choice(l4)
    while r == r1 or r == r2 or r1 == r2:
        r = random.choice(l4)
        r2 = random.choice(l4)

    buttons = types.ReplyKeyboardMarkup(resize_keyboard=True)
    button1 = types.InlineKeyboardButton(r, callback_data=r)
    buttons.add(button1)
    button2 = types.InlineKeyboardButton(r1, callback_data=r1)
    buttons.add(button2)
    button3 = types.InlineKeyboardButton(r2, callback_data=r2)
    buttons.add(button3)
    bot.send_message(message.chat.id, lines[x], reply_markup=buttons)
    lines2 = lines1[x]

@bot.message_handler(func=lambda message: message.text.lower() in lines2)
def correct(message):
    button_message1(message)

@bot.message_handler(func=lambda message: True)
def incorrect(message):
    if message.text != lines2:
        markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
        item1 = types.KeyboardButton("Да")
        markup.add(item1)
        item2 = types.KeyboardButton("Нет")
        markup.add(item2)
        item3 = types.KeyboardButton("Топ-10")
        markup.add(item3)
        bot.send_message(message.chat.id, 'Неверно, попробуете еще раз?', reply_markup=markup)
  • Вопрос задан
  • 51 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы