LiteyukiBot-TriM/liteyuki/utils/data_manager.py

46 lines
1.4 KiB
Python
Raw Normal View History

2024-03-24 09:43:34 +08:00
import os
from pydantic import Field
from liteyuki.utils.data import LiteModel, Database as DB
DATA_PATH = "data/liteyuki"
2024-03-26 17:14:41 +08:00
user_db = DB(os.path.join(DATA_PATH, "users.ldb"))
group_db = DB(os.path.join(DATA_PATH, "groups.ldb"))
plugin_db = DB(os.path.join(DATA_PATH, "plugins.ldb"))
common_db = DB(os.path.join(DATA_PATH, "common.ldb"))
2024-03-24 09:43:34 +08:00
class User(LiteModel):
2024-03-26 17:14:41 +08:00
user_id: str = Field(str(), alias="user_id")
username: str = Field(str(), alias="username")
profile: dict[str, str] = Field(dict(), alias="profile")
enabled_plugins: list[str] = Field(list(), alias="enabled_plugins")
disabled_plugins: list[str] = Field(list(), alias="disabled_plugins")
2024-03-24 09:43:34 +08:00
class GroupChat(LiteModel):
# Group是一个关键字所以这里用GroupChat
2024-03-26 17:14:41 +08:00
group_id: str = Field(str(), alias="group_id")
group_name: str = Field(str(), alias="group_name")
enabled_plugins: list[str] = Field([], alias="enabled_plugins")
disabled_plugins: list[str] = Field([], alias="disabled_plugins")
2024-03-24 09:43:34 +08:00
class InstalledPlugin(LiteModel):
2024-03-26 17:14:41 +08:00
module_name: str = Field(str(), alias="module_name")
version: str = Field(str(), alias="version")
2024-03-24 09:43:34 +08:00
class GlobalPlugin(LiteModel):
2024-03-26 17:14:41 +08:00
module_name: str = Field(str(), alias="module_name")
enabled: bool = Field(True, alias="enabled")
2024-03-24 09:43:34 +08:00
def auto_migrate():
2024-03-24 09:44:23 +08:00
user_db.auto_migrate(User)
group_db.auto_migrate(GroupChat)
plugin_db.auto_migrate(InstalledPlugin)
common_db.auto_migrate(GlobalPlugin)