mirror of
https://github.com/Xevion/contest-assistant.git
synced 2025-12-08 08:06:47 -06:00
Fix critical mistake in Submission.clear_other_votes
- As well as other possible flaws in various functions of the bot's operation. - Fixed inactive prematurely closed Period's showing their final state instead of Finished.
This commit is contained in:
@@ -109,7 +109,7 @@ class ContestBot(commands.Bot):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
for submission in submissions:
|
for submission in submissions:
|
||||||
message: discord.PartialMessage = channel.get_partial_message(submission.id)
|
message: discord.Message = await channel.fetch_message(submission.id)
|
||||||
await message.add_reaction(self.get_emoji(constants.Emoji.UPVOTE))
|
await message.add_reaction(self.get_emoji(constants.Emoji.UPVOTE))
|
||||||
|
|
||||||
def get_message(self, channel_id: int, message_id: int) -> discord.PartialMessage:
|
def get_message(self, channel_id: int, message_id: int) -> discord.PartialMessage:
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ class ContestCommandsCog(commands.Cog, name='Contest'):
|
|||||||
# noinspection PyDunderSlots,PyUnresolvedReferences
|
# noinspection PyDunderSlots,PyUnresolvedReferences
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
@commands.bot_has_guild_permissions(add_reactions=True)
|
||||||
@commands.has_permissions(send_messages=True, add_reactions=True, read_message_history=True, manage_roles=True)
|
@commands.has_permissions(send_messages=True, add_reactions=True, read_message_history=True, manage_roles=True)
|
||||||
@commands.max_concurrency(1, per=BucketType.guild, wait=True)
|
@commands.max_concurrency(1, per=BucketType.guild, wait=True)
|
||||||
@checks.privileged()
|
@checks.privileged()
|
||||||
@@ -231,7 +232,8 @@ class ContestCommandsCog(commands.Cog, name='Contest'):
|
|||||||
embed.add_field(name='Submission Channel', value=value)
|
embed.add_field(name='Submission Channel', value=value)
|
||||||
|
|
||||||
if period is not None:
|
if period is not None:
|
||||||
value = 'None' if guild.current_period is None else guild.current_period.state.name.capitalize()
|
value = 'None' if guild.current_period is None else \
|
||||||
|
(guild.current_period.state.name.capitalize() if guild.current_period.active else 'Finished')
|
||||||
embed.add_field(name='Status', inline=False, value=f'{value} - {period.permission_explanation()}')
|
embed.add_field(name='Status', inline=False, value=f'{value} - {period.permission_explanation()}')
|
||||||
value = len(period.submissions)
|
value = len(period.submissions)
|
||||||
value = str(value) + ' submission' + ('s' if value > 1 or value == 0 else '')
|
value = str(value) + ' submission' + ('s' if value > 1 or value == 0 else '')
|
||||||
|
|||||||
@@ -100,13 +100,13 @@ class Submission(Base):
|
|||||||
self._votes = votes
|
self._votes = votes
|
||||||
self.count = len(votes)
|
self.count = len(votes)
|
||||||
|
|
||||||
def __init__(self, **kwds):
|
def __init__(self, **kwargs):
|
||||||
# Adds default column behavior for Mutable JSON votes column
|
# Adds default column behavior for Mutable JSON votes column
|
||||||
kwds.setdefault("votes", [])
|
kwargs.setdefault("votes", [])
|
||||||
super().__init__(**kwds)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return 'Submission(id={id}, user={user}, period={period_id}, {votes})'.format(**self.__dict__)
|
return 'Submission(id={id}, user={user}, period={period_id}, {count} votes)'.format(**self.__dict__)
|
||||||
|
|
||||||
def increment(self, user: int) -> None:
|
def increment(self, user: int) -> None:
|
||||||
"""Increase the number of votes by one."""
|
"""Increase the number of votes by one."""
|
||||||
@@ -148,7 +148,7 @@ class Submission(Base):
|
|||||||
# Find what users voted for this submission that we are clearing
|
# Find what users voted for this submission that we are clearing
|
||||||
votes = set(submission.votes)
|
votes = set(submission.votes)
|
||||||
same = votes.intersection(users)
|
same = votes.intersection(users)
|
||||||
if len(same) > 0:
|
if len(same) == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Remove votes from the submission by said users
|
# Remove votes from the submission by said users
|
||||||
@@ -201,7 +201,7 @@ class Submission(Base):
|
|||||||
for reaction_marker in reaction_tuples:
|
for reaction_marker in reaction_tuples:
|
||||||
await message_to_clear.remove_reaction(
|
await message_to_clear.remove_reaction(
|
||||||
bot.get_emoji(constants.Emoji.UPVOTE),
|
bot.get_emoji(constants.Emoji.UPVOTE),
|
||||||
message.guild.get_member(reaction_marker.user)
|
await message.guild.fetch_member(reaction_marker.user)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update the current list of votes
|
# Update the current list of votes
|
||||||
@@ -300,7 +300,8 @@ class Period(Base):
|
|||||||
else:
|
else:
|
||||||
if self.state == PeriodStates.FINISHED: return 'Voting closed. Contest results available.'
|
if self.state == PeriodStates.FINISHED: return 'Voting closed. Contest results available.'
|
||||||
elif self.state == PeriodStates.VOTING: return 'Voting closed (prematurely). 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.'
|
elif self.state == PeriodStates.READY: return 'Closed before any submissions could be submitted.'
|
||||||
|
else: return 'Closed prematurely. Submissions were remembered, but no votes could be cast.'
|
||||||
return "Error."
|
return "Error."
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user