Rate Limit Provider
Interface to declare rate limits, ran once at startup.
Usage: Register your instance as a service with @BService.
Example
@Command
public class SlashSkip implements RateLimitProvider {
private static final String SKIP_RATE_LIMIT_NAME = "SlashSkip: skip";
@JDASlashCommand(name = "skip")
@RateLimitReference(SKIP_RATE_LIMIT_NAME)
public void onSlashSkip(GuildSlashEvent event) {
// Handle command
}
@Override
public void declareRateLimit(@NotNull RateLimitManager manager) {
final var bucketFactory = Buckets.spikeProtected(
/* Capacity */5,
/* Duration */Duration.ofMinutes(1),
/* Spike capacity */2,
/* Spike duration */Duration.ofSeconds(5)
);
manager.rateLimit(
SKIP_RATE_LIMIT_NAME,
RateLimiter.createDefault(RateLimitScope.USER, BucketConfigurationSupplier.constant(bucketFactory), /* deleteOnRefill */true)
);
}
}
Content copied to clipboard