Esempio n. 1
0
def rank():
    try:
        if request.form.get('token') == SLACK_WEBHOOK_SECRET:
            # Get channel name and text after command
            channel     = request.form.get('channel_name')
            text        = request.form.get('text')
            # Get summoner information
            summoner    = riotapi.get_summoner_by_name(text)
            # Get ranked information about the summoner
            rank        = riotapi.get_league_entries_by_summoner(summoner)
            rankInfo    = [rank[0].tier, rank[0].entries[0].division, rank[0].entries[0].league_points]
            message     = str(text) + " is currently " + str(rankInfo[0])[5:].capitalize() + " " + str(rankInfo[1])[9:].capitalize() + " with " + str(rankInfo[2]) + " lp."
            send_message(channel,message)
        return Response(),200
    except Exception as e:
        return "I could not find that summoner, maybe they are not ranked yet."
Esempio n. 2
0
def winrate():
    try:
        if request.form.get('token') == SLACK_WEBHOOK_SECRET:
            # Code for winrate
            # Get channel name and text after command
            channel     = request.form.get('channel_name')
            text        = request.form.get('text')
            # Get summoner information
            summoner    = riotapi.get_summoner_by_name(text)
            # Get winrates for summoner
            rank        = riotapi.get_league_entries_by_summoner(summoner)
            winrate    = (int(rank[0].entries[0].wins)/(int(rank[0].entries[0].wins) + int(rank[0].entries[0].losses)))
            message     = str(text) + " has a ranked winrate of " + "{0:.0%}".format(winrate)
            send_message(channel,message)
        return Response(),200
    except Exception as e:
        return "I could not find that summoner"
Esempio n. 3
0
def test_league_entries_by_summoner():
    int_test_handler.test_result(
        riotapi.get_league_entries_by_summoner(
            riotapi.get_summoner_by_id(int_test_handler.summoner_id)))
Esempio n. 4
0
    async def lookup(self, ctx, sumName: str, region: str):
        """'Summoner Name' 'Region'"""
        if "'" in sumName:
            await self.bot.send_message(
                ctx.message.channel,
                "Please use double quotes to enclose names.")
            return
        await self.bot.send_typing(ctx.message.channel)
        title = "Summoner Lookup - {0} ({1})".format(sumName, region)
        em = discord.Embed(title=title, colour=0x1affa7)
        loop = 0
        overallWins = 0
        overallLosses = 0
        riotapi.set_region(region)
        summoner = riotapi.get_summoner_by_name(sumName)
        leagues = riotapi.get_league_entries_by_summoner(summoner)
        topChamp = riotapi.get_top_champion_masteries(summoner, max_entries=3)
        topChamps = "{0}, {1} and {2}".format(topChamp[0].champion.name,
                                              topChamp[1].champion.name,
                                              topChamp[2].champion.name)
        em.add_field(name="Top Champions", value=topChamps, inline=False)
        if " " in topChamp[0].champion.name:
            urlChampName = topChamp[0].champion.name.replace(" ", "")
            url = 'http://ddragon.leagueoflegends.com/cdn/7.3.3/img/champion/{}.png'.format(
                urlChampName)
        elif "Vel'Koz" in topChamp[0].champion.name:
            url = 'http://ddragon.leagueoflegends.com/cdn/7.3.3/img/champion/Velkoz.png'
        elif "Kha'Zix" in topChamp[0].champion.name:
            url = 'http://ddragon.leagueoflegends.com/cdn/7.3.3/img/champion/Khazix.png'
        elif "Rek'Sai" in topChamp[0].champion.name:
            url = 'http://ddragon.leagueoflegends.com/cdn/7.3.3/img/champion/RekSai.png'
        elif "Cho'Gath" in topChamp[0].champion.name:
            url = 'http://ddragon.leagueoflegends.com/cdn/7.8.1/img/champion/Chogath.png'
        elif "Kog'Maw" in topChamp[0].champion.name:
            url = 'http://ddragon.leagueoflegends.com/cdn/7.8.1/img/champion/KogMaw.png'
        else:
            url = 'http://ddragon.leagueoflegends.com/cdn/7.3.3/img/champion/{}.png'.format(
                topChamp[0].champion.name)
        em.set_thumbnail(url=url)
        for league in leagues:
            loop += 1
            queue = league.queue.value
            tier = league.tier.value
            for entries in league.entries:
                division = entries.division.value
                lp = str(entries.league_points) + ' LP'
                wins = entries.wins
                overallWins += wins
                losses = entries.losses
                overallLosses += losses
            if queue == 'RANKED_SOLO_5x5':
                ratio = (wins / (wins + losses) * 100)
                value = "{0} {1} {2} ({3}W/{4}L {5:.2f}%)".format(
                    tier, division, lp, wins, losses, ratio)
                em.add_field(name="Ranked Solo", value=value, inline=False)
            elif queue == 'RANKED_FLEX_SR':
                ratio = (wins / (wins + losses) * 100)
                value = "{0} {1} {2} ({3}W/{4}L {5:.2f}%)".format(
                    tier, division, lp, wins, losses, ratio)
                em.add_field(name="Ranked Flex", value=value, inline=False)
            elif queue == 'RANKED_FLEX_TT':
                ratio = (wins / (wins + losses) * 100)
                value = "{0} {1} {2} ({3}W/{4}L {5:.2f}%)".format(
                    tier, division, lp, wins, losses, ratio)
                em.add_field(name="Ranked TT", value=value, inline=False)
            overallRatio = (overallWins / (overallWins + overallLosses) * 100)
        value1 = "{0}W/{1}L ({2:.2f})%".format(overallWins, overallLosses,
                                               overallRatio)

        em.add_field(name="Overall", value=value1, inline=False)
        await self.bot.send_message(ctx.message.channel, "", embed=em)
