S
S
Stivux2019-07-21 03:16:58
Python
Stivux, 2019-07-21 03:16:58

How to implement the work of a VK-bot in Python with several users at the same time?

There is a group VK bot written in Python. If during the communication of the bot with one user (for example: a) another user writes to the bot (for example: b), then the bot will think that both messages were written by the first user (a). That is, several users will not be able to communicate with the bot at the same time. How to fix it? What needs to be added to the code, changed in it, to solve the problem?
I tried to write a VK bot in two ways: using longpoll and without it. (The above problem is present in both methods!)
The code itself (very ugly :) ):
Ya.Disk - https://yadi.sk/d/n3IhqYkXwPwPzw

Answer the question

In order to leave comments, you need to log in

5 answer(s)
T
Taus, 2019-07-21
@Taus

You need to store a step/question number (some people call it a conversation context, a state) for each user who started a conversation with the bot. Unfortunately, I did not find such libraries for vk in python in the public domain. Therefore, I will give a general algorithm for solving such a problem. For a specific implementation, you already need to go to a neighboring site .
In the case of a linear chain of questions without the possibility of going back

Начало +-> Вопрос 1 +-> Вопрос 2 +-> Вопрос 3 +-> Конец
            ^   +        ^   +        ^   +
            +---+        +---+        +---+

it is enough just to store the number of the question on which the user stopped.
If the dialogue is supposed to be more complex, branched, and even with returns to previous steps,
Начало +-> Вопрос 1 +-> Вопрос 2 +-> Конец
             +              ^
             +-> Вопрос 3 +-+

then it is worth thinking about the finite automaton . Then it will be necessary to save the state of the state machine where the user stopped.

P
Puma Thailand, 2019-07-21
@opium

What kind of AI bot do you have there,
he doesn’t know how to think
, a message comes from a he sees that from a
comes from b he sees that from b
he doesn’t think anything

L
lightmanLP, 2019-07-21
@lightmanLP

compare from_id and use database

L
l7_7l, 2019-07-22
@l7_7l

Why reinvent the wheel? There are tons of ready-made platforms for creating bots on the Internet.

M
Mychenik, 2019-11-07
@Mychenik

Stivux, were you able to implement this? I faced the same problem and can't solve it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question