Skip to content

Commit

Permalink
feat(user): 使用独立的用户插件 (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 authored Sep 23, 2023
1 parent 3c8197c commit 0f84e07
Show file tree
Hide file tree
Showing 27 changed files with 192 additions and 1,224 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/

## [Unreleased]

### Added

- 添加多适配器支持
- 添加用户插件

### Fixed

- 修复和风天气无法找到城市时报错的问题
Expand Down
300 changes: 149 additions & 151 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ nonebot-adapter-red = "^0.4.1"
nonebot-plugin-datastore = "^1.1.2"
nonebot-plugin-wordcloud = "^0.5.2"
nonebot-plugin-treehelp = "^0.3.0"
nonebot-plugin-user = "^0.0.1"

nonebot-plugin-apscheduler = "^0.3.0"
nonebot-plugin-send-anything-anywhere = "^0.3.0"
Expand Down Expand Up @@ -65,7 +66,7 @@ plugins = [
"nonebot_plugin_datastore",
"nonebot_plugin_session",
"nonebot_plugin_userinfo",
"src.user",
"nonebot_plugin_user",
"nonebot_plugin_sentry",
"nonebot_plugin_treehelp",
"nonebot_plugin_wordcloud",
Expand Down
6 changes: 3 additions & 3 deletions 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.user")
require("nonebot_plugin_user")
from pathlib import Path

import nonebot
Expand All @@ -16,15 +16,15 @@ async def upgrade_user():
from nonebot_plugin_datastore.script.command import upgrade
from nonebot_plugin_datastore.script.utils import Config

config = Config("user")
config = Config("nonebot_plugin_user")
await upgrade(config, "head")


__plugin_meta__ = PluginMetadata(
name="打卡",
description="每日打卡,记录健身数据",
usage="",
supported_adapters=inherit_supported_adapters("user"),
supported_adapters=inherit_supported_adapters("nonebot_plugin_user"),
)

check_in = CommandGroup("check_in", block=True)
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/check_in/migrations/84cf08678c89_migrate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def upgrade() -> None:

OldUser = Base.classes.check_in_user
UserInfo = Base.classes.check_in_userinfo
User = Base.classes.user_user
Bind = Base.classes.user_bind
User = Base.classes.nonebot_plugin_user_user
Bind = Base.classes.nonebot_plugin_user_bind
user_id_map = {}
with Session(op.get_bind()) as session:
users = session.scalars(sa.select(OldUser)).all()
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/check_in/plugins/check_in_body_fat.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from nonebot.params import Arg, Depends
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
from nonebot.typing import T_State
from nonebot_plugin_user import UserSession
from sqlalchemy import select

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

Expand All @@ -21,7 +21,7 @@
记录体脂
/体脂打卡
/体制打卡 20""",
supported_adapters=inherit_supported_adapters("user"),
supported_adapters=inherit_supported_adapters("nonebot_plugin_user"),
)

target_body_fat_cmd = check_in.command("body_fat", aliases={"目标体脂"})
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/check_in/plugins/check_in_dietary.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from nonebot.params import Arg, Depends
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
from nonebot.typing import T_State
from nonebot_plugin_user import UserSession

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

Expand All @@ -14,7 +14,7 @@
description="记录饮食是否健康",
usage="""记录饮食是否健康
/饮食打卡""",
supported_adapters=inherit_supported_adapters("user"),
supported_adapters=inherit_supported_adapters("nonebot_plugin_user"),
)
dietary_cmd = check_in.command("dietary", aliases={"饮食打卡"})

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/check_in/plugins/check_in_fitness.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from nonebot.params import Arg, Depends
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
from nonebot.typing import T_State
from nonebot_plugin_user import UserSession

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

Expand All @@ -14,7 +14,7 @@
description="记录健身情况",
usage="""记录健身情况
/健身打卡""",
supported_adapters=inherit_supported_adapters("user"),
supported_adapters=inherit_supported_adapters("nonebot_plugin_user"),
)
fitness_cmd = check_in.command("fitness", aliases={"健身打卡"})

Expand Down
6 changes: 4 additions & 2 deletions src/plugins/check_in/plugins/check_in_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
Text,
on_alconna,
)
from nonebot_plugin_user import UserSession
from sqlalchemy import func, select

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

from ..models import BodyFatRecord, DietaryRecord, FitnessRecord, WeightRecord
Expand All @@ -32,7 +32,9 @@
/打卡历史 C
查看体脂历史
/打卡历史 D""",
supported_adapters=inherit_supported_adapters("nonebot_plugin_alconna", "user"),
supported_adapters=inherit_supported_adapters(
"nonebot_plugin_alconna", "nonebot_plugin_user"
),
)

history_cmd = on_alconna(Alconna("打卡历史", Args["content?", str]), use_cmd_start=True)
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/check_in/plugins/check_in_weight.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from nonebot.params import Arg, Depends
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
from nonebot.typing import T_State
from nonebot_plugin_user import UserSession

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

Expand All @@ -20,7 +20,7 @@
记录体重
/体重打卡
/体重打卡 60""",
supported_adapters=inherit_supported_adapters("user"),
supported_adapters=inherit_supported_adapters("nonebot_plugin_user"),
)
target_weight_cmd = check_in.command("weight", aliases={"目标体重"})

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 nonebot_plugin_user import UserSession
from sqlalchemy import select

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

from .models import UserInfo
Expand Down
10 changes: 6 additions & 4 deletions src/plugins/cyber_hospital/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
on_alconna,
)
from nonebot_plugin_datastore.db import pre_db_init
from nonebot_plugin_user import UserSession
from nonebot_plugin_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 All @@ -27,7 +27,7 @@ async def upgrade_user():
from nonebot_plugin_datastore.script.command import upgrade
from nonebot_plugin_datastore.script.utils import Config

config = Config("user")
config = Config("nonebot_plugin_user")
await upgrade(config, "head")


Expand All @@ -49,7 +49,9 @@ async def upgrade_user():
查看所有人入院次数,或指定人出入院时间
/入院记录
/入院记录 @病人""",
supported_adapters=inherit_supported_adapters("nonebot_plugin_alconna", "user"),
supported_adapters=inherit_supported_adapters(
"nonebot_plugin_alconna", "nonebot_plugin_user"
),
)

