Exemplo n.º 1
0
def summoner(message):
    name = util.extract_arguments(message.text)

    if not name:
        bot.send_message(message.chat.id, "Especifique un nombre de invocador")
    else:
        cid = chat_id = message.chat.id
        region = Chat.get_config(cid, "region")

        if region is None:
            bot.send_message(
                message.chat.id,
                "Utiliza /region para seleccionar una region primero")
        else:
            url = 'https://' + region.value + '.api.riotgames.com/lol/summoner/v4/summoners/by-name/' + name
            params = {'api_key': RIOT_KEY}
            r = requests.get(url, params)

            if (r.status_code in range(200, 299)):  #Request accepted
                content = r.json()
                summonerId = content["id"]

                url = 'https://' + region.value + '.api.riotgames.com/lol/league/v4/positions/by-summoner/' + summonerId
                r = requests.get(url, params)
                contentLeague = r.json()

                text = "*Nombre:* " + str(
                    content["name"]) + "\n*Nivel:* " + str(
                        content["summonerLevel"]) + "\n"
                text += "*SoloQ:* " + contentLeague[0][
                    "tier"] + " " + contentLeague[0]["rank"] + " -> " + str(
                        contentLeague[0]["leaguePoints"]) + " LP\n"
                text += "             *Victorias:* " + str(
                    contentLeague[0]["wins"]) + "\n"
                text += "             *Derrotas:* " + str(
                    contentLeague[0]["losses"]) + "\n\n"

                url = 'https://' + region.value + '.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/' + summonerId
                r = requests.get(url, params)
                contentChamp = r.json()

                champ = ""
                with open('champion.json') as json_file:
                    file = json.load(json_file)
                    champion_list = file['data']
                    for champion_name in champion_list.keys():
                        if champion_list[champion_name]['key'] == str(
                                contentChamp[0]["championId"]):
                            champ += champion_list[champion_name]['name']

                text += "*Mejor campeón:* " + champ

                bot.send_message(message.chat.id, text, parse_mode="Markdown")
            else:  #Request error
                bot.send_message(message.chat.id, "Invocador desconocido")
Exemplo n.º 2
0
def load(message):
    """
    Recupera un dato guardado con save
    """

    chat_id = message.chat.id
    data = Chat.get_config(chat_id, 'memory')
    if not data:
        bot.reply_to(message, "Aún no has guardado nada")
        return

    bot.reply_to(message, "Dato recuperado: %s" % data.value)
Exemplo n.º 3
0
def region(message):
    uid = message.chat.id
    data = Chat.get_config(uid, "region")
    if data is not None:
        bot.reply_to(message, "%s actualmente seleccionada" %data.value)
    region_board(message)