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

Function recordBlockedAttempt

src/utils/abuseProtection.js:80–108  ·  view source on GitHub ↗
(key, commandName, interaction, command, remainingMs)

Source from the content-addressed store, hash-verified

78}
79
80function 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
110export function formatCooldownDuration(ms) {
111 if (!Number.isFinite(ms) || ms <= 0) {

Callers 1

enforceAbuseProtectionFunction · 0.85

Calls 4

getAnomalyPolicyFunction · 0.85
normalizeCommandNameFunction · 0.85
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected