
























@@ -4,6 +4,11 @@ import type {
44TelegramGroupConfig,
55TelegramTopicConfig,
66} from "openclaw/plugin-sdk/config-contracts";
7+import {
8+asDateTimestampMs,
9+isFutureDateTimestampMs,
10+resolveExpiresAtMsFromDurationMs,
11+} from "openclaw/plugin-sdk/number-runtime";
712813type TelegramErrorPolicy = "always" | "once" | "silent";
914@@ -18,7 +23,7 @@ const DEFAULT_ERROR_COOLDOWN_MS = 14400000;
18231924function pruneExpiredCooldowns(messageStore: Map<string, number>, now: number) {
2025for (const [message, expiresAt] of messageStore) {
21-if (expiresAt <= now) {
26+if (!isFutureDateTimestampMs(expiresAt, { nowMs: now })) {
2227messageStore.delete(message);
2328}
2429}
@@ -67,9 +72,13 @@ export function shouldSuppressTelegramError(params: {
6772errorMessage?: string;
6873}): boolean {
6974const { scopeKey, cooldownMs, errorMessage } = params;
70-const now = Date.now();
75+const now = asDateTimestampMs(Date.now());
7176const messageKey = errorMessage ?? "";
7277const scopeStore = errorCooldownStore.get(scopeKey);
78+if (now === undefined) {
79+errorCooldownStore.delete(scopeKey);
80+return false;
81+}
73827483if (scopeStore) {
7584pruneExpiredCooldowns(scopeStore, now);
@@ -88,12 +97,17 @@ export function shouldSuppressTelegramError(params: {
8897}
89989099const expiresAt = scopeStore?.get(messageKey);
91-if (typeof expiresAt === "number" && expiresAt > now) {
100+if (isFutureDateTimestampMs(expiresAt, { nowMs: now })) {
92101return true;
93102}
94103104+const nextExpiresAt = resolveExpiresAtMsFromDurationMs(cooldownMs, { nowMs: now });
105+if (nextExpiresAt === undefined) {
106+scopeStore?.delete(messageKey);
107+return false;
108+}
95109const nextScopeStore = scopeStore ?? new Map<string, number>();
96-nextScopeStore.set(messageKey, now + cooldownMs);
110+nextScopeStore.set(messageKey, nextExpiresAt);
97111errorCooldownStore.set(scopeKey, nextScopeStore);
98112return false;
99113}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。