async def getErbsLeaderboard(self, ctx, gameMode: str): """Gets Global Leaderboard of a specific game mode.""" mode = gameModeSwitch(gameMode) if not mode: embedVar.add_field( name='getErbsLeaderboard', value= f'Game mode was incorrect. Please input any ONE of these:| Solo(s) | Duo(s) | Squad(s) |' ) await ctx.send(embed=embedVar) return leaders = await getLeaderboard(baseUrl=BASE_URL, seasonId=currentSeasonId, teamMode=mode, apiKey=API_KEY) if leaders: embeds: list = [] i = 1 for page in leaders: embeds.append( discord.Embed(color=ctx.author.color).add_field( name=f"Rank {i}-{i+24}", value=f"{''.join(page)}")) i += 25 paginator = Pagination.AutoEmbedPaginator(ctx) await paginator.run(embeds) else: embedVar.add_field(name="getErbsSquadLeaderboard", value=f"No Leaderboard was found.", inline=False) await ctx.send(embed=embeds)
async def getItemTree(self, ctx, *, itemName: str): item = await findItem(itemName) fields = parseItem(item) embeds: list = [] tree: dict = {} embed = discord.Embed() if 'makeMaterial1' in item and item['makeMaterial1']: parseBuildTree(item['makeMaterial1'], item['makeMaterial2'], item['name'], tree) fields.append( ("Builds From: ", f"```{tree[item['name']][0]} + {tree[item['name']][1]}```", True)) print(tree) i = 0 for name, value, inline in fields: if i < 25: embed.add_field(name=name, value=value, inline=inline) i += 1 else: i = 0 embeds.append(embed) embed = discord.Embed() embed.add_field(name=name, value=value, inline=inline) embeds.append(embed) if tree: for node in tree: print(tree[node]) if item['name'] == node: continue else: embed = discord.Embed() item = await findItem(node) fields: list = parseItem(item) fields.append( ("Builds From: ", f"```{tree[node][0]} + {tree[node][1]}```", True)) i = 0 for name, value, inline in fields: if i < 25: embed.add_field(name=name, value=value, inline=inline) i += 1 else: i = 0 embeds.append(embed) embed = discord.Embed() embed.add_field(name=name, value=value, inline=inline) embeds.append(embed) for x in range(len(embeds)): embeds[x].set_thumbnail(url=getThumbnailUrl()) paginator = Pagination.AutoEmbedPaginator(ctx) await paginator.run(embeds)
async def gitlog(self, ctx, username=None): """ Show the past gitgud history of a user """ query = Query() username = username or query.get_handle(ctx.author.id, ctx.guild.id) try: user = await query.get_user(username) username = user.username except TypeError: username = None if username is None: return await ctx.send("You have not entered a valid DMOJ handle or linked with a DMOJ Account") gitgud_util = Gitgud_utils() history = gitgud_util.get_all(username, ctx.guild.id) if len(history) == 0: embed = discord.Embed(description="User have not completed any challenge") return await ctx.send(embed=embed) # paginate count = 0 page_cnt = min(10, len(history)//10 + bool(len(history)%10)) embeds = [] content = "" paginator = Pagination.CustomEmbedPaginator(ctx, timeout=60, remove_reactions=True) paginator.add_reaction('⏮️', "first") paginator.add_reaction('⏪', "back") paginator.add_reaction('⏩', "next") paginator.add_reaction('⏭️', "last") for solved in history: # print(solved.problem_id) problem = await query.get_problem(solved.problem_id) days = (datetime.now() - solved.time).days if days==0: days_str = "today" elif days==1: days_str = "yesterday" else: days_str = f"{days} days ago" content += f"[{problem.name}](https://dmoj.ca/{problem.code}) [+{solved.point}] ({days_str})\n" count += 1 if count % 10 == 0: embed = discord.Embed() embed.add_field(name=f"Gitgud Log for {username} (page {count//10}/{page_cnt})", value=content, inline=True) embeds.append(embed) content = "" if count == 100: break if count % 10 != 0: embed = discord.Embed() embed.add_field(name=f"Gitlog for {username} (page {count//10 + 1}/{page_cnt})", value=content, inline=True) embeds.append(embed) return await paginator.run(embeds)
async def ranking(ctx): ranking = get_activity_ranking(ctx.guild.id) string = "" for i, (user, time) in enumerate(ranking): tier = get_tier(i) if tier not in string: string += f"**{tier}:**\n" name = user.split("#")[0] string += f"{name}: {pretty_time_delta(time)}\n" if string == "": string = "Todavía no hay un ranking." lines_per_page = 17 pages = get_pages(string, lines_per_page) embeds = [discord.Embed().add_field(name="Ranking", value=page) for page in pages] paginator = Pagination.CustomEmbedPaginator(ctx, auto_footer=True) paginator.add_reaction('⏪', "back") paginator.add_reaction('⏩', "next") await paginator.run(embeds)
async def getMatchHistory(self, ctx, gameId: Greedy[int] = None, nickname: str = ''): """Gets the author's match history in a specific game mode. If no nickname passed, uses linked account assigned to user. If a gameId is passed in, will user's stats for that game.""" user: dict if nickname: user = await getUser(baseUrl=BASE_URL, nickname=nickname, apiKey=API_KEY) else: erbsUsername = await getAccountName(ctx.author.name) if not erbsUsername: embedVar.add_field( name="getMatchHistory", value= f"No erbs account name was found linked to this user.", inline=False) await ctx.send(embed=embedVar) return else: user = (await getUser(baseUrl=BASE_URL, nickname=erbsUsername, apiKey=API_KEY)) if not user: embedVar.add_field(name="getMatchHistory", value=f"User was not found in ERBS.", inline=False) await ctx.send(embed=embedVar) return else: history = await getMatchHistory(baseUrl=BASE_URL, userId=user['userNum'], apiKey=API_KEY) if not history: embedVar.add_field(name="getMatchHistory", value=f"No history was found for this user.", inline=False) await ctx.send(embed=embedVar) return elif gameId: while (True): match = await findGameStats(matchHistory=history, gameId=gameId[0]) if not match: if not 'next' in history: embedVar.add_field( name="getMatchHistory", value= f"No game with that id was found for this user.", inline=False) await ctx.send(embed=embedVar) return else: history = await getMatchHistory(baseUrl=BASE_URL, userId=user['userNum'], apiKey=API_KEY, nextId=history['next']) continue else: embeds: list = [] page0 = [ ("Game ID", f"```{match['id']}```", False), ("Character", f"```{match['character']}```", True), ("Ranked", f"```{match['placement']}```", True), ("Game Mode", f"```{match['mode']}```", True), ("Kills", f"```{match['kills']}```", True), ("Assists", f"```{match['assists']}```", True), ("Hunts", f"```{match['hunts']}```", True), ("Max HP", f"```{match['maxHp']}```", True), ("Max SP", f"```{match['maxSp']}```", True), ("Attack Power", f"```{match['attackPower']}```", True), ("Defense", f"```{match['defense']}```", True), ("HP Regen", f"```{match['hpRegen']}```", True), ("SP Regen", f"```{match['spRegen']}```", True), ("Attack Speed", f"```{match['attackSpeed']}```", True), ("Move Speed", f"```{match['moveSpeed']}```", True), ("Sight Range", f"```{match['sightRange']}```", True), ("Attack Range", f"```{match['attackRange']}```", True), ("Critical Chance", f"```{match['criticalStrikeChance']}```", True), ("Critical Damage", f"```{match['criticalStrikeDamage']}```", True), ("Cooldown Reduction", f"```{match['coolDownReduction']}```", True), ("LifeSteal", f"```{match['lifeSteal']}```", True) ] skills = "" for skill in match['skillLevelOrder']: skills = skills + f"{skill}: {match['skillLevelOrder'][skill]}" mastery = "" for masteryCode in match['masteryLevels']: mastery = mastery + f"```{masteryCode}: {match['masteryLevels'][masteryCode]}```" page1 = [("Level", f"```{match['level']}```", False), ("Mastery", f"{mastery}", False), ("Skill Order", f"```{skills}```", False), ("Weapon", f"```{match['weapon']}```", True), ("Chest", f"```{match['chest']}```", True), ("Head", f"```{match['head']}```", True), ("Gloves", f"```{match['gloves']}```", True), ("Boots", f"```{match['boots']}```", True), ("Accessory", f"```{match['accessory']}```", True)] embeds.append(discord.Embed()) for name, value, inline in page0: embeds[0].add_field(name=name, value=value, inline=inline) embeds.append(discord.Embed()) for name, value, inline in page1: embeds[1].add_field(name=name, value=value, inline=inline) for x in range(len(embeds)): embeds[x].set_thumbnail(url=getThumbnailUrl()) paginator = Pagination.AutoEmbedPaginator(ctx) await paginator.run(embeds) return else: embeds: list = [] while True: matchHistory = history["userGames"] for match in matchHistory: fields = [ ("Game: ", f"```{match['gameId']}```", False), ("Mode: ", f"```{gameModeSwitch(match['matchingTeamMode'])}```", False), ("Level: ", f"```{match['characterLevel']}```", False), ("Placement: ", f"```{match['gameRank']}```", False), ("Kills: ", f"```{match['playerKill']}```", False), ("Assists: ", f"```{match['playerAssistant']}```", False), ("Hunts: ", f"```{match['monsterKill']}```", False) ] embeds.append(discord.Embed()) for name, value, inline in fields: embeds[len(embeds) - 1].add_field(name=name, value=value, inline=inline) for x in range(len(embeds)): embeds[x].set_thumbnail(url=getThumbnailUrl()) if 'next' in history: history = await getMatchHistory(baseUrl=BASE_URL, userId=user['userNum'], apiKey=API_KEY, nextId=history['next']) else: break paginator = Pagination.AutoEmbedPaginator(ctx) await paginator.run(embeds)
async def gitlog(self, ctx, username=None): ''' Show the past gitgud history of a user ''' query = Query() username = username or query.get_handle(ctx.author.id, ctx.guild.id) try: user = await query.get_user(username) username = user.username except TypeError: username = None if username is None: return await ctx.send('You have not entered a valid DMOJ handle ' 'or linked with a DMOJ Account') gitgud_util = Gitgud_utils() history = gitgud_util.get_all(username, ctx.guild.id) if len(history) == 0: embed = discord.Embed(description='User have not completed any ' 'challenge') return await ctx.send(embed=embed) # paginate count = 0 page_cnt = min(10, len(history) // 10 + bool(len(history) % 10)) embeds = [] content = '' paginator = Pagination.CustomEmbedPaginator(ctx, timeout=60, remove_reactions=True) paginator.add_reaction('⏮️', 'first') paginator.add_reaction('⏪', 'back') paginator.add_reaction('⏩', 'next') paginator.add_reaction('⏭️', 'last') for solved in history: problem = await query.get_problem(solved.problem_id) days = (datetime.now() - solved.time).days if days == 0: days_str = 'today' elif days == 1: days_str = 'yesterday' else: days_str = f'{days} days ago' content += f'[{problem.name}](https://dmoj.ca/problem/{problem.code}) ' \ f'[+{solved.point}] ({days_str})\n' count += 1 if count % 10 == 0: embed = discord.Embed(color=0xfcdb05, ) embed.add_field(name=f'Gitgud Log for {username} ' f'(page {count//10}/{page_cnt})', value=content, inline=True) embeds.append(embed) content = '' if count == 100: break if count % 10 != 0: embed = discord.Embed() embed.add_field(name=f'Gitlog for {username} ' f'(page {count//10 + 1}/{page_cnt})', value=content, inline=True) embeds.append(embed) return await paginator.run(embeds)