Ejemplo n.º 1
0
    def on_track(self, event, summoner_name=None, region=None):
        '''Adds a summoner for Zilean to track whether they are in a live game'''
        if event.msg.channel.is_dm:
            return event.msg.reply("You must use this command in a guild!")

        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, author_id=event.msg.author.id)

        if summoner is False:
            event.msg.reply("This summoner `" + summoner_name +
                            "` does not exist on `" + region +
                            "` Maybe try another region!")
            return

        self._add_summoner(event, region, summoner)
Ejemplo n.º 2
0
    def on_remove(self, event, summoner_name=None, region=None):
        '''Removes a summoner that is being tracked by Zilean'''
        if event.msg.channel.is_dm:
            return event.msg.reply("You must use this command in a guild!")

        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))
            summoner_name = LiveDataHelper.get_user_bound_name(
                str(event.msg.author.id))

        region = LeagueHelper.validate_region(region,
                                              event,
                                              send_event_msg=False)

        if not self._summoner_is_tracked(event.guild.id, summoner_name,
                                         region):
            event.msg.reply(
                "This summoner `" + summoner_name + " " + region +
                "` is not being tracked. Track them by ~tracker add <region> <summoner_name>"
            )
            return

        self._remove_summoner(event, region, summoner_name)
Ejemplo n.º 3
0
    def on_iam(self, event, summoner_name=None, region=None):
        '''Set a default summoner for yourself that all league commands will use if you leave their summoner name and region arguments blank'''
        summoner_binds = LiveDataHelper.load_summoner_binds()
        author_id = str(event.author.id)

        if summoner_name is None and region is None:
            if LiveDataHelper.user_is_bound(summoner_binds, author_id):
                summoner_tuple = summoner_binds[author_id]
                event.msg.reply("You are `" + summoner_tuple[0] + " " + summoner_tuple[1] + "` If you want to change this type ~iam [summoner_name] [region]")
            else:
                event.msg.reply("You have not bound a summoner to your discord user! To do this type `~iam [summoner_name] [region]`")
        elif (summoner_name is not None) and (region is not None):
            region = LeagueHelper.validate_region(region, event)
            if region is None:
                return

            summoner = self.league_helper.user_exists(region, summoner_name, event)
            if summoner is False:
                return

            summoner_tuple = (summoner["name"], region)
            summoner_binds[author_id] = summoner_tuple
            LiveDataHelper.save_summoner_binds(summoner_binds)
            event.msg.reply("You have updated your summoner, You are `" + summoner["name"] + " " + region + "`")
        else:
            event.msg.reply("You must enter both a summoner name and region!")
Ejemplo n.º 4
0
    def on_live_game(self, event, summoner_name=None, region=None):
        '''Displays the live game info if a summoner is in a game. Supports all game types and ranked modes'''

        # 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 summoner:
            spectate_info = self.league_helper.user_in_game(
                region, summoner["id"])
            if spectate_info:
                game_info = GameInfo(self.league_helper)
                game_info.display_live_game(event.msg.channel, region,
                                            spectate_info)
            else:
                event.msg.reply("This summoner `" + summoner["name"] + " " +
                                region + "` is not currently in a game!")
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 def on_gpm_graph(self, event, summoner_name=None, region=None):
     """Displays a graph of the league games played per month per year"""
     region = LeagueHelper.validate_region(region, event)
     if region:
         gpm_graph = GamesPerMonthGraph(self.league_helper.watcher, region)
         if summoner_name is not None:
             filepath = "gpm-" + summoner_name + ".png"
         else:
             filepath = "gpm-default.png"
         self._graph_renderer(event,
                              gpm_graph,
                              summoner_name,
                              region,
                              filepath,
                              match_validation=True)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
    def on_auto(self, event, region, summoner_name):
        '''Toggles a summoner that is being tracked to auto-display there game'''

        # Need to rework this command!
        event.msg.reply(
            "This command is currently being rehauled. For more information join the support server: https://discord.gg/ZjAyh7N"
        )
        return
        # TODO: Rework this command

        if event.msg.channel.is_dm:
            return event.msg.reply("You must use this command in a guild!")

        region = LeagueHelper.validate_region(region)

        if not self._summoner_is_tracked(event.guild.id, summoner_name,
                                         region):
            event.msg.reply(
                "This summoner is not being tracked. Track them by ~tracker add <region> <summoner_name>"
            )
            return

        tracker = self.tracker
        guild_id = str(event.guild.id)
        summoner_list = tracker[guild_id]
        auto_message = "no longer being auto-displayed :x:"

        for index, summoner_tuple in enumerate(summoner_list):
            if summoner_tuple[1] == summoner_name.lower(
            ) and region == summoner_tuple[2]:
                summoner_tuple = summoner_list[index]
                summoner_list[index] = (summoner_tuple[0], summoner_tuple[1],
                                        summoner_tuple[2],
                                        not summoner_tuple[3]
                                        )  # Invert the current bool
                if summoner_list[index][3]:
                    auto_message = "now being auto-displayed :white_check_mark:"

        tracker[guild_id] = summoner_list
        self.update_tracker(tracker)
        event.msg.reply("The summoner `" + summoner_name + "` is " +
                        auto_message)
