From 813bb7ea1d827ab9d18614ac93b108f0a214472c Mon Sep 17 00:00:00 2001 From: Xevion Date: Thu, 18 Feb 2021 08:04:27 -0600 Subject: [PATCH] Improve permission_explanation for prematurely closed Periods - Periods closed improperly through the 'close' command were not being shown properly through the 'status' command. - Fixed error in Submission state checking in on_message handling. - Added embed support to 'close' command message responses. --- bot/cogs/contest_commands.py | 4 ++-- bot/cogs/contest_events.py | 2 +- bot/models.py | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/bot/cogs/contest_commands.py b/bot/cogs/contest_commands.py index 2ef56e0..6ddd99b 100644 --- a/bot/cogs/contest_commands.py +++ b/bot/cogs/contest_commands.py @@ -210,13 +210,13 @@ class ContestCommandsCog(commands.Cog, name='Contest'): period: Period = guild.current_period if period is None or not period.active: - await ctx.send('No period is currently active.') + await ctx.send(embed=helpers.error_embed(message='No period is currently active.')) else: overwrite = discord.PermissionOverwrite() overwrite.send_messages = False overwrite.add_reactions = False period.deactivate() - await ctx.send('The current period has been closed.') + await ctx.send(embed=helpers.success_embed(message='The current period has been closed.')) @commands.command() @commands.guild_only() diff --git a/bot/cogs/contest_events.py b/bot/cogs/contest_events.py index 3d4af98..7992976 100644 --- a/bot/cogs/contest_events.py +++ b/bot/cogs/contest_events.py @@ -40,7 +40,7 @@ class ContestEventsCog(commands.Cog): await self.bot.reject(message, f'Each submission must contain exactly one image.') elif guild.current_period is None: await self.bot.reject(message, f'A period has not been started. Submissions should not be allowed at this moment.') - elif guild.current_period != PeriodStates.SUBMISSIONS: + elif guild.current_period.state != PeriodStates.SUBMISSIONS: logger.warning(f'Valid submission was sent outside of Submissions in' f' {channel.id}/{message.id}. Permissions error? Removing.') await message.delete() diff --git a/bot/models.py b/bot/models.py index caf7600..b02c304 100644 --- a/bot/models.py +++ b/bot/models.py @@ -292,11 +292,15 @@ class Period(Base): def permission_explanation(self) -> str: """Returns a quick explanation of the period's current state.""" - if self.state == PeriodStates.READY: return 'No voting or submissions quite yet.' - elif self.state == PeriodStates.SUBMISSIONS: return 'Submissions open; upload now.' - elif self.state == PeriodStates.PAUSED: return 'Submissions closed. No voting *yet*.' - elif self.state == PeriodStates.VOTING: return 'Vote on submissions now.' - elif self.state == PeriodStates.FINISHED: return 'Voting closed. Contest results available.' + if self.active: + if self.state == PeriodStates.READY: return 'No voting or submissions quite yet.' + elif self.state == PeriodStates.SUBMISSIONS: return 'Submissions open; upload now.' + elif self.state == PeriodStates.PAUSED: return 'Submissions closed. No voting *yet*.' + elif self.state == PeriodStates.VOTING: return 'Vote on submissions now.' + else: + if self.state == PeriodStates.FINISHED: return 'Voting closed. Contest results available.' + elif self.state == PeriodStates.VOTING: return 'Voting closed (prematurely). Contest results available.' + else: return 'Closed prematurely. Submissions were remembered, but no votes were cast.' return "Error." def __repr__(self) -> str: