Пример #1
0
class Skill(Model, metaclass=SkillMeta):
    id = IntField(pk=True, generated=False)
    name = CharField(max_length=255)
    image = CharField(max_length=255)
    level_required = IntField(default=0)
    mp_cost = IntField(default=0)

    passive: bool = BooleanField(default=False)  # type: ignore
    noncombat: bool = BooleanField(default=False)  # type: ignore
    shruggable: bool = BooleanField(default=False)  # type: ignore
    combat: bool = BooleanField(default=False)  # type: ignore
    healing: bool = BooleanField(default=False)  # type: ignore
    summon: bool = BooleanField(default=False)  # type: ignore
    expression: bool = BooleanField(default=False)  # type: ignore
    walk: bool = BooleanField(default=False)  # type: ignore
    mutex_song: bool = BooleanField(default=False)  # type: ignore

    @property
    def buff(self) -> bool:
        return self.shruggable

    def have(self):
        return self in self.kol.state.skills

    async def cast(self, times: int = 1):
        return await request.skill_use(self.kol, self, times).parse()
Пример #2
0
class Role(NamedMixin, BaseModel):
    """
    The role model.

    Users can have multiple roles. Roles can have multiple rights. This is how user rights
    are modeled.
    """

    DESCRIPTION_LENGTH = 60
    HOME_ROUTE_LENGTH = 40

    description = CharField(DESCRIPTION_LENGTH, null=True, default="")
    home_route = CharField(HOME_ROUTE_LENGTH, null=True)

    # pylint: disable=missing-docstring
    rights = ManyToManyField("model.Right",
                             related_name="roles",
                             through="roles_rights")

    class Meta:
        # pylint: disable=too-few-public-methods
        # pylint: disable=missing-docstring
        table = "role"

    def __str__(self):
        return f"{self.name} [id={self.id}]"
Пример #3
0
class Tag(Model):
    id = BigIntField(pk=True, generated=True)
    guild_id = BigIntField(null=False)
    author_id = BigIntField(null=False)
    tag_name = CharField(max_length=2000, null=False)
    tag_content = CharField(max_length=2000, null=False)
    tag_added = DateField(null=False)
Пример #4
0
class Panel_Widget(Model):
    id = IntField(pk=True)
    url = CharField(255)
    prefix = CharField(128)
    color_name = CharField(40)

    group: ForeignKeyRelation[Panel_Group] = ForeignKeyField(
        "models.Panel_Group", related_name="panel_widgets")
Пример #5
0
class Users(Model):

    id = IntField(pk=True)
    name = CharField(max_length=100)
    email = CharField(max_length=50, unique=True)
    password = CharField(max_length=255)

    satellite_dataset: ReverseRelation["SatelliteDatasets"]
Пример #6
0
class User(Model):
    id = BigIntField(pk=True, generated=False)
    time_zone = CharField(max_length=255, null=True)
    time_format = CharField(max_length=255, null=True)

    messages: ReverseRelation['Message']

    def __str__(self):
        return f'{self.__class__}: {self.id}'
class Category(Model):
    id = UUIDField(pk=True)
    name = CharField(max_length=255)
    description = CharField(max_length=255)
    keywords = ManyToManyField(
        "models.Keyword", related_name="categories", through="category_keywords"
    )
    created_on = DatetimeField(auto_now_add=True)
    updated_on = DatetimeField(auto_now=True)
Пример #8
0
class Article(Model):
    uid = IntField(pk=True)
    title = CharField(max_length=120)
    slug = CharField(max_length=150, unique=True)
    intro = TextField()
    content = TextField()
    html = TextField()

    class Meta:
        table = "articles"
Пример #9
0
class Infraction(Model):
    id = BigIntField(pk=True, generated=True)
    guild_id = BigIntField(null=False)
    moderator_id = BigIntField(null=False)
    user_id = BigIntField(null=False)
    type = CharField(max_length=50, null=False)
    reason = CharField(max_length=2000,
                       null=False,
                       default="No reason was provided.")
    given_at = DateField(null=False)
Пример #10
0
class SatelliteDatasets(Model):

    id = IntField(pk=True)
    satellite_name = CharField(max_length=50)
    dataset_path = TextField()
    dataset_type = CharField(max_length=50)

    # class PydanticMeta:
    #     exclude = ['dataset_path']

    # user: ForeignKeyRelation[Users] = ForeignKeyField('models.Users', related_name='satellite_dataset')
    data_visualization: ReverseRelation['DataVisualization']
Пример #11
0
class Outfit(Model):
    id = IntField(pk=True, generated=False)
    name = CharField(max_length=255)
    image = CharField(max_length=255)
    variants: List["libkol.OutfitVariant"]

    async def is_fulfilled(self, equipment: List["libkol.Item"]):
        # Doesn't cover if you need more than one of an item to fulfil an outfit
        await self.fetch_related("variants", "variants__pieces")
        return any(
            all(p in equipment for p in variant.pieces) for variant in self.variants
        )
