(
userId,
guildId,
maxAttempts = defaultMaxAttempts,
windowMs = defaultAttemptWindowMs
)
| 535 | } |
| 536 | |
| 537 | export async function trackVerificationAttempt( |
| 538 | userId, |
| 539 | guildId, |
| 540 | maxAttempts = defaultMaxAttempts, |
| 541 | windowMs = defaultAttemptWindowMs |
| 542 | ) { |
| 543 | pruneVerificationTrackers(); |
| 544 | |
| 545 | const key = `${guildId}:${userId}`; |
| 546 | const attempts = attemptTracker.get(key) || []; |
| 547 | const now = Date.now(); |
| 548 | |
| 549 | const recentAttempts = attempts.filter(timestamp => now - timestamp < windowMs); |
| 550 | |
| 551 | if (recentAttempts.length >= maxAttempts) { |
| 552 | throw createError( |
| 553 | "Too many verification attempts", |
| 554 | ErrorTypes.RATE_LIMIT, |
| 555 | "You've attempted too many times. Please wait a moment.", |
| 556 | { attempts: recentAttempts.length, maxAttempts } |
| 557 | ); |
| 558 | } |
| 559 | |
| 560 | recentAttempts.push(now); |
| 561 | attemptTracker.set(key, recentAttempts); |
| 562 | } |
| 563 | |
| 564 | async function sendAutoVerifyNotification(member, role, guild) { |
| 565 | try { |
no test coverage detected