Как правильно организовать получение данных от пользователя? Сейчас я получаю данные через глобальную переменную, но если данные будут вводить 2 пользователи одновременно, тогда ничего не будет работать.
Сейчас это выглядит следующим образом:
def create_user():
global user_data, create_user_steps
db.create_user(user_data)
create_user_steps = 0
@dp.message_handler(commands=['start'])
async def process_start_command(message: types.Message):
answer = db.get_user_name(message.from_user.id)
print(message.from_user.first_name, ' - ', message.from_user.id)
if answer == "No much":
await message.answer("Ohh, " + message.from_user.first_name + " first time with us?")
await message.answer('Lets create your profile!\nSend me your first and second name')
global create_user_steps, user_data
user_data.append(message.from_user.id)
create_user_steps = 1
else:
await message.answer('Hi, ' + str(answer.get('name')) + ' .\nYour balance is ' +
str(answer.get('balance')) + '\nlets start learning!\nAvailable teachers: ' +
str(db.available_teachers()), parse_mode='Markdown')
@dp.message_handler(commands=['help'])
async def process_help_command(message: types.Message):
await message.answer("Тут повинен бути текст про бота")
@dp.message_handler(commands=['create'])
async def process_help_command(message: types.Message):
await message.answer("Тут повинен бути текст про бота")
@dp.message_handler()
async def echo_message(message: types.Message):
global create_user_steps, user_data
if create_user_steps == 0:
await message.answer("Sorry, didn't understand")
elif create_user_steps == 1:
user_data.append(message.text)
await message.answer("Ok, nice!\nNow input number with your english level\n"
"1 - Beginner\n"
"2 - Pre-Intermediate\n"
"3 - Intermediate\n"
"4 - Advanced")
create_user_steps = 2
elif create_user_steps == 2:
if message.text == '1':
user_data.append('Beginner')
await bot.send_message(user_data[0], "Nice, now you are at team!")
create_user()
elif message.text == '2':
user_data.append(' Pre-Intermediate')
await bot.send_message(user_data[0], "Nice, now you are at team!")
create_user()
elif message.text == '3':
user_data.append('Intermediate')
await bot.send_message(user_data[0], "Nice, now you are at team!")
create_user()
elif message.text == '4':
user_data.append('Advanced')
await bot.send_message(user_data[0], "Nice, now you are at team!")
create_user()
else:
await message.answer("Its not what im expected, try again")
print(user_data)
user_data = []