Esempio n. 5
0
def test_league_entries_by_summoner():
    int_test_handler.test_result(riotapi.get_league_entries_by_summoner(riotapi.get_summoner_by_id(int_test_handler.summoner_id)))
Esempio n. 6
0
def matchlistpage(zone, name):


    # Set region and after region is set, fetch latest API version, maybe move the version to a scheduled task if it uses a call.
    riotapi.set_region(zone)

    if zone in ['na', 'kr', 'euw', 'eune']:
        cassdb = SQLAlchemyDB(connector, host, dbnames[zone]+"?charset=utf8", user, passwd)
        riotapi.set_data_store(cassdb)

    print("======================")
    print(zone)
    print(name)
    print("======================")

    patch = riotapi.get_versions()[0]


    # Used to convert numerals to/from numbers
    romans =    {
                    'I': 1,
                    'II': 2,
                    'III': 3,
                  'IV': 4,
                  'V': 5
                }


    print("==========   DB MADE Trying to get summoner by name     ===========")
    # Get summoner
    s = riotapi.get_summoner_by_name(name)
    print("Summoner object:")
    print(s)
    print("id:{} name:{} level:{}".format(s.id, s.name, s.level))
    print("==========   GOT S, trying to get league entries     ===========")
    try:
        le = riotapi.get_league_entries_by_summoner(s)[0]
        entry = le.entries[0]
        print("Got league entries for ranked")
    except:
        print("Couldnt fetch le/entry. Perhaps unranked.")
        le = None
        entry = None
    print("==========   Trying to get ranked stats     ===========")
    try:
        stats = riotapi.get_ranked_stats(s, season=None)[None]
    except:
        print("Couldnt fetch ranked stats. Maybe not lv30/never did ranked.")
        stats = None
    print("==========   Trying to get matches     ===========")
    ml = riotapi.get_match_list(s, seasons=[x.value for x in Season][-1], num_matches=10)
    if ml is not None:
        matches = [][-10:]
        for x in ml:
            try:
                m_to_add = riotapi.get_match(x)
                matches.append(m_to_add)
            except exc.IntegrityError as ie:
                print("==SQL ERROR ---> {}".format(ie))
                print("==Python traceback==")
                print(traceback.print_exc())
                cassdb.session.rollback()
    else:
        matches = []



    print("==========   Trying to render template     ===========")


    return render_template('matchlist.html',
                            s = s,
                            entry = entry,
                            le = le,
                            matches = matches,
                            patch = patch,
                            stats = stats,
                            zone = zone,
                            round = round,
                            len = len,
                            romans = romans)
Esempio n. 7
0
def matchlistpage(zone, name):


    # Set region & fetch latest api version
    riotapi.set_region(zone)

    # Set data store
    # *** REMOVED UNTIL CASSIOPEIA 2.0 ***

    patch = riotapi.get_versions()[0]


    # Roman->number conversion
    romans = {
        'I': 1,
        'II': 2,
        'III': 3,
        'IV': 4,
        'V': 5
    }


    # Get summoner
    s = riotapi.get_summoner_by_name(name)
    print("Summoner object: {}".format(s))
    print("ID: {} NAME: {} LEVEL: {}".format(s.id, s.name, s.level))

    # Get league entries
    try:
        le = riotapi.get_league_entries_by_summoner(s)[0]
        entry = le.entries[0]
        print("Got League entries for ranked")
    except:
        le = None
        entry = None
        print("Couldnt fetch le/entry. Perhaps unranked. Setting le and entry to None. Exception traceback:")
        print(traceback.print_exc())

    # Get ranked stats
    try:
        stats = riotapi.get_ranked_stats(s, season=None)[None]
        print("Got ranked stats")
    except:
        stats = None
        print("Couldnt fetch ranked stats. Perhaps not lv30 or never ranked. Setting stats to None. Exception traceback:")
        traceback.print_exc()

    # Get matches
    # *** DISABLED. PAGE WILL ONLY CHECK IF IN CURRENT GAME THROUGH JAVASCRIPT THEN OFFER CURRENTGAME BUTTON ***


    print("===== RENDERING TEMPLATE =====")

    return render_template('matchlist2.html',
                            s = s,
                            entry = entry,
                            le = le,
                            patch = patch,
                            stats = stats,
                            zone = zone,
                            round = round,
                            len = len,
                            romans = romans)
