MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / isRateLimited

Function isRateLimited

web/src/discord/rate-limiter.ts:12–33  ·  view source on GitHub ↗
(userId: string)

Source from the content-addressed store, hash-verified

10const rateLimits = new Map<string, RateLimit>()
11
12export function isRateLimited(userId: string): boolean {
13 const now = Date.now()
14 const userRateLimit = rateLimits.get(userId)
15
16 // Clean up expired rate limits
17 if (userRateLimit && userRateLimit.resetAt < now) {
18 rateLimits.delete(userId)
19 }
20
21 if (!rateLimits.has(userId)) {
22 rateLimits.set(userId, {
23 count: 1,
24 resetAt: now + RATE_LIMIT_WINDOW,
25 })
26 return false
27 }
28
29 const limit = rateLimits.get(userId)!
30 limit.count++
31
32 return limit.count > MAX_REQUESTS
33}

Callers 1

startDiscordBotFunction · 0.90

Calls 3

deleteMethod · 0.80
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected