(key, commandName, interaction, command, remainingMs)
| 78 | } |
| 79 | |
| 80 | function recordBlockedAttempt(key, commandName, interaction, command, remainingMs) { |
| 81 | const now = Date.now(); |
| 82 | const anomalyPolicy = getAnomalyPolicy(command); |
| 83 | const current = blockedAttemptStore.get(key); |
| 84 | |
| 85 | if (!current || now - current.windowStart > anomalyPolicy.windowMs) { |
| 86 | blockedAttemptStore.set(key, { |
| 87 | count: 1, |
| 88 | windowStart: now, |
| 89 | thresholdReachedAt: null |
| 90 | }); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | current.count += 1; |
| 95 | |
| 96 | if (current.count >= anomalyPolicy.threshold && !current.thresholdReachedAt) { |
| 97 | current.thresholdReachedAt = now; |
| 98 | logger.warn('Abuse anomaly detected for risky command cooldown breaches', { |
| 99 | event: 'interaction.command.abuse_anomaly', |
| 100 | guildId: interaction.guildId, |
| 101 | userId: interaction.user?.id, |
| 102 | command: normalizeCommandName(commandName), |
| 103 | anomalyCount: current.count, |
| 104 | anomalyWindowMs: anomalyPolicy.windowMs, |
| 105 | cooldownRemainingMs: remainingMs |
| 106 | }); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | export function formatCooldownDuration(ms) { |
| 111 | if (!Number.isFinite(ms) || ms <= 0) { |
no test coverage detected