Any way to prevent the user from making many touches to a button or command? #363
juankstylez
started this conversation in
General
Replies: 2 comments 4 replies
-
class CheckSpamMiddleware
{
public function __invoke(Nutgram $bot, $next)
{
// Get the last request time
$lastRequest = $bot->getUserData($bot->userId());
// If the last request was within the last 5 seconds
if ($lastRequest && time() - $lastRequest < 5) {
// Return an error
return $bot->sendMessage('Too many requests. Please try again later.');
// Or simply return to end script execution;
return;
}
// Set the last request time
$bot->setUserData($bot->userId(), time());
$next($bot);
}
} $bot = new Nutgram('token');
$bot->middleware(CheckSpamMiddleware::class);
// ...
$bot->run(); |
Beta Was this translation helpful? Give feedback.
0 replies
-
The middleware works, but the problem is that if the user continues pressing the button or command many more times, the middleware keeps responding to the 1000 clicks that the user made to the button or command. Is there any way to stop the user? So that the bot cannot receive their requests for a certain time and thus avoid filling the Telegram server with too many requests? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If I make 1000 clicks or touches to a button or command the bot will respond 1000 times.
Any way to limit this so that the user, for example, can only do it every 5 seconds?
Beta Was this translation helpful? Give feedback.
All reactions