Пример #12
0
class ApiUser(Model):
    """API user."""

    username = CharField(max_length=128, unique=True)
    password = CharField(max_length=255)
    routes = ManyToManyField("models.ApiRoute", related_name="users")
    jobs: ReverseRelation["ApiJob"]

    class Meta:
        """Tortoise ORM Config."""

        table = "api_users"
Пример #13
0
class BoardModel(Model):

    mac = CharField(pk=True,
                    max_length=17,
                    description="MAC address as primary key")
    ip = CharField(max_length=15,
                   description="String representation of the local ip")
    firmware = CharField(max_length=12, description="Firmware version")
    name = CharField(max_length=20,
                     description="The non unique name of the board")

    class Meta:
        ordering = ["name"]
Пример #14
0
class Clan(Model):
    clan_id = BigIntField(unique=True)
    name = CharField(max_length=255)
    callsign = CharField(max_length=4)
    platform = IntField(null=True, validators=[PlatformValidator()])
    the100_group_id = IntField(unique=True, null=True)
    activity_tracking = BooleanField(default=True)

    guild: ForeignKeyRelation[Guild] = ForeignKeyField(
        "seraphsix.Guild", related_name="clans", to_field="id"
    )

    members: ReverseRelation["ClanMember"]
Пример #15
0
class Modifier(Model):
    item = ForeignKeyField("models.Item", related_name="modifiers", null=True)
    item_id: Optional[int]

    effect = ForeignKeyField("models.Effect",
                             related_name="modifiers",
                             null=True)
    effect_id: Optional[int]

    key = CharField(max_length=255)
    numeric_value = IntField(null=True)
    string_value = CharField(max_length=255, null=True)
    expression_value = CharField(max_length=255, null=True)
    percentage = BooleanField(default=False)
Пример #16
0
class Post(Model):
    id = IntField(pk=True)
    created_at = DatetimeField(auto_now_add=True)
    modified_at = DatetimeField(auto_now=True)
    title = CharField(max_length=32)
    content = TextField(null=True)
    image_url = TextField()

    author: ForeignKeyRelation[User] = ForeignKeyField("models.User", "posts")
    comments = ReverseRelation["Comment"]

    class Meta:
        table = "posts"
        ordering = ["created_at"]

    class PydanticMeta:
        exclude = ("author", "comments")

    def __repr__(self):
        return (
            f"Post({self.id=}, {self.created_at=}, {self.modified_at=}, "
            f"{self.title=}, {self.content=}, {self.image_url}, {self.author=})"
        )

    def __str__(self):
        return self.__repr__()
Пример #17
0
class DataVisualization(Model):

    id = IntField(pk=True)
    image_name = CharField(max_length=100)

    satellite_dataset: ForeignKeyRelation[SatelliteDatasets] = ForeignKeyField(
        'models.SatelliteDatasets', related_name='data_visualization')
Пример #18
0
class Guild(Model):
    guild_id = BigIntField(unique=True)
    prefix = CharField(max_length=5, null=True, default="?")
    clear_spam = BooleanField(default=False)
    aggregate_clans = BooleanField(default=True)
    track_sherpas = BooleanField(default=False)
    admin_channel = BigIntField(unique=True, null=True)
    announcement_channel = BigIntField(unique=True, null=True)
Пример #19
0
class Log(BaseModel):
    email_id: ManyToManyRelation['Email'] = ManyToManyField(
        "models.Email", related_name='emails')
    date = DateTimeField(index=True, default=datetime.datetime.now())
    exception_type = CharField(null=True)
    message = TextField()
    status = IntField(index=True, null=True)

    class Meta:
        table = 'data_log'
Пример #20
0
class ApiRoute(Model):
    """API route definition for access control."""

    name = CharField(max_length=255, unique=True)
    users: ReverseRelation["models.ApiUser"]  # noqa: F821

    class Meta:
        """Tortoise ORM Config."""

        table = "api_routes"
Пример #21
0
class User(Model):
    id = IntField(pk=True)
    created_at = DatetimeField(auto_now_add=True)
    modified_at = DatetimeField(auto_now=True)
    username = CharField(max_length=32, unique=True)
    mail = CharField(max_length=64, null=True)
    password = CharField(max_length=64)
    bio = TextField(null=True)

    posts = ReverseRelation["Post"]
    comments = ReverseRelation["Comment"]

    class Meta:
        table = "users"

    class PydanticMeta:
        exclude = ("password", "access_token", "posts", "comments")

    def __repr__(self):
        return (
            f"User({self.id=}, {self.created_at=}, {self.modified_at=}, "
            f"{self.username=}, {self.mail=}, {self.password=},{self.bio=})"
        )

    def __str__(self):
        return self.__repr__()

    def verify_password(self, password: str) -> bool:
        return bcrypt.verify(password, self.password)

    def access_token(self) -> str:
        data = {
            "iat": datetime.utcnow(),
            "exp": datetime.utcnow() + timedelta(minutes=60),
            "sub": str(self.id),
        }
        token: str = jwt.encode(
            data,
            getenv("JWT_SECRET"),
            algorithm="HS256",
        )
        return token
