(userId, guildId, cooldownMs = defaultCooldownMs)
| 516 | } |
| 517 | |
| 518 | export async function checkVerificationCooldown(userId, guildId, cooldownMs = defaultCooldownMs) { |
| 519 | pruneVerificationTrackers(); |
| 520 | |
| 521 | const key = `${guildId}:${userId}`; |
| 522 | const lastVerified = verificationCooldowns.get(key); |
| 523 | |
| 524 | if (lastVerified && Date.now() - lastVerified < cooldownMs) { |
| 525 | const remaining = cooldownMs - (Date.now() - lastVerified); |
| 526 | throw createError( |
| 527 | "User on verification cooldown", |
| 528 | ErrorTypes.RATE_LIMIT, |
| 529 | `Please wait ${Math.ceil(remaining / 1000)} seconds before verifying again.`, |
| 530 | { userId, guildId, cooldownRemaining: remaining } |
| 531 | ); |
| 532 | } |
| 533 | |
| 534 | verificationCooldowns.set(key, Date.now()); |
| 535 | } |
| 536 | |
| 537 | export async function trackVerificationAttempt( |
| 538 | userId, |
no test coverage detected