From 3fa2210c2a999d8864316dcd444a1b80541facc3 Mon Sep 17 00:00:00 2001 From: meetwq Date: Fri, 11 Oct 2024 23:27:12 +0800 Subject: [PATCH] replace session with uninfo --- nonebot_plugin_handle/__init__.py | 18 ++++++++-------- poetry.lock | 34 ++++++++----------------------- pyproject.toml | 2 +- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/nonebot_plugin_handle/__init__.py b/nonebot_plugin_handle/__init__.py index 821ee8e..6cf78bf 100644 --- a/nonebot_plugin_handle/__init__.py +++ b/nonebot_plugin_handle/__init__.py @@ -5,12 +5,12 @@ from nonebot import on_regex, require from nonebot.log import logger from nonebot.matcher import Matcher -from nonebot.params import EventToMe, RegexDict +from nonebot.params import Depends, EventToMe, RegexDict from nonebot.plugin import PluginMetadata, inherit_supported_adapters from nonebot.utils import run_sync require("nonebot_plugin_alconna") -require("nonebot_plugin_session") +require("nonebot_plugin_uninfo") from nonebot_plugin_alconna import ( AlcMatches, @@ -24,7 +24,7 @@ on_alconna, store_true, ) -from nonebot_plugin_session import SessionId, SessionIdType +from nonebot_plugin_uninfo import Uninfo from .config import Config, handle_config from .data_source import GuessResult, Handle @@ -49,18 +49,20 @@ homepage="https://github.com/noneplugin/nonebot-plugin-handle", config=Config, supported_adapters=inherit_supported_adapters( - "nonebot_plugin_alconna", "nonebot_plugin_session" + "nonebot_plugin_alconna", "nonebot_plugin_uninfo" ), - extra={ - "example": "猜成语", - }, ) games: dict[str, Handle] = {} timers: dict[str, TimerHandle] = {} -UserId = Annotated[str, SessionId(SessionIdType.GROUP)] + +def get_user_id(uninfo: Uninfo) -> str: + return f"{uninfo.scope}_{uninfo.self_id}_{uninfo.scene_path}" + + +UserId = Annotated[str, Depends(get_user_id)] def game_is_running(user_id: UserId) -> bool: diff --git a/poetry.lock b/poetry.lock index fe58ca0..ddd235c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -251,19 +251,19 @@ nonebot2 = ">=2.3.0" tarina = ">=0.5.5" [[package]] -name = "nonebot-plugin-session" -version = "0.3.2" -description = "Nonebot2 会话信息提取与会话id定义" +name = "nonebot-plugin-uninfo" +version = "0.4.1" +description = "Universal Information Model for Nonebot2" optional = false -python-versions = "<4.0,>=3.9" +python-versions = ">=3.9" files = [ - {file = "nonebot_plugin_session-0.3.2-py3-none-any.whl", hash = "sha256:785e74ff656e46d84c4dbbac125f9a9adebcc4b9ff7db700527e6e47d47aabd6"}, - {file = "nonebot_plugin_session-0.3.2.tar.gz", hash = "sha256:da0dabe9108151052a6e83d9923068d2ec43a93810ad37b264ed65aee2c69f93"}, + {file = "nonebot_plugin_uninfo-0.4.1-py3-none-any.whl", hash = "sha256:2075874a540f27cb650ff5e64482324121c39e4374b850df323482744910beac"}, + {file = "nonebot_plugin_uninfo-0.4.1.tar.gz", hash = "sha256:8c36d62684029d813dd01acd2cc759f07163923b8274935250dcd3e9293ef560"}, ] [package.dependencies] -nonebot2 = ">=2.3.0,<3.0.0" -strenum = ">=0.4.15,<0.5.0" +importlib-metadata = ">=4.13.0" +nonebot2 = ">=2.3.0" [[package]] name = "nonebot-plugin-waiter" @@ -674,22 +674,6 @@ files = [ [package.extras] cli = ["click (>=5.0)"] -[[package]] -name = "strenum" -version = "0.4.15" -description = "An Enum that inherits from str." -optional = false -python-versions = "*" -files = [ - {file = "StrEnum-0.4.15-py3-none-any.whl", hash = "sha256:a30cda4af7cc6b5bf52c8055bc4bf4b2b6b14a93b574626da33df53cf7740659"}, - {file = "StrEnum-0.4.15.tar.gz", hash = "sha256:878fb5ab705442070e4dd1929bb5e2249511c0bcf2b0eeacf3bcd80875c82eff"}, -] - -[package.extras] -docs = ["myst-parser[linkify]", "sphinx", "sphinx-rtd-theme"] -release = ["twine"] -test = ["pylint", "pytest", "pytest-black", "pytest-cov", "pytest-pylint"] - [[package]] name = "tarina" version = "0.5.8" @@ -916,4 +900,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "90807a3142d623432d7b43da29cebbc04868efb033e31e95553c1e5863686da7" +content-hash = "dc0e7ea763fe344cccf54c975963ccde13dbffe19025e9f04c58023f0e708d5b" diff --git a/pyproject.toml b/pyproject.toml index 450465b..6102e46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ repository = "https://github.com/noneplugin/nonebot-plugin-handle" python = "^3.9" nonebot2 = "^2.3.0" nonebot-plugin-alconna = ">=0.46.3,<1.0.0" -nonebot-plugin-session = "^0.3.0" +nonebot-plugin-uninfo = ">=0.4.0,<1.0.0" Pillow = "^10.0.0" pypinyin = ">=0.40.0,<1.0.0"