mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
publish: 5.8.20
This commit is contained in:
parent
614d3274e7
commit
630fc19179
10 changed files with 133 additions and 13 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "royalpack"
|
name = "royalpack"
|
||||||
version = "5.8.19"
|
version = "5.8.20"
|
||||||
description = "A Royalnet command pack for the Royal Games community"
|
description = "A Royalnet command pack for the Royal Games community"
|
||||||
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
||||||
license = "AGPL-3.0+"
|
license = "AGPL-3.0+"
|
||||||
|
|
|
@ -15,6 +15,7 @@ from .api_polls_get import ApiPollsGet
|
||||||
from .api_polls_list import ApiPollsList
|
from .api_polls_list import ApiPollsList
|
||||||
from .api_cvstats_latest import ApiCvstatsLatestStar
|
from .api_cvstats_latest import ApiCvstatsLatestStar
|
||||||
from .api_cvstats_avg import ApiCvstatsAvgStar
|
from .api_cvstats_avg import ApiCvstatsAvgStar
|
||||||
|
from .api_user_get_ryg import ApiUserGetRygStar
|
||||||
|
|
||||||
# Enter the PageStars of your Pack here!
|
# Enter the PageStars of your Pack here!
|
||||||
available_page_stars = [
|
available_page_stars = [
|
||||||
|
@ -34,6 +35,7 @@ available_page_stars = [
|
||||||
ApiPollsList,
|
ApiPollsList,
|
||||||
ApiCvstatsLatestStar,
|
ApiCvstatsLatestStar,
|
||||||
ApiCvstatsAvgStar,
|
ApiCvstatsAvgStar,
|
||||||
|
ApiUserGetRygStar,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
||||||
|
|
38
royalpack/stars/api_user_get_ryg.py
Normal file
38
royalpack/stars/api_user_get_ryg.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import royalnet.constellation.api as rca
|
||||||
|
import royalnet.utils as ru
|
||||||
|
import royalnet.backpack.tables as rbt
|
||||||
|
|
||||||
|
|
||||||
|
class ApiUserGetRygStar(rca.ApiStar):
|
||||||
|
summary = "Ottieni le informazioni su un utente della Royal Games."
|
||||||
|
|
||||||
|
description = ""
|
||||||
|
|
||||||
|
methods = ["GET"]
|
||||||
|
|
||||||
|
path = "/api/user/get/ryg/v1"
|
||||||
|
|
||||||
|
requires_auth = False
|
||||||
|
|
||||||
|
parameters = {"id": "L'id dell'utente di cui vuoi vedere le informazioni."}
|
||||||
|
|
||||||
|
tags = ["user"]
|
||||||
|
|
||||||
|
async def api(self, data: rca.ApiData) -> dict:
|
||||||
|
user_id_str = data["id"]
|
||||||
|
try:
|
||||||
|
user_id = int(user_id_str)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
raise rca.InvalidParameterError("'id' is not a valid int.")
|
||||||
|
user: rbt.User = await ru.asyncify(data.session.query(self.alchemy.get(rbt.User)).get, user_id)
|
||||||
|
if user is None:
|
||||||
|
raise rca.NotFoundError("No such user.")
|
||||||
|
result = {
|
||||||
|
**user.json(),
|
||||||
|
"bio": user.bio.json(),
|
||||||
|
"fiorygi": user.fiorygi.fiorygi if user.fiorygi is not None else None,
|
||||||
|
"steam": [steam.json() for steam in user.steam],
|
||||||
|
"leagueoflegends": [leagueoflegends.json() for leagueoflegends in user.leagueoflegends],
|
||||||
|
"trivia": user.trivia_score.json() if user.trivia_score is not None else None
|
||||||
|
}
|
||||||
|
return result
|
|
@ -1,7 +1,7 @@
|
||||||
from sqlalchemy import *
|
from sqlalchemy import *
|
||||||
from sqlalchemy.orm import *
|
from sqlalchemy.orm import *
|
||||||
from sqlalchemy.ext.declarative import declared_attr
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
import steam
|
import steam.steamid
|
||||||
from ..types import BrawlhallaRank, BrawlhallaTier, BrawlhallaMetal
|
from ..types import BrawlhallaRank, BrawlhallaTier, BrawlhallaMetal
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class Brawlhalla:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def steamid(self):
|
def steamid(self):
|
||||||
return steam.SteamID(self._steamid)
|
return steam.steamid.SteamID(self._steamid)
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -58,32 +58,49 @@ class Brawlhalla:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rating_2v2(self):
|
def rating_2v2(self):
|
||||||
duos = sorted(self.duos, key=lambda d: -d.rating)
|
duos = sorted(self.duos, key=lambda d: -d.rating_2v2)
|
||||||
if len(duos) == 0:
|
if len(duos) == 0:
|
||||||
return None
|
return None
|
||||||
return duos[0].rating_2v2
|
return duos[0].rating_2v2
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tier_2v2(self):
|
def tier_2v2(self):
|
||||||
duos = sorted(self.duos, key=lambda d: -d.rating)
|
duos = sorted(self.duos, key=lambda d: -d.rating_2v2)
|
||||||
if len(duos) == 0:
|
if len(duos) == 0:
|
||||||
return None
|
return None
|
||||||
return duos[0].tier_2v2
|
return duos[0].tier_2v2
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def metal_2v2(self):
|
def metal_2v2(self):
|
||||||
duos = sorted(self.duos, key=lambda d: -d.rating)
|
duos = sorted(self.duos, key=lambda d: -d.rating_2v2)
|
||||||
if len(duos) == 0:
|
if len(duos) == 0:
|
||||||
return None
|
return None
|
||||||
return duos[0].metal_2v2
|
return duos[0].metal_2v2
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rank_2v2(self):
|
def rank_2v2(self):
|
||||||
duos = sorted(self.duos, key=lambda d: -d.rating)
|
duos = sorted(self.duos, key=lambda d: -d.rating_2v2)
|
||||||
if len(duos) == 0:
|
if len(duos) == 0:
|
||||||
return None
|
return None
|
||||||
return duos[0].rank_2v2
|
return duos[0].rank_2v2
|
||||||
|
|
||||||
|
def json(self):
|
||||||
|
one_rank = self.rank_1v1
|
||||||
|
two_rank = self.rank_2v2
|
||||||
|
return {
|
||||||
|
"name": self.name,
|
||||||
|
"1v1": {
|
||||||
|
"rating": self.rating_1v1,
|
||||||
|
"metal": one_rank.metal.name,
|
||||||
|
"tier": one_rank.tier.name
|
||||||
|
},
|
||||||
|
"2v2": {
|
||||||
|
"rating": self.rating_2v2,
|
||||||
|
"metal": two_rank.metal.name,
|
||||||
|
"tier": two_rank.tier.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Brawlhalla account {self._steamid}>"
|
return f"<Brawlhalla account {self._steamid}>"
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from sqlalchemy import *
|
||||||
from sqlalchemy.orm import relationship, backref
|
from sqlalchemy.orm import relationship, backref
|
||||||
from sqlalchemy.ext.declarative import declared_attr
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
from ..types import DotaMedal, DotaStars, DotaRank
|
from ..types import DotaMedal, DotaStars, DotaRank
|
||||||
import steam
|
import steam.steamid
|
||||||
|
|
||||||
|
|
||||||
class Dota:
|
class Dota:
|
||||||
|
@ -19,7 +19,7 @@ class Dota:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def steamid(self):
|
def steamid(self):
|
||||||
return steam.SteamID(self._steamid)
|
return steam.steamid.SteamID(self._steamid)
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def _rank_tier(self):
|
def _rank_tier(self):
|
||||||
|
@ -72,6 +72,19 @@ class Dota:
|
||||||
def losses(self):
|
def losses(self):
|
||||||
return Column(Integer)
|
return Column(Integer)
|
||||||
|
|
||||||
|
def json(self):
|
||||||
|
rank = self.rank
|
||||||
|
|
||||||
|
return {
|
||||||
|
"rank": {
|
||||||
|
"raw": self._rank_tier,
|
||||||
|
"medal": rank.medal.name,
|
||||||
|
"rank": rank.stars.name
|
||||||
|
},
|
||||||
|
"wins": self.wins,
|
||||||
|
"losses": self.losses
|
||||||
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Dota account {self._steamid}>"
|
return f"<Dota account {self._steamid}>"
|
||||||
|
|
||||||
|
|
|
@ -249,6 +249,21 @@ class LeagueOfLegends:
|
||||||
def mastery_score(self):
|
def mastery_score(self):
|
||||||
return Column(Integer, nullable=False, default=0)
|
return Column(Integer, nullable=False, default=0)
|
||||||
|
|
||||||
|
def json(self):
|
||||||
|
return {
|
||||||
|
"region": self.region,
|
||||||
|
"profile_icon_id": self.profile_icon_id,
|
||||||
|
"summoner_name": self.summoner_name,
|
||||||
|
"puuid": self.puuid,
|
||||||
|
"summoner_level": self.summoner_level,
|
||||||
|
"summoner_id": self.summoner_id,
|
||||||
|
"account_id": self.account_id,
|
||||||
|
"soloq": self.rank_soloq.json() if self.rank_soloq is not None else None,
|
||||||
|
"twtrq": self.rank_twtrq.json() if self.rank_twtrq is not None else None,
|
||||||
|
"flexq": self.rank_flexq.json() if self.rank_flexq is not None else None,
|
||||||
|
"tftq": self.rank_tftq.json() if self.rank_tftq is not None else None,
|
||||||
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<{self.__class__.__qualname__} {str(self)}>"
|
return f"<{self.__class__.__qualname__} {str(self)}>"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from sqlalchemy import *
|
from sqlalchemy import *
|
||||||
from sqlalchemy.orm import relationship, backref
|
from sqlalchemy.orm import relationship, backref
|
||||||
from sqlalchemy.ext.declarative import declared_attr
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
import steam
|
import steam.steamid
|
||||||
|
|
||||||
|
|
||||||
class Steam:
|
class Steam:
|
||||||
|
@ -21,7 +21,7 @@ class Steam:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def steamid(self):
|
def steamid(self):
|
||||||
return steam.SteamID(self._steamid)
|
return steam.steamid.SteamID(self._steamid)
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def persona_name(self):
|
def persona_name(self):
|
||||||
|
@ -43,6 +43,19 @@ class Steam:
|
||||||
def account_creation_date(self):
|
def account_creation_date(self):
|
||||||
return Column(DateTime)
|
return Column(DateTime)
|
||||||
|
|
||||||
|
def json(self):
|
||||||
|
return {
|
||||||
|
"steamid": self._steamid,
|
||||||
|
"persona_name": self.persona_name,
|
||||||
|
"profile_url": self.profile_url,
|
||||||
|
"avatar": self.avatar,
|
||||||
|
"primary_clan_id": self.primary_clan_id,
|
||||||
|
"account_creation_date": self.account_creation_date.isoformat(),
|
||||||
|
|
||||||
|
"dota": self.dota.json() if self.dota is not None else None,
|
||||||
|
"brawlhalla": self.brawlhalla.json() if self.brawlhalla is not None else None
|
||||||
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Steam account {self._steamid} of {self.user}>"
|
return f"<Steam account {self._steamid} of {self.user}>"
|
||||||
|
|
||||||
|
|
|
@ -42,5 +42,14 @@ class TriviaScore:
|
||||||
def score(self) -> float:
|
def score(self) -> float:
|
||||||
return (self.correct_answers + self.correct_answers * self.correct_rate) * 10
|
return (self.correct_answers + self.correct_answers * self.correct_rate) * 10
|
||||||
|
|
||||||
|
def json(self):
|
||||||
|
return {
|
||||||
|
"correct": self.correct_answers,
|
||||||
|
"wrong": self.wrong_answers,
|
||||||
|
"total": self.total_answers,
|
||||||
|
"rate": self.correct_rate,
|
||||||
|
"score": self.score
|
||||||
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<TriviaScore of {self.user}: ({self.correct_answers}|{self.wrong_answers})>"
|
return f"<TriviaScore of {self.user}: ({self.correct_answers}|{self.wrong_answers})>"
|
||||||
|
|
|
@ -150,3 +150,16 @@ class LeagueLeague:
|
||||||
fresh_blood=d["freshBlood"],
|
fresh_blood=d["freshBlood"],
|
||||||
veteran=d["veteran"],
|
veteran=d["veteran"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def json(self):
|
||||||
|
return {
|
||||||
|
"tier": self.tier.name if self.tier is not None else None,
|
||||||
|
"rank": self.rank.name if self.tier is not None else None,
|
||||||
|
"points": self.points,
|
||||||
|
"wins": self.wins,
|
||||||
|
"losses": self.losses,
|
||||||
|
"inactive": self.inactive,
|
||||||
|
"hot_streak": self.hot_streak,
|
||||||
|
"fresh_blood": self.fresh_blood,
|
||||||
|
"veteran": self.veteran,
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
semantic = "5.8.19"
|
semantic = "5.8.20"
|
||||||
|
|
Loading…
Reference in a new issue