Skip to content

Commit

Permalink
fix: 将 user 独立出来,再次调整插件加载顺序
Browse files Browse the repository at this point in the history
优先加载 library 插件
  • Loading branch information
he0119 committed Sep 20, 2023
1 parent 8b48891 commit 037bde0
Show file tree
Hide file tree
Showing 24 changed files with 41 additions and 45 deletions.
13 changes: 13 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
driver.register_adapter(RedAdapter)

# 加载插件
nonebot.load_all_plugins(
[
"onebot_qqguild_extension",
"nonebot_plugin_apscheduler",
"nonebot_plugin_saa",
"nonebot_plugin_alconna",
"nonebot_plugin_datastore",
"nonebot_plugin_session",
"nonebot_plugin_userinfo",
"src.user",
],
[],
)
nonebot.load_from_toml("pyproject.toml")

if __name__ == "__main__":
Expand Down
7 changes: 0 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,8 @@ adapters = [
]
plugin_dirs = ["src/plugins"]
plugins = [
"onebot_qqguild_extension",
"nonebot_plugin_apscheduler",
"nonebot_plugin_saa",
"nonebot_plugin_alconna",
"nonebot_plugin_sentry",
"nonebot_plugin_treehelp",
"nonebot_plugin_datastore",
"nonebot_plugin_session",
"nonebot_plugin_userinfo",
"nonebot_plugin_wordcloud",
"nonebot_plugin_memes",
"nonebot_bison",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/check_in/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
from nonebot import require

require("src.plugins.user")
require("src.user")
from pathlib import Path

import nonebot
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/check_in/plugins/check_in_body_fat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from nonebot.typing import T_State
from sqlalchemy import select

from src.plugins.user import UserSession
from src.user import UserSession
from src.utils.annotated import AsyncSession, OptionalPlainTextArgs, PlainTextArgs
from src.utils.helpers import parse_str

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/check_in/plugins/check_in_dietary.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
from nonebot.typing import T_State

from src.plugins.user import UserSession
from src.user import UserSession
from src.utils.annotated import AsyncSession, PlainTextArgs
from src.utils.helpers import parse_str

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/check_in/plugins/check_in_fitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
from nonebot.typing import T_State

from src.plugins.user import UserSession
from src.user import UserSession
from src.utils.annotated import AsyncSession, PlainTextArgs
from src.utils.helpers import parse_str

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/check_in/plugins/check_in_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from sqlalchemy import func, select

from src.plugins.user import UserSession
from src.user import UserSession
from src.utils.annotated import AsyncSession

from ..models import BodyFatRecord, DietaryRecord, FitnessRecord, WeightRecord
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/check_in/plugins/check_in_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
from nonebot.typing import T_State

from src.plugins.user import UserSession
from src.user import UserSession
from src.utils.annotated import AsyncSession, OptionalPlainTextArgs, PlainTextArgs
from src.utils.helpers import parse_str

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/check_in/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sqlalchemy import select

from src.plugins.user import UserSession
from src.user import UserSession
from src.utils.annotated import AsyncSession

from .models import UserInfo
Expand Down
8 changes: 2 additions & 6 deletions src/plugins/cyber_hospital/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
""" 赛博查房 """
from nonebot import require

require("nonebot_plugin_alconna")
require("src.plugins.user")
from nonebot.matcher import Matcher
from nonebot.params import ArgPlainText
from nonebot.permission import Permission
Expand All @@ -19,8 +15,8 @@
)
from nonebot_plugin_datastore.db import pre_db_init

from src.plugins.user import UserSession
from src.plugins.user.utils import get_or_create_user, get_user_by_id
from src.user import UserSession
from src.user.utils import get_or_create_user, get_user_by_id
from src.utils.helpers import admin_permission

