def on_ability(self, event, champion_name, ability="all"): ''' Displays information about a specific champions ability ''' champions = LeagueHelper.get_champion_data() game_info = GameInfo(self.league_helper) abilities = ["q", "w", "e", "r", "passive", "all"] champ_found = False if ability.lower() in ["ult", "ultimate"]: ability = "r" elif ability.lower() not in abilities: event.msg.reply( "This is not a valid ability, Try from one of these " + str(abilities)) return for key, name in champions["keys"].items(): if champion_name.lower() == name.lower(): champ_found = True if ability == "all": game_info.display_champ(event.msg.channel, champions["version"], champions["data"][name]) else: game_info.display_ability(event.msg.channel, champions["version"], champions["data"][name], ability) if not champ_found: event.msg.reply( "This champion does not exist! Try ~ability Akali Q as an example..." )
def on_patch(self, event, version=None): '''Displays the latest patch notes for League of Legends''' s = "." if not version: version = s.join(LeagueHelper.get_champion_data()["version"].split( ".", 2)[:2]) version_url = version.replace(".", "") patch_url = "http://na.leagueoflegends.com/en/news/game-updates/patch/patch-" + version_url + "-notes" version_url = "http://ddragon.leagueoflegends.com/api/versions.json" with urllib.request.urlopen(version_url) as url: raw_json = json.loads(url.read().decode()) versionExists = False for patch in raw_json: if patch.startswith(version): versionExists = True if not versionExists: event.msg.reply( "This is not a valid patch number. Try ~patch for the most recent patch notes!" ) return embed = CacheHelper.getZileanEmbed( title="League of Legends Patch Notes", description=version + " Patch Notes", footer=version + " Patch Notes") embed.add_field(name="Notes", value=patch_url) event.msg.reply(embed=embed)
def on_cm_graph(self, event, summoner_name=None, region=None): """Displays a graph of the summoners top 5 champions by mastery""" region = LeagueHelper.validate_region(region, event) if region: cm_graph = ChampionMasteryGraph(self.league_helper.watcher, region, LeagueHelper.get_champion_data()) if summoner_name is not None: filepath = "cm-" + summoner_name + ".png" else: filepath = "cm-default.png" self._graph_renderer(event, cm_graph, summoner_name, region, filepath)
def on_build(self, event, champion_name): '''Displays the highest winrate championGG build for the given champion''' champions = LeagueHelper.get_champion_data() champ_found = False for key, name in champions["keys"].items(): if champion_name.lower() == name.lower(): champion_builder = ChampionGGHelper() champion_builder.generate_build(event, champions["data"][name], champions["version"]) champ_found = True if not champ_found: event.msg.reply( "This champion does not exist! Try ~champion Akali as an example..." )
def on_champion(self, event, champion_name): '''Searches and displays the corresponding league of legends champion''' champions = LeagueHelper.get_champion_data() game_info = GameInfo(self.league_helper) champ_found = False for key, name in champions["keys"].items(): if champion_name.lower() == name.lower(): game_info.display_champ(event.msg.channel, champions["version"], champions["data"][name]) champ_found = True if not champ_found: event.msg.reply( "This champion does not exist! Try ~champion Akali as an example..." )
def on_kp_graph(self, event, summoner_name=None, region=None): """Displays a graph of your kill participation percentage over the last 20 games played""" region = LeagueHelper.validate_region(region, event) if region: kp_graph = KillParticipationGraph(self.league_helper.watcher, region, LeagueHelper.get_champion_data()) if summoner_name is not None: filepath = "kp-" + summoner_name + ".png" else: filepath = "kp-default.png" self._graph_renderer(event, kp_graph, summoner_name, region, filepath, match_validation=True)
def on_cw_graph(self, event, summoner_name=None, region=None): """Displays a graph of your wins per individual champion over the last 20 games played""" region = LeagueHelper.validate_region(region, event) if region: cw_graph = ChampionWinsGraph(self.league_helper.watcher, region, LeagueHelper.get_champion_data()) if summoner_name is not None: filepath = "cw-" + summoner_name + ".png" else: filepath = "cw-default.png" self._graph_renderer(event, cw_graph, summoner_name, region, filepath, match_validation=True)
def display_past_game(self, channel, region, match, summoner_id): # Find the current game mode that is being played using a CDragon json match["gameQueueConfigId"] = match["queueId"] description, queue_name, pick_type, is_ranked = self._get_queue_info( region, match) game_epoch = match["gameCreation"] game_duration = datetime.timedelta(seconds=match["gameDuration"]) game_date = datetime.datetime.fromtimestamp(game_epoch / 1000).strftime('%d-%m-%Y') champion_data = LeagueHelper.get_champion_data() image_url = "http://ddragon.leagueoflegends.com/cdn/" + champion_data[ "version"] + "/img/champion/" for participant in match["participantIdentities"]: if participant["player"]["currentAccountId"] == summoner_id: target_player = participant for participant in match["participants"]: if participant["participantId"] == target_player["participantId"]: target_champion_id = participant["championId"] target_stats = str(participant["stats"]["kills"]) + "/" + str( participant["stats"]["deaths"]) + "/" + str( participant["stats"]["assists"]) target_team = participant["teamId"] for team in match["teams"]: if team["teamId"] == target_team: match_outcome = team["win"] if match_outcome == "Fail": match_outcome = "Defeat" embed_color = 16711686 else: match_outcome = "Victory" embed_color = 65286 target_champion = champion_data["keys"][str(target_champion_id)] embed = CacheHelper.getZileanEmbed(title="Match History Game Info", description=queue_name) embed.set_thumbnail(url=image_url + target_champion + ".png") embed.color = embed_color embed.add_field(name="Summoner Name", value=target_player["player"]["summonerName"], inline=True) embed.add_field(name="Champion", value=target_champion, inline=True) embed.add_field(name="k/d/a", value=target_stats, inline=True) embed.add_field(name="Match Outcome", value=match_outcome, inline=True) embed.add_field(name="Game Duration:", value=str(game_duration), inline=True) embed.add_field(name="Game Date:", value=game_date, inline=True) embed.add_field( name="More Info", value= "http://matchhistory.euw.leagueoflegends.com/en/#match-details/" + region + "/" + str(match["gameId"]) + "/" + str(summoner_id) + "?tab=overview") channel.send_message(embed=embed)
def display_live_game(self, channel, region, spectate_info): channel.send_message("Game found generating live info...") if spectate_info["gameType"] == "CUSTOM_GAME": channel.send_message( "Custom game spectating is not supported SOONtm") return champion_data = LeagueHelper.get_champion_data() team_info = list() for participant in spectate_info["participants"]: champ_info = (participant["teamId"], participant["summonerName"], champion_data["keys"][str( participant["championId"])], participant["summonerId"]) team_info.append(champ_info) blue_names = "" blue_champs = "" red_names = "" red_champs = "" blue_rank = "" red_rank = "" # Find the current game mode that is being played using a CDragon json # Currently the CDragon json needs to be updated manually -> TODO description, queue_name, pick_type, is_ranked = self._get_queue_info( region, spectate_info) # Find the summoners names, champions and ranks on each team for participant in team_info: ranked_positions = self.league_helper.watcher.league.positions_by_summoner( region, participant[3]) rank, rank_type = self._get_rank_by_queue(queue_name, is_ranked, ranked_positions) if participant[0] == 100: blue_names += participant[1] + "\n" blue_champs += participant[2] + "\n" blue_rank += rank + "\n" else: red_names += participant[1] + "\n" red_champs += participant[2] + "\n" red_rank += rank + "\n" # Find the list of banned champions for both teams blue_ban, red_ban = self._get_banned_champions( spectate_info["bannedChampions"], champion_data) if description == "": description = "Playing an unknown gamemode/map -> Please update queue.json " # Format all of the live game info using a discord embed message embed = CacheHelper.getZileanEmbed(title="Live Game Info", description=description, footer="Live Game Info") embed.add_field(name=":large_blue_circle: Blue Team", value=blue_names, inline=True) embed.add_field(name="Rank", value=blue_rank, inline=True) embed.add_field(name="Champions:", value=blue_champs, inline=True) embed.add_field(name=":red_circle: Red Team", value=red_names, inline=True) embed.add_field(name="Rank", value=red_rank, inline=True) embed.add_field(name="Champions:", value=red_champs, inline=True) if "DRAFT" in pick_type: embed.add_field( name=":no_entry_sign: Red Team Bans :no_entry_sign:", value=red_ban, inline=True) embed.add_field( name=":no_entry_sign: Blue Team Bans :no_entry_sign:", value=blue_ban, inline=True) channel.send_message(embed=embed)
def on_summoner(self, event, summoner_name=None, region=None): '''Displays information about a League of Legends summoner''' # TODO: Tidy this up... # Prevent command quit on no region given if the discord user has bound a summoner to there account if region is None and summoner_name is None and LiveDataHelper.user_is_bound( LiveDataHelper.load_summoner_binds(), str( event.msg.author.id)): region = LiveDataHelper.get_user_bound_region( str(event.msg.author.id)) region = LeagueHelper.validate_region(region, event) if region is None: return summoner = self.league_helper.user_exists(region, summoner_name, event, event.msg.author.id) if not summoner: return version = LeagueHelper.get_champion_data()["version"] embed = CacheHelper.getZileanEmbed( title="Summoner Profile: ", footer="Displaying summoner info for " + summoner["name"], description=summoner["name"] + " " + region) embed.set_thumbnail(url="http://ddragon.leagueoflegends.com/cdn/" + version + "/img/profileicon/" + str(summoner["profileIconId"]) + ".png") embed.add_field(name="Summoner Level", value=str(summoner["summonerLevel"])) ranked_positions = self.league_helper.watcher.league.positions_by_summoner( region, summoner["id"]) ranks_array = ["RANKED SOLO 5x5", "RANKED FLEX TT", "RANKED FLEX SR"] for rank in ranked_positions: rank_name = rank["queueType"].replace("_", " ") embed.add_field(name="Queue Type", value=rank_name, inline=True) ranks_array.remove(rank_name) winrate = round( (rank["wins"] / (rank["wins"] + rank["losses"])) * 100) rank_msg = rank["tier"] + " " + rank["rank"] + " (" + str( rank["leaguePoints"]) + "lp)" winrate_msg = " | " + str(winrate) + "%" winloss_msg = " | W:" + str(rank["wins"]) + " L:" + str( rank["losses"]) embed.add_field(name="Rank | Wins/Losses | Winrate", value=rank_msg + winloss_msg + winrate_msg, inline=True) for rank in ranks_array: embed.add_field(name="Queue Type", value=rank, inline=True) embed.add_field(name="Rank | Wins/Losses | Winrate", value="UNRANKED", inline=True) try: matchlist = self.league_helper.watcher.match.matchlist_by_account( region, summoner["accountId"]) match = self.league_helper.watcher.match.by_id( region, matchlist["matches"][0]["gameId"]) for participant in match["participantIdentities"]: if participant["player"]["currentAccountId"] == summoner[ "accountId"]: target_player = participant for participant in match["participants"]: if participant["participantId"] == target_player[ "participantId"]: target_champion_id = participant["championId"] target_stats = str( participant["stats"]["kills"]) + "/" + str( participant["stats"]["deaths"]) + "/" + str( participant["stats"]["assists"]) target_team = participant["teamId"] for team in match["teams"]: if team["teamId"] == target_team: match_outcome = team["win"] if match_outcome == "Fail": match_outcome = "Defeat :x:" else: match_outcome = "Victory :white_check_mark:" target_champion = LeagueHelper.get_champion_data()["keys"][str( target_champion_id)] embed.add_field( name="Last Game Played:", value="**" + match_outcome + "**\n" + target_champion + " " + target_stats + " http://matchhistory.euw.leagueoflegends.com/en/#match-details/" + region + "/" + str(match["gameId"]) + "/" + str(summoner["accountId"]) + "?tab=overview") except HTTPError as err: if err.response.status_code == 404: embed.add_field( name="Last Game Played", value="This summoner has not recently played a game.") if not self.league_helper.user_in_game(region, summoner["id"]): embed.add_field( name="Live Game", value="This summoner is not currently in a live game.") else: embed.add_field( name="Live Game", value="This summoner is in a live game, type ~live_game " + region + " " + summoner_name + " for more info.") event.msg.reply(embed=embed)