mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Osu!
This commit is contained in:
parent
4e9bbd1b86
commit
ede3d10c2c
4 changed files with 89 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -142,3 +142,4 @@ discordtoken.txt
|
||||||
db.json
|
db.json
|
||||||
leaguetoken.txt
|
leaguetoken.txt
|
||||||
telegramtoken.txt
|
telegramtoken.txt
|
||||||
|
osutoken.txt
|
||||||
|
|
67
main.py
67
main.py
|
@ -9,6 +9,7 @@ import strings as s
|
||||||
import telegram
|
import telegram
|
||||||
import bs4
|
import bs4
|
||||||
import brawlhalla
|
import brawlhalla
|
||||||
|
import osu
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
d_client = discord.Client()
|
d_client = discord.Client()
|
||||||
|
@ -287,6 +288,49 @@ async def opendota_last_match(timeout):
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
async def osu_pp(timeout):
|
||||||
|
while True:
|
||||||
|
if discord_is_ready:
|
||||||
|
print("[Osu!] Starting pp check...")
|
||||||
|
for mode in range(0, 4):
|
||||||
|
for player in db:
|
||||||
|
try:
|
||||||
|
r = await osu.get_user(db[player]["osu"]["id"], mode)
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
if r["pp_raw"] is not None:
|
||||||
|
pp = float(r["pp_raw"])
|
||||||
|
else:
|
||||||
|
pp = 0
|
||||||
|
if pp != 0:
|
||||||
|
try:
|
||||||
|
old = db[player]["osu"][str(mode)]
|
||||||
|
except KeyError:
|
||||||
|
old = 0
|
||||||
|
if pp != old:
|
||||||
|
db[player]["osu"][str(mode)] = pp
|
||||||
|
f = {
|
||||||
|
"player": player,
|
||||||
|
"mode": s.osu_modes[mode],
|
||||||
|
"pp": int(pp),
|
||||||
|
"change": int(pp - old)
|
||||||
|
}
|
||||||
|
loop.create_task(send_event(s.osu_pp_change, **f))
|
||||||
|
else:
|
||||||
|
db[player]["osu"][str(mode)] = 0.0
|
||||||
|
f = open("db.json", "w")
|
||||||
|
json.dump(db, f)
|
||||||
|
f.close()
|
||||||
|
finally:
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
print("[Osu!] Check successful.")
|
||||||
|
await asyncio.sleep(timeout)
|
||||||
|
else:
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Send a new event to both Discord and Telegram
|
# Send a new event to both Discord and Telegram
|
||||||
async def send_event(eventmsg: str, player: str, **kwargs):
|
async def send_event(eventmsg: str, player: str, **kwargs):
|
||||||
# Create arguments dict
|
# Create arguments dict
|
||||||
|
@ -309,20 +353,23 @@ async def send_event(eventmsg: str, player: str, **kwargs):
|
||||||
# Send the message
|
# Send the message
|
||||||
loop.create_task(telegram.send_message(msg, -2141322))
|
loop.create_task(telegram.send_message(msg, -2141322))
|
||||||
|
|
||||||
loop.create_task(overwatch_status_change(600))
|
#loop.create_task(overwatch_status_change(600))
|
||||||
print("[Overwatch] Added level up check to the queue.")
|
#print("[Overwatch] Added level up check to the queue.")
|
||||||
|
|
||||||
loop.create_task(league_rank_change(900))
|
#loop.create_task(league_rank_change(900))
|
||||||
print("[League] Added rank change check to the queue.")
|
#print("[League] Added rank change check to the queue.")
|
||||||
|
|
||||||
loop.create_task(league_level_up(900))
|
#loop.create_task(league_level_up(900))
|
||||||
print("[League] Added level change check to the queue.")
|
#print("[League] Added level change check to the queue.")
|
||||||
|
|
||||||
loop.create_task(brawlhalla_update_mmr(7200))
|
#loop.create_task(brawlhalla_update_mmr(7200))
|
||||||
print("[Brawlhalla] Added mmr change check to the queue.")
|
#print("[Brawlhalla] Added mmr change check to the queue.")
|
||||||
|
|
||||||
loop.create_task(opendota_last_match(600))
|
#loop.create_task(opendota_last_match(600))
|
||||||
print("[OpenDota] Added last match check to the queue.")
|
#print("[OpenDota] Added last match check to the queue.")
|
||||||
|
|
||||||
|
loop.create_task(osu_pp(600))
|
||||||
|
print("[Osu!] Added pp change check to the queue.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(d_client.start(token))
|
loop.run_until_complete(d_client.start(token))
|
||||||
|
|
22
osu.py
Normal file
22
osu.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import asyncio
|
||||||
|
import requests
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
# Load Osu API key from the osutoken.txt file
|
||||||
|
file = open("osutoken.txt", "r")
|
||||||
|
token = file.read()
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
async def get_user(user, mode=0):
|
||||||
|
print("[Osu!] Getting profile data for {} mode {}".format(user, mode))
|
||||||
|
params = {
|
||||||
|
"k": token,
|
||||||
|
"m": mode,
|
||||||
|
"u": user
|
||||||
|
}
|
||||||
|
# Get the data
|
||||||
|
r = await loop.run_in_executor(None, requests.get, 'https://osu.ppy.sh/api/get_user?k={k}&m={m}&u={u}'.format(**params))
|
||||||
|
if r.status_code == 200:
|
||||||
|
return r.json()[0]
|
||||||
|
else:
|
||||||
|
raise Exception("[Osu!] Unhandled exception during the API request")
|
|
@ -44,6 +44,15 @@ brawlhalla_new_mmr = "{player} è passato da {oldmmr} MMR a **{mmr}** MMR su _Br
|
||||||
# Dota: new match
|
# Dota: new match
|
||||||
dota_new_match = "{player} ha **{result}** a _Dota 2_ con {k}/{d}/{a}, giocando **{hero}**!"
|
dota_new_match = "{player} ha **{result}** a _Dota 2_ con {k}/{d}/{a}, giocando **{hero}**!"
|
||||||
|
|
||||||
|
# Osu: modes
|
||||||
|
osu_modes = ["osu!",
|
||||||
|
"osu!taiko",
|
||||||
|
"osu!catch",
|
||||||
|
"osu!mania"]
|
||||||
|
|
||||||
|
# Osu: moar pp
|
||||||
|
osu_pp_change = "{player} è salito a **{pp}pp** (+{change}) su _{mode}_ !"
|
||||||
|
|
||||||
# Win: past participle
|
# Win: past participle
|
||||||
won = "vinto"
|
won = "vinto"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue