Skip to content

Ratelimit Middleware

Pre-release
Pre-release
Compare
Choose a tag to compare
@ShindouMihou ShindouMihou released this 05 Mar 06:27
· 301 commits to master since this release
e7f9e70

Ratelimit Middleware Patch

This patch introduces a new standard and also fixes a known issue with the previous rate-limiter implementation which doesn't take middleware into consideration, this newer standard makes rate-limiters as a middleware to fully utilize the middleware functionality and also to allow developers to create their own rate-limiters with the data available.

The cooldown field is kept for several reasons:

  • It is still used by the middleware itself.
  • It can be used by developers to introduce their own middleware for rate-limiting.

How to add the default rate-limiter as a middleware?

Adding the rate-limiter middleware is simple and easy, all you need is to have a Nexus instance or even just create a new instance of the NexusRatelimiter yourself but we recommend using the Nexus instance's own rate limiter middleware which can be added to your command by adding this as a middleware:

NexusCommonInterceptors.NEXUS_RATELIMITER

You can add it to a command by adding this field in your command class:

List<String> middlewares = List.of(NexusCommonInterceptors.NEXUS_RATELIMITER, ...);

You can also add it as a global middleware by using the Nexus instance's addGlobalMiddleware function:

Nexus nexus = ...
nexus.addGlobalMiddleware(NexusCommonInterceptors.NEXUS_RATELIMITER);