mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 13:42:56 +08:00
parent
8fbb574228
commit
f70b07e5a3
33
.pre-commit-config.yaml
Normal file
33
.pre-commit-config.yaml
Normal file
@ -0,0 +1,33 @@
|
||||
default_install_hook_types: [pre-commit, prepare-commit-msg]
|
||||
ci:
|
||||
autofix_commit_msg: ":rotating_light: auto fix by pre-commit hooks"
|
||||
autofix_prs: true
|
||||
autoupdate_branch: dev
|
||||
autoupdate_schedule: weekly
|
||||
autoupdate_commit_msg: ":arrow_up: auto update by pre-commit hooks"
|
||||
repos:
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.5.6
|
||||
hooks:
|
||||
- id: ruff
|
||||
args: [--fix, --exit-non-zero-on-fix]
|
||||
stages: [commit]
|
||||
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: 5.13.2
|
||||
hooks:
|
||||
- id: isort
|
||||
stages: [commit]
|
||||
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 24.8.0
|
||||
hooks:
|
||||
- id: black
|
||||
stages: [commit]
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||
rev: v4.0.0-alpha.8
|
||||
hooks:
|
||||
- id: prettier
|
||||
types_or: [javascript, jsx, ts, tsx, markdown, yaml, json]
|
||||
stages: [commit]
|
||||
@ -4,6 +4,7 @@ version = "0.1.1"
|
||||
description = "基于 Nonebot2 和 go-cqhttp 开发,以 postgresql 作为数据库,非常可爱的绪山真寻bot"
|
||||
authors = ["HibiKier <775757368@qq.com>"]
|
||||
license = "AGPL"
|
||||
package-mode = false
|
||||
|
||||
[[tool.poetry.source]]
|
||||
name = "ali"
|
||||
@ -15,7 +16,7 @@ python = "^3.10"
|
||||
playwright = "^1.41.1"
|
||||
nonebot-adapter-onebot = "^2.3.1"
|
||||
nonebot-plugin-apscheduler = "^0.3.0"
|
||||
tortoise-orm = {extras = ["asyncpg"], version = "^0.20.0"}
|
||||
tortoise-orm = { extras = ["asyncpg"], version = "^0.20.0" }
|
||||
cattrs = "^23.2.3"
|
||||
ruamel-yaml = "^0.18.5"
|
||||
strenum = "^0.4.15"
|
||||
@ -43,11 +44,94 @@ cn2an = "^0.5.22"
|
||||
aiohttp = "^3.9.5"
|
||||
dateparser = "^1.2.0"
|
||||
bilireq = "0.2.3post0"
|
||||
python-jose = {extras = ["cryptography"], version = "^3.3.0"}
|
||||
python-jose = { extras = ["cryptography"], version = "^3.3.0" }
|
||||
python-multipart = "^0.0.9"
|
||||
nonebot-plugin-alconna = "^0.51.1"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
nonebug = "^0.3.2"
|
||||
pytest-cov = "^5.0.0"
|
||||
pytest-mock = "^3.6.1"
|
||||
pytest-asyncio = "^0.23.5"
|
||||
pytest-xdist = "^3.3.1"
|
||||
respx = "^0.21.1"
|
||||
|
||||
[tool.nonebot]
|
||||
plugins = [
|
||||
"nonebot_plugin_apscheduler",
|
||||
"nonebot_plugin_session",
|
||||
"nonebot_plugin_htmlrender",
|
||||
"nonebot_plugin_userinfo",
|
||||
"nonebot_plugin_alconna",
|
||||
]
|
||||
plugin_dirs = ["zhenxun/services", "zhenxun/builtin_plugins", "zhenxun/plugins"]
|
||||
adapters = [
|
||||
{ name = "OneBot V11", module_name = "nonebot.adapters.onebot.v11" },
|
||||
{ name = "DoDo", module_name = "nonebot.adapters.dodo" },
|
||||
{ name = "开黑啦", module_name = "nonebot.adapters.kaiheila" },
|
||||
]
|
||||
|
||||
[tool.black]
|
||||
line-length = 88
|
||||
target-version = ["py39", "py310", "py311", "py312"]
|
||||
include = '\.pyi?$'
|
||||
extend-exclude = '''
|
||||
'''
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
line_length = 88
|
||||
length_sort = true
|
||||
skip_gitignore = true
|
||||
force_sort_within_sections = true
|
||||
src_paths = ["zhenxun", "tests"]
|
||||
extra_standard_library = ["typing_extensions"]
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 88
|
||||
target-version = "py310"
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = [
|
||||
"F", # Pyflakes
|
||||
"W", # pycodestyle warnings
|
||||
"E", # pycodestyle errors
|
||||
"UP", # pyupgrade
|
||||
"ASYNC", # flake8-async
|
||||
"C4", # flake8-comprehensions
|
||||
"T10", # flake8-debugger
|
||||
"T20", # flake8-print
|
||||
"PYI", # flake8-pyi
|
||||
"PT", # flake8-pytest-style
|
||||
"Q", # flake8-quotes
|
||||
"RUF", # Ruff-specific rules
|
||||
]
|
||||
ignore = [
|
||||
"E402", # module-import-not-at-top-of-file
|
||||
"UP037", # quoted-annotation
|
||||
"RUF001", # ambiguous-unicode-character-string
|
||||
"RUF002", # ambiguous-unicode-character-docstring
|
||||
"RUF003", # ambiguous-unicode-character-comment
|
||||
]
|
||||
|
||||
[tool.ruff.lint.flake8-pytest-style]
|
||||
fixture-parentheses = false
|
||||
mark-parentheses = false
|
||||
|
||||
[tool.pyright]
|
||||
pythonVersion = "3.9"
|
||||
pythonPlatform = "All"
|
||||
defineConstant = { PYDANTIC_V2 = true }
|
||||
executionEnvironments = [
|
||||
{ root = "./tests", extraPaths = [
|
||||
"./",
|
||||
] },
|
||||
{ root = "./" },
|
||||
]
|
||||
|
||||
typeCheckingMode = "standard"
|
||||
reportShadowedImports = false
|
||||
disableBytesTypePromotions = true
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
import re
|
||||
|
||||
import nonebot
|
||||
|
||||
# from nonebot.adapters.discord import Adapter as DiscordAdapter
|
||||
from nonebot.adapters.dodo import Adapter as DoDoAdapter
|
||||
from nonebot.adapters.kaiheila import Adapter as KaiheilaAdapter
|
||||
from nonebot.adapters.onebot.v11 import Adapter as OneBotV11Adapter
|
||||
from regex import F
|
||||
|
||||
nonebot.init()
|
||||
|
||||
from zhenxun.models.plugin_info import PluginInfo
|
||||
|
||||
driver = nonebot.get_driver()
|
||||
driver.register_adapter(OneBotV11Adapter)
|
||||
@ -23,11 +22,14 @@ nonebot.load_plugins("zhenxun/plugins")
|
||||
|
||||
all_plugins = [name.replace(":", ".") for name in nonebot.get_available_plugin_names()]
|
||||
print("所有插件:", all_plugins)
|
||||
loaded_plugins = tuple(re.sub(r"^zhenxun\.(plugins|builtin_plugins)\.", "", plugin.module_name) for plugin in nonebot.get_loaded_plugins())
|
||||
loaded_plugins = tuple(
|
||||
re.sub(r"^zhenxun\.(plugins|builtin_plugins)\.", "", plugin.module_name)
|
||||
for plugin in nonebot.get_loaded_plugins()
|
||||
)
|
||||
print("已加载插件:", loaded_plugins)
|
||||
|
||||
for plugin in all_plugins.copy():
|
||||
if plugin.startswith(("platform")):
|
||||
if plugin.startswith(("platform",)):
|
||||
print(f"平台插件:{plugin}")
|
||||
elif plugin.endswith(loaded_plugins):
|
||||
print(f"已加载插件:{plugin}")
|
||||
@ -40,4 +42,4 @@ if all_plugins:
|
||||
print("出现未加载的插件:", all_plugins)
|
||||
exit(1)
|
||||
else:
|
||||
print("所有插件均已加载")
|
||||
print("所有插件均已加载")
|
||||
|
||||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
37
tests/conftest.py
Normal file
37
tests/conftest.py
Normal file
@ -0,0 +1,37 @@
|
||||
from pathlib import Path
|
||||
|
||||
import nonebot
|
||||
import pytest
|
||||
from nonebot.plugin import Plugin
|
||||
from nonebug import NONEBOT_INIT_KWARGS
|
||||
from nonebug.app import App
|
||||
from pytest_mock import MockerFixture
|
||||
from respx import MockRouter
|
||||
|
||||
|
||||
def pytest_configure(config: pytest.Config) -> None:
|
||||
config.stash[NONEBOT_INIT_KWARGS] = {
|
||||
"driver": "~fastapi+~httpx+~websockets",
|
||||
"superusers": ["AkashiCoin"],
|
||||
"command_start": "",
|
||||
"session_running_expression": "别急呀,小真寻要宕机了!QAQ",
|
||||
"image_to_bytes": False,
|
||||
"nickname": ["真寻", "小真寻", "绪山真寻", "小寻子"],
|
||||
"session_expire_timeout": 30,
|
||||
"self_nickname": "小真寻",
|
||||
"db_url": "sqlite://:memory:",
|
||||
"platform_superusers": {"qq": ["qq_su"], "dodo": ["dodo_su"]},
|
||||
"host": "127.0.0.1",
|
||||
"port": 8080,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def load_plugin(nonebug_init: None) -> set[Plugin]:
|
||||
return nonebot.load_plugins("zhenxun.plugins")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def app(app: App, tmp_path: Path, mocker: MockerFixture):
|
||||
mocker.patch("nonebot.drivers.websockets.connect", return_value=MockRouter())
|
||||
return app
|
||||
Loading…
Reference in New Issue
Block a user