mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
osu! improvements
This commit is contained in:
parent
dc76a28718
commit
91f397e025
3 changed files with 60 additions and 16 deletions
37
db.py
37
db.py
|
@ -20,7 +20,7 @@ from discord import User as DiscordUser
|
||||||
# noinspection PyPackageRequirements
|
# noinspection PyPackageRequirements
|
||||||
from telegram import User as TelegramUser
|
from telegram import User as TelegramUser
|
||||||
import loldata
|
import loldata
|
||||||
from dirty import Dirty
|
from dirty import Dirty, DirtyDelta
|
||||||
import query_discord_music
|
import query_discord_music
|
||||||
from flask import escape
|
from flask import escape
|
||||||
import libgravatar
|
import libgravatar
|
||||||
|
@ -589,10 +589,14 @@ class Osu(Base, Mini):
|
||||||
|
|
||||||
osu_id = Column(Integer, primary_key=True)
|
osu_id = Column(Integer, primary_key=True)
|
||||||
osu_name = Column(String)
|
osu_name = Column(String)
|
||||||
std_pp = Column(Float)
|
std_pp = Column(Float, default=0)
|
||||||
taiko_pp = Column(Float)
|
std_best_song = Column(BigInteger)
|
||||||
catch_pp = Column(Float)
|
taiko_pp = Column(Float, default=0)
|
||||||
mania_pp = Column(Float)
|
taiko_best_song = Column(BigInteger)
|
||||||
|
catch_pp = Column(Float, default=0)
|
||||||
|
catch_best_song = Column(BigInteger)
|
||||||
|
mania_pp = Column(Float, default=0)
|
||||||
|
mania_best_song = Column(BigInteger)
|
||||||
|
|
||||||
_mini_full_name = "osu!"
|
_mini_full_name = "osu!"
|
||||||
_mini_name = "osu"
|
_mini_name = "osu"
|
||||||
|
@ -629,23 +633,32 @@ class Osu(Base, Mini):
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
def update(self, session=None):
|
def update(self, session=None):
|
||||||
|
std = DirtyDelta(self.std_pp)
|
||||||
|
taiko = DirtyDelta(self.taiko_pp)
|
||||||
|
catch = DirtyDelta(self.catch_pp)
|
||||||
|
mania = DirtyDelta(self.mania_pp)
|
||||||
r0 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=0")
|
r0 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=0")
|
||||||
r0.raise_for_status()
|
r0.raise_for_status()
|
||||||
|
j0 = r0.json()[0]
|
||||||
r1 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=1")
|
r1 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=1")
|
||||||
r1.raise_for_status()
|
r1.raise_for_status()
|
||||||
|
j1 = r1.json()[0]
|
||||||
r2 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=2")
|
r2 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=2")
|
||||||
r2.raise_for_status()
|
r2.raise_for_status()
|
||||||
|
j2 = r2.json()[0]
|
||||||
r3 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=3")
|
r3 = requests.get(f"https://osu.ppy.sh/api/get_user?k={config['Osu!']['ppy_api_key']}&u={self.osu_name}&m=3")
|
||||||
r3.raise_for_status()
|
r3.raise_for_status()
|
||||||
j0 = r0.json()[0]
|
|
||||||
j1 = r1.json()[0]
|
|
||||||
j2 = r2.json()[0]
|
|
||||||
j3 = r3.json()[0]
|
j3 = r3.json()[0]
|
||||||
self.osu_name = j0["username"]
|
self.osu_name = j0["username"]
|
||||||
self.std_pp = j0["pp_raw"]
|
std.value = j0["pp_raw"]
|
||||||
self.taiko_pp = j1["pp_raw"]
|
taiko.value = j1["pp_raw"]
|
||||||
self.catch_pp = j2["pp_raw"]
|
catch.value = j2["pp_raw"]
|
||||||
self.mania_pp = j3["pp_raw"]
|
mania.value = j3["pp_raw"]
|
||||||
|
self.std_pp = std.value
|
||||||
|
self.taiko_pp = taiko.value
|
||||||
|
self.catch_pp = catch.value
|
||||||
|
self.mania_pp = mania.value
|
||||||
|
return std, taiko, catch, mania
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if not self.osu_name:
|
if not self.osu_name:
|
||||||
|
|
10
dirty.py
10
dirty.py
|
@ -11,3 +11,13 @@ class Dirty:
|
||||||
|
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
return self.is_dirty()
|
return self.is_dirty()
|
||||||
|
|
||||||
|
|
||||||
|
class DirtyDelta(Dirty):
|
||||||
|
@property
|
||||||
|
def delta(self):
|
||||||
|
return self.value - self.initial_value
|
||||||
|
|
||||||
|
@delta.setter
|
||||||
|
def delta(self, value):
|
||||||
|
self.value = self.initial_value + value
|
||||||
|
|
|
@ -11,7 +11,7 @@ import telegram
|
||||||
import sys
|
import sys
|
||||||
import coloredlogs
|
import coloredlogs
|
||||||
import requests
|
import requests
|
||||||
from dirty import Dirty
|
from dirty import Dirty, DirtyDelta
|
||||||
from sentry_sdk import configure_scope
|
from sentry_sdk import configure_scope
|
||||||
|
|
||||||
logging.getLogger().disabled = True
|
logging.getLogger().disabled = True
|
||||||
|
@ -78,10 +78,8 @@ def new_dota_rank(item: db.Dota, change):
|
||||||
logger.warning(f"Couldn't notify on Telegram: {item}")
|
logger.warning(f"Couldn't notify on Telegram: {item}")
|
||||||
|
|
||||||
|
|
||||||
def new_lol_rank(item, change: typing.Tuple[Dirty]):
|
def new_lol_rank(item, change: typing.Tuple[Dirty, Dirty, Dirty]):
|
||||||
# It always gets called, even when there is no change
|
# It always gets called, even when there is no change
|
||||||
# Assignment inspection is wrong
|
|
||||||
# noinspection PyTupleAssignmentBalance
|
|
||||||
solo, flex, twtr = change
|
solo, flex, twtr = change
|
||||||
try:
|
try:
|
||||||
if solo:
|
if solo:
|
||||||
|
@ -109,6 +107,29 @@ def new_lol_rank(item, change: typing.Tuple[Dirty]):
|
||||||
logger.warning(f"Couldn't notify on Telegram: {item}")
|
logger.warning(f"Couldn't notify on Telegram: {item}")
|
||||||
|
|
||||||
|
|
||||||
|
def osu_pp_change(item, change: typing.Tuple[DirtyDelta, DirtyDelta, DirtyDelta, DirtyDelta]):
|
||||||
|
std, taiko, catch, mania = change
|
||||||
|
try:
|
||||||
|
if std.delta >= 1:
|
||||||
|
telegram_bot.send_message(config["Telegram"]["main_group"],
|
||||||
|
f"✳️ {item.royal.username} ha ora **{std.value}pp** (+{std.value.delta}) su osu!",
|
||||||
|
parse_mode="Markdown")
|
||||||
|
if taiko.delta >= 1:
|
||||||
|
telegram_bot.send_message(config["Telegram"]["main_group"],
|
||||||
|
f"✳️ {item.royal.username} ha ora **{std.value}pp** (+{std.value.delta}) su osu!taiko!",
|
||||||
|
parse_mode="Markdown")
|
||||||
|
if catch.delta >= 1:
|
||||||
|
telegram_bot.send_message(config["Telegram"]["main_group"],
|
||||||
|
f"✳️ {item.royal.username} ha ora **{std.value}pp** (+{std.value.delta}) su osu!catch!",
|
||||||
|
parse_mode="Markdown")
|
||||||
|
if mania.delta >= 1:
|
||||||
|
telegram_bot.send_message(config["Telegram"]["main_group"],
|
||||||
|
f"✳️ {item.royal.username} ha ora **{std.value}pp** (+{std.value.delta}) su osu!mania!",
|
||||||
|
parse_mode="Markdown")
|
||||||
|
except Exception:
|
||||||
|
logger.warning(f"Couldn't notify on Telegram: {item}")
|
||||||
|
|
||||||
|
|
||||||
def process():
|
def process():
|
||||||
while True:
|
while True:
|
||||||
session = db.Session()
|
session = db.Session()
|
||||||
|
|
Loading…
Reference in a new issue