npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@disckit/antiflood

v1.3.0

Published

Advanced per-user+command+guild rate limiter with burst window, progressive penalty and role whitelist.

Readme


Features

  • Sliding window — tracks hits over a rolling time window, not a fixed interval
  • Progressive penaltyADDITIVE or EXPONENTIAL backoff on repeated abuse
  • Role whitelist — skip checks entirely for specific roles (owners, mods)
  • Per-command rules — different limits for heavy commands like /gamble
  • Guild isolation — separate buckets per guild by default
  • stats() — lifetime counters: hits, blocked, whitelisted, block ratio
  • Master switchdisable() / enable() for maintenance
  • Full TypeScript types included · Zero dependencies · Node.js 18+

Installation

npm install @disckit/antiflood
yarn add @disckit/antiflood
pnpm add @disckit/antiflood

TypeScript / ESM

// ESM
import { AntifloodManager, FLOOD_RESULT, PENALTY_MODE } from '@disckit/antiflood';

// CommonJS
const { AntifloodManager, FLOOD_RESULT, isBlocked } = require('@disckit/antiflood');

Usage

Basic setup

const { AntifloodManager, isBlocked, formatRetryAfter } = require('@disckit/antiflood');

const antiflood = new AntifloodManager({
  globalRule: { windowMs: 5000, maxHits: 3, penaltyMode: 'NONE' },
  whitelistRoleIds: ['OWNER_ROLE_ID'],
});

// In your interactionCreate handler:
const check = antiflood.check({
  userId:        interaction.user.id,
  guildId:       interaction.guildId,
  commandName:   interaction.commandName,
  memberRoleIds: interaction.member.roles.cache.map(r => r.id),
});

if (isBlocked(check)) {
  return interaction.reply({
    content: `⛔ Devagar! Tente novamente em ${formatRetryAfter(check.retryAfterMs)}.`,
    ephemeral: true,
  });
}

Per-command rules

const { AntifloodManager, PENALTY_MODE } = require('@disckit/antiflood');

const antiflood = new AntifloodManager({
  globalRule: { windowMs: 5000, maxHits: 5, penaltyMode: 'NONE' },
});

// Stricter rule for expensive commands
antiflood.setRule('gamble', {
  windowMs:    10_000,
  maxHits:     1,
  penaltyMode: PENALTY_MODE.ADDITIVE,
  penaltyStep: 15_000,  // +15s per excess hit
  maxPenalty:  120_000, // cap at 2 minutes
});

Exponential backoff

antiflood.setRule('api-call', {
  windowMs:    3000,
  maxHits:     2,
  penaltyMode: PENALTY_MODE.EXPONENTIAL, // doubles: 1s → 2s → 4s → 8s...
  penaltyStep: 1000,
  maxPenalty:  30_000,
});

Stats monitoring

const s = antiflood.stats();
// → { hits: 1240, blocked: 37, whitelisted: 5, ratio: 0.03 }

console.log(`${s.blocked} blocked / ${s.hits + s.blocked} total (${(s.ratio * 100).toFixed(1)}%)`);

// Reset counters without clearing flood state
antiflood.resetStats();

Manual reset

antiflood.reset({ userId: 'USER_ID', commandName: 'gamble', guildId: 'GUILD_ID' });
antiflood.resetAll();

API Reference

new AntifloodManager(options?)

| Option | Type | Description | |--------|------|-------------| | globalRule | RuleConfig | Default rule applied to all commands | | whitelistRoleIds | string[] | Role IDs that always bypass all checks | | enabled | boolean | Master switch. Default: true |

RuleConfig

| Field | Type | Default | Description | |-------|------|---------|-------------| | windowMs | number | 5000 | Sliding window size in ms | | maxHits | number | 3 | Allowed hits per window | | penaltyMode | "NONE"\|"ADDITIVE"\|"EXPONENTIAL" | "ADDITIVE" | How penalties grow | | penaltyStep | number | 5000 | Ms added per excess hit | | maxPenalty | number | 60000 | Hard cap on penalty duration |

check(params)CheckResult

| Param | Type | Description | |-------|------|-------------| | userId | string | Required | | guildId | string | Optional. Defaults to "*" (global) | | commandName | string | Optional. Used to look up per-command rule | | memberRoleIds | string[] | Optional. Checked against whitelist |

Returns { result, retryAfterMs, hitsInWindow, penaltyUntil, rule }.

stats(){ hits, blocked, whitelisted, ratio }

Lifetime counters since the manager was created (or last resetStats()).

FLOOD_RESULT

"ALLOWED" · "THROTTLED" · "PENALIZED" · "WHITELISTED"

Helpers

isBlocked(result)boolean — true when THROTTLED or PENALIZED

formatRetryAfter(ms)string — e.g. "2m 30s"

Links