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.
This commit is contained in:
Xevion
2021-02-18 08:04:27 -06:00
parent 0ee89fc607
commit 813bb7ea1d
3 changed files with 12 additions and 8 deletions

View File

@@ -210,13 +210,13 @@ class ContestCommandsCog(commands.Cog, name='Contest'):
period: Period = guild.current_period period: Period = guild.current_period
if period is None or not period.active: 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: else:
overwrite = discord.PermissionOverwrite() overwrite = discord.PermissionOverwrite()
overwrite.send_messages = False overwrite.send_messages = False
overwrite.add_reactions = False overwrite.add_reactions = False
period.deactivate() 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.command()
@commands.guild_only() @commands.guild_only()

View File

@@ -40,7 +40,7 @@ class ContestEventsCog(commands.Cog):
await self.bot.reject(message, f'Each submission must contain exactly one image.') await self.bot.reject(message, f'Each submission must contain exactly one image.')
elif guild.current_period is None: 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.') 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' logger.warning(f'Valid submission was sent outside of Submissions in'
f' {channel.id}/{message.id}. Permissions error? Removing.') f' {channel.id}/{message.id}. Permissions error? Removing.')
await message.delete() await message.delete()

View File

@@ -292,11 +292,15 @@ class Period(Base):
def permission_explanation(self) -> str: def permission_explanation(self) -> str:
"""Returns a quick explanation of the period's current state.""" """Returns a quick explanation of the period's current state."""
if self.active:
if self.state == PeriodStates.READY: return 'No voting or submissions quite yet.' 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.SUBMISSIONS: return 'Submissions open; upload now.'
elif self.state == PeriodStates.PAUSED: return 'Submissions closed. No voting *yet*.' 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.VOTING: return 'Vote on submissions now.'
elif self.state == PeriodStates.FINISHED: return 'Voting closed. Contest results available.' 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." return "Error."
def __repr__(self) -> str: def __repr__(self) -> str: