Compatible with pydantic 2.0 using the pydantic compatibility layer provided by nonebot

This commit is contained in:
HibiKier 2025-01-07 14:20:30 +08:00 committed by BalconyJH
parent 23ef00d01f
commit e814469b75
69 changed files with 178 additions and 147 deletions

69
poetry.lock generated
View File

@ -1,4 +1,4 @@
# This file is automatically @generated by Poetry 1.8.5 and should not be changed by hand.
# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
[[package]]
name = "aiocache"
@ -902,7 +902,6 @@ files = [
{file = "cryptography-44.0.0-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:761817a3377ef15ac23cd7834715081791d4ec77f9297ee694ca1ee9c2c7e5eb"},
{file = "cryptography-44.0.0-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:3c672a53c0fb4725a29c303be906d3c1fa99c32f58abe008a82705f9ee96f40b"},
{file = "cryptography-44.0.0-cp37-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:4ac4c9f37eba52cb6fbeaf5b59c152ea976726b865bd4cf87883a7e7006cc543"},
{file = "cryptography-44.0.0-cp37-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:60eb32934076fa07e4316b7b2742fa52cbb190b42c2df2863dbc4230a0a9b385"},
{file = "cryptography-44.0.0-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:ed3534eb1090483c96178fcb0f8893719d96d5274dfde98aa6add34614e97c8e"},
{file = "cryptography-44.0.0-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:f3f6fdfa89ee2d9d496e2c087cebef9d4fcbb0ad63c40e821b39f74bf48d9c5e"},
{file = "cryptography-44.0.0-cp37-abi3-win32.whl", hash = "sha256:eb33480f1bad5b78233b0ad3e1b0be21e8ef1da745d8d2aecbb20671658b9053"},
@ -913,7 +912,6 @@ files = [
{file = "cryptography-44.0.0-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:c5eb858beed7835e5ad1faba59e865109f3e52b3783b9ac21e7e47dc5554e289"},
{file = "cryptography-44.0.0-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f53c2c87e0fb4b0c00fa9571082a057e37690a8f12233306161c8f4b819960b7"},
{file = "cryptography-44.0.0-cp39-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:9e6fc8a08e116fb7c7dd1f040074c9d7b51d74a8ea40d4df2fc7aa08b76b9e6c"},
{file = "cryptography-44.0.0-cp39-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:9abcc2e083cbe8dde89124a47e5e53ec38751f0d7dfd36801008f316a127d7ba"},
{file = "cryptography-44.0.0-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:d2436114e46b36d00f8b72ff57e598978b37399d2786fd39793c36c6d5cb1c64"},
{file = "cryptography-44.0.0-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:a01956ddfa0a6790d594f5b34fc1bfa6098aca434696a03cfdbe469b8ed79285"},
{file = "cryptography-44.0.0-cp39-abi3-win32.whl", hash = "sha256:eca27345e1214d1b9f9490d200f9db5a874479be914199194e746c893788d417"},
@ -2145,64 +2143,6 @@ type = "legacy"
url = "https://mirrors.aliyun.com/pypi/simple"
reference = "aliyun"
[[package]]
name = "nonebot-adapter-discord"
version = "0.1.8"
description = "Discord adapter for nonebot2"
optional = false
python-versions = ">=3.9,<4.0"
files = [
{file = "nonebot_adapter_discord-0.1.8-py3-none-any.whl", hash = "sha256:d063bf524f6a75c5c123f2d04227e0ec62c2433f56b28fb92fa5eb2aebef1c16"},
{file = "nonebot_adapter_discord-0.1.8.tar.gz", hash = "sha256:5d3a7a8e0ab23b7ae84551b479c40c5d09733b15d09538d64765c5af54721781"},
]
[package.dependencies]
nonebot2 = ">=2.2.1,<3.0.0"
[package.source]
type = "legacy"
url = "https://mirrors.aliyun.com/pypi/simple"
reference = "aliyun"
[[package]]
name = "nonebot-adapter-dodo"
version = "0.1.4"
description = "Dodo adapter for nonebot2"
optional = false
python-versions = ">=3.8,<4.0"
files = [
{file = "nonebot_adapter_dodo-0.1.4-py3-none-any.whl", hash = "sha256:3bbe8ce1d686923dc7347d49e9e7164a93bc87e79626d6067e77b7c3d41d6861"},
{file = "nonebot_adapter_dodo-0.1.4.tar.gz", hash = "sha256:21375ee712e97fe546ef24654dcb479f51e972335f13b4208af9ef53cc5fca29"},
]
[package.dependencies]
nonebot2 = ">=2.0.0,<3.0.0"
[package.source]
type = "legacy"
url = "https://mirrors.aliyun.com/pypi/simple"
reference = "aliyun"
[[package]]
name = "nonebot-adapter-kaiheila"
version = "0.3.4"
description = "kaiheila adapter for nonebot2"
optional = false
python-versions = ">=3.8,<4.0"
files = [
{file = "nonebot_adapter_kaiheila-0.3.4-py3-none-any.whl", hash = "sha256:a4cc0e43bd24e015b8312f1753705116274d5b7e9a68be266384dd413ca4f510"},
{file = "nonebot_adapter_kaiheila-0.3.4.tar.gz", hash = "sha256:1fea823e5bc2bb5dc8e56a4c10a8f6698dac6e4f77d4526768275fa0925340f2"},
]
[package.dependencies]
nonebot2 = ">=2.2.0,<3.0.0"
typing-extensions = ">=4.8.0,<5.0.0"
[package.source]
type = "legacy"
url = "https://mirrors.aliyun.com/pypi/simple"
reference = "aliyun"
[[package]]
name = "nonebot-adapter-onebot"
version = "2.4.6"
@ -3824,6 +3764,7 @@ files = [
{file = "ruamel.yaml.clib-0.2.12-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f66efbc1caa63c088dead1c4170d148eabc9b80d95fb75b6c92ac0aad2437d76"},
{file = "ruamel.yaml.clib-0.2.12-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:22353049ba4181685023b25b5b51a574bce33e7f51c759371a7422dcae5402a6"},
{file = "ruamel.yaml.clib-0.2.12-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:932205970b9f9991b34f55136be327501903f7c66830e9760a8ffb15b07f05cd"},
{file = "ruamel.yaml.clib-0.2.12-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:a52d48f4e7bf9005e8f0a89209bf9a73f7190ddf0489eee5eb51377385f59f2a"},
{file = "ruamel.yaml.clib-0.2.12-cp310-cp310-win32.whl", hash = "sha256:3eac5a91891ceb88138c113f9db04f3cebdae277f5d44eaa3651a4f573e6a5da"},
{file = "ruamel.yaml.clib-0.2.12-cp310-cp310-win_amd64.whl", hash = "sha256:ab007f2f5a87bd08ab1499bdf96f3d5c6ad4dcfa364884cb4549aa0154b13a28"},
{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-macosx_13_0_arm64.whl", hash = "sha256:4a6679521a58256a90b0d89e03992c15144c5f3858f40d7c18886023d7943db6"},
@ -3832,6 +3773,7 @@ files = [
{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:811ea1594b8a0fb466172c384267a4e5e367298af6b228931f273b111f17ef52"},
{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:cf12567a7b565cbf65d438dec6cfbe2917d3c1bdddfce84a9930b7d35ea59642"},
{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:7dd5adc8b930b12c8fc5b99e2d535a09889941aa0d0bd06f4749e9a9397c71d2"},
{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1492a6051dab8d912fc2adeef0e8c72216b24d57bd896ea607cb90bb0c4981d3"},
{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-win32.whl", hash = "sha256:bd0a08f0bab19093c54e18a14a10b4322e1eacc5217056f3c063bd2f59853ce4"},
{file = "ruamel.yaml.clib-0.2.12-cp311-cp311-win_amd64.whl", hash = "sha256:a274fb2cb086c7a3dea4322ec27f4cb5cc4b6298adb583ab0e211a4682f241eb"},
{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-macosx_14_0_arm64.whl", hash = "sha256:20b0f8dc160ba83b6dcc0e256846e1a02d044e13f7ea74a3d1d56ede4e48c632"},
@ -3840,6 +3782,7 @@ files = [
{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:749c16fcc4a2b09f28843cda5a193e0283e47454b63ec4b81eaa2242f50e4ccd"},
{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:bf165fef1f223beae7333275156ab2022cffe255dcc51c27f066b4370da81e31"},
{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:32621c177bbf782ca5a18ba4d7af0f1082a3f6e517ac2a18b3974d4edf349680"},
{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:b82a7c94a498853aa0b272fd5bc67f29008da798d4f93a2f9f289feb8426a58d"},
{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-win32.whl", hash = "sha256:e8c4ebfcfd57177b572e2040777b8abc537cdef58a2120e830124946aa9b42c5"},
{file = "ruamel.yaml.clib-0.2.12-cp312-cp312-win_amd64.whl", hash = "sha256:0467c5965282c62203273b838ae77c0d29d7638c8a4e3a1c8bdd3602c10904e4"},
{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-macosx_14_0_arm64.whl", hash = "sha256:4c8c5d82f50bb53986a5e02d1b3092b03622c02c2eb78e29bec33fd9593bae1a"},
@ -3848,6 +3791,7 @@ files = [
{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:96777d473c05ee3e5e3c3e999f5d23c6f4ec5b0c38c098b3a5229085f74236c6"},
{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-musllinux_1_1_i686.whl", hash = "sha256:3bc2a80e6420ca8b7d3590791e2dfc709c88ab9152c00eeb511c9875ce5778bf"},
{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:e188d2699864c11c36cdfdada94d781fd5d6b0071cd9c427bceb08ad3d7c70e1"},
{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:4f6f3eac23941b32afccc23081e1f50612bdbe4e982012ef4f5797986828cd01"},
{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-win32.whl", hash = "sha256:6442cb36270b3afb1b4951f060eccca1ce49f3d087ca1ca4563a6eb479cb3de6"},
{file = "ruamel.yaml.clib-0.2.12-cp313-cp313-win_amd64.whl", hash = "sha256:e5b8daf27af0b90da7bb903a876477a9e6d7270be6146906b276605997c7e9a3"},
{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-macosx_12_0_arm64.whl", hash = "sha256:fc4b630cd3fa2cf7fce38afa91d7cfe844a9f75d7f0f36393fa98815e911d987"},
@ -3856,6 +3800,7 @@ files = [
{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e2f1c3765db32be59d18ab3953f43ab62a761327aafc1594a2a1fbe038b8b8a7"},
{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:d85252669dc32f98ebcd5d36768f5d4faeaeaa2d655ac0473be490ecdae3c285"},
{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:e143ada795c341b56de9418c58d028989093ee611aa27ffb9b7f609c00d813ed"},
{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:2c59aa6170b990d8d2719323e628aaf36f3bfbc1c26279c0eeeb24d05d2d11c7"},
{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-win32.whl", hash = "sha256:beffaed67936fbbeffd10966a4eb53c402fafd3d6833770516bf7314bc6ffa12"},
{file = "ruamel.yaml.clib-0.2.12-cp39-cp39-win_amd64.whl", hash = "sha256:040ae85536960525ea62868b642bdb0c2cc6021c9f9d507810c0c604e66f5a7b"},
{file = "ruamel.yaml.clib-0.2.12.tar.gz", hash = "sha256:6c8fbb13ec503f99a91901ab46e0b07ae7941cd527393187039aec586fdfd36f"},
@ -4932,4 +4877,4 @@ reference = "aliyun"
[metadata]
lock-version = "2.0"
python-versions = "^3.10"
content-hash = "37341271bbd43fcb6af878cb09491459cf21b13c24659a5fd94f9c2b5248a5d8"
content-hash = "1bc744798ef5453d2d8c257b43bd022676098e47f00d9c82f2324a5f14eab43d"

View File

@ -22,12 +22,9 @@ ruamel-yaml = "^0.18.5"
strenum = "^0.4.15"
nonebot-plugin-session = "^0.2.3"
ujson = "^5.9.0"
nonebot-adapter-kaiheila = "^0.3.0"
nb-cli = "^1.3.0"
nonebot2 = "^2.1.3"
pydantic = "1.10.18"
nonebot-adapter-discord = "^0.1.3"
nonebot-adapter-dodo = "^0.1.4"
pillow = "^10.0.0"
retrying = "^1.3.4"
aiofiles = "^23.2.1"

View File

@ -33,5 +33,5 @@ __plugin_meta__ = PluginMetadata(
检测b站
bil_logout 12345<-(退出登录的b站uid通过检测b站获取)
""",
).dict(),
).to_dict(),
)

View File

@ -20,5 +20,5 @@ __plugin_meta__ = PluginMetadata(
extra=PluginExtraData(
author="xuanerwa",
version="0.7",
).dict(),
).to_dict(),
)

View File

@ -13,5 +13,5 @@ __plugin_meta__ = PluginMetadata(
extra=PluginExtraData(
author="HibiKier",
version="0.1",
).dict(),
).to_dict(),
)

View File

@ -14,5 +14,5 @@ __plugin_meta__ = PluginMetadata(
author="HibiKier",
version="0.1",
menu_type="一些工具",
).dict(),
).to_dict(),
)

View File

@ -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(),
)

View File

@ -33,7 +33,7 @@ __plugin_meta__ = PluginMetadata(
default_value="zhenxun",
)
],
).dict(),
).to_dict(),
)
_matcher = on_alconna(

View File

@ -27,7 +27,7 @@ __plugin_meta__ = PluginMetadata(
default_value=5,
)
],
).dict(),
).to_dict(),
)

View File

@ -78,7 +78,7 @@ __plugin_meta__ = PluginMetadata(
type=int,
)
],
).dict(),
).to_dict(),
)

View File

@ -30,7 +30,7 @@ __plugin_meta__ = PluginMetadata(
version="0.1",
plugin_type=PluginType.SUPER_AND_ADMIN,
admin_level=1,
).dict(),
).to_dict(),
)

View File

@ -23,7 +23,7 @@ __plugin_meta__ = PluginMetadata(
version="0.1",
plugin_type=PluginType.SUPER_AND_ADMIN,
admin_level=1,
).dict(),
).to_dict(),
)

View File

@ -80,7 +80,7 @@ __plugin_meta__ = PluginMetadata(
type=int,
)
],
).dict(),
).to_dict(),
)

View File

@ -57,7 +57,7 @@ __plugin_meta__ = PluginMetadata(
default_value=2,
)
],
).dict(),
).to_dict(),
)
_matcher = on_command(

View File

@ -47,7 +47,7 @@ __plugin_meta__ = PluginMetadata(
author="HibiKier",
version="0.1",
plugin_type=PluginType.SUPERUSER,
).dict(),
).to_dict(),
)
_matcher = on_alconna(

View File

@ -28,7 +28,7 @@ __plugin_meta__ = PluginMetadata(
type=bool,
)
],
).dict(),
).to_dict(),
)

View File

@ -45,7 +45,7 @@ __plugin_meta__ = PluginMetadata(
version="0.1",
plugin_type=PluginType.NORMAL,
menu_type="数据统计",
).dict(),
).to_dict(),
)

View File

@ -37,7 +37,7 @@ __plugin_meta__ = PluginMetadata(
default_value="mix",
)
],
).dict(),
).to_dict(),
)

View File

@ -38,7 +38,7 @@ __plugin_meta__ = PluginMetadata(
default_value="zhenxun",
)
],
).dict(),
).to_dict(),
)

View File

@ -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)

View File

@ -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(),
)

View File

@ -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"):

View File

@ -46,7 +46,7 @@ __plugin_meta__ = PluginMetadata(
type=list[str],
)
],
).dict(),
).to_dict(),
)
_nickname_matcher = on_regex(

View File

@ -84,7 +84,7 @@ __plugin_meta__ = PluginMetadata(
default_status=False,
),
],
).dict(),
).to_dict(),
)

View File

@ -25,7 +25,7 @@ __plugin_meta__ = PluginMetadata(
author="HibiKier",
version="0.1",
plugin_type=PluginType.SUPERUSER,
).dict(),
).to_dict(),
)
_matcher = on_alconna(

View File

@ -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)

View File

@ -42,7 +42,7 @@ __plugin_meta__ = PluginMetadata(
default_value=False,
)
],
).dict(),
).to_dict(),
)

View File

@ -27,7 +27,7 @@ __plugin_meta__ = PluginMetadata(
""".strip(),
extra=PluginExtraData(
author="HibiKier", version="0.1", plugin_type=PluginType.SUPERUSER
).dict(),
).to_dict(),
)

View File

@ -28,7 +28,7 @@ __plugin_meta__ = PluginMetadata(
default_status=False,
)
],
).dict(),
).to_dict(),
)
driver = nonebot.get_driver()

View File

@ -53,7 +53,7 @@ __plugin_meta__ = PluginMetadata(
default_value="zhenxun",
)
],
).dict(),
).to_dict(),
)
from .goods_register import * # noqa: F403

View File

@ -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],

View File

@ -82,7 +82,7 @@ __plugin_meta__ = PluginMetadata(
),
],
limits=[PluginCdBlock()],
).dict(),
).to_dict(),
)

View File

@ -45,7 +45,7 @@ __plugin_meta__ = PluginMetadata(
"全局周功能调用统计",
"全局月功能调用统计",
""".strip(),
).dict(),
).to_dict(),
)

View File

@ -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 = []

View File

@ -32,7 +32,7 @@ __plugin_meta__ = PluginMetadata(
author="",
version="0.1",
plugin_type=PluginType.SUPERUSER,
).dict(),
).to_dict(),
)
from .bot_switch import * # noqa: F403

View File

@ -38,7 +38,7 @@ __plugin_meta__ = PluginMetadata(
)
],
tasks=[Task(module="broadcast", name="广播")],
).dict(),
).to_dict(),
)
_matcher = on_command("广播", priority=1, permission=SUPERUSER, block=True)

View File

@ -26,7 +26,7 @@ __plugin_meta__ = PluginMetadata(
author="HibiKier",
version="0.1",
plugin_type=PluginType.SUPERUSER,
).dict(),
).to_dict(),
)

View File

@ -25,7 +25,7 @@ __plugin_meta__ = PluginMetadata(
author="HibiKier",
version="0.1",
plugin_type=PluginType.SUPERUSER,
).dict(),
).to_dict(),
)
_matcher = on_command(

View File

@ -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()

View File

@ -53,7 +53,7 @@ __plugin_meta__ = PluginMetadata(
author="HibiKier",
version="0.1",
plugin_type=PluginType.SUPERUSER,
).dict(),
).to_dict(),
)

View File

@ -37,7 +37,7 @@ __plugin_meta__ = PluginMetadata(
type=int,
),
],
).dict(),
).to_dict(),
)
_matcher = on_alconna(

View File

@ -46,7 +46,7 @@ __plugin_meta__ = PluginMetadata(
author="HibiKier",
version="0.1",
plugin_type=PluginType.SUPERUSER,
).dict(),
).to_dict(),
)

View File

@ -36,7 +36,7 @@ __plugin_meta__ = PluginMetadata(
author="HibiKier",
version="0.1",
plugin_type=PluginType.SUPERUSER,
).dict(),
).to_dict(),
)

View File

@ -32,7 +32,7 @@ __plugin_meta__ = PluginMetadata(
default_value="zhenxun",
)
],
).dict(),
).to_dict(),
)
_matcher = on_alconna(

View File

@ -22,7 +22,7 @@ __plugin_meta__ = PluginMetadata(
author="HibiKier",
version="0.1",
plugin_type=PluginType.SUPERUSER,
).dict(),
).to_dict(),
)

View File

@ -61,7 +61,7 @@ __plugin_meta__ = PluginMetadata(
default_value=None,
),
],
).dict(),
).to_dict(),
)
driver = nonebot.get_driver()

View File

@ -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:

View File

@ -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)

View File

@ -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"

View File

@ -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)

View File

@ -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"""

View File

@ -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}")

View File

@ -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语句

View File

@ -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:

View File

@ -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):
"""

View File

@ -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())

View File

@ -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 = (

View File

@ -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):
"""

View File

@ -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(

View File

@ -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}")

View File

@ -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))

View File

@ -43,7 +43,7 @@ class AddFile(BaseModel):
新建文件
"""
parent: str | None
parent: str | None = None
"""父路径"""
name: str
"""新名称"""

View File

@ -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")

View File

@ -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(),
)

View File

@ -5,6 +5,7 @@ from pathlib import Path
from typing import Any, Literal
import cattrs
from nonebot.compat import model_dump
from pydantic import BaseModel
from ruamel.yaml import YAML
from ruamel.yaml.scanner import ScannerError
@ -81,6 +82,9 @@ class ConfigModel(BaseModel):
arg_parser: Callable | None = None
"""参数解析"""
def to_dict(self, **kwargs):
return model_dump(self, **kwargs)
class ConfigGroup(BaseModel):
"""
@ -103,6 +107,9 @@ class ConfigGroup(BaseModel):
return cfg.default_value
return default
def to_dict(self, **kwargs):
return model_dump(self, **kwargs)
class BaseBlock(BaseModel):
"""
@ -120,6 +127,9 @@ class BaseBlock(BaseModel):
_type: PluginLimitType = PluginLimitType.BLOCK
"""类型"""
def to_dict(self, **kwargs):
return model_dump(self, **kwargs)
class PluginCdBlock(BaseBlock):
"""
@ -236,6 +246,9 @@ class PluginExtraData(BaseModel):
is_show: bool = True
"""是否显示在菜单中"""
def to_dict(self, **kwargs):
return model_dump(self, **kwargs)
class NoSuchConfig(Exception):
pass

View File

@ -174,6 +174,8 @@ class UserConsole(Model):
if goods_uuid not in user.props or user.props[goods_uuid] < num:
raise GoodsNotFound("未找到商品或道具数量不足...")
user.props[goods_uuid] -= num
if user.props[goods_uuid] <= 0:
del user.props[goods_uuid]
await user.save(update_fields=["props"])
@classmethod

View File

@ -15,7 +15,7 @@ class ChartUtils:
@classmethod
async def barh(cls, data: Barh) -> BuildImage:
"""横向统计图"""
to_json = data.dict()
to_json = data.to_dict()
to_json["background_image"] = (
f"./background/{random.choice(os.listdir(BACKGROUND_PATH))}"
)

View File

@ -1,3 +1,4 @@
from nonebot.compat import model_dump
from pydantic import BaseModel
@ -8,3 +9,6 @@ class Barh(BaseModel):
"""实际数据"""
title: str
"""标题"""
def to_dict(self, **kwargs):
return model_dump(self, **kwargs)

View File

@ -1,6 +1,7 @@
from typing import Protocol
from aiocache import cached
from nonebot.compat import model_dump
from pydantic import BaseModel
from strenum import StrEnum
@ -36,27 +37,30 @@ class RepoInfo(BaseModel):
async def get_raw_download_urls(self, path: str) -> list[str]:
url_formats = await get_fastest_raw_formats()
return [
url_format.format(**self.dict(), path=path) for url_format in url_formats
url_format.format(**self.to_dict(), path=path) for url_format in url_formats
]
async def get_archive_download_urls(self) -> list[str]:
url_formats = await get_fastest_archive_formats()
return [url_format.format(**self.dict()) for url_format in url_formats]
return [url_format.format(**self.to_dict()) for url_format in url_formats]
async def get_release_source_download_urls_tgz(self, version: str) -> list[str]:
url_formats = await get_fastest_release_source_formats()
return [
url_format.format(**self.dict(), version=version, compress="tar.gz")
url_format.format(**self.to_dict(), version=version, compress="tar.gz")
for url_format in url_formats
]
async def get_release_source_download_urls_zip(self, version: str) -> list[str]:
url_formats = await get_fastest_release_source_formats()
return [
url_format.format(**self.dict(), version=version, compress="zip")
url_format.format(**self.to_dict(), version=version, compress="zip")
for url_format in url_formats
]
def to_dict(self, **kwargs):
return model_dump(self, **kwargs)
class APIStrategy(Protocol):
"""API策略"""
@ -184,7 +188,7 @@ class Tree(BaseModel):
mode: str
type: TreeType
sha: str
size: int | None
size: int | None = None
url: str