update to ignore 5h quota

This commit is contained in:
Shinuwa 2026-09-07 16:16:43 +02:00
parent 4680b3ac44
commit 2aac95128f
2 changed files with 82 additions and 42 deletions

View file

@ -75,17 +75,41 @@ function getCodexLimit(result) {
);
}
function getState(limit) {
const usedPercent = Number(limit?.primary?.usedPercent ?? 0);
function getGlobalLimitWindow(limit) {
const windows = [
limit?.primary,
limit?.secondary,
].filter(Boolean);
const blocked =
limit?.rateLimitReachedType === "rate_limit_reached" ||
usedPercent >= 100;
return (
windows.find(
(window) => Number(window?.windowDurationMins) === 10080
) ??
windows.sort(
(a, b) =>
Number(b?.windowDurationMins ?? 0) -
Number(a?.windowDurationMins ?? 0)
)[0] ??
null
);
}
function getState(limit) {
const globalWindow = getGlobalLimitWindow(limit);
const usedPercent = Number(globalWindow?.usedPercent ?? 0);
const blocked = usedPercent >= 100;
return {
usedPercent,
blocked,
resetsAt: limit?.primary?.resetsAt ?? null,
resetsAt: globalWindow?.resetsAt ?? null,
windowDurationMins:
globalWindow?.windowDurationMins ?? null,
primaryUsedPercent:
limit?.primary?.usedPercent ?? null,
primaryWindowDurationMins:
limit?.primary?.windowDurationMins ?? null,
reachedType: limit?.rateLimitReachedType ?? null,
};
}
@ -149,7 +173,7 @@ async function sendStartupNotification() {
priority: "default",
body:
`👀 Codex Reset Alerts vient de démarrer.\n\n` +
`Surveillance du quota Codex en cours.`,
`Surveillance du quota global Codex en cours.`,
});
}
@ -159,7 +183,7 @@ async function sendResetNotification(oldState, newState) {
tags: "robot,white_check_mark",
priority: "high",
body:
`🚀 Ton quota Codex est de nouveau disponible !\n\n` +
`🚀 Ton quota global Codex est de nouveau disponible !\n\n` +
`Avant : ${oldState.usedPercent}% utilisé\n` +
`Maintenant : ${newState.usedPercent}% utilisé`,
});
@ -226,16 +250,28 @@ async function processLimit(limit, source) {
console.log("");
console.log(`🔎 Source : ${source}`);
console.log(`📊 Utilisé : ${state.usedPercent}%`);
console.log(`📊 Global utilisé : ${state.usedPercent}%`);
if (
state.primaryUsedPercent !== null &&
state.primaryWindowDurationMins !== null &&
state.primaryWindowDurationMins !== state.windowDurationMins
) {
console.log(
`📊 Fenêtre ${state.primaryWindowDurationMins}min ignorée : ` +
`${state.primaryUsedPercent}%`
);
}
console.log(
state.blocked
? "🔴 État : quota épuisé"
: "🟢 État : quota disponible"
? "🔴 État : quota global épuisé"
: "🟢 État : quota global disponible"
);
if (state.resetsAt) {
console.log(
`🕒 Reset annoncé : ${formatDate(state.resetsAt)}`
`🕒 Reset global annoncé : ${formatDate(state.resetsAt)}`
);
const remaining =
@ -244,7 +280,7 @@ async function processLimit(limit, source) {
if (remaining > 0) {
console.log(
`⏳ Temps théorique : ${formatDuration(remaining)}`
`⏳ Temps théorique global : ${formatDuration(remaining)}`
);
}
}
@ -255,7 +291,7 @@ async function processLimit(limit, source) {
if (!state.blocked) {
console.log("");
console.log("✅ Ton quota Codex est encore disponible.");
console.log("✅ Ton quota global Codex est encore disponible.");
console.log("👋 Rien à surveiller, arrêt.");
setTimeout(() => stop(0), 100);
@ -263,8 +299,8 @@ async function processLimit(limit, source) {
}
console.log("");
console.log("🔴 Quota épuisé.");
console.log("👀 Surveillance du reset activée.");
console.log("🔴 Quota global épuisé.");
console.log("👀 Surveillance du reset global activée.");
scheduleTheoreticalResetCheck(state);
@ -273,13 +309,13 @@ async function processLimit(limit, source) {
// La transition importante :
//
// bloqué -> disponible
// quota global épuisé -> quota global disponible
if (
previousState.blocked === true &&
state.blocked === false
) {
console.log("");
console.log("🎉 RESET RÉEL DÉTECTÉ !");
console.log("🎉 RESET GLOBAL RÉEL DÉTECTÉ !");
console.log(
`📉 ${previousState.usedPercent}% → ${state.usedPercent}%`
);
@ -310,7 +346,7 @@ async function processLimit(limit, source) {
if (state.usedPercent < previousState.usedPercent) {
console.log(
`📉 Utilisation en baisse : ` +
`📉 Utilisation globale en baisse : ` +
`${previousState.usedPercent}% → ${state.usedPercent}%`
);
}
@ -320,7 +356,7 @@ async function processLimit(limit, source) {
state.resetsAt &&
previousState.resetsAt !== state.resetsAt
) {
console.log("🔄 Date de reset modifiée par Codex.");
console.log("🔄 Date de reset global modifiée par Codex.");
console.log(
` Avant : ${formatDate(previousState.resetsAt)}`
);