F
F
fokioff2022-03-13 09:36:38
Python
fokioff, 2022-03-13 09:36:38

How to implement a message queue?

When writing a bot, I ran into a problem: I can’t figure out how to implement a message queue. Briefly, after registering the questionnaire, the administrator is sent this very questionnaire and buttons for it "to approve", "reject". In the database, in a separate line, the userid of the user who registered is recorded:

cur.execute(
                f'''UPDATE users SET userid = {message.from_user.id} WHERE username = "admin"'''
)

cur.execute(
                f'''SELECT userid FROM users WHERE username = "admin"''')
userid = cur.fetchone()[0]

When you click approve, the userid gets from the database and the bot sends a message to it:

await bot.send_message(userid, "Ваша анкета одобрена!")


However, if, for example, 1 person registers, his userid will go to the database (assume that the administrator did not process it) and then the second person will register, and accordingly his userid will also go to the database, in which he will replace the previous userid.

It turns out that if the administrator does not have time, then we will no longer be able to send a response to the first user, because his userid will no longer be in the database.

How can this be resolved? I will be very grateful!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2022-03-13
@fokioff

Store in the database all applications in general, immediately enter them. Just add a "considered" boolean and an "approved" boolean (both false by default). When the admin gets to the consideration of applications, he receives applications where "considered" == false, and after consideration it becomes true, and "approved" will either remain false or become true.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question