feat(global): init structure
This commit is contained in:
27
src/utils/db/models/config.py
Normal file
27
src/utils/db/models/config.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from beanie import Document
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class BotConfig(BaseModel):
|
||||
admins: 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
|
||||
Reference in New Issue
Block a user