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

47 lines
1.6 KiB
Python
Raw Normal View History

2020-06-20 01:49:48 +00:00
import royalnet.backpack.tables as rbt
2020-06-26 14:13:11 +00:00
import royalnet.constellation.api as rca
2020-06-20 01:49:48 +00:00
2020-06-22 17:27:11 +00:00
class ApiUserRygStar(rca.ApiStar):
path = "/api/user/ryg/v2"
2020-06-20 01:49:48 +00:00
2020-06-22 17:27:11 +00:00
parameters = {
"get": {
"uid": "(Choose one) The id of the user to get information about.",
"alias": "(Choose one) The alias of the user to get information about.",
}
}
2020-06-20 01:49:48 +00:00
tags = ["user"]
async def get_user(self, data: rca.ApiData):
2020-06-22 17:27:11 +00:00
uid = data.int("uid", optional=True)
alias = data.str("alias", optional=True)
if uid:
user = await rbt.User.find(self.alchemy, data.session, uid)
elif alias:
user = await rbt.User.find(self.alchemy, data.session, alias)
else:
raise rca.MissingParameterError("Neither uid or alias were specified.")
2020-06-20 01:49:48 +00:00
if user is None:
raise rca.NotFoundError("No such user.")
2020-06-22 17:27:11 +00:00
2020-06-20 01:49:48 +00:00
return user
2020-06-26 14:13:11 +00:00
@rca.magic
2020-06-22 17:27:11 +00:00
async def get(self, data: rca.ApiData) -> dict:
"""Get Royalpack information about a user."""
2020-06-20 01:49:48 +00:00
user = await self.get_user(data)
result = {
**user.json(),
"bio": user.bio.json() if user.bio is not None else None,
"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],
2020-08-29 18:36:58 +00:00
"osu": [osu.json() for osu in user.osu],
2020-09-20 15:45:57 +00:00
"trivia": user.trivia_score.json() if user.trivia_score is not None else None,
2020-06-20 01:49:48 +00:00
}
return result