diff --git a/main.py b/main.py index e48e17e..0a84db6 100644 --- a/main.py +++ b/main.py @@ -50,7 +50,7 @@ async def check_time_periods(): logger.info("1 hour left for voting") embed = await embed_scoreboard(daily_data['submissions'], daily_data['votes'], "1 hour left for voting", "There's still time to vote! Here are the current scores") embed.set_footer(text="Remember to vote for your submission to be valid!") - await vote_reminder() + await private_vote_reminder() await voting_channel.send(embed=embed) elif hour == 12 and minute == 00 and len(daily_data['submissions']) > 1 and len(daily_data['voters']) > 0: await results_period(voting_channel, submission_channel, results_channel) diff --git a/results.py b/results.py index 2a4e7fc..9780003 100644 --- a/results.py +++ b/results.py @@ -18,17 +18,18 @@ async def results_period(voting_channel, submission_channel, results_channel): await bot.change_presence(status=discord.Status.idle, activity=activity) winner_message = await get_winner(results_channel) logger.debug(winner_message) + embed = discord.Embed(title="RESULTS", description="", colour=0xff0000) embed.set_author(name=winner_message) embed.set_footer(text=random.choice(quotes['rude'])) - sorted_submissions_dict = sort_submissions() + sorted_submissions_dict = sort_submissions() for index, val in enumerate(sorted_submissions_dict['votes']): - votes_str = "Votes: " - votes_str = votes_str + str(val) - user_obj = bot.get_guild(config.config['server_id']).get_member(sorted_submissions_dict['submissions'][index]) - embed.add_field(name=user_obj.nick, value=votes_str, inline=False) + votes = "Votes: " + str(val) + user = bot.get_guild(config.config['server_id']).get_member(sorted_submissions_dict['submissions'][index]) + embed.add_field(name=user.nick, value=votes, inline=False) await results_channel.send(embed=embed) + reset_daily_data() data_dict_to_json() await channel_permissions(False, False, voting_channel, submission_channel) @@ -36,7 +37,7 @@ async def results_period(voting_channel, submission_channel, results_channel): async def get_winner(results_channel): for index, value in enumerate(daily_data['submissions']): if not check_winner_vote(value): - disqualify_winner(value, index) + disqualify_winner(value, index, results_channel) if len(daily_data['submissions']) == 0: embed = discord.Embed( @@ -46,10 +47,9 @@ async def get_winner(results_channel): max_vote = max(daily_data['votes']) winner_message = "Winner: " - winner_indexes = [i for i, j in enumerate( + max_index = [i for i, j in enumerate( daily_data['votes']) if j == max_vote] - - if len(winner_indexes) > 1: + if len(max_index) > 1: winner_message = "Winners: " for index, value in enumerate(daily_data['submissions']): @@ -68,11 +68,11 @@ def check_winner_vote(winner): logger.warning("Winner disqualified") return False -async def disqualify_winner(winner, index): +async def disqualify_winner(winner, index, channel): winner_message = "Winner disqualified: " + str(winner.nick) - embed = discord.Embed(title=winner_message, description="Winner did not vote, therefore their submission is invalid", colour=0xff0000) - await bot.get_channel(config.config['results_channel_id']).send(embed=embed) - logger.debug("New winner selected" + str(daily_data['submissions'][index])) + embed = discord.Embed( + title=winner_message, description="Winner did not vote, therefore their submission is invalid", colour=0xff0000) + await channel.send(embed=embed) del daily_data['votes'][index] del daily_data['submissions'][index] await asyncio.sleep(5) diff --git a/scoreboard.py b/scoreboard.py index 69a26a8..88669ca 100644 --- a/scoreboard.py +++ b/scoreboard.py @@ -37,12 +37,6 @@ async def scoreboard(channel): sorted_scoreboard_dict = sort_scoreboard() embed = await embed_scoreboard(sorted_scoreboard_dict['users'], sorted_scoreboard_dict['scores'], "SCOREBOARD", "Scoreboard for this term") await channel.send(embed=embed) - -async def auto_scoreboard(): - sorted_scoreboard_dict = sort_scoreboard() - embed = await embed_scoreboard(sorted_scoreboard_dict['users'], sorted_scoreboard_dict['scores'], "SCOREBOARD", "Scoreboard for this term") - await bot.get_channel(config.config['results_channel_id']).send(embed=embed) - @bot.command(description="Shows the overall score for the food flex") async def score(ctx): diff --git a/voting.py b/voting.py index 4cfc782..9575b9f 100644 --- a/voting.py +++ b/voting.py @@ -28,33 +28,24 @@ async def voting_period(submission_channel, voting_channel): data_dict_to_json() await channel_permissions(False, True, submission_channel, voting_channel) -async def vote_reminder(): - logger.debug("Reminding users who submitted") +async def private_vote_reminder(): for member_id in daily_data['submissions']: - if member_id in daily_data['voters']: - logger.debug(str(member_id) + " has voted - no reminder") - else: + if member_id not in daily_data['voters']: user = bot.get_guild(config.config['server_id']).get_member(member_id) await user.send("Remember to vote for your submission to be valid!!!") logger.debug("Vote reminder sent for " + str(user.nick)) async def check_vote(message, voting_channel): logger.info("Vote by: " + str(message.author.nick)) - raw = str(message.clean_content) - vote = raw[0] - vote_index = ord(vote) - 65 + vote_index = ord(message.clean_content[0]) - 65 logger.debug("vote_index: " + str(vote_index)) # this is an index if vote_index < len(daily_data['submissions']) and vote_index >= 0: # Checks if it's in range duplicate = check_duplicate(vote_index, voting_channel, message) - if (duplicate == True): - logger.info("Vote invalid") - elif duplicate == False: + if duplicate == False: await is_valid(vote_index, voting_channel, message) def check_duplicate(vote_index, voting_channel, message): - if check_self_vote(vote_index, voting_channel, message) == True: - return True - elif message.author.id in daily_data['voters']: + if check_self_vote(vote_index, voting_channel, message) == True or message.author.id in daily_data['voters']: return True else: return False @@ -62,11 +53,9 @@ def check_duplicate(vote_index, voting_channel, message): def check_self_vote(vote_index, voting_channel, message): if message.author.id in daily_data['submissions']: voter_index = daily_data['submissions'].index(message.author.id) - else: - voter_index = -1 - if voter_index == vote_index: - logger.warn("Invalid vote: same submission") - return True + if voter_index == vote_index: + logger.warn("Invalid vote: same submission") + return True else: return False @@ -81,4 +70,4 @@ async def voting(ctx): if await bot.is_owner(ctx.author): await voting_period(bot.get_channel(config.config['submission_channel_id']), bot.get_channel(config.config['voting_channel_id'])) logger.debug("Voting started manually") - await ctx.message.delete() \ No newline at end of file + await ctx.message.delete()