Exemple #1
0
 class MySchema(Schema):
     # Passing a mutable as default is a bad idea in real life
     d_dict = fields.DictField(values=fields.IntField,
                               default={
                                   '1': 1,
                                   '2': 2
                               })
     c_dict = fields.DictField(values=fields.IntField,
                               default=lambda: {
                                   '1': 1,
                                   '2': 2
                               })
Exemple #2
0
class UserMessage(Message):
    """
    :ivar Dict intent:
    :ivar Dict photo:
    :ivar Dict sentiment:
    :ivar Dict googleTopic:
    """

    # All of them can be empty
    intent = fields.DictField(required=False)
    photo = fields.DictField(required=False)
    sentiment = fields.DictField(required=False)
    googleTopic = fields.ListField(fields.DictField(), required=False)
Exemple #3
0
class Member(Document):
    class Meta:
        collection_name = "member"

    # vouch = fields.ListField(fields.IntegerField, default=list)
    id = fields.IntegerField(attribute="_id")
    balance = fields.IntegerField(default=0)
    banker_balance = fields.IntegerField(default=0)
    joined_at = fields.DateTimeField(default=None)
    suspended = fields.BooleanField(default=False)
    invites = fields.IntegerField(default=0)

    gatcha_counter = fields.DictField(fields.StringField(),
                                      fields.IntegerField(),
                                      default=dict)

    # shitty event collected code
    has_collected = fields.BooleanField(default=False)

    # even more shitty reputation system
    vouched_for = fields.ListField(fields.IntegerField())
    vouched_by = fields.ListField(fields.IntegerField())

    reported_for = fields.ListField(fields.IntegerField())
    reported_by = fields.ListField(fields.IntegerField())

    pray_count = fields.IntegerField(default=0)
    pray_winnings = fields.IntegerField(default=0)

    #event system
    event_activated = fields.BooleanField(default=False)
    event_multiplier = fields.FloatField(default=1.0)
    work_activated = fields.BooleanField(default=False)
    bonus_bought = fields.BooleanField(default=False)
    points = fields.FloatField(default=0.0)
Exemple #4
0
class Anime(Document):
    name = fields.DictField(required=True)
    format = fields.StrField(validate=validate.OneOf(
        ["ONA", "OVA", "TV", "Movie", "Special", "Music", "TV Short"]))
    tags = fields.ListField(fields.StrField())  #array
    genres = fields.ListField(fields.StrField())  #array
    synopsis = fields.StrField()
    season = fields.StrField()
    duration = fields.IntField()
    release_date = fields.StrField()
    studios = fields.ListField(fields.StrField())  #array
    episodes = fields.IntField()
    source = fields.StrField(validate=validate.OneOf([
        "Original", "Manga", "Light Novel", "Visual Novel", "Novel",
        "Video Game", "Doujinshi"
    ]))

    #TODO: controller logic will have to implement String ID to ObjectID from bson.objectid.ObjectId for queries
    id = fields.StrField()
    #TODO: client facing JSON response in API controller will have to output characters with proper structure/dictionary
    #TODO: client facing JSON request in API controller will have to parse through characters and make separate queries for them.
    #TODO: frontend will use the same API
    #TODO: same goes with staff, as in their pictures, names, roles
    rating = fields.FloatField()
    cover = fields.ReferenceField("Image")

    class Meta:
        collection = db.anime
Exemple #5
0
class Item(Document):
    name = fields.StringField(required=True)
    description = fields.StringField()
    parameters = fields.DictField()

    class Meta:
        collection_name = "items"
Exemple #6
0
 class MySchema(BaseSchema):
     # EmbeddedField need instance to retrieve implementation
     required = fields.IntField(required=True)
     embedded = fields.EmbeddedField(MyEmbedded, instance=self.instance)
     listed = fields.ListField(
         fields.EmbeddedField(MyEmbedded, instance=self.instance))
     dicted = fields.DictField(values=fields.EmbeddedField(
         MyEmbedded, instance=self.instance))
Exemple #7
0
class Rule(Document):
    """
    :ivar Dict condition:
    :ivar int score:
    :ivar Action action:
    """
    condition = fields.DictField(required=True)
    score = fields.IntField(required=True)
    action = fields.EmbeddedField(Action, required=True)
