1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
This commit is contained in:
Steffo 2016-08-12 23:29:09 +02:00
parent 8e04859091
commit de9d824a8a
3 changed files with 35 additions and 7 deletions

27
dbeditingtool.py Normal file
View file

@ -0,0 +1,27 @@
import requests
import json
file = open("db.json")
db = json.load(file)
file.close()
namelist = ["Cosimo03", "fedececco", "Il Gattopardo", "lordlake", "Luzcuzz", "MRdima98", "RYGFrankez",
"Sensei the great", "UnsavouryComb2"]
for player in namelist:
r = requests.get("https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/"
"{player}?api_key=d2e4cf8f-9a6d-4ce1-8eeb-6342c19f1ae4".format(player=player))
r = r.json()[player.lower().replace(" ", "")]
lolid = r["id"]
print(str(lolid) + " | " + r["name"])
discordid = str(input())
db[discordid] = dict()
db[discordid]["league"] = dict()
db[discordid]["league"]["summonerid"] = lolid
db[discordid]["league"]["region"] = "euw"
db[discordid]["league"]["tier"] = -1
db[discordid]["league"]["division"] = -1
file = open("db.json", "w")
json.dump(db, file)
file.close()

View file

@ -29,11 +29,8 @@ async def get_player_rank(region: str, summonerid: int, **kwargs):
'/entry?api_key={token}'.format(region=region, summonerid=summonerid, token=token)) '/entry?api_key={token}'.format(region=region, summonerid=summonerid, token=token))
# Ensure the request is successful # Ensure the request is successful
if r.status_code == 200: if r.status_code == 200:
if len(r.json()[str(summonerid)]) > 0: return r.json()[str(summonerid)][0]
return r.json()[str(summonerid)][0]
else:
raise NoRankedGamesCompletedException("This player hasn't completed any ranked games.")
elif r.status_code == 404: elif r.status_code == 404:
raise NotFoundException("Player not found.") raise NoRankedGamesCompletedException("This player hasn't completed any ranked games.")
else: else:
raise Exception("Unhandled API response.") raise Exception("Unhandled API response.")

View file

@ -23,6 +23,7 @@ async def overwatch_level_up(timeout):
while True: while True:
# Wait for the timeout # Wait for the timeout
await asyncio.sleep(timeout) await asyncio.sleep(timeout)
print("Checking for Overwatch updates.")
# Update data for every player in list # Update data for every player in list
for player in db: for player in db:
if "overwatch" in db[player]: if "overwatch" in db[player]:
@ -39,12 +40,14 @@ async def overwatch_level_up(timeout):
f = open("db.json", "w") f = open("db.json", "w")
json.dump(db, f) json.dump(db, f)
f.close() f.close()
print("Check for Overwatch completed.")
# Every timeout seconds, update player league and check for rank changes # Every timeout seconds, update player league and check for rank changes
async def league_rank_change(timeout): async def league_rank_change(timeout):
while True: while True:
# Wait for the timeout # Wait for the timeout
await asyncio.sleep(timeout) await asyncio.sleep(timeout)
print("Checking for League of Legends updates.")
# Update data for every player in list # Update data for every player in list
for player in db: for player in db:
if "league" in db[player]: if "league" in db[player]:
@ -58,7 +61,7 @@ async def league_rank_change(timeout):
tier_number = league.ranklist.index(r["tier"]) tier_number = league.ranklist.index(r["tier"])
roman_number = league.roman.index(r["entries"][0]["division"]) roman_number = league.roman.index(r["entries"][0]["division"])
# Check for tier changes # Check for tier changes
if tier_number != db[player]["league"]["tier"] or roman_number < db[player]["league"]["division"]: if tier_number != db[player]["league"]["tier"] or roman_number != db[player]["league"]["division"]:
# Convert user ID into a mention # Convert user ID into a mention
user = "<@" + player + ">" user = "<@" + player + ">"
# Prepare the message to send # Prepare the message to send
@ -73,9 +76,10 @@ async def league_rank_change(timeout):
f = open("db.json", "w") f = open("db.json", "w")
json.dump(db, f) json.dump(db, f)
f.close() f.close()
print("Check for League of Legends completed.")
loop.create_task(overwatch_level_up(900)) loop.create_task(overwatch_level_up(900))
loop.create_task(league_rank_change(120)) loop.create_task(league_rank_change(5))
try: try:
loop.run_until_complete(d_client.start(token)) loop.run_until_complete(d_client.start(token))