Ejemplo n.º 11
0
    def on_region(self, event, region=None):
        '''Sets the overall default region for League of Legends commands'''
        region_binds = LiveDataHelper.load_region_binds()
        endpoints = str(LeagueHelper.API_ENDPOINTS).replace("[","").replace("'","").replace("]", "")

        if region is None:
            if LiveDataHelper.guild_has_region(region_binds, str(event.guild.id)):
                event.msg.reply("The current default region for League of Legends commands is: `" + region_binds[str(event.guild.id)] + "`")
            else:
                event.msg.reply("This server does not currently have a default region for League of Legends commands.\nTry ~region [region] where the region is one of the following: `" + endpoints + "`")
        else:
            region = LeagueHelper.validate_region(region, event, send_event_msg=False)
            if region is None:
                event.msg.reply("You have entered an invalid region, please enter one of the following: `" + endpoints + "`")
                return

            region_binds = LiveDataHelper.load_region_binds()
            region_binds[str(event.guild.id)] = region
            LiveDataHelper.save_region_binds(region_binds)
            event.msg.reply("The default region for League of Legends commands is now `" + region + "`")
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
    def on_recent_game(self,
                       event,
                       summoner_name=None,
                       region=None,
                       game_number=0):
        '''Displays a match in the summoners match history, by default displays the most recent game'''

        game_number = game_number - 1

        if game_number < 0:
            game_number = 0

        # If we want users to have a summoner bound to them we have to deal with the game number being passed as the summoner_name...
        if region 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))
            try:
                game_number = int(summoner_name)
                game_number = game_number - 1
                if game_number < 0:
                    game_number = 0
                summoner_name = None
            except ValueError as err:
                pass
            except TypeError as err:
                pass

        # If we want users to choose a match history game and use the default region for the server
        # Then the game number is actually passed to the region variable
        # So we swap them or just leave it if the game number they has passed is not an int
        if LiveDataHelper.guild_has_region(
                LiveDataHelper.load_region_binds(), str(
                    event.guild.id)) and region is not None:
            try:
                game_number = int(region)
                game_number = game_number - 1
                if game_number < 0:
                    game_number = 0
                region = None
            except ValueError as err:
                pass
            except TypeError as err:
                pass

        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

        # TODO: has_match_history returns false if history < 20, need to change this...
        if not self.league_helper.has_match_history(region, summoner["name"]):
            event.msg.reply(
                "This summoner has no valid match history at this time `" +
                region + "`")
            return

        matchlist = self.league_helper.watcher.match.matchlist_by_account(
            region, summoner["accountId"])

        if game_number > len(matchlist["matches"]):
            event.msg.reply(
                "The game number entered has exceeded the number of games available `Max Games: "
                + str(len(matchlist["matches"])) + "`")
            return
        else:
            game_info = GameInfo(self.league_helper)
            match = self.league_helper.watcher.match.by_id(
                region, matchlist["matches"][game_number]["gameId"])
            game_info.display_past_game(event.msg.channel, region, match,
                                        summoner["accountId"])