From 1d514f80c696e0b7170cbf168a86862747fab540 Mon Sep 17 00:00:00 2001 From: Brad Duncan <51077147+XargsUK@users.noreply.github.com> Date: Thu, 8 Jul 2021 07:37:37 +0100 Subject: [PATCH 1/3] adding no response exit condition Previously, if no response was provided by the user, the function would continuously loop. I've modified the timeout to 20 seconds. When there's no response, +! to timeoutcount variable. When there's been 3 timeouts, break. --- recyclingplant/recyclingplant.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recyclingplant/recyclingplant.py b/recyclingplant/recyclingplant.py index cc7bf57..2bf0753 100644 --- a/recyclingplant/recyclingplant.py +++ b/recyclingplant/recyclingplant.py @@ -32,6 +32,7 @@ class RecyclingPlant(Cog): x = 0 reward = 0 + timeoutcount = 0 await ctx.send( "{0} has signed up for a shift at the Recycling Plant! Type ``exit`` to terminate it early.".format( ctx.author.display_name @@ -53,7 +54,7 @@ class RecyclingPlant(Cog): return m.author == ctx.author and m.channel == ctx.channel try: - answer = await self.bot.wait_for("message", timeout=120, check=check) + answer = await self.bot.wait_for("message", timeout=20, check=check) except asyncio.TimeoutError: answer = None From 15ecf72c6483fe8e61467f042dc890b66bc2bf61 Mon Sep 17 00:00:00 2001 From: Brad Duncan <51077147+XargsUK@users.noreply.github.com> Date: Thu, 8 Jul 2021 07:37:45 +0100 Subject: [PATCH 2/3] Update recyclingplant.py --- recyclingplant/recyclingplant.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/recyclingplant/recyclingplant.py b/recyclingplant/recyclingplant.py index 2bf0753..74ff6e8 100644 --- a/recyclingplant/recyclingplant.py +++ b/recyclingplant/recyclingplant.py @@ -59,9 +59,14 @@ class RecyclingPlant(Cog): answer = None if answer is None: - await ctx.send( - "``{}`` fell down the conveyor belt to be sorted again!".format(used["object"]) - ) + if timeoutcount == 2: + await ctx.send( + "{} slacked off at work, so they were sacked with no pay.".format(ctx.author.display_name) + ) + break + else: + await ctx.send("{} is slacking, and if they carry on not working, they'll be fired.".format(ctx.author.display_name)) + timeoutcount += 1 elif answer.content.lower().strip() == used["action"]: await ctx.send( "Congratulations! You put ``{}`` down the correct chute! (**+50**)".format( From 3eb499bf0e0dd3dbc72553fcef39d992d359592b Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 8 Jul 2021 08:30:21 -0400 Subject: [PATCH 3/3] black reformat --- recyclingplant/recyclingplant.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/recyclingplant/recyclingplant.py b/recyclingplant/recyclingplant.py index 74ff6e8..3751648 100644 --- a/recyclingplant/recyclingplant.py +++ b/recyclingplant/recyclingplant.py @@ -61,11 +61,17 @@ class RecyclingPlant(Cog): if answer is None: if timeoutcount == 2: await ctx.send( - "{} slacked off at work, so they were sacked with no pay.".format(ctx.author.display_name) + "{} slacked off at work, so they were sacked with no pay.".format( + ctx.author.display_name ) + ) break else: - await ctx.send("{} is slacking, and if they carry on not working, they'll be fired.".format(ctx.author.display_name)) + await ctx.send( + "{} is slacking, and if they carry on not working, they'll be fired.".format( + ctx.author.display_name + ) + ) timeoutcount += 1 elif answer.content.lower().strip() == used["action"]: await ctx.send(