Implement simple 'status' command

Implements the status command, creating a new Submission.permission_explanation
function in the process. Also changes the leaderboard command's embed
formatting slightly.
This commit is contained in:
Xevion
2021-02-18 04:31:45 -06:00
parent 95a87cb6dd
commit 5a4da4cec0
2 changed files with 27 additions and 4 deletions

View File

@@ -152,8 +152,22 @@ class ContestCommandsCog(commands.Cog):
@commands.guild_only() @commands.guild_only()
async def status(self, ctx: Context) -> None: async def status(self, ctx: Context) -> None:
"""Provides the bot's current state in relation to internal configuration and the server's contest, if active.""" """Provides the bot's current state in relation to internal configuration and the server's contest, if active."""
# TODO: Implement status command with self.bot.get_session() as session:
pass guild: Guild = session.query(Guild).get(ctx.guild.id)
period: Period = guild.current_period
embed = discord.Embed(color=discord.Color(0x4a90e2), title='Status')
value = f'<#{guild.submission_channel}>' if guild.submission_channel else 'Please set a submission channel.'
embed.add_field(name='Submission Channel', value=value)
if period is not None:
value = 'None' if guild.current_period is None else guild.current_period.state.name.capitalize()
embed.add_field(name='Status', inline=False, value=f'{value} - {period.permission_explanation()}')
value = len(period.submissions)
value = str(value) + ' submission' + ('s' if value > 1 or value == 0 else '')
embed.add_field(name='Submissions', inline=False, value=value)
await ctx.send(embed=embed)
@commands.command() @commands.command()
@commands.guild_only() @commands.guild_only()
@@ -183,11 +197,11 @@ class ContestCommandsCog(commands.Cog):
description += f'`{str(i).zfill(2)}` {emote}<@{submission.user}> [Jump]({message.jump_url})\n' description += f'`{str(i).zfill(2)}` {emote}<@{submission.user}> [Jump]({message.jump_url})\n'
embed = discord.Embed(colour=discord.Colour(0x4a90e2), embed = discord.Embed(title='Leaderboard',
colour=discord.Colour(0x4a90e2),
description=description, description=description,
timestamp=datetime.datetime.utcnow()) timestamp=datetime.datetime.utcnow())
embed.set_footer(text='Contest is still in progress...' if guild.current_period.active else 'Contest has finished.') embed.set_footer(text='Contest is still in progress...' if guild.current_period.active else 'Contest has finished.')
embed.set_author(name="Leaderboard")
# embed.add_field(name="🤔", value="some of these properties have certain limits...", inline=True) # embed.add_field(name="🤔", value="some of these properties have certain limits...", inline=True)
await ctx.send(embed=embed) await ctx.send(embed=embed)

View File

@@ -284,5 +284,14 @@ class Period(Base):
self.finished_time = datetime.datetime.utcnow() self.finished_time = datetime.datetime.utcnow()
self.active = False self.active = False
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.'
return "Error."
def __repr__(self) -> str: def __repr__(self) -> str:
return 'Period(id={id}, guild={guild_id}, {state.name}, active={active})'.format(**self.__dict__) return 'Period(id={id}, guild={guild_id}, {state.name}, active={active})'.format(**self.__dict__)