hospital_service = Hospital()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def upgrade() -> None:
Base.prepare(op.get_bind())

Patient = Base.classes.cyber_hospital_patient
User = Base.classes.user_user
Bind = Base.classes.user_bind
User = Base.classes.nonebot_plugin_user_user
Bind = Base.classes.nonebot_plugin_user_bind
with Session(op.get_bind()) as session:
patients = session.scalars(sa.select(Patient)).all()
for patient in patients:
Expand Down
10 changes: 6 additions & 4 deletions src/plugins/ff14/plugins/ff14_fflogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from nonebot_plugin_alconna import Alconna, Args, At, MultiVar, Text, on_alconna
from nonebot_plugin_datastore import get_plugin_data
from nonebot_plugin_datastore.db import post_db_init, pre_db_init
from nonebot_plugin_user import UserSession, get_user
from nonebot_plugin_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 All @@ -38,7 +38,9 @@
/dps me 角色名 服务器名
查询他人绑定的角色
/dps @他人""",
supported_adapters=inherit_supported_adapters("nonebot_plugin_alconna", "user"),
supported_adapters=inherit_supported_adapters(
"nonebot_plugin_alconna", "nonebot_plugin_user"
),
)

plugin_data = get_plugin_data()
Expand Down Expand Up @@ -223,5 +225,5 @@ async def upgrade_user():
from nonebot_plugin_datastore.script.command import upgrade
from nonebot_plugin_datastore.script.utils import Config

config = Config("user")
config = Config("nonebot_plugin_user")
await upgrade(config, "head")
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def upgrade() -> None:
Base.prepare(op.get_bind())

FF14User = Base.classes.ff14_fflogs_user
User = Base.classes.user_user
Bind = Base.classes.user_bind
User = Base.classes.nonebot_plugin_user_user
Bind = Base.classes.nonebot_plugin_user_bind
with Session(op.get_bind()) as session:
users = session.scalars(sa.select(FF14User)).all()
for user in users:
Expand Down
117 changes: 0 additions & 117 deletions src/user/__init__.py

This file was deleted.

10 changes: 0 additions & 10 deletions src/user/annotated.py

This file was deleted.

Loading

0 comments on commit 0f84e07

Please sign in to comment.