UNPKG

aifordiscord-api

Version:

An advanced npm package for Discord bots providing AI-enhanced random content, memes, jokes, and utilities with comprehensive documentation.

45 lines 1.36 kB
"use strict"; /** * Rate limiting utility */ Object.defineProperty(exports, "__esModule", { value: true }); exports.RateLimiter = void 0; class RateLimiter { constructor(maxRequests = 100, windowMs = 60000) { this.limits = new Map(); this.maxRequests = maxRequests; this.windowMs = windowMs; } isAllowed(identifier) { const now = Date.now(); const limit = this.limits.get(identifier); if (!limit || now > limit.resetTime) { this.limits.set(identifier, { requests: 1, resetTime: now + this.windowMs }); return true; } if (limit.requests >= this.maxRequests) { return false; } limit.requests++; return true; } getRemainingRequests(identifier) { const limit = this.limits.get(identifier); if (!limit || Date.now() > limit.resetTime) { return this.maxRequests; } return Math.max(0, this.maxRequests - limit.requests); } getResetTime(identifier) { const limit = this.limits.get(identifier); if (!limit || Date.now() > limit.resetTime) { return Date.now() + this.windowMs; } return limit.resetTime; } } exports.RateLimiter = RateLimiter; //# sourceMappingURL=ratelimit.js.map