From ee0b61b8df14943d14d1eaaff2e0624a4fa6740b Mon Sep 17 00:00:00 2001 From: minecraft1024a Date: Wed, 20 Aug 2025 12:56:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(bot):=20=E7=A7=BB=E9=99=A4=E5=8A=A0?= =?UTF-8?q?=E6=9D=83=E9=9A=8F=E6=9C=BA=E5=BD=A9=E8=9B=8B=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E3=80=82=EF=BC=88=E4=B8=8D=E8=A6=81=E5=86=8D=E9=97=B2=E7=9A=84?= =?UTF-8?q?=E6=B2=A1=E4=BA=8B=E5=8A=A8=E9=82=A3beyond=E7=9A=84=E5=BD=A9?= =?UTF-8?q?=E8=9B=8B=E4=BA=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/bot.py b/bot.py index 2ba0be809..c05b0a644 100644 --- a/bot.py +++ b/bot.py @@ -66,48 +66,10 @@ async def request_shutdown() -> bool: logger.error(f"请求关闭程序时发生错误: {e}") return False -def weighted_choice(data: Sequence[str], - weights: Optional[List[float]] = None) -> str: - """ - 从 data 中按权重随机返回一条。 - 若 weights 为 None,则所有元素权重默认为 1。 - """ - if weights is None: - weights = [1.0] * len(data) - - if len(data) != len(weights): - raise ValueError("data 和 weights 长度必须相等") - - # 计算累计权重区间 - total = 0.0 - acc = [] - for w in weights: - total += w - acc.append(total) - - if total <= 0: - raise ValueError("总权重必须大于 0") - - # 随机落点 - r = random.random() * total - # 二分查找落点所在的区间 - left, right = 0, len(acc) - 1 - while left < right: - mid = (left + right) // 2 - if r < acc[mid]: - right = mid - else: - left = mid + 1 - return data[left] - def easter_egg(): # 彩蛋 init() - items = ["多年以后,面对AI行刑队,张三将会回想起他2023年在会议上讨论人工智能的那个下午", - "你知道吗?诺狐的耳朵很软,很好rua", - "喵喵~你的麦麦被猫娘入侵了喵~"] - w = [10, 5, 2] - text = weighted_choice(items, w) + text = "多年以后,面对AI行刑队,张三将会回想起他2023年在会议上讨论人工智能的那个下午" #谁再在这加彩蛋我就用草喂养它 rainbow_colors = [Fore.RED, Fore.YELLOW, Fore.GREEN, Fore.CYAN, Fore.BLUE, Fore.MAGENTA] rainbow_text = "" for i, char in enumerate(text):