D
D
Dream2021-06-28 13:02:39
Bots
Dream, 2021-06-28 13:02:39

Is there any way to make achievements in the bot easier?

I have the issuance of achievements through the database. If I want to add some achievement, then I write a code at the end of the command that checks: if the achievement "Name" is not in the list of achievements for the user (from the database), then we add and send a message that the achievement has been received, if the achievement already exists - there is no message about it, but it's just empty code that removes optimization. And so for each command or messages (let's say achievement for 10, 100, 1000 messages through on_message, i.e., with each new user message, checks whether he has an achievement or not. So, how can we put all the achievements in one file and issue them as certain actions? Or do it somehow easier? (I know that the question may not be clear)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-06-28
@dreameddd

Think about what is required to describe an achievement:
1. The event that causes it to be received (message, reaction, joining a channel, etc.)
2. Program code that receives data about the event and updates the state of the achievement (for example, increments the counter messages). It can tell if the user got some kind of achievement along with this event.
3. The base where information about the achievements of a particular user is stored. In the simplest case, it will look like "user-indicator-counter", i.e. for example "vasya - messages - 254". The code from paragraph 2 will read this indicator, increase it, and if the desired value is reached, then issue a message. For simplicity, you can store messages in a separate table of the "indicator-threshold-message" type, then if the indicator is equal to one or another threshold, the bot should send the corresponding message.
It turns out that the bot or its component should contain a set of small procedures that establish a connection between the event and the indicator. And after updating the indicator, the general logic can be used to check if the next threshold has been reached.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question