Exemple #8
0
class Member(Document):
    class Meta:
        strict = False

    id = fields.IntegerField(attribute="_id")
    pokemon = fields.ListField(fields.EmbeddedField(Pokemon), required=True)

    selected = fields.IntegerField(required=True)

    order_by = fields.StringField(default="number")
    pokedex = fields.DictField(fields.StringField(),
                               fields.IntegerField(),
                               default=dict)
    shinies_caught = fields.IntegerField(default=0)
    balance = fields.IntegerField(default=0)
    redeems = fields.IntegerField(default=0)

    shiny_hunt = fields.IntegerField(default=None)
    shiny_streak = fields.IntegerField(default=0)

    boost_expires = fields.DateTimeField(default=datetime.min)

    last_voted = fields.DateTimeField(default=datetime.min)
    vote_total = fields.IntegerField(default=0)
    vote_streak = fields.IntegerField(default=0)
    gifts_normal = fields.IntegerField(default=0)
    gifts_great = fields.IntegerField(default=0)
    gifts_ultra = fields.IntegerField(default=0)
    gifts_master = fields.IntegerField(default=0)

    silence = fields.BooleanField(default=False)
    joined_at = fields.DateTimeField(default=None)
    invites = fields.IntegerField(default=0)

    suspended = fields.BooleanField(default=False)

    @property
    def selected_pokemon(self):
        try:
            return next(
                filter(lambda x: x.number == int(self.selected), self.pokemon))
        except StopIteration:
            return None

    @property
    def boost_active(self):
        return datetime.utcnow() < self.boost_expires

    @property
    def shiny_hunt_chance(self):
        return (1 + 2 * math.tanh(self.shiny_streak / 100)) / 4096

    def determine_shiny(self, species):
        if self.shiny_hunt != species.dex_number:
            return random.randint(1, 4096) == 1
        else:
            return random.random() < self.shiny_hunt_chance
Exemple #9
0
class RoutePoint(Document, metaclass=MetaBaseTemplate):
    route = fields.ReferenceField(Route, required=True)
    point = fields.DictField(required=True)
    photos = fields.ListField(fields.ObjectIdField, missing=list)
    text = fields.StringField()
    tags = fields.ListField(fields.StringField, missing=list)
    liked = fields.IntegerField(missing=0)

    class Meta:
        collection_name = "route_points"
Exemple #10
0
 class IOStudent(Student):
     io_field = fields.StrField(io_validate=io_validate)
     list_io_field = fields.ListField(fields.IntField(io_validate=io_validate))
     dict_io_field = fields.DictField(
         fields.StrField(),
         fields.IntField(io_validate=io_validate),
     )
     reference_io_field = fields.ReferenceField(
         classroom_model.Course, io_validate=io_validate)
     embedded_io_field = fields.EmbeddedField(EmbeddedDoc, io_validate=io_validate)
Exemple #11
0
class Channel(Document):
    _id = fields.StrField(unique=True)
    title = fields.StrField()
    guilds = fields.ListField(fields.DictField(
        guild_id=fields.IntegerField(unique=True),
        channel_id=fields.IntegerField(),
        role_id=fields.IntegerField())
    )

    class Meta:
        abstract = True
Exemple #12
0
class AutoRole(Document):
    _id = fields.IntegerField(unique=True)
    delay = fields.IntegerField()
    active_auto_role = fields.ListField(fields.DictField(
        user_id=fields.IntegerField(),
        date_of_accession=fields.DateTimeField())
    )
    guild = fields.ReferenceField(document=Guild)

    class Meta:
        collection_name = 'autorole'
Exemple #13
0
class Action(EmbeddedDocument):
    """
    :ivar typing.List[str] text:
    :ivar List[Dict] operations:
    :ivar isQuestion bool:
    :ivar immediatlyNext bool:
    """

    text = fields.ListField(fields.StringField(), required=True, null=False)
    operations = fields.ListField(fields.DictField(), required=False)
    isQuestion = fields.BooleanField(required=True)
    immediatlyNext = fields.BooleanField(required=True)
Exemple #14
0
class Posts(Document):
    # title, body, author, published, meta{ upvotes, favs },
    title = fields.StrField(required=True)
    body = fields.StrField()
    author = fields.StrField()
    published = fields.BoolField(False)
    meta = fields.DictField()

    class Meta:
        exclude = [
            'date',
        ]
