Exemplo n.º 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()
Exemplo n.º 2
0
class Comment(Model):
    id = IntField(pk=True)
    dataset = ForeignKeyField('models.Dataset', related_name='comments')

    author = TextField()
    time_added = IntField()  # ms since epoch
    text = TextField()
Exemplo n.º 3
0
class Dataset(Model):
    id = IntField(pk=True)

    collection = ForeignKeyField('models.Collection', related_name='datasets')
    discarded = BooleanField(default=False)
    name = TextField()
    status = IntField(default=0)
    time_added = IntField()  # ms since epoch
    timestamp = IntField()  # ms since epoch

    setid = custom.SetIDField(unique=True)
    tags = ManyToManyField('models.Tag', related_name='datasets')
    acn = ForeignKeyField('models.Acn',
                          related_name='datasets',
                          on_delete=RESTRICT)

    # Populated by backreferences: comments, files

    error = make_status_property(1)
    missing = make_status_property(2)
    outdated = make_status_property(4)
    pending = make_status_property(8)

    def __repr__(self):
        return f'<{type(self).__name__} {self.setid} {self.name}>'
Exemplo n.º 4
0
def make_listing_model(name, filter_specs):
    models = []
    listing_name = f'l_{name}'
    listing_model_name = underscore_to_camelCase(listing_name)

    def generate_relation(fname):
        rel_name = f'{listing_name}_{fname}'
        rel_model_name = underscore_to_camelCase(rel_name)
        assert '_' not in rel_model_name, rel_model_name

        model = type(
            rel_model_name, (Model, ), {
                'Meta':
                type('Meta', (), {'table': rel_name}),
                'id':
                IntField(pk=True),
                'value':
                CharField(max_length=255, index=True, unique=True),
                '__repr__':
                lambda self:
                f'<{type(self).__name__} {self.id} {self.value!r}>',
            })

        models.append(model)
        return ManyToManyField(f'models.{rel_model_name}',
                               related_name='listing')

    coltype_factories = {
        # All dates and times in ms (since epoch)
        'datetime': lambda name: IntField(null=True),
        'filesize': lambda name: IntField(null=True),
        'float': lambda name: FloatField(null=True),
        'int': lambda name: IntField(null=True),
        'string': lambda name: TextField(null=True),
        'string[]': generate_relation,
        'subset': generate_relation,
        'timedelta': lambda name: IntField(null=True),
        'words': lambda name: TextField(null=True),
    }

    dct = {
        'Meta': type('Meta', (), {'table': listing_name}),
        'id': IntField(pk=True),
        'row': TextField(null=True),
        '__repr__': lambda self: f'<{type(self).__name__} {self.dataset_id}>',
    }

    dct.update(
        (fspec.name, coltype_factories[fspec.value_type](fspec.name))
        for fspec in filter_specs.values()
        if fspec.name not in ('row', 'f_comments', 'f_status', 'f_tags'))

    models.append(type(listing_model_name, (Model, ), dct))
    return models
Exemplo n.º 5
0
class File(Model):
    id = IntField(pk=True)
    dataset = ForeignKeyField('models.Dataset', related_name='files')
    idx = IntField()  # files are counted per dataset

    missing = BooleanField(default=False)
    mtime = IntField()  # ms since epoch
    path = TextField()
    size = IntField()

    def __repr__(self):
        return f"<{type(self).__name__} '{self.path}'>"
Exemplo n.º 6
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"]
Exemplo n.º 7
0
class ClanMember(Model):
    platform_id = IntField()
    join_date = DatetimeField()
    is_active = BooleanField(default=True)
    last_active = DatetimeField(null=True)
    is_sherpa = BooleanField(default=False)
    member_type = IntField(null=True, validators=[ClanMemberRankValidator()])

    clan: ForeignKeyRelation[Clan] = ForeignKeyField(
        "seraphsix.Clan", related_name="members", to_field="id"
    )

    member: ForeignKeyRelation[Member] = ForeignKeyField(
        "seraphsix.Member", related_name="clans", to_field="id"
    )
Exemplo n.º 8
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__()
Exemplo n.º 9
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')
Exemplo n.º 10
0
class TortoiseModel(Model):
    class Meta:
        abstract = True

    id: int = IntField(pk=True)
    created_at: datetime = DatetimeField(auto_now_add=True)
    updated_at: datetime = DatetimeField(auto_now=True)
