@stambha/gates
v1.3.2
Published
Built-in Stambha gates — cooldown, permissions, NSFW, RunIn, and entitlements
Downloads
272
Maintainers
Readme
@stambha/gates
Built-in gates — cooldown, permissions, NSFW, and channel-type checks for the Stambha command pipeline. No discord.js required.
Part of the @stambha monorepo · GitHub · Gates guide
Install
npm install @stambha/gates @stambha/coreRequires Node.js 20+.
Quick start
Declarative options
import { Command, ok, type CommandContext, type Registry } from "@stambha/core";
import "@stambha/gates"; // registers cooldown / runIn / nsfw / permissions options
export class PingCommand extends Command {
constructor(registry: Registry<Command>) {
super(registry, {
name: "ping",
cooldown: 5,
runIn: "guild",
});
}
async execute(ctx: CommandContext) {
await ctx.reply("Pong!");
return ok(undefined);
}
}Attach inline gates
import { Command, ok, type CommandContext, type Registry } from "@stambha/core";
import { cooldownGate, guildOnlyGate } from "@stambha/gates";
export class PingCommand extends Command {
constructor(registry: Registry<Command>) {
super(registry, {
name: "ping",
description: "Pong!",
kinds: ["slash"],
gates: [
guildOnlyGate(),
cooldownGate({ limit: 1, delay: 3_000, scope: "user" }),
],
});
}
async execute(ctx: CommandContext) {
await ctx.reply("Pong!");
return ok(undefined);
}
}Auto-reply when a gate denies
import { attachGateDeniedReply } from "@stambha/gates";
attachGateDeniedReply(client);Available gates
| Gate | Description |
|------|-------------|
| cooldownGate | Per-user/channel/global cooldown |
| permissionsGate | Member permission flags |
| userPermissionsGate / clientPermissionsGate | Shorthand permission checks |
| nsfwGate | NSFW channel requirement |
| guildOnlyGate / dmOnlyGate | Channel type restriction |
| runInGate / RunIn | Run in specific channel types |
| entitlementGate | Active SKU entitlement (monetization) |
Combine custom gates in @stambha/core with gateAnd() / gateOr().
Key exports
| Export | Purpose |
|--------|---------|
| cooldownGate, MemoryCooldownStore, CooldownStore, setDefaultCooldownStore | Rate-limit commands (inject Redis via @stambha/cooldown-redis) |
| permissionsGate, Permission | Discord permission math |
| nsfwGate | Age-restricted channels |
| guildOnlyGate, dmOnlyGate, runInGate | Where commands may run |
| entitlementGate, hasEntitlement | SKU entitlement checks |
| resolveCommandGates | Build gates from Command options |
| attachGateDeniedReply | User-facing denial messages |
Related packages
| Package | Role |
|---------|------|
| @stambha/core | Gate, defineGate, pipeline |
| @stambha/loader | Load custom gates from src/gates/ |
Development
pnpm --filter @stambha/gates build
pnpm --filter @stambha/gates test