Exemple #15
0
class User(Document):
    '''
    Represents user of bot
    '''
    chat_id = fields.IntField(required=True, unique=True)
    username = fields.StrField(required=True)
    email = fields.EmailField(required=True)
    track = fields.DictField()
    current_survey = fields.DictField(default={})
    current_question_number = fields.IntField(default=-1)
    answers = fields.ListField(fields.ListField(
        fields.StringField(default='')))

    def update(self, **attrs) -> Union[UpdateResult, InsertOneResult]:
        for attr in attrs:
            self[attr] = attrs[attr]
        return self.commit()

    def __str__(self):
        return f"User({self.email})"

    class Meta:
        collection_name = 'users'
Exemple #16
0
class Params(EmbeddedDocument):
    """
    :ivar Topic ofTopic:
    :ivar Dict values:
    :ivar datetime startTime:
    :ivar int priority:
    """

    ofTopic = fields.ReferenceField(Topic, dbRef=True, required=True)
    values = fields.DictField(required=False)
    startTime = fields.StrictDateTimeField(tz_aware=True,
                                           format="iso",
                                           required=True)
    priority = fields.IntegerField(required=True)
Exemple #17
0
class Article(Document):
    ts = fields.NumberField(required=True, default=0)
    text = fields.StringField()
    tags = fields.ListField(fields.StringField(), default=[])
    source = fields.ReferenceField("Feed")
    address = fields.StringField(default="")
    # Location: {
    #       type: "Point",
    #       coordinates: [-73.856077, 40.848447]
    # }
    location = fields.DictField(default={})

    class Meta:
        collection_name = "article"
Exemple #18
0
class Product(Document):
    id = fields.ObjectIdField(attribute='_id')
    name = fields.StringField()
    description = fields.StringField()
    properties = fields.DictField()

    class Meta:
        collection = db.product

    def toFullDict(self):
        return {
            'id': str(self.id),
            'name': self.name,
            'description': self.description,
            'properties': self.properties
        }

    def toSmallDict(self):
        return {'id': str(self.id), 'name': self.name}
class GameMove(BaseDocument):
    """
    This collection will track the moves of the users
    on the given game
    """

    SYMBOLS = [
        'X',
        'O'
    ]

    game = fields.ReferenceField(
        "Game",
    )

    cell = fields.DictField(
        required=True
    )

    symbol = fields.StrField(
        validate=validate.OneOf(SYMBOLS),
        required=True,
    )

    player = fields.ReferenceField(
        "User",
        required=True,
    )

    created_at = fields.DateTimeField(
        default=datetime.datetime.now(),
    )

    class Meta:
        """
        ODM Metadata
        """
        collection = db.moves
class Item(Document):
    name = fields.StringField(required=True)
    description = fields.StrField()
    parameters = fields.DictField()
Exemple #21
0
class Member(Document):
    class Meta:
        strict = False

    # General
    id = fields.IntegerField(attribute="_id")
    joined_at = fields.DateTimeField(default=None)
    suspended = fields.BooleanField(default=False)

    # Pokémon
    next_idx = fields.IntegerField(default=1)
    selected_id = fields.ObjectIdField(required=True)
    order_by = fields.StringField(default="number")

    # Pokédex
    pokedex = fields.DictField(fields.StringField(),
                               fields.IntegerField(),
                               default=dict)
    shinies_caught = fields.IntegerField(default=0)

    # Shop
    balance = fields.IntegerField(default=0)
    premium_balance = fields.IntegerField(default=0)
    redeems = fields.IntegerField(default=0)
    redeems_purchased = fields.DictField(fields.IntegerField(),
                                         fields.IntegerField(),
                                         default=dict)
    embed_colors = fields.IntegerField(default=0)

    # Shiny Hunt
    shiny_hunt = fields.IntegerField(default=None)
    shiny_streak = fields.IntegerField(default=0)

    # Boosts
    boost_expires = fields.DateTimeField(default=datetime.min)
    shiny_charm_expires = fields.DateTimeField(default=datetime.min)

    # Voting
    last_voted = fields.DateTimeField(default=datetime.min)
    need_vote_reminder = fields.BooleanField(default=False)
    vote_total = fields.IntegerField(default=0)
    vote_streak = fields.IntegerField(default=0)
    gifts_normal = fields.IntegerField(default=0)
    gifts_great = fields.IntegerField(default=0)
    gifts_ultra = fields.IntegerField(default=0)
    gifts_master = fields.IntegerField(default=0)

    # Settings
    show_balance = fields.BooleanField(default=True)
    silence = fields.BooleanField(default=False)

    # Events
    halloween_tickets = fields.IntegerField(default=0)
    hquests = fields.DictField(fields.StringField(),
                               fields.BooleanField(),
                               default=dict)
    hquest_progress = fields.DictField(fields.StringField(),
                                       fields.IntegerField(),
                                       default=dict)
    halloween_badge = fields.BooleanField(default=False)

    @property
    def selected_pokemon(self):
        try:
            return next(
                filter(lambda x: x.number == int(self.selected), self.pokemon))
        except StopIteration:
            return None

    @property
    def boost_active(self):
        return datetime.utcnow() < self.boost_expires

    @property
    def shiny_charm_active(self):
        return datetime.utcnow() < self.shiny_charm_expires

    @property
    def shiny_hunt_multiplier(self):
        # NOTE math.log is the natural log (log base e)
        return 1 + math.log(1 + self.shiny_streak / 30)

    def determine_shiny(self, species):
        chance = 1 / 4096
        if self.shiny_charm_active:
            chance *= 1.2
        if self.shiny_hunt == species.dex_number:
            chance *= self.shiny_hunt_multiplier

        return random.random() < chance
