async def level_distribution(ctx, args): player = ctx.message.author playerid = bot0.id(player) brawltag = bot0.get_brawltag(playerid) if brawltag is None: await bot0.request_brawltag(ctx) return playerdata = bot0.get_playerdata(brawltag) all_brawlers = bot0.get_all_brawlers() await check_missing_brawler(ctx, all_brawlers=all_brawlers) leveldist = [] for b in all_brawlers: brawler = find_brawler(b['name'], playerdata['brawlers']) if brawler is None: leveldist.append('0') elif brawler['power'] < 10: leveldist.append(str(brawler['power'])) elif len(brawler['starPowers']) == len(b['starPowers']) \ and len(brawler['gadgets']) == len(b['gadgets']): leveldist.append(';') # 11 else: leveldist.append(':') # 10 leveldist.sort() leveldist = ''.join(sorted(leveldist)).replace(':', '*').replace(';', '!') embed = discord.Embed(colour=0xf0b420) embed.set_author(name=player.name, icon_url=bot0.profile_icon(str(playerdata['icon']['id']), player.avatar_url)) embed.description = ( 'Shows the distribution of brawler power levels at a glance.\n' '* denotes power 10s missing at least one gadget or star power.\n' '! denotes power 10s with all (released) gadgets and star powers.') embed.add_field(name='Level Distribution', value=f'```[{leveldist}]```') await ctx.send(embed=embed)
async def display_levels(ctx, args, emojis): player = ctx.message.author playerid = bot0.id(player) brawltag = bot0.get_brawltag(playerid) if brawltag is None: await bot0.request_brawltag(ctx) return playerdata = bot0.get_playerdata(brawltag) all_brawlers = bot0.get_all_brawlers() await check_missing_brawler(ctx, all_brawlers=all_brawlers) # Prepare items to print lock_emoji = str(get_emoji(emojis, name='locked')) levels = [] spga = [] sp_emoji = str(get_emoji(emojis, name='sp')) nosp_emoji = str(get_emoji(emojis, name='nosp')) ga_emoji = str(get_emoji(emojis, name='ga')) noga_emoji = str(get_emoji(emojis, name='noga')) # Loop through all brawlers for brawler_name, _ in BRAWLER_ORDER: b = find_brawler(brawler_name, playerdata['brawlers']) if b is not None: # Add to values levels.append(str(b['power'])) max_b = find_brawler(brawler_name, all_brawlers) if max_b is None: continue icons = [] for ga in max_b['gadgets']: if ga in b['gadgets']: icons.append(ga_emoji) else: icons.append(noga_emoji) for sp in max_b['starPowers']: if sp in b['starPowers']: icons.append(sp_emoji) else: icons.append(nosp_emoji) spga.append(' '.join(icons)) else: levels.append('0') spga.append('') B_PER_PAGE = 24 totalpages = ceil(len(BRAWLER_ORDER) / B_PER_PAGE) for p in range(totalpages): embed = discord.Embed(colour=0xf0b420) embed.set_footer(text=f"Page {p+1} of {totalpages}") embed.set_author(name=player.name, icon_url=bot0.profile_icon( str(playerdata['icon']['id']), player.avatar_url)) for index in range(B_PER_PAGE * p, min(B_PER_PAGE * (p + 1), len(BRAWLER_ORDER))): if levels[index] != '0': value = f"Power {levels[index]}\n" value += ''.join(spga[index]) value += '\u0009\u200b\n\u200b' else: value = f"Locked\n{lock_emoji}\n\u200b" embed.add_field(name=BRAWLER_ORDER[index][0], value=value, inline=True) if p + 1 == totalpages: if totalpages % 3 > 0: for _ in range(3 - totalpages % 3): embed.add_field(name='\u200b', value='\u200b', inline=True) await ctx.send(embed=embed)
async def profile(ctx, args, emojis): player = ctx.message.author playerid = bot0.id(player) brawltag = bot0.get_brawltag(playerid) if brawltag is None: await bot0.request_brawltag(ctx) return playerdata = bot0.get_playerdata(brawltag) all_brawlers = bot0.get_all_brawlers() # Emoji search trophy_emoji = str(get_emoji(emojis, name='trophy')) rank_emoji = str(get_emoji(emojis, name='rank')) stp_emoji = str(get_emoji(emojis, name='starpoints')) pptrophy_emoji = str(get_emoji(emojis, name='pptrophy')) log_emoji = str(get_emoji(emojis, name='battlelog')) sp_emoji = str(get_emoji(emojis, name='sp')) ga_emoji = str(get_emoji(emojis, name='ga')) # Embed embed = discord.Embed() if 'nameColor' in playerdata: embed.colour = int(playerdata['nameColor'][4:], base=16) embed.set_author(name=f"{player.name} #{brawltag}", icon_url=bot0.profile_icon(str(playerdata['icon']['id']), player.avatar_url)) # Brawler iteration total_rank = 0 maximal_trophies = 0 num_sp = 0 num_ga = 0 total_trophy_loss = 0 total_starpoints = 0 for b in playerdata['brawlers']: total_rank += b['rank'] maximal_trophies += b['highestTrophies'] num_sp += len(b['starPowers']) num_ga += len(b['gadgets']) trophy_loss, starpoints = bsmath.trophy_reset(b['trophies']) total_trophy_loss += trophy_loss total_starpoints += starpoints total_sp = 0 total_ga = 0 for b in all_brawlers: total_sp += len(b['starPowers']) total_ga += len(b['gadgets']) # Data Validation trophies = playerdata.get('trophies', 0) highest_trophies = playerdata.get('highestTrophies', 0) num_brawlers = len(playerdata.get('brawlers', [])) pp_points = playerdata.get('powerPlayPoints', 0) highest_pp_points = playerdata.get('highestPowerPlayPoints', 0) # Trophies embed.add_field( name='Trophies', value=(f"Current: {trophy_emoji} {trophies}\n" f"Highest: {trophy_emoji} {highest_trophies}\n" f"Total Rank: {rank_emoji} {total_rank}\n" f"Average Rank: {rank_emoji} {total_rank/num_brawlers:.01f}\n" f"Individual Max: {trophy_emoji} {maximal_trophies}"), inline=False) # Trophy League embed.add_field( name='Trophy League', value=(f"Remaining Trophies: {trophy_emoji} " f"{playerdata['trophies'] - total_trophy_loss}\n" f"Trophy Loss: {trophy_emoji} {total_trophy_loss}\n" f"Reward: {stp_emoji} {total_starpoints}\n" f"Time left: :clock3: {brawltime.time_remaining('trophies')}"), inline=False) # Power Play embed.add_field( name='Power Play', value=(f"Trophies: {pptrophy_emoji} {pp_points}\n" f"Reward: {stp_emoji} {bsmath.pp_reset(pp_points)}\n" f"Highest: {pptrophy_emoji} {highest_pp_points}\n" f"Time left: :clock3: {brawltime.time_remaining('powerplay')}"), inline=False) # Brawl Pass Season (Retired) # embed.add_field( # name=brawltime.season_name(), # value=( # f"Time left: :clock3: {brawltime.time_remaining('brawlpass')}" # ), # inline=False # ) # Unlocked (Brawlers, SP, GA) embed.add_field(name='Progress', value=(f"{log_emoji} {num_brawlers}/{len(all_brawlers)}\n" f"{sp_emoji} {num_sp}/{total_sp}\n" f"{ga_emoji} {num_ga}/{total_ga}\n"), inline=False) await ctx.send(embed=embed)
async def progression_remaining(ctx, args, emojis): player = ctx.message.author playerid = bot0.id(player) brawltag = bot0.get_brawltag(playerid) if brawltag is None: await bot0.request_brawltag(ctx) return playerdata = bot0.get_playerdata(brawltag) all_brawlers = bot0.get_all_brawlers() await check_missing_brawler(ctx, all_brawlers=all_brawlers) brawlers_missing = [ b['name'] for b in all_brawlers if find_brawler(b['name'], playerdata['brawlers']) is None ] points_remaining = 0 coins_remaining = 0 sp_remaining = [0, 0] ga_remaining = [0, 0] for brawler in playerdata['brawlers']: # Points and Coins points, coins = bsmath.prog_remaining(brawler['power']) # Check to see if power points are stored points_stored = bsmath.points_to_display(0, brawler['power'])[0] points_remaining += (points - points_stored) coins_remaining += coins # SP and Gadgets max_brawler = find_brawler(brawler['name'], all_brawlers) if max_brawler is None: continue ga_diff = len(max_brawler['gadgets']) - len(brawler['gadgets']) sp_diff = len(max_brawler['starPowers']) - len(brawler['starPowers']) if ga_diff > 0: ga_remaining[0] += ga_diff ga_remaining[1] += 1 if sp_diff > 0: sp_remaining[0] += sp_diff sp_remaining[1] += 1 # Prepare output points_emoji = str(get_emoji(emojis, name='powerpoints')) coins_emoji = str(get_emoji(emojis, name='coin')) ga_emoji = str(get_emoji(emojis, name='ga')) sp_emoji = str(get_emoji(emojis, name='sp')) gale_emoji = str(get_emoji(emojis, name='Gale_PinGG')) embed = discord.Embed(colour=0xff03cc) embed.set_author(name=player.name, icon_url=bot0.profile_icon(str(playerdata['icon']['id']), player.avatar_url)) embed.description = "Progress to max" if len(brawlers_missing) > 0: embed.add_field(name='Brawlers missing', value=', '.join(brawlers_missing), inline=False) if points_remaining > 0 or coins_remaining > 0: embed.add_field(name='Points and Coins', value=(f'{points_emoji} {points_remaining} and ' f'{coins_emoji} {coins_remaining}'), inline=False) if ga_remaining[0] > 0: embed.add_field(name='Gadgets', value=(f'{ga_emoji} {ga_remaining[0]} over ' f'{ga_remaining[1]} brawlers'), inline=False) if sp_remaining[0] > 0: embed.add_field(name='Star Powers', value=(f'{sp_emoji} {sp_remaining[0]} over ' f'{sp_remaining[1]} brawlers'), inline=False) if len(embed.fields) == 0: embed.description = f'Your account is maxed! {gale_emoji}' await ctx.send(embed=embed)
async def auto_pp_search(channel_func, emojis): # Possible rewards: solosd = [38, 34, 30, 26, 22, 18, 14, 10, 6, 2] duosd = [34, 26, 18, 10, 2] three = {'victory': [33, 30], 'draw': [15], 'defeat': [5]} # Colors epic = 0xe600ff win = 0x00bd5b draw = 0x1071e0 loss = 0xd60606 # Power Play pptrophy_emoji = str(get_emoji(emojis, name='pptrophy')) pp_channel = channel_func(720098854887882845) # Today today = (datetime.utcnow() - timedelta(hours=2)).date() # Open tracking members with open('pptracking.json') as f: players = {p:get_playerdata(p)['name'] for p in load(f)['players']} def username(fulltag): """ Returns the name of the player with the tag, if it is a tracked tag. """ ptag = fulltag[1:] if ptag in players: return players[ptag] else: return fulltag # Search for playertag in players.keys(): fulltag = '#' + playertag # Battlelog in chronological order (first is earliest) battlelog = get_battlelog(playertag)['items'][::-1] for b in battlelog: battledate = battletime(b['battleTime']) if battledate < (today - timedelta(days=1)): # Battle was fought at least two PP days ago # Unnecessary optimization? continue # API changed with Oct 22 update (Amber) # if 'type' not in b['battle'] or b['battle']['type'] != 'ranked': # # Type is absent in weekend (aka ticketed) events # continue if battle_exists(b['battleTime'], playertag): # Already recorded # Might be a bug here? Duplicated 129 continue # Find Trophy Change, set up embed trophychange = b['battle'].get('trophyChange', 0) mode = camel_to_title(b['battle']['mode']) bmap = b['event']['map'] embed = discord.Embed(title="Power Play Match Found") embed.colour = draw embed.add_field(name='Mode', value=mode) embed.add_field(name='Map', value=bmap) embed.add_field(name='Played', value=time_ago(b['battleTime'])) # Calculate possible results if b['battle']['mode'] == 'soloShowdown': rank = b['battle']['rank'] if solosd[rank - 1] != trophychange: continue # Guaranteed to be new at this point brawler_raw = [ p['brawler'] for p in b['battle']['players'] if p['tag'] == fulltag ][0] brawler = brawler_raw['name'] trophies = brawler_raw['trophies'] embed.add_field(name='Rank', value=rank) embed.add_field( name='Result', value=f"{pptrophy_emoji} {trophychange:+}" ) embed.add_field(name='\u200b', value='\u200b') embed.add_field( name="Player 1", value=( f"{pptrophy_emoji} {trophies}\n" f"{brawler}\n" f"{players[playertag]}" ) ) # Need 2 more blanks? # Set embed colour if rank == 1: embed.colour = epic elif rank <= 4: embed.colour = win elif rank >= 6: embed.colour = loss # Write to DB insert_pp( battledate, b['battleTime'], mode, bmap, trophychange, playertag, brawler ) elif b['battle']['mode'] == 'duoShowdown': rank = b['battle']['rank'] if duosd[rank - 1] != trophychange: continue # Guaranteed to be new at this point for t in b['battle']['teams']: team = [ t[0]['brawler'], t[0]['tag'], t[1]['brawler'], t[1]['tag'] ] if fulltag in team: break embed.add_field(name='Rank', value=rank) embed.add_field( name='Result', value=f"{pptrophy_emoji} {trophychange:+}" ) embed.add_field(name='\u200b', value='\u200b') embed.add_field( name="Player 1", value=( f"{pptrophy_emoji} {team[0]['trophies']}\n" f"{team[0]['name']}\n" f"{username(team[1])}" ) ) embed.add_field( name="Player 2", value=( f"{pptrophy_emoji} {team[2]['trophies']}\n" f"{team[2]['name']}\n" f"{username(team[3])}" ) ) # Need 1 more blank? # Set embed colour if rank == 1: embed.colour = epic elif rank <= 2: embed.colour = win elif rank >= 4: embed.colour = loss # Write to DB insert_pp( battledate, b['battleTime'], mode, bmap, trophychange, team[1][1:], team[0]['name'], p2tag=team[3][1:], p2brawler=team[2]['name'] ) else: result = b['battle']['result'] if trophychange not in three[result]: continue # Guaranteed to be new at this point for t in b['battle']['teams']: team = [ t[0]['brawler'], t[0]['tag'], t[1]['brawler'], t[1]['tag'], t[2]['brawler'], t[2]['tag'] ] if fulltag in team: break # Star Player search sp = ['', '', ''] if b['battle']['starPlayer']['tag'] in team: i = team.index(b['battle']['starPlayer']['tag']) sp[i // 2] = "\n:star: STAR PLAYER :star:" embed.add_field(name='Outcome', value=result.capitalize()) embed.add_field( name='Result', value=f"{pptrophy_emoji} {trophychange:+}" ) embed.add_field(name='\u200b', value='\u200b') embed.add_field( name="Player 1", value=( f"{pptrophy_emoji} {team[0]['trophies']}\n" f"{team[0]['name']}\n" f"{username(team[1])}{sp[0]}" ) ) embed.add_field( name="Player 2", value=( f"{pptrophy_emoji} {team[2]['trophies']}\n" f"{team[2]['name']}\n" f"{username(team[3])}{sp[1]}" ) ) embed.add_field( name="Player 3", value=( f"{pptrophy_emoji} {team[4]['trophies']}\n" f"{team[4]['name']}\n" f"{username(team[5])}{sp[2]}" ) ) # Set embed colour if result == 'victory': if trophychange == 33: embed.colour = epic else: embed.colour = win elif result == 'defeat': embed.colour = loss # Write to DB insert_pp( battledate, b['battleTime'], mode, bmap, trophychange, team[1][1:], team[0]['name'], p2tag=team[3][1:], p2brawler=team[2]['name'], p3tag=team[5][1:], p3brawler=team[4]['name'] ) await pp_channel.send(embed=embed)