From 84f85b3ebc3ac01a55138beddcf4e199bfef6579 Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:08:04 +0800 Subject: [PATCH] =?UTF-8?q?lottery=20=E4=BF=AE=E5=A4=8D=E6=97=A0=E4=BA=BA?= =?UTF-8?q?=E5=8F=82=E4=B8=8E=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lottery/main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lottery/main.py b/lottery/main.py index bbbe749..32de555 100644 --- a/lottery/main.py +++ b/lottery/main.py @@ -33,12 +33,13 @@ async def lottery_end(): secret_generator = secrets.SystemRandom() win_user = [] win_user_num = min(lottery_json["win"], len(all_user)) - while True: - temp = secret_generator.choice(all_user) - if temp not in win_user: - win_user.append(temp) - if len(win_user) >= win_user_num: - break + if all_user: + while True: + temp = secret_generator.choice(all_user) + if temp not in win_user: + win_user.append(temp) + if len(win_user) >= win_user_num: + break win_text = end_text.format( lottery_json["title"], "\n".join(f"@{uid}" for uid in win_user