def display_champ(self, channel, version, champion): image_url = "http://ddragon.leagueoflegends.com/cdn/" + version + "/img/champion/" spells = "" ability_list = ["Q", "W", "E", "R"] embed = CacheHelper.getZileanEmbed(title="Champion Info", description=champion["name"] + " " + champion["title"]) embed.add_field(name="Lore", value=champion["lore"]) embed.add_field(name="Passive - " + champion["passive"]["name"], value="\n" + champion["passive"]["description"]) for index, spell in enumerate(champion["spells"]): ability = ability_list[index] name = spell["name"] description = spell["description"] embed.add_field(name=ability + "- " + name, value="\n" + description) embed.set_thumbnail(url=image_url + champion["image"]["full"]) skin_num = random.randint(0, len(champion["skins"]) - 1) embed.set_image( url="http://ddragon.leagueoflegends.com/cdn/img/champion/splash/" + champion["name"] + "_" + str(skin_num) + ".jpg") embed.set_footer(text="Splash art: " + str(champion["skins"][skin_num]["name"])) channel.send_message(embed=embed)
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 display_ability(self, channel, version, champion, ability): embed = CacheHelper.getZileanEmbed(title="Champion Ability", description=champion["name"] + " " + champion["title"]) ability_list = ["Q", "W", "E", "R"] image_url = "http://ddragon.leagueoflegends.com/cdn/" + version + "/img/spell/" passive_url = "http://ddragon.leagueoflegends.com/cdn/" + version + "/img/passive/" if ability.lower() == "passive": embed.add_field(name="Passive - " + champion["passive"]["name"], value="\n" + champion["passive"]["description"]) embed.set_thumbnail(url=passive_url + champion["passive"]["image"]["full"]) else: spellIndex = 0 for index, abilityTrigger in enumerate(ability_list): if abilityTrigger.lower() == ability.lower(): spellIndex = index spell = champion["spells"][spellIndex] name = spell["name"] description = spell["description"] embed.add_field(name=ability.upper() + "- " + name, value="\n" + description) embed.set_thumbnail(url=image_url + spell["image"]["full"]) channel.send_message(embed=embed)
def on_help(self, event): """Displays help and command information about Zilean""" embed = CacheHelper.getZileanEmbed(title="Zilean Command List", footer="Zilean Commands", description="Note that [arg] is a required argument and (arg) is an optional argument") embed.add_field(name="Zilean Commands", value="You can view the commands by following the link below" + "\nhttps://samuel-maddock.github.io/Zilean/#command-section") embed.add_field(name="If you enjoy the bot please upvote it below:heart_exclamation:", value="https://discordbots.org/bot/459139146544578571") embed.add_field(name="If you have feature suggestions/spotted some bugs", value="Join the support server: https://discord.gg/ZjAyh7N") event.msg.author.open_dm().send_message(embed=embed) event.msg.author.open_dm().send_message(embed=self.get_notification()) event.msg.reply("Check your DMs for more information... :cyclone:")
def get_notification(self): embed = CacheHelper.getZileanEmbed(title="Recent Zilean Changes (" + self.version + ")", footer="Zilean Update", description= "For previous updates and changes go to the changelog here:\nhttps://samuel-maddock.github.io/Zilean/changelog.html\n\n" + "You can now bind a League of Legends summoner to your discord user by using the ~iam command. Try **~iam [summoner_name] [region]** to get started!\n\n" + "If you do this any command that requires a summoner name and region will work without writing those arguments eg ~match_history will display your own match history.\n\n" + "In order to support adding a default LoL region, the command structure for some commands have changed!" "\n\n" "For many LoL commands you used to state **[region] [summoner_name]** but now the order is **[summoner_name] (region)**." "\n\n" "The region is only optional if you set a default region for your server using **~region [league region]**" "\n\n**Note that you need to remove any spaces from a summoner name for the commands to work!**") embed.color = 0xFF3B73 return embed
def _display_region_status(self, event, region): region = LeagueHelper.validate_region(region) if region is None: event.msg.reply( "Please enter a valid **region**: *EUW, NA, EUN, JP, LAN, LAS, OCE, TR, RU, KR* :warning:" ) return embed = CacheHelper.getZileanEmbed( title="Zilean Bot", footer="League of Legends Server Status for " + region, description="Type ~status to see every regions status!") endpoint_status = self.league_helper.watcher.lol_status.shard_data( region) embed.add_field(name=endpoint_status["name"] + " (" + endpoint_status["slug"].upper() + ")", value="Server Status") services = endpoint_status["services"] for service in endpoint_status["services"]: embed.add_field(name=service["name"], value=self._emojify_status(service["status"]), inline=True) if len(service["incidents"]) != 0: embed.add_field(name="Incidents", value=str(len(service["incidents"])), inline=True) incident_msg = "" for incident in service["incidents"]: if len(incident["updates"]) != 0: recent_update = incident["updates"][0] incident_msg += incident["created_at"][ 0:10] + " " + recent_update["severity"].upper( ) + ": " + recent_update["content"] + "\n" embed.add_field(name="Incident Description", value=incident_msg, inline=True) else: embed.add_field(name="Incidents", value="No incidents!", inline=True) embed.add_field(name="Incident Description", value="N/A", inline=True) event.msg.reply(embed=embed)
def on_uptime(self, event): '''Displays how long Zilean has been online for''' uptime = datetime.now() - self.start_time hours = str(uptime.seconds//3600) minutes = str((uptime.seconds//60)%60) seconds = str(uptime.seconds%60) if (hours == "0"): hours = "00" if (minutes=="0"): minutes = "00" uptime_string = str(uptime.days) + " Days, " + hours + ":" + minutes + ":" + seconds + " (Hrs/Min/Sec)" embed = CacheHelper.getZileanEmbed(title="Zilean Uptime", footer="Zilean Bot", description="Zilean has been online for: " + uptime_string) event.msg.reply(embed=embed)
def on_info(self, event): """Displays information about the bot""" guild_list = self.client.state.guilds user_list = self.client.state.users channel_list = self.client.state.channels embed = CacheHelper.getZileanEmbed(title="Zilean Bot Info", footer="Bot Information", description="A discord bot that tracks time spent playing league and other statistics :hourglass_flowing_sand: https://samuel-maddock.github.io/Zilean/") embed.add_field(name="Version:", value=self.version) embed.add_field(name="Developed using:", value="https://github.com/pseudonym117/Riot-Watcher https://github.com/b1naryth1ef/disco") embed.add_field(name="Guilds Connected: ", value=len(guild_list), inline=True) embed.add_field(name="Users Connected: ", value=len(user_list), inline=True) embed.add_field(name="Channels Connected: ", value=len(channel_list), inline=True) embed.add_field(name="If you enjoy the bot please upvote it below:heart_exclamation:", value="https://discordbots.org/bot/459139146544578571") embed.add_field(name="If you have feature suggestions/spotted some bugs", value="Join the support server: https://discord.gg/ZjAyh7N") embed.add_field(name="Use ~help for a list of commands!", value=":wave:") event.msg.reply(embed=embed)
def display_item(self, channel, version, item): image_url = "http://ddragon.leagueoflegends.com/cdn/" + version + "/img/item/" embed = CacheHelper.getZileanEmbed(title=item["name"], description=item["plaintext"]) embed.set_thumbnail(url=image_url + item["image"]["full"]) description = re.sub('<[^<]+?>', '\n ', item["description"]) description = re.sub(r'(\n\s*)+\n+', '\n\n', description) embed.add_field(name="Item Description", value=description, inline=True) embed.add_field(name="Buy Price", value=str(item["gold"]["total"]) + " gold", inline=True) embed.add_field(name="Sell Price", value=str(item["gold"]["sell"]) + " gold", inline=True) channel.send_message(embed=embed)
def on_status(self, event, region=None): '''Displays the status of the league of legends servers. Use ~status (region) for a more detailed breakdown''' if region: self._display_region_status(event, region) return embed = CacheHelper.getZileanEmbed( title="League of Legends Server Status", description= "Use ~status [region] for a more detailed breakdown of server status! Displayed below is the game status", footer="League of Legends Server Status") for endpoint in LeagueHelper.API_ENDPOINTS: endpoint_status = self.league_helper.watcher.lol_status.shard_data( endpoint) embed.add_field(name=endpoint_status["name"] + " (" + endpoint_status["slug"].upper() + ")", value=self._emojify_status( endpoint_status["services"][0]["status"]), inline=True) event.msg.reply(embed=embed)
def _display_track(self, summoner_list, channel): game_found = False has_live_games = False summoner_names = "" regions = "" in_game = "" footer = "" connection_failure = False for summoner in summoner_list: summoner_failed = False auto_display = summoner[3] summoner_names += summoner[1] + "\n" regions += summoner[2] + "\n" try: spectate_info = self.league_helper.user_in_game( summoner[2], summoner[0]) except ConnectionError as e: logger = CacheHelper.get_logger("TrackerError") logger.zilean("Could not connect to the Riot API. Summoner: " + summoner[1] + "Channel: " + channel.name) summoner_failed = True connection_failure = True if spectate_info and not summoner_failed: in_game += "**Yes** | " + self.boolMsg(auto_display) + "\n" if auto_display: game_info = GameInfo(self.league_helper) game_info.display_live_game(channel, summoner[2], spectate_info) has_live_games = True elif not summoner_failed: in_game += "No | " + self.boolMsg(auto_display) + "\n" else: in_game += "Summoner info cannot be retrieved at this time\n" if connection_failure: footer = "Error retrieving one or more summoners info" if not has_live_games: footer = "No one is currently in a live game :(" else: footer = "To view a summoner in game use ~game_info <region> <summoner_name>" description = "This message is automatically displayed every " + str(int(TRACKER_SCHEDULE/60)) + " minutes!" + \ "\n If auto-display is turned on for a summoner their game is automatically displayed" embed = CacheHelper.getZileanEmbed( title=":eye: Tracking Live Games... :eye:", description=description, footer=footer) embed.add_field(name="Summoner Name", value=summoner_names, inline=True) embed.add_field(name="Region", value=regions, inline=True) embed.add_field(name="In Game | Auto-Display", value=in_game, inline=True) if connection_failure: embed.add_field( name="Connection Issue", value= "One or more summoners info could not be retrieved. Please try again in a few minutes." ) try: channel.send_message(embed=embed) except ConnectionError as e: logger = CacheHelper.get_logger("TrackerError") logger.zilean( "Tracker message failed to send. Could not connect to the Discord API" ) except APIException as e: logger = CacheHelper.get_logger("TrackerError") logger.zilean("APIException - " + str(e.status_code))
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)
def generate_build(self, event, champion, version): # For ChampionGG API Documentation: http://api.champion.gg/docs/#api-Champions-GetChampion # This sends a GET request to the championGG API and retrieves the champions highest winrate build champion_id = champion["key"] embed = CacheHelper.getZileanEmbed(title="Champion Build", description=champion["name"] + " " + champion["title"]) api_url = "http://api.champion.gg/v2/champions/" + champion_id + "?champData=hashes&api_key=" + self.key response = urllib.request.urlopen(api_url) build_info = json.loads(response.read().decode("utf-8"))[ 0] # Decode the byte response to json object # The above also stores the json dict and not the array of the dict # Retrieve hashes for the highest winrate build hashes = build_info["hashes"] skill_order = hashes["skillorderhash"]["highestWinrate"]["hash"].strip( "skill-") start_items = hashes["firstitemshash"]["highestWinrate"]["hash"].strip( "first-") final_items = hashes["finalitemshashfixed"]["highestWinrate"][ "hash"].strip("items-") rune_hash = hashes["runehash"]["highestWinrate"]["hash"] # Convert hashes into viewable strings items = LeagueHelper.get_item_data() runes = LeagueHelper.get_rune_data() start_items, start_build_urls = self.parse_item_hash( start_items, items, True) final_items, final_build_urls = self.parse_item_hash( final_items, items, True) rune_message_1, rune_message_2, rune_path_urls = self.parse_rune_hash( rune_hash, runes) skill_order = skill_order.replace("-", ">") # Generate the final build image self.generate_build_image(final_build_urls, "finalbuild.png") self.generate_build_image(start_build_urls, "startbuild.png") self.generate_build_image(rune_path_urls[0:5], "runepath1.png") self.generate_build_image(rune_path_urls[5:8], "runepath2.png") # Append and send message embed and images image_url = "http://ddragon.leagueoflegends.com/cdn/" + version + "/img/champion/" embed.set_thumbnail(url=image_url + champion["image"]["full"]) embed.add_field(name="ProBuilds: " + champion["name"], value="https://www.probuilds.net/champions/details/" + champion["name"]) embed.add_field(name="In-Depth Builds:", value="https://www.mobafire.com/league-of-legends/" + champion["name"] + "-guide?sort=patch&order=ascending&author=all&page=1") embed.add_field(name="Skill Order", value=skill_order) event.msg.reply(embed=embed) event.msg.reply("**Recommended Starting Items:**\n" + start_items, attachments=[("startbuild.png", open("startbuild.png", "rb"))]) event.msg.reply("**Recommended Final Build:**\n" + final_items, attachments=[("finalbuild.png", open("finalbuild.png", "rb"))]) event.msg.reply("**Recommended Runes:**\n" + rune_message_1, attachments=[("runepath1.png", open("runepath1.png", "rb"))]) event.msg.reply(rune_message_2, attachments=[("runepath2.png", open("runepath2.png", "rb"))])