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

89 lines
2.6 KiB
Python
Raw Permalink Normal View History

2020-01-20 21:47:45 +00:00
from sqlalchemy import *
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declared_attr
2020-06-19 15:39:46 +00:00
import steam.steamid
2020-01-20 21:47:45 +00:00
class Steam:
__tablename__ = "steam"
@declared_attr
def user_id(self):
return Column(Integer, ForeignKey("users.uid"))
@declared_attr
def user(self):
return relationship("User", backref=backref("steam"))
@declared_attr
2020-01-20 23:54:55 +00:00
def _steamid(self):
2020-01-20 21:47:45 +00:00
return Column(BigInteger, primary_key=True)
2020-01-20 23:54:55 +00:00
@property
def steamid(self):
2020-06-19 15:39:46 +00:00
return steam.steamid.SteamID(self._steamid)
2020-01-20 23:54:55 +00:00
2020-01-20 21:47:45 +00:00
@declared_attr
def persona_name(self):
return Column(String)
@declared_attr
def profile_url(self):
return Column(String)
@declared_attr
def avatar(self):
return Column(String)
@declared_attr
def primary_clan_id(self):
return Column(BigInteger)
@declared_attr
def account_creation_date(self):
return Column(DateTime)
2020-07-09 02:13:54 +00:00
@declared_attr
def account_level(self):
return Column(Integer, nullable=False, default=0)
@declared_attr
def owned_games_count(self):
return Column(Integer, nullable=False, default=0)
@declared_attr
def most_played_game_2weeks(self):
return Column(Integer, nullable=False, default=753)
@declared_attr
def most_played_game_forever(self):
return Column(Integer, nullable=False, default=753)
2020-06-19 15:39:46 +00:00
def json(self):
return {
2020-07-07 18:19:11 +00:00
"steamid2": self.steamid.as_steam2,
"steamid3": self.steamid.as_steam3,
"steamid32": self.steamid.as_32,
"steamid64": self.steamid.as_64,
2020-06-19 15:39:46 +00:00
"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(),
2020-07-10 12:14:50 +00:00
"account_level": self.account_level,
"owned_games_count": self.owned_games_count,
"most_played_game_2weeks": self.most_played_game_2weeks,
"most_played_game_forever": self.most_played_game_forever,
2020-06-19 15:39:46 +00:00
"dota": self.dota.json() if self.dota is not None else None,
2020-09-22 02:01:22 +00:00
"brawlhalla": self.brawlhalla.json() if self.brawlhalla is not None else None,
2020-09-26 01:02:04 +00:00
"trionfistatus": self.trionfistatus.json() if (self.trionfistatus is not None and self.trionfistatus.zero
2020-10-13 20:38:41 +00:00
is not None) else None,
2020-06-19 15:39:46 +00:00
}
2020-01-20 21:47:45 +00:00
def __repr__(self):
2020-01-20 23:54:55 +00:00
return f"<Steam account {self._steamid} of {self.user}>"
2020-01-20 21:47:45 +00:00
def __str__(self):
2020-01-20 23:54:55 +00:00
return f"[c]steam:{self._steamid}[/c]"