from .data_source import Hospital
Expand Down
8 changes: 2 additions & 6 deletions src/plugins/ff14/plugins/ff14_fflogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
查询副本输出数据。
"""
from nonebot import require

require("nonebot_plugin_alconna")
require("src.plugins.user")
from typing import Literal, cast

from nonebot import logger
Expand All @@ -14,8 +10,8 @@
from nonebot_plugin_datastore import get_plugin_data
from nonebot_plugin_datastore.db import post_db_init, pre_db_init

from src.plugins.user import UserSession, get_user
from src.plugins.user.utils import get_or_create_user
from src.user import UserSession, get_user
from src.user.utils import get_or_create_user
from src.utils.helpers import strtobool

from ... import global_config
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/morning/plugins/morning_greeting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
""" 每日早安 """
from nonebot import require

require("nonebot_plugin_saa")
from nonebot.adapters import Message
from nonebot.exception import ActionFailed
from nonebot.log import logger
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ def load_plugin(nonebug_init: None):
nonebot.require("nonebot_plugin_alconna")
nonebot.require("nonebot_plugin_session")
nonebot.require("nonebot_plugin_userinfo")
nonebot.require("src.user")

nonebot.load_plugins(str(Path(__file__).parent.parent / "src" / "plugins"))


@pytest.fixture
async def app(nonebug_init: None, tmp_path: Path, load_plugin):
async def app(tmp_path: Path, load_plugin):
from nonebot_plugin_datastore.config import plugin_config
from nonebot_plugin_datastore.db import init_db

Expand Down Expand Up @@ -61,7 +62,7 @@ def caplog(caplog):
async def default_user(app: App):
from nonebot_plugin_datastore import create_session

from src.plugins.user.models import Bind, User
from src.user.models import Bind, User

async with create_session() as session:
user = User(id=1, name="nickname")
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/user/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def app(app: App):
# 清理数据库
from nonebot_plugin_datastore.db import create_session

from src.plugins.user.models import Bind, User
from src.user.models import Bind, User

async with create_session() as session, session.begin():
await session.execute(delete(Bind))
Expand All @@ -37,7 +37,7 @@ async def session(app: App):
# https://stackoverflow.com/questions/29116718/how-to-mocking-created-time-in-sqlalchemy
@contextmanager
def patch_time(time_to_freeze, tick=True):
from src.plugins.user.models import User
from src.user.models import User

with freeze_time(time_to_freeze, tick=tick) as frozen_time:

Expand Down
8 changes: 4 additions & 4 deletions tests/plugins/user/test_bind_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

async def test_bind_group(app: App, patch_current_time, mocker: MockerFixture):
"""群聊绑定用户"""
from src.plugins.user import bind_cmd, user_cmd
from src.user import bind_cmd, user_cmd

mocked_random = mocker.patch("src.plugins.user.random.randint")
mocked_random = mocker.patch("src.user.random.randint")
mocked_random.return_value = 123456

with patch_current_time("2023-09-14 10:46:10.416389", tick=False):
Expand Down Expand Up @@ -128,9 +128,9 @@ async def test_bind_group_different_user(
app: App, patch_current_time, mocker: MockerFixture
):
"""群聊绑定用户,不是最开始发送绑定命令的用户"""
from src.plugins.user import bind_cmd, user_cmd
from src.user import bind_cmd, user_cmd

mocked_random = mocker.patch("src.plugins.user.random.randint")
mocked_random = mocker.patch("src.user.random.randint")
mocked_random.return_value = 123456

with patch_current_time("2023-09-14 10:46:10.416389", tick=False):
Expand Down
8 changes: 4 additions & 4 deletions tests/plugins/user/test_bind_private.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

async def test_bind_private(app: App, patch_current_time, mocker: MockerFixture):
"""私聊绑定用户"""
from src.plugins.user import bind_cmd, user_cmd
from src.user import bind_cmd, user_cmd

mocked_random = mocker.patch("src.plugins.user.random.randint")
mocked_random = mocker.patch("src.user.random.randint")
mocked_random.return_value = 123456

with patch_current_time("2023-09-14 10:46:10.416389", tick=False):
Expand Down Expand Up @@ -111,9 +111,9 @@ async def test_bind_private_invalid_token(
app: App, patch_current_time, mocker: MockerFixture
):
"""私聊绑定用户,无效的令牌"""
from src.plugins.user import bind_cmd, user_cmd
from src.user import bind_cmd, user_cmd

mocked_random = mocker.patch("src.plugins.user.random.randint")
mocked_random = mocker.patch("src.user.random.randint")
mocked_random.return_value = 123456

with patch_current_time("2023-09-14 10:46:10.416389", tick=False):
Expand Down
6 changes: 3 additions & 3 deletions tests/plugins/user/test_remove_bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ async def test_remove_bind(app: App, patch_current_time, mocker: MockerFixture):
"""解除绑定"""
from nonebot_plugin_datastore import create_session

from src.plugins.user import bind_cmd
from src.plugins.user.models import Bind, User
from src.user import bind_cmd
from src.user.models import Bind, User

with patch_current_time("2023-09-14 10:46:10.416389", tick=False):
async with create_session() as session:
Expand Down Expand Up @@ -54,7 +54,7 @@ async def test_remove_bind(app: App, patch_current_time, mocker: MockerFixture):

async def test_remove_bind_self(app: App, patch_current_time, mocker: MockerFixture):
"""解除最初的绑定"""
from src.plugins.user import bind_cmd
from src.user import bind_cmd

with patch_current_time("2023-09-14 10:46:10.416389", tick=False):
async with app.test_matcher(bind_cmd) as ctx:
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/user/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

async def test_user(app: App, patch_current_time):
"""获取用户信息"""
from src.plugins.user import user_cmd
from src.user import user_cmd

with patch_current_time("2023-09-14 10:46:10.416389", tick=False):
async with app.test_matcher(user_cmd) as ctx:
Expand Down

0 comments on commit 037bde0

Please sign in to comment.