示例#1
0
    def on_item(self, event, item_name):
        '''Searches and displays the corresponding league of legends item'''
        items = LeagueHelper.get_item_data()
        game_info = GameInfo(self.league_helper)
        item_found = False

        for key, value in items["data"].items():
            if item_name.lower() in value["name"].lower(
            ) and len(item_name) > 3:
                game_info.display_item(event.msg.channel, items["version"],
                                       items["data"][key])
                item_found = True

        if not item_found:
            event.msg.reply("This item does not exist...")
示例#2
0
    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"))])