1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

publish: 5.8.20

This commit is contained in:
Steffo 2020-06-19 17:39:46 +02:00
parent 614d3274e7
commit 630fc19179
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
10 changed files with 133 additions and 13 deletions

View file

@ -2,7 +2,7 @@
[tool.poetry]
name = "royalpack"
version = "5.8.19"
version = "5.8.20"
description = "A Royalnet command pack for the Royal Games community"
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
license = "AGPL-3.0+"

View file

@ -15,6 +15,7 @@ from .api_polls_get import ApiPollsGet
from .api_polls_list import ApiPollsList
from .api_cvstats_latest import ApiCvstatsLatestStar
from .api_cvstats_avg import ApiCvstatsAvgStar
from .api_user_get_ryg import ApiUserGetRygStar
# Enter the PageStars of your Pack here!
available_page_stars = [
@ -34,6 +35,7 @@ available_page_stars = [
ApiPollsList,
ApiCvstatsLatestStar,
ApiCvstatsAvgStar,
ApiUserGetRygStar,
]
# Don't change this, it should automatically generate __all__

View 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

View file

@ -1,7 +1,7 @@
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declared_attr
import steam
import steam.steamid
from ..types import BrawlhallaRank, BrawlhallaTier, BrawlhallaMetal
@ -23,7 +23,7 @@ class Brawlhalla:
@property
def steamid(self):
return steam.SteamID(self._steamid)
return steam.steamid.SteamID(self._steamid)
@declared_attr
def name(self):
@ -58,34 +58,51 @@ class Brawlhalla:
@property
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:
return None
return duos[0].rating_2v2
@property
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:
return None
return duos[0].tier_2v2
@property
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:
return None
return duos[0].metal_2v2
@property
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:
return None
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):
return f"<Brawlhalla account {self._steamid}>"
def __str__(self):
return f"[c]brawlhalla:{self.brawlhalla_id}[/c]"
return f"[c]brawlhalla:{self.brawlhalla_id}[/c]"

View file

@ -3,7 +3,7 @@ from sqlalchemy import *
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declared_attr
from ..types import DotaMedal, DotaStars, DotaRank
import steam
import steam.steamid
class Dota:
@ -19,7 +19,7 @@ class Dota:
@property
def steamid(self):
return steam.SteamID(self._steamid)
return steam.steamid.SteamID(self._steamid)
@declared_attr
def _rank_tier(self):
@ -72,6 +72,19 @@ class Dota:
def losses(self):
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):
return f"<Dota account {self._steamid}>"

View file

@ -249,6 +249,21 @@ class LeagueOfLegends:
def mastery_score(self):
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):
return f"<{self.__class__.__qualname__} {str(self)}>"

View file

@ -1,7 +1,7 @@
from sqlalchemy import *
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declared_attr
import steam
import steam.steamid
class Steam:
@ -21,7 +21,7 @@ class Steam:
@property
def steamid(self):
return steam.SteamID(self._steamid)
return steam.steamid.SteamID(self._steamid)
@declared_attr
def persona_name(self):
@ -43,6 +43,19 @@ class Steam:
def account_creation_date(self):
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):
return f"<Steam account {self._steamid} of {self.user}>"

View file

@ -42,5 +42,14 @@ class TriviaScore:
def score(self) -> float:
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):
return f"<TriviaScore of {self.user}: ({self.correct_answers}|{self.wrong_answers})>"

View file

@ -150,3 +150,16 @@ class LeagueLeague:
fresh_blood=d["freshBlood"],
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,
}

View file

@ -1 +1 @@
semantic = "5.8.19"
semantic = "5.8.20"