def match_problems_embed(match_info): a, b = match_score(match_info.status) problems = match_info.problems.split() points = [f"{100 * (i + 1)}" for i in range(5)] names = [ f"[{db.get_problems(problems[i])[0].name}](https://codeforces.com/contest/{problems[i].split('/')[0]}" f"/problem/{problems[i].split('/')[1]})" if match_info.status[i] == '0' else "This problem has been solved" for i in range(5) ] rating = [f"{match_info.rating + i * 100}" for i in range(5)] handle1, handle2 = db.get_handle(match_info.guild, match_info.p1_id), db.get_handle( match_info.guild, match_info.p2_id) embed = discord.Embed( description= f"[{handle1}](https://codeforces.com/profile/{handle1}) (**{a}** points) vs " f"(**{b}** points) [{handle2}](https://codeforces.com/profile/{handle2})", color=discord.Color.green()) embed.set_author(name=f"Problems") embed.add_field(name="Points", value='\n'.join(points), inline=True) embed.add_field(name="Problem Name", value='\n'.join(names), inline=True) embed.add_field(name="Rating", value='\n'.join(rating), inline=True) embed.set_footer( text= f"Time left: {timeez((match_info.time + 60 * match_info.duration) - int(time.time()))}" ) return embed
def recent_matches_embed(data): content = [] for match in data: try: handle1, handle2 = db.get_handle(match.guild, match.p1_id), db.get_handle(match.guild, match.p2_id) a, b = updation.match_score(match.status) profile_url = "https://codeforces.com/profile/" content.append(f"{len(content)+1}. [{handle1}]({profile_url+handle1})(**{a}** points) vs (**{b}** points) [{handle2}]" f"({profile_url+handle2}) {f'was won by **{handle1 if a>b else handle2}**' if a!=b else 'ended in a **draw**!'} | {match.rating} rated | {timeez(int(time.time())-match.time)} ago") except Exception: pass return content
def ongoing_matches_embed(data): content = [] for match in data: try: handle1, handle2 = db.get_handle(match.guild, match.p1_id), db.get_handle(match.guild, match.p2_id) a, b = updation.match_score(match.status) profile_url = "https://codeforces.com/profile/" content.append(f"{len(content)+1}. [{handle1}]({profile_url+handle1})(**{a}** points) vs (**{b}** points) [{handle2}]" f"({profile_url+handle2}) | {match.rating} rated | Time left: {timeez(match.time+60*match.duration-int(time.time()))}") except Exception: pass return content
async def update(self, ctx): await ctx.send(embed=discord.Embed( description=f"Updating matches for this server", color=discord.Color.green())) matches = self.db.get_all_matches(ctx.guild.id) for match in matches: try: # updates, over, match_status resp = await updation.update_match(match) if not resp[0]: logging_channel = await self.client.fetch_channel( os.environ.get("LOGGING_CHANNEL")) await logging_channel.send( f"Error while updating matches: {resp[1]}") continue resp = resp[1] channel = self.client.get_channel(match.channel) if resp[1] or len(resp[0]) > 0: mem1, mem2 = await discord_.fetch_member(ctx.guild, match.p1_id), \ await discord_.fetch_member(ctx.guild, match.p2_id) await channel.send( f"{mem1.mention} {mem2.mention}, there is an update in standings!" ) for x in resp[0]: await channel.send(embed=discord.Embed( description= f"{' '.join([(await discord_.fetch_member(ctx.guild, m)).mention for m in x[1]])} has solved problem worth {x[0]*100} points", color=discord.Color.blue())) if not resp[1] and len(resp[0]) > 0: await channel.send(embed=discord_.match_problems_embed( self.db.get_match_info(ctx.guild.id, match.p1_id))) if resp[1]: a, b = updation.match_score(resp[2]) p1_rank, p2_rank = 1 if a >= b else 2, 1 if b >= a else 2 ranklist = [] ranklist.append([ await discord_.fetch_member(ctx.guild, match.p1_id), p1_rank, self.db.get_match_rating(ctx.guild.id, match.p1_id)[-1] ]) ranklist.append([ await discord_.fetch_member(ctx.guild, match.p2_id), p2_rank, self.db.get_match_rating(ctx.guild.id, match.p2_id)[-1] ]) ranklist = sorted(ranklist, key=itemgetter(1)) res = elo.calculateChanges(ranklist) self.db.add_rating_update(ctx.guild.id, match.p1_id, res[match.p1_id][0]) self.db.add_rating_update(ctx.guild.id, match.p2_id, res[match.p2_id][0]) self.db.delete_match(match.guild, match.p1_id) self.db.add_to_finished(match, resp[2]) embed = discord.Embed(color=discord.Color.dark_magenta()) pos, name, ratingChange = '', '', '' for user in ranklist: pos += f"{':first_place:' if user[1] == 1 else ':second_place:'}\n" name += f"{user[0].mention}\n" ratingChange += f"{res[user[0].id][0]} (**{'+' if res[user[0].id][1] >= 0 else ''}{res[user[0].id][1]}**)\n" embed.add_field(name="Position", value=pos) embed.add_field(name="User", value=name) embed.add_field(name="Rating changes", value=ratingChange) embed.set_author( name=f"Match over! Final standings\nScore: {a}-{b}") await channel.send(embed=embed) except Exception as e: logging_channel = await self.client.fetch_channel( os.environ.get("LOGGING_CHANNEL")) await logging_channel.send( f"Error while updating matches: {str(traceback.format_exc())}" )