Exemplo n.º 11
0
class Game(Model):
    mode_id = IntField()
    instance_id = BigIntField(unique=True)
    date = DatetimeField()
    reference_id = BigIntField(null=True)

    class Meta:
        indexes = ("mode_id", "reference_id")
Exemplo n.º 12
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")
Exemplo n.º 13
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"]
Exemplo n.º 14
0
class User(Model):
    id = BigIntField(pk=True)
    exp = IntField(default=0)
    level = IntField(default=0)
    balance = IntField(default=0)
    daily_streak = IntField(default=0)
    last_daily = DatetimeField(null=True)
    mutes: ReverseRelation["Mute"]
    warns: ReverseRelation["Warn"]

    @property
    def next_daily(self):
        if not self.last_daily:
            return None

        return datetime.fromtimestamp(
            (self.last_daily + timedelta(hours=23)).timestamp()
        )

    @property
    def daily_available(self):
        if not self.last_daily:
            return True

        return datetime.utcnow().timestamp() > self.next_daily.timestamp()

    @property
    def daily_streak_expired(self):
        if not self.last_daily:
            return None

        return (
            datetime.utcnow().timestamp()
            > (self.last_daily + timedelta(days=2)).timestamp()
        )

    class Meta:
        table = "users"

    def __str__(self):
        return (
            f"<User id:{self.id} exp:{self.exp} "
            f"level:{self.level} bal:{self.balance}>"
        )
Exemplo n.º 15
0
class MonsterDrop(Model):
    item = ForeignKeyField("models.Item", related_name="drops")
    monster = ForeignKeyField("models.Monster", related_name="drops")

    rate = IntField()
    pickpocket_only = BooleanField(default=False)
    no_pickpocket = BooleanField(default=False)
    conditional = BooleanField(default=False)
    fixed = BooleanField(default=False)
    stealable_accordion = BooleanField(default=False)
Exemplo n.º 16
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'
Exemplo n.º 17
0
class Moderator(Model):
    id = IntField(pk=True)
    user: ForeignKeyRelation[User] = ForeignKeyField(
        "models.User", related_name="moderator_on")
    guild: ForeignKeyRelation[Guild] = ForeignKeyField(
        "models.Guild", related_name="moderators")
    title = TextField(null=True)

    class Meta:
        table = "moderators"
Exemplo n.º 18
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"
Exemplo n.º 19
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()
Exemplo n.º 20
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'
Exemplo n.º 21
0
class BaseModel(Model):
    """
    This is the base model for all models in the digicube domain.
    """

    id: IntField = IntField(pk=True, description="Primary key")
    created_at: DatetimeField = DatetimeField(null=True, auto_now_add=True)
    modified_at: DatetimeField = DatetimeField(null=True, auto_now=True)

    class Meta:
        # pylint: disable=too-few-public-methods,missing-docstring
        abstract = True
Exemplo n.º 22
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')
Exemplo n.º 23
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']
Exemplo n.º 24
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
        )
Exemplo n.º 25
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}'
Exemplo n.º 26
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"]
Exemplo n.º 27
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)
Exemplo n.º 28
0
class Journal(Model):
    id = IntField(pk=True, index=True)

    user: ForeignKeyRelation[User] = ForeignKeyField("models.User",
                                                     related_name="journals",
                                                     on_delete=CASCADE)

    name = TextField(null=False)
    name_lower = TextField(null=False)

    # YYYY-MM-DD or None
    deleted_on = DateField(null=True)

    entries: ReverseRelation["Entry"]
Exemplo n.º 29
0
class Role(Model):
    role_id = BigIntField()
    platform_id = IntField(null=True)
    is_sherpa = BooleanField(null=True)
    is_clanmember = BooleanField(null=True)
    is_new_clanmember = BooleanField(null=True)
    is_non_clanmember = BooleanField(null=True)
    is_protected_clanmember = BooleanField(null=True)

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

    class Meta:
        indexes = ("guild", "role_id")
Exemplo n.º 30
0
class Entry(Model):
    id = IntField(pk=True, index=True)

    journal: ForeignKeyRelation[Journal] = ForeignKeyField(
        "models.Journal", related_name="entries", on_delete=CASCADE)

    short = TextField(null=False)
    long = TextField(null=False)

    # YYYY-MM-DD HH:MM format in UTC timezone
    date = DatetimeField(null=False)
    # YYYY-MM-DD or None
    deleted_on = DateField(null=True)

    keywords: ReverseRelation["Keyword"]