def import_champs(): w = RiotWatcher(os.environ.get('RIOT_API_KEY')) champs = w.static_get_champion_list() new_champs = {} for champ in champs['data'].itervalues(): new_champs[champ['id']] = champ['name'] return new_champs
def fill_champions(c, api_key): api = RiotWatcher(api_key) try: all_champions = api.static_get_champion_list(None, None, None, None, "image") except: print("Error getting all champions:", sys.exc_info()[0]) return for _, champion in all_champions["data"].iteritems(): wiki_url = "http://leagueoflegends.wikia.com/wiki/" + champion["name"] splash_image = champion["key"] + "_0.jpg" c.execute(''' INSERT INTO Champion (Id, Name, Title, WikiLink, Image, SplashImage) VALUES (?, ?, ?, ?, ?, ?) ''', (champion["id"], champion["name"], champion["title"], wiki_url, champion["image"]["full"], splash_image))
class Request: def __init__(self): self.riot = RiotWatcher(LoL.API_KEY) self.champions = self._getChampions() def _getChampions(self): champion_list = {} champions = self.riot.static_get_champion_list() for champion in champions["data"]: champion_list[champions["data"][champion]["id"]] = champion return champion_list def _checkRequestStatus(self): return self.riot.can_make_request() def retrievePlayerData(self, playerId): while not self._checkRequestStatus(): sleep(2.6) else: player = {} player["id"] = playerId player["summoner"] = self.riot.get_summoner(name=playerId) player["match_history"] = self.riot.get_match_history(player["summoner"]["id"]) return player
async def on_ready(bot): # Obtain all static data required watcher = RiotWatcher(bot.configurations['discrank.py']['token']) if not watcher.can_make_request(): raise BotException(ErrorTypes.STARTUP, EXCEPTION, "The given Riot API token cannot get requests.") # Add champions by ID and name, and skills by ID champions = watcher.static_get_champion_list(data_by_id=True)['data'] champions_named = watcher.static_get_champion_list()['data'] champions_named = dict( (key.lower(), value) for key, value in champions_named.items()) champions.update(champions_named) spells = watcher.static_get_summoner_spell_list(data_by_id=True)['data'] # Add game modes by queue type and name modes = { "0": "Custom", "8": "Normal 3v3", "2": "Normal", "14": "Normal Draft", "4": "Dynamic Queue", "6": "Dynamic Queue", "9": "Ranked 3v3", "41": "Ranked 3v3", "42": "Ranked 5v5", "16": "This Gamemode doesn't even exist anymore", "17": "Same with this one", "7": "Co-op vs AI", "25": "Co-op vs AI", "31": "Co-op vs AI", "32": "Co-op vs AI", "33": "Co-op vs AI", "52": "Co-op vs AI (3v3)", "61": "Team Builder", "65": "ARAM", "70": "One For All", "72": "Magma Chamber 1v1", "73": "Magma Chamber 2v2", "75": "Hexakill", "76": "URF", "83": "Co-op vs AI (URF)", "91": "Doom Bots Lv 1", "92": "Doom Bots Lv 2", "93": "Doom Bots Lv 3", "96": "Ascension", "98": "Hexakill", "100": "Bilgewater", "300": "Legend of the Poro King", "313": "Bilgewater ARAM", "400": "Team Builder", "410": "Dynamic Queue", "CUSTOM": "0", "NORMAL_3x3": "8", "NORMAL_5x5_BLIND": "2", "NORMAL_5x5_DRAFT": "14", "RANKED_SOLO_5x5": "4", "RANKED_PREMADE_5x5*": "6", "RANKED_PREMADE_3x3*": "9", "RANKED_TEAM_3x3": "41", "RANKED_TEAM_5x5": "42", "ODIN_5x5_BLIND": "16", "ODIN_5x5_DRAFT": "17", "BOT_5x5*": "7", "BOT_ODIN_5x5": "25", "BOT_5x5_INTRO": "31", "BOT_5x5_BEGINNER": "32", "BOT_5x5_INTERMEDIATE": "33", "BOT_TT_3x3": "52", "GROUP_FINDER_5x5": "61", "ARAM_5x5": "65", "ONEFORALL_5x5": "70", "FIRSTBLOOD_1x1": "72", "FIRSTBLOOD_2x2": "73", "SR_6x6": "75", "URF_5x5": "76", "BOT_URF_5x5": "83", "NIGHTMARE_BOT_5x5_RANK1": "91", "NIGHTMARE_BOT_5x5_RANK2": "92", "NIGHTMARE_BOT_5x5_RANK5": "93", "ASCENSION_5x5": "96", "HEXAKILL": "98", "BILGEWATER_ARAM_5x5": "100", "KING_PORO_5x5": "300", "COUNTER_PICK": "310", "BILGEWATER_5x5": "313", "TEAM_BUILDER_DRAFT_UNRANKED_5x5": "400", "TEAM_BUILDER_DRAFT_RANKED_5x5": "410" } bot.data['discrank.py'] = [watcher, champions, spells, modes]
BOT_ID = token_file.readline() BOT_ID = BOT_ID.rstrip() #BOT_ID = os.environ.get("BOT_ID") print "Starting with BOT_ID = '" + BOT_ID + "'" # constants AT_BOT = "<@" + BOT_ID + ">" COMMAND_LIST = ["add", "print", "remove", "pbe"] #Get Rito games client riot_token = open("riot_token", "r").readline().rstrip() riot_client = RiotWatcher(riot_token) #Might as well generate a useful list once.. CHAMPION_LIST = [] champ_json = riot_client.static_get_champion_list() champ_json = champ_json['data'] for i in champ_json: string_name = champ_json[i]['name'].encode('utf-8') CHAMPION_LIST.append(string_name.lower()) #Summoner/slack map SUMMONERS = [] #SurrenderAt20 Current PBE Balance Changes URL PBE_CHANGE_URL = "http://www.surrenderat20.net/p/current-pbe-balance-changes.html" def handle_command(command, channel): """ Receives commands directed at the bot and determines if they
class Lol: def __init__(self, key, default_region=EUROPE_WEST): self.lol_watcher = RiotWatcher(key, default_region=default_region) self.wait() self.champion_list = self.lol_watcher.static_get_champion_list( )['data'] def wait(self): while not self.lol_watcher.can_make_request(): time.sleep(1) def test_map(self, _id): if _id == 1: return "Summoner's Rift" elif _id == 2: return "Summoner's Rift" elif _id == 3: return "The Proving Grounds (tuto)" elif _id == 4: return "Twisted Treeline" elif _id == 8: return "The Crystal Scar" elif _id == 10: return "Twisted Treeline" elif _id == 11: return "Summoner's Rift" elif _id == 12: return "Howling Abyss" elif _id == 14: return "Butcher's Bridge" def test_queue(self, _id): if _id == 0: return "Custom" elif _id == 2: return "Normal 5v5 blind" elif _id == 4: return "Ranked Solo 5v5" elif _id == 6: return "Ranked Premade 5v5" elif _id == 7: return "Coop vs ia 5v5" elif _id == 8: return "Normal 3v3" elif _id == 9: return "Ranked flex" elif _id == 14: return "Normal Draft 5v5" elif _id == 16: return "Odin 5v5 Blind" elif _id == 17: return "Odin 5v5 Draft" elif _id == 25: return "Coop vs ia 5v5" elif _id == 31: return "Coop vs ia (intro)" elif _id == 32: return "Coop vs ia (beginner)" elif _id == 33: return "Coop vs ia (Intermediate)" elif _id == 41: return "Ranked Team 3v3" elif _id == 52: return "Ranked Team 5v5" elif _id == 61: return "GROUP_FINDER_5v5" elif _id == 65: return "Aram" elif _id == 70: return "One For All" elif _id == 72: return "FIRSTBLOOD_1v1" elif _id == 73: return "FIRSTBLOOD_2v2" elif _id == 75: return "Hexakill" elif _id == 76: return "URF" elif _id == 78: return "One For All" elif _id == 83: return "Bot URF" elif _id == 91: return "DOOM Bot (rank 1)" elif _id == 92: return "DOOM Bot (rank 2)" elif _id == 93: return "DOOM Bot (rank 5)" elif _id == 96: return "Ascension" elif _id == 98: return "Hexakill" elif _id == 100: return "BILGEWATER_ARAM_5v5" elif _id == 300: return "Poro King" elif _id == 310: return "COUNTER_PICK" elif _id == 313: return "BILGEWATER_5v5" elif _id == 315: return "Siege" elif _id == 317: return "Definitly Not Dominion" elif _id == 318: return "Aram URF" elif _id == 400: return "Normal Draft" elif _id == 410: return "Ranked" elif _id == 420: return "Ranked Solo/Duo" elif _id == 440: return "Ranked Flex" def test_champ(self, _id): temp = [] for k in self.champion_list: temp.append(self.champion_list[k]) temp = [nb for nb in temp if nb['id'] == _id] return temp[0]['name'] def test_ranked_stats(self, stats, key): stats = stats['champions'] stats = [nb for nb in stats if nb['id'] == 0] stats = stats[0]['stats'] return stats[key] def test_team(self, _id): if _id == 100: return ":large_blue_circle:" else: return ":red_circle:" def check_lol(self, player, region): try: self.wait() return self.lol_watcher.get_summoner(name=player, region=region) except LoLException as e: if e == error_429: return ":x: Resseye dans {} secondes.".format( e.headers['Retry-After']) elif e == error_404: return ":x: Summoner inconnu : {}".format(player) def message_lol(self, summoner): message = ":information_source: {} :video_game:\n\n".format( summoner['name']) message += " :information_source: Général Stats\n" message += " **ID**: {}\n".format(summoner['id']) message += " **Level**: {}\n".format(summoner['summonerLevel']) self.wait() temp = self.lol_watcher.get_league(summoner_ids=[summoner['id']]) rank = [] for i in temp[str(summoner['id'])]: rank.append(i['queue'] + " " + i['tier']) message += " **Rank**: {}\n".format(rank) #message += " **Mastery Levels**: {}\n".format() #message += " **Mastery Points**: {}\n".format() #message += " **Mastery Tokens**: {}\n".format() self.wait() player_stats = self.lol_watcher.get_stat_summary( summoner['id'])['playerStatSummaries'] player_stats = [ nb for nb in player_stats if nb['playerStatSummaryType'] == 'Unranked' ] player_stats = player_stats[0] message += " **Wins**: {}\n".format(player_stats['wins']) message += " **Kills**: {}\n".format( player_stats['aggregatedStats']['totalChampionKills']) message += " **Assistances**: {}\n".format( player_stats['aggregatedStats']['totalAssists']) message += " **Creeps tués**: {}\n".format( player_stats['aggregatedStats']['totalMinionKills']) message += " **Tourelles détruite**: {}\n\n".format( player_stats['aggregatedStats']['totalTurretsKilled']) #message += " **Dernière connexion**: {}\n\n".format() message += ":information_source: Ranked Stats :\n" try: self.wait() ranked_stats = self.lol_watcher.get_ranked_stats(summoner['id']) message += " **Win:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalSessionsWon')) message += " **Loose:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalSessionsLost')) message += " **Kill:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalChampionKills')) message += " **Assistance:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalAssists')) message += " **Damages infligés:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalDamageDealt')) message += " **Damages Reçus:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalDamageTaken')) message += " **Argent gagné:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalGoldEarned')) message += " **Creeps tués:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalMinionKills')) message += " **Tourelles détruites:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalTurretsKilled')) message += " **Double kills:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalDoubleKills')) message += " **Triple kills:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalTripleKills')) message += " **Quadra kills:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalQuadraKills')) message += " **Penta kills:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalPentaKills')) message += " **Total Killing Spree:** {}\n\n".format( self.test_ranked_stats(ranked_stats, 'killingSpree')) except: message += "**Aucune Stats de Ranked n'a été trouvée !**\n\n" message += ":information_source: Game en cours :\n" try: self.wait() temp = self.lol_watcher.get_current_game(summoner['id']) message += " **ID Partie:** {}\n".format(temp['gameId']) message += " **GameMode:** {}\n".format(temp['gameMode']) message += " **GameType:** {}\n".format(temp['gameType']) message += " **ID Queue:** {}\n".format( self.test_queue(temp['gameQueueConfigId'])) message += " **ID Platform:** {}\n".format(temp['platformId']) message += " **ID Map:** {}\n".format(self.test_map(temp['mapId'])) for i in temp['participants']: message += " " + i['summonerName'] + " (" + self.test_champ( i['championId']) + ") Team: " + self.test_team( i['teamId']) + "\n" except: message += "**Aucune game en cours...**" return message