29 lines
614 B
Python
29 lines
614 B
Python
from beanie import Document
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class BotConfig(BaseModel):
|
|
admins: list[int] = []
|
|
chats_whitelist: list[int] = []
|
|
|
|
|
|
class DynamicConfigBase(BaseModel):
|
|
bot: BotConfig = Field(default_factory=BotConfig)
|
|
|
|
|
|
class DynamicConfig(DynamicConfigBase, Document):
|
|
class Settings:
|
|
name = "config"
|
|
|
|
async def save(self): # noqa
|
|
await super().save() # noqa
|
|
|
|
@classmethod
|
|
async def get_or_create(cls):
|
|
config = await cls.find_one()
|
|
if not config:
|
|
config = cls()
|
|
await config.save()
|
|
|
|
return config
|