lottery 修复开奖人数少于预定人数的问题

This commit is contained in:
xtaodada 2022-09-09 19:08:53 +08:00
parent e93d1cf6b8
commit 0b3485a90e
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -32,10 +32,13 @@ async def lottery_end():
all_user = lottery_bot.get_subs()[:lottery_json["num"]]
secret_generator = secrets.SystemRandom()
win_user = []
for _ in range(min(lottery_json["win"], len(all_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
win_text = end_text.format(
lottery_json["title"],
"\n".join(f"<a href=\"tg://user?id={uid}\">@{uid}</a>" for uid in win_user