🏷️ update type hints 2

This commit is contained in:
suyiiyii 2024-11-26 00:03:43 +08:00
parent 2c605fc2dc
commit fdfad8a6c7
Signed by: suyiiyii
GPG Key ID: 044704CB29B8AD85
5 changed files with 14 additions and 13 deletions

View File

@ -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

View File

@ -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:

View File

@ -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("序号错误")

View File

@ -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("请在私聊中使用此命令")

View File

@ -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