From 91454b35cca4f18bcff98453eb0474722979a5e7 Mon Sep 17 00:00:00 2001 From: Conatum Date: Tue, 19 Oct 2021 21:26:03 +0300 Subject: [PATCH] fix (studybadges): Detect level duplicates. Detect and complain about duplications in provided studybadge levels. --- bot/modules/study/studybadge_cmd.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bot/modules/study/studybadge_cmd.py b/bot/modules/study/studybadge_cmd.py index b43dae4b..99e28fec 100644 --- a/bot/modules/study/studybadge_cmd.py +++ b/bot/modules/study/studybadge_cmd.py @@ -265,6 +265,13 @@ async def cmd_studybadges(ctx, flags): # Parse the input lines = ctx.args.splitlines() results = [await parse_level(ctx, line) for line in lines] + # Check for duplicates + _set = set() + duplicate = next((time for time, _ in results if time in _set or _set.add(time)), None) + if duplicate: + return await ctx.error_reply( + "Level `{}` provided twice!".format(strfdur(duplicate, short=False)) + ) current_times = set(row.required_time for row in guild_roles) # Split up the provided lines into levels to add and levels to edit