From afda0680ecdde812772a5e25a28a5f2c1b30b087 Mon Sep 17 00:00:00 2001 From: passthem Date: Fri, 24 Oct 2025 01:59:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=A1=B0=E5=87=8F=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- konabot/plugins/fortune/random_text_record.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/konabot/plugins/fortune/random_text_record.py b/konabot/plugins/fortune/random_text_record.py index 7739c20..ee3b385 100644 --- a/konabot/plugins/fortune/random_text_record.py +++ b/konabot/plugins/fortune/random_text_record.py @@ -1,10 +1,17 @@ import base64 +import math import random import time from pathlib import Path +def dec_func(t: float) -> float: + if t < 86400: + return 0.5 * (1 + math.tanh(t / 43200 - 1)) + return math.exp(-0.00000043 * (t - 86400)) + + class RandomTextManager: _cache: list[tuple[float, str]] @@ -55,7 +62,8 @@ class RandomTextManager: for ts, cn in self._cache: contents.append(cn) - weights.append((abs(now - ts) + 0.01) ** (-1)) + # weights.append((abs(now - ts) + 0.01) ** (-1)) + weights.append(dec_func(now - ts)) return random.choices(contents, weights)[0]