Esempio n. 8
0
    async def search(self, ctx, sum_name: str, region=None):
        """'Summoner Name' '[optional] Region'"""
        if region is None:
            try:
                db = database.Database('guilds.db')
                region = db.find_entry(ctx.guild.id)
                db.close_connection()
            except TypeError:
                embed = utilities.error_embed(
                    ctx,
                    "Please specify a region, or set a default region with `b!region set [region]`."
                )
                await ctx.send("", embed=embed)
                return

        if "'" in sum_name:
            embed = utilities.error_embed(
                ctx, "Please use quotation marks to enclose names")
            await ctx.send("", embed=embed)
            return

        await ctx.trigger_typing()

        try:
            riotapi.set_region(region)
        except ValueError:
            embed = utilities.error_embed(
                ctx,
                "{0} is not a valid region! Valid regions are listed in `b!region list`."
                .format(region))
            await ctx.send("", embed=embed)
            return

        try:
            summoner = riotapi.get_summoner_by_name(sum_name)
            leagues = riotapi.get_league_entries_by_summoner(summoner)
            top_champ = riotapi.get_top_champion_masteries(summoner,
                                                           max_entries=3)
        except APIError as exception:
            await Summoner.raise_exception(self, ctx, exception, sum_name,
                                           region)
            return

        db = database.Database("guilds.db")
        user = db.find_user(str(ctx.guild.id), sum_name)
        if user is None:
            db.add_user(str(ctx.guild.id), sum_name, region)
            db.close_connection()

        embed = discord.Embed(colour=0x1affa7)
        top_champs = "{0}, {1} and {2}".format(top_champ[0].champion.name,
                                               top_champ[1].champion.name,
                                               top_champ[2].champion.name)
        icon_url = 'http://ddragon.leagueoflegends.com/cdn/6.24.1/img/profileicon/{}.png'.format(
            summoner.profile_icon_id)
        overall_wins, overall_losses = 0, 0

        for league in leagues:
            queue = league.queue.value
            tier = league.tier.value
            for entries in league.entries:
                division = entries.division.value
                league_points = str(entries.league_points) + ' LP'
                wins = entries.wins
                losses = entries.losses
                overall_wins += wins
                overall_losses += losses
                ratio = (wins / (wins + losses) * 100)

            if queue == 'RANKED_SOLO_5x5':
                embed.add_field(name="Ranked Solo:",
                                value=u'\u200B',
                                inline=True)
                embed.add_field(name="Division",
                                value="{0} {1} - {2}".format(
                                    tier, division, league_points),
                                inline=True)
                embed.add_field(name="W/L",
                                value="{0}W - {1}L ({2:.0F}%)".format(
                                    wins, losses, ratio),
                                inline=True)
                embed.add_field(name=u"\u200B", value=u"\u200B", inline=False)
            elif queue == 'RANKED_FLEX_SR':
                embed.add_field(name="Ranked Flex:",
                                value=u'\u200B',
                                inline=True)
                embed.add_field(name="Division",
                                value="{0} {1} - {2}".format(
                                    tier, division, league_points),
                                inline=True)
                embed.add_field(name="W/L",
                                value="{0}W - {1}L ({2:.0F}%)".format(
                                    wins, losses, ratio),
                                inline=True)
                embed.add_field(name=u"\u200B", value=u"\u200B", inline=False)
            elif queue == 'RANKED_FLEX_TT':
                embed.add_field(name="Ranked TT:",
                                value=u'\u200B',
                                inline=True)
                embed.add_field(name="Division",
                                value="{0} {1} - {2}".format(
                                    tier, division, league_points),
                                inline=True)
                embed.add_field(name="W/L",
                                value="{0}W - {1}L ({2:.0F}%)".format(
                                    wins, losses, ratio),
                                inline=True)
                embed.add_field(name=u"\u200B", value=u"\u200B", inline=False)

            overall_ratio = (overall_wins / (overall_wins + overall_losses) *
                             100)

        overall = "{0}W/{1}L ({2:.2f})%".format(overall_wins, overall_losses,
                                                overall_ratio)
        op_gg = "https://{0}.op.gg/summoner/userName={1}".format(
            region, sum_name.replace(" ", "%20"))
        embed.set_author(name="Summoner Lookup - {0} ({1})".format(
            sum_name, region),
                         url=op_gg,
                         icon_url=icon_url)
        embed.add_field(name="Overall:", value=u'\u200B', inline=True)
        embed.add_field(name="Top Champions", value=top_champs, inline=True)
        embed.add_field(name="W/L", value=overall, inline=True)
        utilities.footer(ctx, embed)
        await ctx.send("", embed=embed)