From fdfad8a6c7c88ba8230602fcecfef92a1845b40a Mon Sep 17 00:00:00 2001 From: suyiiyii Date: Tue, 26 Nov 2024 00:03:43 +0800 Subject: [PATCH] :label: update type hints 2 --- nonebot_bison/config/subs_io/subs_io.py | 2 +- nonebot_bison/script/cli.py | 2 +- nonebot_bison/sub_manager/add_cookie_target.py | 8 ++++---- nonebot_bison/sub_manager/utils.py | 9 +++++---- tests/subs_io/test_subs_io.py | 6 +++--- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/nonebot_bison/config/subs_io/subs_io.py b/nonebot_bison/config/subs_io/subs_io.py index 9b9ce48..c871096 100644 --- a/nonebot_bison/config/subs_io/subs_io.py +++ b/nonebot_bison/config/subs_io/subs_io.py @@ -65,7 +65,7 @@ async def subscribes_export(selector: Callable[[Select], Select]) -> v3.SubGroup target_payload = type_validate_python(v3.Target, cookie_target.target) cookie_target_dict[cookie_target.cookie].append(target_payload) - def cookie_transform(cookie: Cookie, targets: [Target]) -> v3.Cookie: + def cookie_transform(cookie: Cookie, targets: list[v3.Target]) -> v3.Cookie: cookie_dict = row2dict(cookie) cookie_dict["tags"] = cookie.tags cookie_dict["targets"] = targets diff --git a/nonebot_bison/script/cli.py b/nonebot_bison/script/cli.py index 790a7dd..f17e431 100644 --- a/nonebot_bison/script/cli.py +++ b/nonebot_bison/script/cli.py @@ -83,7 +83,7 @@ async def subs_export(path: Path, format: str): export_file = path / f"bison_subscribes_export_{int(time.time())}.{format}" logger.info("正在获取订阅信息...") - export_data: v2.SubGroup = await subscribes_export(lambda x: x) + export_data: v3.SubGroup = await subscribes_export(lambda x: x) with export_file.open("w", encoding="utf-8") as f: match format: diff --git a/nonebot_bison/sub_manager/add_cookie_target.py b/nonebot_bison/sub_manager/add_cookie_target.py index 8fd4780..b3f7361 100644 --- a/nonebot_bison/sub_manager/add_cookie_target.py +++ b/nonebot_bison/sub_manager/add_cookie_target.py @@ -24,9 +24,9 @@ def do_add_cookie_target(add_cookie_target_matcher: type[Matcher]): await MessageFactory(await parse_text(res)).send() @add_cookie_target_matcher.got("target_idx", parameterless=[handle_cancel]) - async def got_target_idx(state: T_State, target_idx: str = ArgPlainText()): + async def got_target_idx(state: T_State, target_idx_str: str = ArgPlainText()): try: - target_idx = int(target_idx) + target_idx = int(target_idx_str) state["target"] = state["sub_table"][target_idx] state["site"] = platform_manager[state["target"]["platform_name"]].site except Exception: @@ -55,9 +55,9 @@ def do_add_cookie_target(add_cookie_target_matcher: type[Matcher]): ) @add_cookie_target_matcher.got("cookie_idx", MessageTemplate("{_prompt}"), [handle_cancel]) - async def got_cookie_idx(state: T_State, cookie_idx: str = ArgPlainText()): + async def got_cookie_idx(state: T_State, cookie_idx_str: str = ArgPlainText()): try: - cookie_idx = int(cookie_idx) + cookie_idx = int(cookie_idx_str) state["cookie"] = state["cookies"][cookie_idx - 1] except Exception: await add_cookie_target_matcher.reject("序号错误") diff --git a/nonebot_bison/sub_manager/utils.py b/nonebot_bison/sub_manager/utils.py index 8126b9a..b9b5704 100644 --- a/nonebot_bison/sub_manager/utils.py +++ b/nonebot_bison/sub_manager/utils.py @@ -8,11 +8,13 @@ from nonebot.adapters import Event from nonebot.typing import T_State from nonebot.matcher import Matcher from nonebot.permission import SUPERUSER +from nonebot.adapters.onebot.v11 import PrivateMessageEvent from nonebot.params import Depends, EventToMe, EventPlainText from nonebot_plugin_saa import PlatformTarget, extract_target from ..config import config from ..types import Category +from ..types import Target as T_Target from ..platform import platform_manager from ..plugin_config import plugin_config from ..utils.site import is_cookie_client_manager @@ -88,7 +90,7 @@ async def generate_sub_list_text( sub_list = [ sub for sub in sub_list - if is_cookie_client_manager(platform_manager.get(sub.target.platform_name).site.client_mgr) + if is_cookie_client_manager(platform_manager[sub.target.platform_name].site.client_mgr) ] if not sub_list: await matcher.finish("暂无已订阅账号\n请使用“添加订阅”命令添加订阅") @@ -109,7 +111,7 @@ async def generate_sub_list_text( res += " {}".format(", ".join(sub.tags)) + "\n" if is_show_cookie: target_cookies = await config.get_cookie( - target=sub.target.target, site_name=platform.site.name, is_anonymous=False + target=T_Target(sub.target.target), site_name=platform.site.name, is_anonymous=False ) if target_cookies: res += " 关联的 Cookie:\n" @@ -126,6 +128,5 @@ async def only_allow_private( event: Event, matcher: type[Matcher], ): - # if not issubclass(PrivateMessageEvent, event.__class__): - if event.message_type != "private": + if not issubclass(PrivateMessageEvent, event.__class__): await matcher.finish("请在私聊中使用此命令") diff --git a/tests/subs_io/test_subs_io.py b/tests/subs_io/test_subs_io.py index 700becf..5164672 100644 --- a/tests/subs_io/test_subs_io.py +++ b/tests/subs_io/test_subs_io.py @@ -16,7 +16,7 @@ async def test_subs_export(app: App, init_scheduler): await config.add_subscribe( TargetQQGroup(group_id=1232), - target=TTarget("weibo_id"), + target=TTarget(TTarget("weibo_id")), target_name="weibo_name", platform_name="weibo", cats=[], @@ -24,7 +24,7 @@ async def test_subs_export(app: App, init_scheduler): ) await config.add_subscribe( TargetQQGroup(group_id=2342), - target=TTarget("weibo_id"), + target=TTarget(TTarget("weibo_id")), target_name="weibo_name", platform_name="weibo", cats=[], @@ -45,7 +45,7 @@ async def test_subs_export(app: App, init_scheduler): cookie_name="test cookie", ) ) - await config.add_cookie_target("weibo_id", "weibo", cookie_id) + await config.add_cookie_target(TTarget("weibo_id"), "weibo", cookie_id) data = await config.list_subs_with_all_info() assert len(data) == 3