Skip to content

Commit

Permalink
Feat: Add check to ensure at least one participant submits WPM before…
Browse files Browse the repository at this point in the history
… advancing
  • Loading branch information
LifeAdventurer committed Oct 7, 2024
1 parent de190fd commit 1b67ff1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cogs/typing_contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
JOIN_SUCCESS,
MEMBER_NOT_IN_CONTEST,
MEMBER_NOT_IN_GUILD,
MUST_SUBMIT_WPM,
NO_ACTIVE_CONTEST,
NO_PARTICIPANTS,
NOT_CONTEST_CREATOR,
Expand Down Expand Up @@ -51,6 +52,7 @@ class TypingContestBot(commands.Cog):
participants: The set of participants in the contest.
banned_participants: The set of banned participants.
round: The current round number.
last_next_used: Indicates whether the `!next` command was used in the last round.
wpm_results: WPM results for each participant.
top_three_participants: The top three participant based on average WPM.
ranking_emojis: Emojis used to represent rankings.
Expand All @@ -73,6 +75,7 @@ def __init__(self, bot: commands.Bot, debug: bool) -> None:
self.participants: set[discord.Member] = set()
self.banned_participants: set[discord.Member] = set()
self.round: int = 0
self.last_next_used: bool = False
self.wpm_results: dict[discord.Member, list[str]] = {}
self.top_three_participants: list[tuple[discord.Member, float]] = []
self.ranking_emojis: list[str] = RANKING_EMOJIS
Expand Down Expand Up @@ -371,6 +374,7 @@ async def end(self, ctx) -> None:
self.participants.clear()
self.banned_participants.clear()
self.round = 0
self.last_next_used = False
self.wpm_results = {}
self.top_three_participants = []
self.update_contest_held()
Expand Down Expand Up @@ -490,6 +494,10 @@ async def next(self, ctx) -> None:
await ctx.reply(NOT_CONTEST_CREATOR)
return

if self.last_next_used:
await ctx.reply(MUST_SUBMIT_WPM)
return

for participant in self.participants:
if len(self.wpm_results[participant]) != self.round:
self.wpm_results[participant].append("-")
Expand All @@ -504,6 +512,7 @@ async def next(self, ctx) -> None:
f"{self.participant_role.mention} Get ready! Round {self.round} is starting!"
)

self.last_next_used = True
self.update_activity_time()

@commands.command(name="wpm")
Expand Down Expand Up @@ -539,6 +548,7 @@ async def wpm(self, ctx, wpm: str) -> None:
self.wpm_results[ctx.author][-1] = wpm
await ctx.message.add_reaction(CHECKMARK_EMOJI)

self.last_next_used = False
self.update_activity_time()

@commands.command(name="result")
Expand Down
1 change: 1 addition & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
ALL_SUBMITTED_SUCCESS = (
"All participants have submitted their WPM for this round."
)
MUST_SUBMIT_WPM = "At least one participant must submit a WPM before advancing to the next round."

# Ranking and Emojis
RANKING_EMOJIS = [":first_place:", ":second_place:", ":third_place:"]
Expand Down

0 comments on commit 1b67ff1

Please sign in to comment.