-
Notifications
You must be signed in to change notification settings - Fork 2
/
riotapi.py
118 lines (82 loc) · 4.57 KB
/
riotapi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import requests
import discord
import asyncio
from bs4 import BeautifulSoup
from urllib.request import urlretrieve
import json
import time
client = discord.Client()
token = "Your Discord Bot Token"
@client.event
async def on_ready():
print("=========================")
print("다음으로 로그인 합니다 : ")
print(client.user.name)
print("connection was successful")
game = discord.Game("League of Legends")
print("=========================")
await client.change_presence(status=discord.Status.online, activity=game)
@client.event
async def on_message(message):
if message.content.startswith('!티어'):
start = time.time()
Name = message.content[4:len(message.content)]
Final_Name = Name.replace(" ","+")
api_key = "Your Riot Games API"
URL = "https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/"+Final_Name #0.8초 소요
res = requests.get(URL, headers={"X-Riot-Token": api_key})
print(res.text)
if res.status_code == 200:
#코드가 200일때
resobj = json.loads(res.text)
URL = "https://kr.api.riotgames.com/lol/league/v4/entries/by-summoner/"+resobj["id"]
player_icon = str(resobj["profileIconId"])
player_id = str(resobj["id"])
res = requests.get(URL, headers={"X-Riot-Token": api_key})
rankinfo = json.loads(res.text) #list class
if len(rankinfo) == 0:
await message.channel.send("소환사의 랭크 정보가 없습니다")
print(time.time()-start)
for i in rankinfo:
if i["queueType"] == "RANKED_SOLO_5x5":
rank = str(i["rank"])
tier = str(i["tier"])
leaguepoints = str(i["leaguePoints"])
wins = str(i["wins"])
losses = str(i["losses"])
ratio = str(round(int(wins)*100/(int(wins)+int(losses)), 1))
print(rank)
print(tier)
URL = "https://kr.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/"+player_id
res = requests.get(URL, headers={"X-Riot-Token": api_key})
player_mastery = json.loads(res.text) # player mastery : list class
print(time.time()-start)
for i in player_mastery: # i : dictionary class
most_champion_id = int(i["championId"])
most_champion_points = str(i["championPoints"])
URL = "http://ddragon.leagueoflegends.com/cdn/10.25.1/data/ko_KR/champion.json"
res = requests.get(URL)
print(time.time()-start)
champion_name = json.loads(res.text)
#print(champion_name)
champion_name_list = champion_name["data"] #champion_name : dictionary class / list : dict class
print(type(champion_name_list))
global most_champion_name
for i in champion_name_list: #key 값은 str class
if(champion_name["data"][i]["key"]) == str(most_champion_id):
most_champion_name = champion_name["data"][i]["name"]
break
print(most_champion_name)
print(most_champion_points)
print(time.time()-start)
embed = discord.Embed(title="", description="", color=0xd5d5d5)
embed.set_author(name=Final_Name +"님의 전적 검색", url="http://www.op.gg/summoner/userName="+Final_Name, icon_url="http://ddragon.leagueoflegends.com/cdn/10.25.1/img/profileicon/"+player_icon+".png")
embed.add_field(name=tier+" "+rank+" | "+leaguepoints+" LP", value=wins+"승"+" "+losses +"패"+" | "+ratio+"%", inline=False)
embed.add_field(name="가장 높은 숙련도",value= most_champion_name +" "+ most_champion_points +" 점 ", inline= False)
embed.set_footer(text='CuriHuS LAB')
embed.set_thumbnail(url="http://z.fow.kr/img/emblem/"+tier.lower()+".png")
await message.channel.send(embed=embed)
break
else:
await message.channel.send("소환사가 존재하지 않습니다")
client.run(token)