1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-30 15:04:18 +00:00
royalnet/royalpack/tables/brawlhalla.py

59 lines
1.5 KiB
Python
Raw Normal View History

2020-03-18 17:06:15 +00:00
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declared_attr
import steam
2020-03-19 15:26:11 +00:00
from ..types import BrawlhallaRank, BrawlhallaTier, BrawlhallaMetal
2020-03-18 17:06:15 +00:00
2020-03-19 15:26:11 +00:00
# noinspection PyAttributeOutsideInit
2020-03-18 17:06:15 +00:00
class Brawlhalla:
__tablename__ = "brawlhalla"
@declared_attr
def brawlhalla_id(self):
return Column(Integer, primary_key=True)
@declared_attr
def _steamid(self):
return Column(BigInteger, ForeignKey("steam._steamid"), primary_key=True)
@declared_attr
def steam(self):
return relationship("Steam", backref=backref("brawlhalla", uselist=False))
@property
def steamid(self):
return steam.SteamID(self._steamid)
@declared_attr
def name(self):
2020-03-19 15:26:11 +00:00
return Column(String, nullable=False)
2020-03-18 17:06:15 +00:00
@declared_attr
def rating_1v1(self):
return Column(Integer)
2020-03-19 15:26:11 +00:00
@declared_attr
2020-03-18 17:06:15 +00:00
def tier_1v1(self):
2020-03-19 15:26:11 +00:00
return Column(Enum(BrawlhallaTier))
@declared_attr
def metal_1v1(self):
return Column(Enum(BrawlhallaMetal))
@property
def rank_1v1(self):
return BrawlhallaRank(metal=self.metal_1v1, tier=self.tier_1v1)
@rank_1v1.setter
def rank_1v1(self, value):
if not isinstance(value, BrawlhallaRank):
raise TypeError("rank_1v1 can only be set to BrawlhallaRank values.")
self.metal_1v1 = value.metal
self.tier_1v1 = value.tier
def __repr__(self):
return f"<Brawlhalla account {self._steamid}>"
def __str__(self):
return f"[c]brawlhalla:{self.brawlhalla_id}[/c]"