Exemple #22
0
 class MySchema(Schema):
     dict = fields.DictField(attribute='in_mongo_dict')
Exemple #23
0
class Role(umongo.Document):  # noqa
    """
    Custom role
    """

    name = fields.StringField(required=True)
    chat = fields.ReferenceField(Chat, required=True)
    permissions = fields.DictField(default={})

    priority = fields.IntegerField(required=True)

    class Meta:
        collection = instance.db.roles

    @staticmethod
    async def get_role_in_chat(chat: str, name: str):
        role = await Role.find_one({"chat": chat, "name": name})
        return role

    @staticmethod
    async def get_roles_in_chat(chat: str) -> typing.List["Role"]:
        roles = Role.find({"chat": chat})
        roles_ = []
        async for role in roles:
            roles_.append(role)
        return roles_

    @staticmethod
    async def create_role(
        chat: Chat,
        name: str = ":sparkles:",
        permissions: dict = None,
        priority: int = 1,
    ):
        """
        Create role in database
        :param priority:
        :param chat:
        :param name: visible name
        :param permissions:
        :return:
        """
        if permissions is None:
            permissions = {}
        role = Role(chat=chat,
                    name=name,
                    permissions=permissions,
                    priority=priority)
        await role.commit()
        return role

    @staticmethod
    async def register_default_roles(chat: Chat):
        roles = {}
        for role_ in DEFAULT_ROLES:
            role = Role(
                chat=chat,
                name=role_.NAME.value,
                permissions=role_.PERMISSIONS.value,
                priority=role_.PRIORITY.value,
            )
            await role.commit()
            roles[role_] = role
        return roles
Exemple #24
0
 class MyDoc(Document):
     embeds = fields.DictField(
         values=fields.EmbeddedField(MyEmbeddedDocument))
     refs = fields.DictField(values=fields.ReferenceField(ToRefDoc))
Exemple #25
0
 class MyDoc(Document):
     embedded = fields.EmbeddedField(MyEmbedded)
     embedded_required = fields.EmbeddedField(MyEmbedded, required=True)
     embedded_list = fields.ListField(fields.EmbeddedField(MyEmbedded))
     embedded_dict = fields.DictField(
         values=fields.EmbeddedField(MyEmbedded))
Exemple #26
0
 class MyDoc(Document):
     embedded_list = fields.ListField(fields.EmbeddedField(MyEmbedded),
                                      allow_none=True)
     embedded_dict = fields.DictField(
         values=fields.EmbeddedField(MyEmbedded), allow_none=True)
     embedded = fields.EmbeddedField(MyEmbedded, allow_none=True)
Exemple #27
0
 class IOStudent(Student):
     io_field = fields.DictField(
         fields.StrField(),
         fields.IntField(io_validate=io_validate),
         allow_none=True)
Exemple #28
0
 class MySchema(Schema):
     dict = fields.DictField(attribute='in_mongo_dict', allow_none=True)
Exemple #29
0
class Product(Document):
    name = fields.StrField(required=True)
    description = fields.StrField(required=True)
    properties = fields.DictField(default=dict)
Exemple #30
0
class Some(Document):
    citizenship = fields.StrField()  # Гражданство
    destination_country = fields.StrField()  # Страна назначения
    document = fields.StrField()  # Необходимый документ
    fields_groups = fields.ListField(fields.DictField())
    fields = fields.ListField(fields.DictField())