Separate AI credential cooldowns from button limits
This commit is contained in:
@@ -1202,8 +1202,6 @@ function buildAIAutoCommentRateLimitStatus(profileNumber, settings = getAIAutoCo
|
|||||||
}
|
}
|
||||||
const normalizedPostKey = sanitizeAIAutoCommentPostKey(options.postKey);
|
const normalizedPostKey = sanitizeAIAutoCommentPostKey(options.postKey);
|
||||||
|
|
||||||
clearExpiredAIAutoCommentProfileCooldown(normalizedProfileNumber, now);
|
|
||||||
|
|
||||||
const nowIso = now.toISOString();
|
const nowIso = now.toISOString();
|
||||||
const minuteWindowStart = new Date(now.getTime() - (60 * 1000)).toISOString();
|
const minuteWindowStart = new Date(now.getTime() - (60 * 1000)).toISOString();
|
||||||
const hourWindowStart = new Date(now.getTime() - (60 * 60 * 1000)).toISOString();
|
const hourWindowStart = new Date(now.getTime() - (60 * 60 * 1000)).toISOString();
|
||||||
@@ -1215,7 +1213,6 @@ function buildAIAutoCommentRateLimitStatus(profileNumber, settings = getAIAutoCo
|
|||||||
const usedBurst = getAIAutoCommentEventCountSince(normalizedProfileNumber, burstWindowStart, nowIso);
|
const usedBurst = getAIAutoCommentEventCountSince(normalizedProfileNumber, burstWindowStart, nowIso);
|
||||||
const usedDay = getAIAutoCommentEventCountSince(normalizedProfileNumber, dayWindowStart, nowIso);
|
const usedDay = getAIAutoCommentEventCountSince(normalizedProfileNumber, dayWindowStart, nowIso);
|
||||||
const lastEvent = getAIAutoCommentLatestEvent(normalizedProfileNumber);
|
const lastEvent = getAIAutoCommentLatestEvent(normalizedProfileNumber);
|
||||||
const profileState = getAIAutoCommentProfileState(normalizedProfileNumber);
|
|
||||||
const activeHours = getAIAutoCommentActiveHoursState(settings, now);
|
const activeHours = getAIAutoCommentActiveHoursState(settings, now);
|
||||||
const samePostExempt = Boolean(normalizedPostKey && hasAIAutoCommentEventForPost(normalizedProfileNumber, normalizedPostKey));
|
const samePostExempt = Boolean(normalizedPostKey && hasAIAutoCommentEventForPost(normalizedProfileNumber, normalizedPostKey));
|
||||||
|
|
||||||
@@ -1240,10 +1237,6 @@ function buildAIAutoCommentRateLimitStatus(profileNumber, settings = getAIAutoCo
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (profileState && profileState.cooldown_until) {
|
|
||||||
addBlockingCandidate('cooldown', profileState.cooldown_until);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (activeHours.configured && !activeHours.active) {
|
if (activeHours.configured && !activeHours.active) {
|
||||||
addBlockingCandidate('active_hours', activeHours.nextAllowedAt);
|
addBlockingCandidate('active_hours', activeHours.nextAllowedAt);
|
||||||
}
|
}
|
||||||
@@ -1309,8 +1302,8 @@ function buildAIAutoCommentRateLimitStatus(profileNumber, settings = getAIAutoCo
|
|||||||
blocked_reason: blockedReason,
|
blocked_reason: blockedReason,
|
||||||
blocked_until: blockedUntil,
|
blocked_until: blockedUntil,
|
||||||
same_post_exempt: samePostExempt,
|
same_post_exempt: samePostExempt,
|
||||||
cooldown_until: profileState?.cooldown_until || null,
|
cooldown_until: null,
|
||||||
cooldown_reason: profileState?.cooldown_reason || null,
|
cooldown_reason: null,
|
||||||
usage: {
|
usage: {
|
||||||
minute: usedMinute,
|
minute: usedMinute,
|
||||||
hour: usedHour,
|
hour: usedHour,
|
||||||
@@ -2701,6 +2694,7 @@ db.exec(`
|
|||||||
CREATE INDEX IF NOT EXISTS idx_ai_auto_comment_rate_limit_events_profile_post
|
CREATE INDEX IF NOT EXISTS idx_ai_auto_comment_rate_limit_events_profile_post
|
||||||
ON ai_auto_comment_rate_limit_events(profile_number, post_key);
|
ON ai_auto_comment_rate_limit_events(profile_number, post_key);
|
||||||
`);
|
`);
|
||||||
|
db.prepare('DELETE FROM ai_auto_comment_rate_limit_profile_state').run();
|
||||||
ensureColumn('ai_credentials', 'is_active', 'is_active INTEGER DEFAULT 1');
|
ensureColumn('ai_credentials', 'is_active', 'is_active INTEGER DEFAULT 1');
|
||||||
ensureColumn('ai_credentials', 'priority', 'priority INTEGER DEFAULT 0');
|
ensureColumn('ai_credentials', 'priority', 'priority INTEGER DEFAULT 0');
|
||||||
ensureColumn('ai_credentials', 'base_url', 'base_url TEXT');
|
ensureColumn('ai_credentials', 'base_url', 'base_url TEXT');
|
||||||
@@ -8205,14 +8199,6 @@ app.post('/api/ai/generate-comment', async (req, res) => {
|
|||||||
console.error(`Failed with credential ${credential.name}:`, error.message);
|
console.error(`Failed with credential ${credential.name}:`, error.message);
|
||||||
lastError = error;
|
lastError = error;
|
||||||
const errorUpdate = updateCredentialUsageOnError(credential.id, error);
|
const errorUpdate = updateCredentialUsageOnError(credential.id, error);
|
||||||
if (traceSource === AI_AUTO_COMMENT_SOURCE && normalizedProfileNumber && autoCommentRateLimitSettings.enabled) {
|
|
||||||
const cooldownDecision = getAIAutoCommentCooldownDecision(autoCommentRateLimitSettings, error);
|
|
||||||
if (cooldownDecision) {
|
|
||||||
setAIAutoCommentProfileCooldown(normalizedProfileNumber, cooldownDecision);
|
|
||||||
autoCommentRateLimitStatus = buildAIAutoCommentRateLimitStatus(normalizedProfileNumber, autoCommentRateLimitSettings);
|
|
||||||
autoCommentRateLimitGlobalStatus = buildAIAutoCommentRateLimitStatus(normalizedProfileNumber, autoCommentRateLimitSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
credentialTimingDetails.push({
|
credentialTimingDetails.push({
|
||||||
credentialId: credential.id,
|
credentialId: credential.id,
|
||||||
credentialName: credential.name,
|
credentialName: credential.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user