class ChannelConfigModel(Model): WITH_OID = False # Votes needed to promote a member to be moderator VotePromoMod = IntegerField("v-m", default=ChannelConfig.VotesToPromoteMod) # Votes needed to promote a member to be admin VotePromoAdmin = IntegerField("v-a", default=ChannelConfig.VotesToPromoteAdmin) EnableAutoReply = BooleanField("e-ar", default=True) EnableTimer = BooleanField("e-tmr", default=True) EnableCalculator = BooleanField("e-calc", default=True) EnableBotCommand = BooleanField("e-bot", default=True) InfoPrivate = BooleanField("prv", default=False) DefaultProfileOid = ObjectIDField("d-prof", allow_none=True) DefaultName = TextField("d-name", allow_none=True)
class ChannelCollectionModel(Model): DefaultName = TextField("dn", default=ModelDefaultValueExt.Required, must_have_content=True) Name = DictionaryField("n", allow_none=False, default={}) Platform = PlatformField("p", default=ModelDefaultValueExt.Required) Token = TextField("t", default=ModelDefaultValueExt.Required, must_have_content=True) BotAccessible = BooleanField("acc", default=True) ChildChannelOids = ArrayField("ch", ObjectId)
class ModelOnInvalid(Model): Field1 = IntegerField("i") Field2 = BooleanField("b") def perform_validity_check(self) -> ModelValidityCheckResult: if self.field1 > 0: return ModelValidityCheckResult.X_UNCATEGORIZED else: return ModelValidityCheckResult.O_OK def on_invalid(self, reason=ModelValidityCheckResult.X_UNCATEGORIZED): raise TestBaseModel.TempInvalidException()
class TimerModel(Model): ChannelOid = ObjectIDField("ch", default=ModelDefaultValueExt.Required) Keyword = TextField("k", default=ModelDefaultValueExt.Required) Title = TextField("t", default=ModelDefaultValueExt.Required) TargetTime = DateTimeField("tt", default=ModelDefaultValueExt.Required) DeletionTime = DateTimeField("del", default=ModelDefaultValueExt.Optional) Countup = BooleanField("c", default=False) PeriodSeconds = IntegerField("p") Notified = BooleanField("nt", default=False) NotifiedExpired = BooleanField("nt-e", default=False) @property def is_periodic(self) -> bool: return self.period_seconds > 0 def get_target_time_diff(self, dt: datetime): return abs(self.target_time - make_tz_aware(dt)) def is_after(self, dt: datetime) -> bool: """Check if the target time of the timer is after the given ``dt``.""" return self.target_time >= make_tz_aware(dt)
class ChannelProfileConnectionModel(Model): ChannelOid = ObjectIDField("c", default=ModelDefaultValueExt.Required) Starred = BooleanField("s", default=False) UserOid = ObjectIDField("u", default=ModelDefaultValueExt.Required, stores_uid=True) # ProfileOids will be empty list if the user is not in the channel ProfileOids = ArrayField("p", ObjectId, default=ModelDefaultValueExt.Required) @property def available(self): return len(self.profile_oids) > 0
class ChannelModel(Model): Platform = PlatformField("p", default=ModelDefaultValueExt.Required) Token = TextField("t", default=ModelDefaultValueExt.Required, must_have_content=True) Name = DictionaryField("n", allow_none=False, default={}) Config = ModelField("c", ChannelConfigModel) BotAccessible = BooleanField("acc", default=True) def get_channel_name(self, root_oid: ObjectId): oid_str = str(root_oid) if oid_str in self.name: return self.name[oid_str] else: return self.config.default_name or self.token
class ModelTest(Model): FModel = ModelField("m", SubModel) FInt = IntegerField("i", default=ModelDefaultValueExt.Required) FModelArray = ModelArrayField("ma", SubModel, default=ModelDefaultValueExt.Optional) FDict = DictionaryField("d") FFloat = FloatField("f", default=7.5) FBool = BooleanField("b") FUrl = UrlField("u", default=ModelDefaultValueExt.Optional) FText = TextField("t") FOid = ObjectIDField("o") FGeneral = GeneralField("g") FDatetime = DateTimeField("dt") FColor = ColorField("c") FArray = ArrayField("a", int, default=[17, 21]) FArContent = AutoReplyContentTypeField("ac")
class ShortUrlRecordModel(Model): # CHANGE THE KEY NAME AS WELL FOR github.com/RaenonX/Jelly-Bot-ShortURL IF CHANGING THE KEY NAME OF THESE FIELDS Code = TextField("cd", default=ModelDefaultValueExt.Required) Target = UrlField("tgt", default=ModelDefaultValueExt.Required) CreatorOid = ObjectIDField("cr", default=ModelDefaultValueExt.Required, stores_uid=True) UsedTimestamp = ArrayField("ts", datetime) Disabled = BooleanField("d", default=False) @property def used_count(self) -> int: return len(self.used_timestamp) @property def short_url(self) -> str: return f"{os.environ['SERVICE_SHORT_URL']}/{self.code}"
class APIStatisticModel(Model): Timestamp = DateTimeField("t", default=ModelDefaultValueExt.Required, allow_none=False) SenderOid = ObjectIDField("sd", default=ModelDefaultValueExt.Optional, allow_none=True, stores_uid=True) ApiAction = APICommandField("a") Parameter = DictionaryField("p", allow_none=True) PathParameter = DictionaryField("pp", allow_none=True) Response = DictionaryField("r", allow_none=True) Success = BooleanField("s", allow_none=True) PathInfo = TextField("pi", default=ModelDefaultValueExt.Required, must_have_content=True, allow_none=False) PathInfoFull = TextField("pf", default=ModelDefaultValueExt.Required, must_have_content=True, allow_none=False)
class ModelTest2(Model): Field1 = IntegerField("f1") Field2 = BooleanField("f2")
class DuplicateJsonModel(Model): Field1 = IntegerField("i") Field2 = BooleanField("i")
def test_repair_b(self): self.missing_has_default("b", {"b": BooleanField.none_obj()})
def get_field(self) -> BaseField: return BooleanField("k")
def get_field(self) -> BaseField: return BooleanField("k", allow_none=True)