2022-11-15 09:19:08 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
from sqlalchemy import Column, ForeignKey
|
2022-05-04 23:09:46 +00:00
|
|
|
from sqlalchemy.orm import relationship
|
2022-11-15 09:19:08 +00:00
|
|
|
from sqlalchemy.sql.sqltypes import *
|
|
|
|
|
|
|
|
from files.classes import Base
|
2023-03-12 13:02:31 +00:00
|
|
|
from files.helpers.config.const import *
|
2022-05-04 23:09:46 +00:00
|
|
|
from files.helpers.lazy import lazy
|
|
|
|
|
|
|
|
class BadgeDef(Base):
|
|
|
|
__tablename__ = "badge_defs"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
name = Column(String)
|
|
|
|
description = Column(String)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
2022-11-29 21:02:38 +00:00
|
|
|
return f"<{self.__class__.__name__}(id={self.id})>"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-08-25 17:29:31 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def path(self):
|
2023-03-12 13:02:31 +00:00
|
|
|
if 20 < self.id < 28 or self.id == 222: return SITE_FULL + f"/i/{SITE_NAME}/badges/{self.id}.webp"
|
|
|
|
return SITE_FULL + f"/i/badges/{self.id}.webp"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
class Badge(Base):
|
|
|
|
|
|
|
|
__tablename__ = "badges"
|
|
|
|
|
|
|
|
user_id = Column(Integer, ForeignKey('users.id'), primary_key=True)
|
2022-09-04 23:15:37 +00:00
|
|
|
badge_id = Column(Integer, ForeignKey('badge_defs.id'), primary_key=True)
|
2022-05-04 23:09:46 +00:00
|
|
|
description = Column(String)
|
|
|
|
url = Column(String)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
user = relationship("User", back_populates="badges")
|
2022-11-09 14:25:47 +00:00
|
|
|
badge = relationship("BadgeDef", primaryjoin="Badge.badge_id == BadgeDef.id", lazy="joined", innerjoin=True)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-09-19 20:40:33 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs:
|
|
|
|
kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
def __repr__(self):
|
2022-11-29 21:02:38 +00:00
|
|
|
return f"<{self.__class__.__name__}(user_id={self.user_id}, badge_id={self.badge_id})>"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-09 08:35:47 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def until(self):
|
2022-08-17 19:17:34 +00:00
|
|
|
if self.badge_id == 28 and self.user.agendaposter != 1: return self.user.agendaposter
|
2022-09-13 18:02:08 +00:00
|
|
|
if self.badge_id == 170 and self.user.marsify != 1: return self.user.marsify
|
|
|
|
|
2022-07-09 08:35:47 +00:00
|
|
|
if self.badge_id == 94: return self.user.progressivestack
|
|
|
|
if self.badge_id == 95: return self.user.bird
|
|
|
|
if self.badge_id == 96: return self.user.flairchanged
|
|
|
|
if self.badge_id == 97: return self.user.longpost
|
|
|
|
if self.badge_id == 98: return self.user.marseyawarded
|
|
|
|
if self.badge_id == 109: return self.user.rehab
|
2022-09-07 03:31:55 +00:00
|
|
|
if self.badge_id == 167: return self.user.owoify
|
|
|
|
if self.badge_id == 168: return self.user.bite
|
|
|
|
if self.badge_id == 169: return self.user.earlylife
|
|
|
|
if self.badge_id == 171: return self.user.rainbow
|
|
|
|
|
2022-07-09 08:35:47 +00:00
|
|
|
return None
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def text(self):
|
2022-09-12 11:51:56 +00:00
|
|
|
if self.until:
|
2022-07-09 08:35:47 +00:00
|
|
|
text = self.badge.description + " until"
|
2022-12-23 22:22:41 +00:00
|
|
|
elif self.badge_id in {28, 170, 179}:
|
2022-09-12 11:51:56 +00:00
|
|
|
text = self.badge.description + " permanently"
|
2022-07-09 08:35:47 +00:00
|
|
|
elif self.description:
|
|
|
|
text = self.description
|
|
|
|
elif self.badge.description:
|
|
|
|
text = self.badge.description
|
|
|
|
else:
|
|
|
|
return self.name
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
return f'{self.name} - {text}'
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def name(self):
|
|
|
|
return self.badge.name
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def path(self):
|
2022-08-25 17:29:31 +00:00
|
|
|
return self.badge.path
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def json(self):
|
|
|
|
return {'text': self.text,
|
|
|
|
'name': self.name,
|
|
|
|
'url': self.url,
|
|
|
|
'icon_url':self.path
|
|
|
|
}
|