mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-09 22:00:01 +08:00
✨ Compatible with pydantic 2.0 using the pydantic compatibility layer provided by nonebot
This commit is contained in:
@@ -19,7 +19,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
指令:
|
||||
关于
|
||||
""".strip(),
|
||||
extra=PluginExtraData(author="HibiKier", version="0.1", menu_type="其他").dict(),
|
||||
extra=PluginExtraData(author="HibiKier", version="0.1", menu_type="其他").to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
default_value="zhenxun",
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
_matcher = on_alconna(
|
||||
|
||||
@@ -27,7 +27,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
default_value=5,
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
type=int,
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPER_AND_ADMIN,
|
||||
admin_level=1,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPER_AND_ADMIN,
|
||||
admin_level=1,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
type=int,
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
default_value=2,
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
_matcher = on_command(
|
||||
|
||||
@@ -47,7 +47,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPERUSER,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
_matcher = on_alconna(
|
||||
|
||||
@@ -28,7 +28,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
type=bool,
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
version="0.1",
|
||||
plugin_type=PluginType.NORMAL,
|
||||
menu_type="数据统计",
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
default_value="mix",
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
default_value="zhenxun",
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
version="0.1",
|
||||
plugin_type=PluginType.DEPENDANT,
|
||||
menu_type="其他",
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
_matcher = on_message(rule=to_me(), priority=996, block=False)
|
||||
|
||||
@@ -20,7 +20,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
指令:
|
||||
我的信息 ?[at]
|
||||
""".strip(),
|
||||
extra=PluginExtraData(author="HibiKier", version="0.1").dict(),
|
||||
extra=PluginExtraData(author="HibiKier", version="0.1").to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ class Manager:
|
||||
del temp_data["test"]["check_type"]
|
||||
else:
|
||||
for v in temp_data:
|
||||
temp_data[v] = temp_data[v].dict()
|
||||
temp_data[v] = temp_data[v].to_dict()
|
||||
if check_type := temp_data[v].get("check_type"):
|
||||
temp_data[v]["check_type"] = str(check_type)
|
||||
if watch_type := temp_data[v].get("watch_type"):
|
||||
|
||||
@@ -46,7 +46,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
type=list[str],
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
_nickname_matcher = on_regex(
|
||||
|
||||
@@ -84,7 +84,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
default_status=False,
|
||||
),
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPERUSER,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
_matcher = on_alconna(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from nonebot.compat import model_dump
|
||||
from pydantic import BaseModel
|
||||
|
||||
from zhenxun.utils.enum import PluginType
|
||||
@@ -31,9 +32,12 @@ class StorePluginInfo(BaseModel):
|
||||
"""插件类型"""
|
||||
is_dir: bool
|
||||
"""是否为文件夹插件"""
|
||||
github_url: str | None
|
||||
github_url: str | None = None
|
||||
"""github链接"""
|
||||
|
||||
@property
|
||||
def plugin_type_name(self):
|
||||
return type2name[self.plugin_type.value]
|
||||
|
||||
def to_dict(self, **kwargs):
|
||||
return model_dump(self, **kwargs)
|
||||
|
||||
@@ -42,7 +42,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
default_value=False,
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
""".strip(),
|
||||
extra=PluginExtraData(
|
||||
author="HibiKier", version="0.1", plugin_type=PluginType.SUPERUSER
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
default_status=False,
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
driver = nonebot.get_driver()
|
||||
|
||||
@@ -53,7 +53,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
default_value="zhenxun",
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
from .goods_register import * # noqa: F403
|
||||
|
||||
@@ -4,9 +4,10 @@ from datetime import datetime, timedelta
|
||||
import inspect
|
||||
import time
|
||||
from types import MappingProxyType
|
||||
from typing import Any, Literal
|
||||
from typing import Any, ClassVar, Literal
|
||||
|
||||
from nonebot.adapters import Bot, Event
|
||||
from nonebot.compat import model_dump
|
||||
from nonebot_plugin_alconna import UniMessage, UniMsg
|
||||
from nonebot_plugin_uninfo import Uninfo
|
||||
from pydantic import BaseModel, create_model
|
||||
@@ -63,14 +64,22 @@ class ShopParam(BaseModel):
|
||||
"""道具单次使用数量"""
|
||||
text: str
|
||||
"""text"""
|
||||
send_success_msg: bool = True
|
||||
send_success_msg: ClassVar[bool] = True
|
||||
"""是否发送使用成功信息"""
|
||||
max_num_limit: int = 1
|
||||
max_num_limit: ClassVar[int] = 1
|
||||
"""单次使用最大次数"""
|
||||
session: Uninfo | None = None
|
||||
"""Uninfo"""
|
||||
message: UniMsg
|
||||
"""UniMessage"""
|
||||
extra_data: ClassVar[dict[str, Any]] = {}
|
||||
"""额外数据"""
|
||||
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
def to_dict(self, **kwargs):
|
||||
return model_dump(self, **kwargs)
|
||||
|
||||
|
||||
async def gold_rank(
|
||||
@@ -207,7 +216,7 @@ class ShopManage:
|
||||
param_list = []
|
||||
_bot = param.bot
|
||||
param.bot = None
|
||||
param_json = param.dict()
|
||||
param_json = {**param.to_dict(), **param.extra_data}
|
||||
param_json["bot"] = _bot
|
||||
for par in args.keys():
|
||||
if par in ["shop_param"]:
|
||||
@@ -366,10 +375,14 @@ class ShopManage:
|
||||
"""
|
||||
if uuid in cls.uuid2goods:
|
||||
raise ValueError("该商品使用函数已被注册!")
|
||||
kwargs["send_success_msg"] = send_success_msg
|
||||
kwargs["max_num_limit"] = max_num_limit
|
||||
cls.uuid2goods[uuid] = Goods(
|
||||
model=create_model(f"{uuid}_model", __base__=ShopParam, **kwargs),
|
||||
model=create_model(
|
||||
f"{uuid}_model",
|
||||
send_success_msg=send_success_msg,
|
||||
max_num_limit=max_num_limit,
|
||||
__base__=ShopParam,
|
||||
extra_data=kwargs,
|
||||
),
|
||||
params=kwargs,
|
||||
before_handle=before_handle,
|
||||
after_handle=after_handle,
|
||||
@@ -457,15 +470,26 @@ class ShopManage:
|
||||
user = await UserConsole.get_user(user_id, platform)
|
||||
if not user.props:
|
||||
return None
|
||||
is_change = False
|
||||
for uuid in list(user.props.keys()):
|
||||
if user.props[uuid] <= 0:
|
||||
is_change = True
|
||||
del user.props[uuid]
|
||||
if is_change:
|
||||
await user.save(update_fields=["props"])
|
||||
result = await GoodsInfo.filter(uuid__in=user.props.keys()).all()
|
||||
data_list = []
|
||||
uuid2goods = {item.uuid: item for item in result}
|
||||
column_name = ["-", "使用ID", "名称", "数量", "简介"]
|
||||
for i, p in enumerate(user.props):
|
||||
if prop := uuid2goods.get(p):
|
||||
icon = ""
|
||||
icon_path = ICON_PATH / prop.icon
|
||||
if icon_path.exists():
|
||||
icon = (icon_path, 33, 33)
|
||||
data_list.append(
|
||||
[
|
||||
(ICON_PATH / prop.icon, 33, 33) if prop.icon else "",
|
||||
icon,
|
||||
i,
|
||||
prop.goods_name,
|
||||
user.props[p],
|
||||
|
||||
@@ -82,7 +82,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
),
|
||||
],
|
||||
limits=[PluginCdBlock()],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
"全局周功能调用统计",
|
||||
"全局月功能调用统计",
|
||||
""".strip(),
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
usage="""""".strip(),
|
||||
extra=PluginExtraData(
|
||||
author="HibiKier", version="0.1", plugin_type=PluginType.HIDDEN
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
TEMP_LIST = []
|
||||
|
||||
@@ -32,7 +32,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPERUSER,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
from .bot_switch import * # noqa: F403
|
||||
|
||||
@@ -38,7 +38,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
)
|
||||
],
|
||||
tasks=[Task(module="broadcast", name="广播")],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
_matcher = on_command("广播", priority=1, permission=SUPERUSER, block=True)
|
||||
|
||||
@@ -26,7 +26,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPERUSER,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPERUSER,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
_matcher = on_command(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.adapters.kaiheila.exception import ApiNotAvailable
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
@@ -22,7 +21,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPERUSER,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
_friend_matcher = on_alconna(
|
||||
@@ -71,8 +70,6 @@ async def _(
|
||||
msg = f"| UID | 昵称 | 共{len(fl)}个好友\n" + msg
|
||||
await MessageUtils.build_message(msg).send()
|
||||
logger.info("查看好友列表", "好友列表", session=session)
|
||||
except (ApiNotAvailable, AttributeError):
|
||||
await MessageUtils.build_message("Api未实现...").send()
|
||||
except Exception as e:
|
||||
logger.error("好友列表发生错误", "好友列表", session=session, e=e)
|
||||
await MessageUtils.build_message("其他未知错误...").send()
|
||||
@@ -91,8 +88,6 @@ async def _(
|
||||
msg = f"| GID | 名称 | 共{len(gl)}个群组\n" + msg
|
||||
await MessageUtils.build_message(msg).send()
|
||||
logger.info("查看群组列表", "群组列表", session=session)
|
||||
except (ApiNotAvailable, AttributeError):
|
||||
await MessageUtils.build_message("Api未实现...").send()
|
||||
except Exception as e:
|
||||
logger.error("查看群组列表发生错误", "群组列表", session=session, e=e)
|
||||
await MessageUtils.build_message("其他未知错误...").send()
|
||||
|
||||
@@ -53,7 +53,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPERUSER,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
type=int,
|
||||
),
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
_matcher = on_alconna(
|
||||
|
||||
@@ -46,7 +46,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPERUSER,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPERUSER,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
default_value="zhenxun",
|
||||
)
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
_matcher = on_alconna(
|
||||
|
||||
@@ -22,7 +22,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPERUSER,
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
default_value=None,
|
||||
),
|
||||
],
|
||||
).dict(),
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
driver = nonebot.get_driver()
|
||||
|
||||
@@ -14,11 +14,11 @@ router = APIRouter(prefix="/menu")
|
||||
@router.get(
|
||||
"/get_menus",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result[list[MenuData]],
|
||||
response_model=Result[MenuData],
|
||||
response_class=JSONResponse,
|
||||
description="获取菜单列表",
|
||||
)
|
||||
async def _() -> Result[list[MenuData]]:
|
||||
async def _() -> Result[MenuData]:
|
||||
try:
|
||||
return Result.ok(menu_manage.get_menus(), "拿到菜单了哦!")
|
||||
except Exception as e:
|
||||
|
||||
@@ -56,7 +56,7 @@ class MenuManage:
|
||||
|
||||
def save(self):
|
||||
self.file.parent.mkdir(parents=True, exist_ok=True)
|
||||
temp = [menu.dict() for menu in self.menu]
|
||||
temp = [menu.to_dict() for menu in self.menu]
|
||||
with self.file.open("w", encoding="utf8") as f:
|
||||
json.dump(temp, f, ensure_ascii=False, indent=4)
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from nonebot.compat import model_dump
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
@@ -13,6 +14,9 @@ class MenuItem(BaseModel):
|
||||
default: bool = False
|
||||
"""默认选中"""
|
||||
|
||||
def to_dict(self, **kwargs):
|
||||
return model_dump(self, **kwargs)
|
||||
|
||||
|
||||
class MenuData(BaseModel):
|
||||
bot_type: str = "zhenxun"
|
||||
|
||||
@@ -14,7 +14,13 @@ from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
from ....base_model import BaseResultModel, QueryModel
|
||||
from ..main.data_source import bot_live
|
||||
from .model import AllChatAndCallCount, BotInfo, ChatCallMonthCount, QueryChatCallCount
|
||||
from .model import (
|
||||
AllChatAndCallCount,
|
||||
BotConnectLogInfo,
|
||||
BotInfo,
|
||||
ChatCallMonthCount,
|
||||
QueryChatCallCount,
|
||||
)
|
||||
|
||||
driver: Driver = nonebot.get_driver()
|
||||
|
||||
@@ -235,6 +241,12 @@ class ApiDataSource:
|
||||
.offset((query.index - 1) * query.size)
|
||||
.limit(query.size)
|
||||
)
|
||||
result_list = []
|
||||
for v in data:
|
||||
v.connect_time = v.connect_time.replace(tzinfo=None).replace(microsecond=0)
|
||||
return BaseResultModel(total=total, data=data)
|
||||
result_list.append(
|
||||
BotConnectLogInfo(
|
||||
bot_id=v.bot_id, connect_time=v.connect_time, type=v.type
|
||||
)
|
||||
)
|
||||
return BaseResultModel(total=total, data=result_list)
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class BotConnectLogInfo(BaseModel):
|
||||
bot_id: str
|
||||
"""机器人ID"""
|
||||
connect_time: datetime
|
||||
"""连接日期"""
|
||||
type: int
|
||||
"""连接类型"""
|
||||
|
||||
|
||||
class BotInfo(BaseModel):
|
||||
self_id: str
|
||||
"""SELF ID"""
|
||||
|
||||
@@ -12,7 +12,7 @@ from zhenxun.services.log import logger
|
||||
from ....base_model import BaseResultModel, QueryModel, Result
|
||||
from ....utils import authentication
|
||||
from .data_source import ApiDataSource, type2sql
|
||||
from .models.model import Column, SqlModel, SqlText
|
||||
from .models.model import Column, SqlLogInfo, SqlModel, SqlText
|
||||
from .models.sql_log import SqlLog
|
||||
|
||||
router = APIRouter(prefix="/database")
|
||||
@@ -125,7 +125,8 @@ async def _(query: QueryModel) -> Result[BaseResultModel]:
|
||||
.offset((query.index - 1) * query.size)
|
||||
.limit(query.size)
|
||||
)
|
||||
return Result.ok(BaseResultModel(total=total, data=data))
|
||||
result_list = [SqlLogInfo(sql=e.sql) for e in data]
|
||||
return Result.ok(BaseResultModel(total=total, data=result_list))
|
||||
except Exception as e:
|
||||
logger.error(f"{router.prefix}/get_sql_log 调用错误", "WebUi", e=e)
|
||||
return Result.fail(f"发生了一点错误捏 {type(e)}: {e}")
|
||||
|
||||
@@ -3,6 +3,11 @@ from pydantic import BaseModel
|
||||
from zhenxun.utils.plugin_models.base import CommonSql
|
||||
|
||||
|
||||
class SqlLogInfo(BaseModel):
|
||||
sql: str
|
||||
"""sql语句"""
|
||||
|
||||
|
||||
class SqlText(BaseModel):
|
||||
"""
|
||||
sql语句
|
||||
|
||||
@@ -37,7 +37,7 @@ class BotLive:
|
||||
self._data = {}
|
||||
|
||||
def add(self, bot_id: str):
|
||||
self._data[bot_id] = time.time()
|
||||
self._data[bot_id] = int(time.time())
|
||||
|
||||
def get(self, bot_id: str) -> int | None:
|
||||
return self._data.get(bot_id)
|
||||
@@ -154,7 +154,7 @@ class ApiDataSource:
|
||||
for bot in bot_list:
|
||||
bot.bot = None # type: ignore
|
||||
select_bot.is_select = True
|
||||
return [BaseInfo(**e.dict()) for e in bot_list]
|
||||
return [BaseInfo(**e.to_dict()) for e in bot_list]
|
||||
|
||||
@classmethod
|
||||
async def get_all_chat_count(cls, bot_id: str | None) -> QueryCount:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from typing import Any
|
||||
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.compat import model_dump
|
||||
from nonebot.config import Config
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -86,6 +87,9 @@ class BaseInfo(BaseModel):
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
def to_dict(self, **kwargs):
|
||||
return model_dump(self, **kwargs)
|
||||
|
||||
|
||||
class TemplateBaseInfo(BaseInfo):
|
||||
"""
|
||||
|
||||
@@ -100,4 +100,4 @@ async def _(
|
||||
name=uname,
|
||||
ava_url=AVA_URL.format(session.user.id),
|
||||
)
|
||||
await ws_conn.send_json(data.dict())
|
||||
await ws_conn.send_json(data.to_dict())
|
||||
|
||||
@@ -107,7 +107,7 @@ class ApiDataSource:
|
||||
"""
|
||||
bot = nonebot.get_bot(bot_id)
|
||||
friend_list, _ = await PlatformUtils.get_friend_list(bot)
|
||||
fd = [x for x in friend_list if x == user_id]
|
||||
fd = [x for x in friend_list if x.user_id == user_id]
|
||||
if not fd:
|
||||
return None
|
||||
like_plugin_list = (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from nonebot.compat import model_dump
|
||||
from pydantic import BaseModel
|
||||
|
||||
from zhenxun.utils.enum import RequestType
|
||||
@@ -256,6 +257,9 @@ class Message(BaseModel):
|
||||
ava_url: str
|
||||
"""用户头像"""
|
||||
|
||||
def to_dict(self, **kwargs):
|
||||
return model_dump(self, **kwargs)
|
||||
|
||||
|
||||
class SendMessageParam(BaseModel):
|
||||
"""
|
||||
|
||||
@@ -41,11 +41,11 @@ async def _(
|
||||
@router.get(
|
||||
"/get_plugin_count",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result[int],
|
||||
response_model=Result[PluginCount],
|
||||
response_class=JSONResponse,
|
||||
description="获取插件数量", # type: ignore
|
||||
)
|
||||
async def _() -> Result[int]:
|
||||
async def _() -> Result[PluginCount]:
|
||||
try:
|
||||
plugin_count = PluginCount()
|
||||
plugin_count.normal = await DbPluginInfo.filter(
|
||||
|
||||
@@ -3,6 +3,7 @@ from fastapi.responses import JSONResponse
|
||||
from nonebot import require
|
||||
|
||||
from zhenxun.models.plugin_info import PluginInfo
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
from ....base_model import Result
|
||||
from ....utils import authentication
|
||||
@@ -25,7 +26,7 @@ async def _() -> Result[dict]:
|
||||
|
||||
data = await ShopManage.get_data()
|
||||
plugin_list = [
|
||||
{**data[name].dict(), "name": name, "id": idx}
|
||||
{**data[name].to_dict(), "name": name, "id": idx}
|
||||
for idx, name in enumerate(data)
|
||||
]
|
||||
modules = await PluginInfo.filter(load_status=True).values_list(
|
||||
@@ -33,6 +34,7 @@ async def _() -> Result[dict]:
|
||||
)
|
||||
return Result.ok({"install_module": modules, "plugin_list": plugin_list})
|
||||
except Exception as e:
|
||||
logger.error("获取插件商店插件信息失败", "WebUi", e=e)
|
||||
return Result.fail(f"获取插件商店插件信息失败: {type(e)}: {e}")
|
||||
|
||||
|
||||
|
||||
@@ -44,11 +44,11 @@ async def _(path: str | None = None) -> Result[list[DirFile]]:
|
||||
@router.get(
|
||||
"/get_resources_size",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result[SystemFolderSize],
|
||||
response_model=Result[list[SystemFolderSize]],
|
||||
response_class=JSONResponse,
|
||||
description="获取文件列表",
|
||||
)
|
||||
async def _(full_path: str | None = None) -> Result[SystemFolderSize]:
|
||||
async def _(full_path: str | None = None) -> Result[list[SystemFolderSize]]:
|
||||
return Result.ok(await get_system_disk(full_path))
|
||||
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class AddFile(BaseModel):
|
||||
新建文件
|
||||
"""
|
||||
|
||||
parent: str | None
|
||||
parent: str | None = None
|
||||
"""父路径"""
|
||||
name: str
|
||||
"""新名称"""
|
||||
|
||||
@@ -18,7 +18,7 @@ class Token(BaseModel):
|
||||
token_type: str
|
||||
|
||||
|
||||
class Result(Generic[RT], BaseModel):
|
||||
class Result(BaseModel, Generic[RT]):
|
||||
"""
|
||||
总体返回
|
||||
"""
|
||||
@@ -58,7 +58,7 @@ class QueryModel(BaseModel, Generic[T]):
|
||||
"""页数"""
|
||||
size: int
|
||||
"""每页数量"""
|
||||
data: T
|
||||
data: T | None = None
|
||||
"""携带数据"""
|
||||
|
||||
@validator("index")
|
||||
|
||||
@@ -17,7 +17,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
usage="""
|
||||
引用消息 撤回
|
||||
""".strip(),
|
||||
extra=PluginExtraData(author="HibiKier", version="0.1", menu_type="其他").dict(),
|
||||
extra=PluginExtraData(author="HibiKier", version="0.1", menu_type="其他").to_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user