MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / checkRateLimit

Function checkRateLimit

src/utils/rateLimiter.js:7–31  ·  view source on GitHub ↗
(key, maxAttempts = 5, windowMs = 60000)

Source from the content-addressed store, hash-verified

5const rateLimitStore = new Map();
6
7export async function checkRateLimit(key, maxAttempts = 5, windowMs = 60000) {
8 try {
9 const now = Date.now();
10 const entry = rateLimitStore.get(key);
11
12 if (!entry || now - entry.windowStart > windowMs) {
13 rateLimitStore.set(key, {
14 count: 1,
15 windowStart: now
16 });
17 return true;
18 }
19
20 if (entry.count < maxAttempts) {
21 entry.count++;
22 return true;
23 }
24
25 logger.debug(`Rate limit exceeded for ${key}`);
26 return false;
27 } catch (error) {
28 logger.error('Error checking rate limit:', error);
29 return true;
30 }
31}
32
33export function getRateLimitStatus(key, windowMs = 60000) {
34 const entry = rateLimitStore.get(key);

Callers 5

enforceAbuseProtectionFunction · 0.90
recordUserInteractionFunction · 0.90
executeFunction · 0.90
executeFunction · 0.90
handleLevelingFunction · 0.90

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected