ModernBot icon indicating copy to clipboard operation
ModernBot copied to clipboard

PoC: Task queue & Idle manager

Open vitdolinek opened this issue 1 year ago • 6 comments

Hey, I've implemented a basic queue for bot tasks and idle manager.

Idle manager A simple mechanism that checks whether the user clicked or moved the mouse within 30 seconds. If the user is marked as idle, the task queue will automatically start performing queued tasks, otherwise, it'll wait for the user to be idle.

Task queue Performs tasks that were queued, one at a time. Each task has its' own unique ID to prevent task duplication.

Key features:

  • Command execution interface - Tasks can be enqueued through commands, enabling the execution of functions based on predefined command structures.
  • Task queue management - Tasks are executed sequentially until the queue is exhausted or halted. It can also be stopped and started if, for example, bot detection is detected.

Implementation details:

  • The mechanism resolves commands to corresponding functions using a mapping mechanism.
  • Both synchronous and asynchronous functions can be called. Each command has to have a predefined function to execute.

To be done:

  • At the moment, once the user turns on a feature, a function is performed in intervals, which results in duplications in the task queue, I've sorted it out by assigning an ID to each command, however, it would be better to get rid of checking interval and implement a better solution

I'd like to know your opinion if this is the way you'd like to go.

vitdolinek avatar Mar 05 '24 22:03 vitdolinek

Oh this is a big one ;)

I'm gonna take a bit of time to check it. The idea it's awesome, right now it's quite easy to catch the bot, this kind of updates are very important to fix that.

Gonna come back as soon as I have a bit of free time!

Sau1707 avatar Mar 05 '24 22:03 Sau1707

I'm currently cleaning the code, and slowly moving to this approach, it will be added eventually but it's gonna takes a bit.

We have to see how to make the quee so that if there is an autotrain active for example, it gives priority to it, but at the same time it doesn't jump from town to town immediately like it doesn't right now, because can be seen from the logs and this creates a lot of bugs.

So probably an auto delay has to be implemented if a task with higher priorities it's coming in the near future, like a real player, need to have time to change the polis.

The other problem is that right now you see that the build command comes from a different town, this means that the bot needs to change the town automatically, or all the build and train sistem has to be changed with a different method (using the premium advisor)

I'm moving in this direction

Sau1707 avatar Mar 08 '24 06:03 Sau1707

@Sau1707 The issue with a command coming from a different town - that is easily solvable. In src/constants/events.js, each command has defined its' function in eventsCommand which can be any synchronous or asynchronous function meaning you can put before the API call mechanism to switch towns.

There is also priority constant. It is not implemented yet but I've planned on putting commands to queue with priority and then an algorithm that will take commands out of queue based on their priority.

As long as it acts as queue (priority queue), we don't have to introduce any auto delay.

WYT?

vitdolinek avatar Mar 08 '24 10:03 vitdolinek

Sorry for the late response.

Sound good, thank you! However before implementing all of this, I still have to clean the old code and change some things here and there. Might take a bit of time, sorry about it.

Sau1707 avatar Mar 23 '24 11:03 Sau1707

any plans for auto-dodge?

NotXina avatar May 20 '24 21:05 NotXina

any plans for auto-dodge?

take a look at #37

Sau1707 avatar May 21 '24 21:05 Sau1707