Пример #22
0
class User(Model):
    id = IntField(pk=True)
    username = CharField(20, unique=True)
    password_hash = BinaryField()
    is_admin = BooleanField(default=False)

    def check_password(self, to_check: str) -> bool:
        return check_password_hash(self.password_hash.decode(), to_check)

    def set_password(self, new_password: str):
        self.password_hash = generate_password_hash(new_password).encode()
Пример #23
0
class Email(BaseModel):

    id = IntField(pk=True)
    from_email = CharField(255)
    to_email = TextField()
    bcc = TextField()
    cc = TextField()
    subject = CharField(255)
    context = TextField(null=True)
    created = DateTimeField(index=True, auto_now_add=True)
    headers = JSONField(null=False)
    html_message = TextField(null=True)
    last_updated = DateTimeField(index=True, default=datetime.datetime.now())
    message = TextField()
    priority = IntField(null=True)
    scheduled_time = DateTimeField(index=True, null=True)
    status = IntField(index=True, null=True)

    class Meta:
        table = 'data_email'
Пример #24
0
class User(Model):
    id = IntField(pk=True)
    name = CharField(max_length=255, unique=True)
    password = TextField(null=True)
    given_name = TextField(null=True)
    family_name = TextField(null=True)
    email = TextField(null=True)
    realm = TextField()
    realmuid = TextField(null=True)
    time_created = DatetimeField(auto_now_add=True)
    time_updated = DatetimeField(auto_now=True)
    groups = ManyToManyField('models.Group', related_name='users')
Пример #25
0
class Member(Model):
    discord_id = BigIntField(null=True)
    bungie_id = BigIntField(null=True)
    bungie_username = CharField(max_length=255, null=True)
    xbox_id = BigIntField(null=True)
    xbox_username = CharField(max_length=255, unique=True, null=True)
    psn_id = BigIntField(null=True)
    psn_username = CharField(max_length=255, unique=True, null=True)
    blizzard_id = BigIntField(null=True)
    blizzard_username = CharField(max_length=255, unique=True, null=True)
    steam_id = BigIntField(null=True)
    steam_username = CharField(max_length=255, unique=True, null=True)
    stadia_id = BigIntField(null=True)
    stadia_username = CharField(max_length=255, unique=True, null=True)
    the100_id = BigIntField(unique=True, null=True)
    the100_username = CharField(max_length=255, unique=True, null=True)
    timezone = CharField(max_length=255, null=True)
    bungie_access_token = CharField(max_length=360, unique=True, null=True)
    bungie_refresh_token = CharField(max_length=360, unique=True, null=True)
    is_cross_save = BooleanField(default=False)
    primary_membership_id = BigIntField(unique=True, null=True)

    clan: ReverseRelation["ClanMember"]
    games: ReverseRelation["GameMember"]

    class Meta:
        indexes = [
            PostgreSQLIndex(
                fields={
                    "discord_id",
                    "bungie_id",
                    "xbox_id",
                    "psn_id",
                    "blizzard_id",
                    "steam_id",
                    "stadia_id",
                    "the100_id",
                }
            )
        ]
Пример #26
0
class Reminder(Model):
    id = IntField(pk=True, generated=True)
    info = CharField(max_length=255, null=True)
    added_dt = DatetimeField()
    expire_dt = DatetimeField()

    for_message = OneToOneField('models.Message',
                                related_name='reminder',
                                on_delete=CASCADE,
                                null=False)

    def __str__(self):
        return f'{self.__class__}: {self.id}'
Пример #27
0
class User(Model):
    id = UUIDField(pk=True, index=True)

    # 0 == Free, 10 == Premium
    tier = IntField(default=0)

    username = CharField(max_length=255, unique=True, index=True)
    hashed_password = TextField(null=False)

    encrypted = BooleanField(default=False)
    admin = BooleanField(default=False)

    journals: ReverseRelation["Journal"]
Пример #28
0
class NamedMixin:
    # pylint: disable=too-few-public-methods,missing-docstring

    NAME_LENGTH = 32

    name = CharField(NAME_LENGTH, unique=True, null=False)

    @classmethod
    async def get_by_name(cls, name):
        """
        Get an instance of this class by its name attribute.
        If no such instance exists, returns None
        """
        return await cls.get_or_None(name=name)
Пример #29
0
class ApiKey(BaseModel):
    # pylint: disable=R0903
    """
    Api Key Model

    To use the api, you need a valid API-KEY
    """

    apikey = CharField(24, unique=True, null=False)
    valid_from = DateField(null=True)
    valid_until = DateField(null=True)

    class Meta:
        # pylint: disable=C0111, R0903
        table = "apikey"
Пример #30
0
class Event(Model):
    id = IntField(pk=True, generated=True)
    name = CharField(max_length=255, null=True)
    scheduled_dt = DatetimeField()

    author_message = OneToOneField('models.Message',
                                   related_name='user_event',
                                   on_delete=CASCADE,
                                   null=False)
    bot_message = OneToOneField('models.Message',
                                related_name='bot_event',
                                on_delete=CASCADE,
                                null=False)

    def __str__(self):
        return f'{self.__class__}: {self.id}'