Hello! Can you please tell me how to limit spam commands from bot users? Just for each team creates its own thread, which executes the command method and closes. Spam does not interfere, if there are less than 10 users. But if it is more, delays begin.

PS In my dreams, do this: if the user started spamming, a stub about spam is sent to him.

  • M, downstream to every team is cool. But in general, you apparently have such a logic - the team has come, they have gotten into a bit of it, have they created a thread and for fulfillment? - KoVadim
  • @KoVadim yes. Exactly .. Otherwise the library does not allow, and indeed it is convenient - Flerry
  • By the way, @KoVadim is done, because if you don’t create a stream, there will be a queue :)
  • There are several exits. The simplest thing is to make the map into which users are logged and when they make requests. This will allow you to make restrictions on the number of requests. Method two is to speed up the execution of queries. The third way is to rewrite in a normal language. What do the threads do? what exactly do they do? - KoVadim
  • @KoVadim for the map thanks :) I'll take a note for now. As for acceleration, there is nowhere faster. And as for a normal language, it is a shame here. What is wrong in Java? - Flerry

2 answers 2

Create a queue - if 10 threads are running (or as many as can be served without loss of performance), then put the user on hold (in a queue) and notify him about it. As soon as the stream is released, take the request from the queue and start a new stream.
This is easier and more accurate than tracking the last request, storing these states and so on.

    The issue is resolved: The most profitable option is to create a Map and put each request from a new user + date into it. Next time, if he writes the same, we compare the date in the Map with the date of the current message, and if the difference between them is less than n-seconds, we send the stub to the user.