Rate Limit Provider
Interface to declare rate limits, ran once at startup.
Usage: Register your instance as a service with @BService or any annotation that enables your class for dependency injection.
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 = BucketFactory.spikeProtected(
/* Capacity */5,
/* Duration */Duration.ofMinutes(1),
/* Spike capacity */2,
/* Spike duration */Duration.ofSeconds(5)
);
manager.rateLimit(SKIP_RATE_LIMIT_NAME, bucketFactory);
}
}
Content copied to clipboard