mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-02 09:26:12 +08:00
🏷️ update type hints 2
This commit is contained in:
parent
2c605fc2dc
commit
fdfad8a6c7
@ -65,7 +65,7 @@ async def subscribes_export(selector: Callable[[Select], Select]) -> v3.SubGroup
|
|||||||
target_payload = type_validate_python(v3.Target, cookie_target.target)
|
target_payload = type_validate_python(v3.Target, cookie_target.target)
|
||||||
cookie_target_dict[cookie_target.cookie].append(target_payload)
|
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 = row2dict(cookie)
|
||||||
cookie_dict["tags"] = cookie.tags
|
cookie_dict["tags"] = cookie.tags
|
||||||
cookie_dict["targets"] = targets
|
cookie_dict["targets"] = targets
|
||||||
|
@ -83,7 +83,7 @@ async def subs_export(path: Path, format: str):
|
|||||||
export_file = path / f"bison_subscribes_export_{int(time.time())}.{format}"
|
export_file = path / f"bison_subscribes_export_{int(time.time())}.{format}"
|
||||||
|
|
||||||
logger.info("正在获取订阅信息...")
|
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:
|
with export_file.open("w", encoding="utf-8") as f:
|
||||||
match format:
|
match format:
|
||||||
|
@ -24,9 +24,9 @@ def do_add_cookie_target(add_cookie_target_matcher: type[Matcher]):
|
|||||||
await MessageFactory(await parse_text(res)).send()
|
await MessageFactory(await parse_text(res)).send()
|
||||||
|
|
||||||
@add_cookie_target_matcher.got("target_idx", parameterless=[handle_cancel])
|
@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:
|
try:
|
||||||
target_idx = int(target_idx)
|
target_idx = int(target_idx_str)
|
||||||
state["target"] = state["sub_table"][target_idx]
|
state["target"] = state["sub_table"][target_idx]
|
||||||
state["site"] = platform_manager[state["target"]["platform_name"]].site
|
state["site"] = platform_manager[state["target"]["platform_name"]].site
|
||||||
except Exception:
|
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])
|
@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:
|
try:
|
||||||
cookie_idx = int(cookie_idx)
|
cookie_idx = int(cookie_idx_str)
|
||||||
state["cookie"] = state["cookies"][cookie_idx - 1]
|
state["cookie"] = state["cookies"][cookie_idx - 1]
|
||||||
except Exception:
|
except Exception:
|
||||||
await add_cookie_target_matcher.reject("序号错误")
|
await add_cookie_target_matcher.reject("序号错误")
|
||||||
|
@ -8,11 +8,13 @@ from nonebot.adapters import Event
|
|||||||
from nonebot.typing import T_State
|
from nonebot.typing import T_State
|
||||||
from nonebot.matcher import Matcher
|
from nonebot.matcher import Matcher
|
||||||
from nonebot.permission import SUPERUSER
|
from nonebot.permission import SUPERUSER
|
||||||
|
from nonebot.adapters.onebot.v11 import PrivateMessageEvent
|
||||||
from nonebot.params import Depends, EventToMe, EventPlainText
|
from nonebot.params import Depends, EventToMe, EventPlainText
|
||||||
from nonebot_plugin_saa import PlatformTarget, extract_target
|
from nonebot_plugin_saa import PlatformTarget, extract_target
|
||||||
|
|
||||||
from ..config import config
|
from ..config import config
|
||||||
from ..types import Category
|
from ..types import Category
|
||||||
|
from ..types import Target as T_Target
|
||||||
from ..platform import platform_manager
|
from ..platform import platform_manager
|
||||||
from ..plugin_config import plugin_config
|
from ..plugin_config import plugin_config
|
||||||
from ..utils.site import is_cookie_client_manager
|
from ..utils.site import is_cookie_client_manager
|
||||||
@ -88,7 +90,7 @@ async def generate_sub_list_text(
|
|||||||
sub_list = [
|
sub_list = [
|
||||||
sub
|
sub
|
||||||
for sub in sub_list
|
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:
|
if not sub_list:
|
||||||
await matcher.finish("暂无已订阅账号\n请使用“添加订阅”命令添加订阅")
|
await matcher.finish("暂无已订阅账号\n请使用“添加订阅”命令添加订阅")
|
||||||
@ -109,7 +111,7 @@ async def generate_sub_list_text(
|
|||||||
res += " {}".format(", ".join(sub.tags)) + "\n"
|
res += " {}".format(", ".join(sub.tags)) + "\n"
|
||||||
if is_show_cookie:
|
if is_show_cookie:
|
||||||
target_cookies = await config.get_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:
|
if target_cookies:
|
||||||
res += " 关联的 Cookie:\n"
|
res += " 关联的 Cookie:\n"
|
||||||
@ -126,6 +128,5 @@ async def only_allow_private(
|
|||||||
event: Event,
|
event: Event,
|
||||||
matcher: type[Matcher],
|
matcher: type[Matcher],
|
||||||
):
|
):
|
||||||
# if not issubclass(PrivateMessageEvent, event.__class__):
|
if not issubclass(PrivateMessageEvent, event.__class__):
|
||||||
if event.message_type != "private":
|
|
||||||
await matcher.finish("请在私聊中使用此命令")
|
await matcher.finish("请在私聊中使用此命令")
|
||||||
|
@ -16,7 +16,7 @@ async def test_subs_export(app: App, init_scheduler):
|
|||||||
|
|
||||||
await config.add_subscribe(
|
await config.add_subscribe(
|
||||||
TargetQQGroup(group_id=1232),
|
TargetQQGroup(group_id=1232),
|
||||||
target=TTarget("weibo_id"),
|
target=TTarget(TTarget("weibo_id")),
|
||||||
target_name="weibo_name",
|
target_name="weibo_name",
|
||||||
platform_name="weibo",
|
platform_name="weibo",
|
||||||
cats=[],
|
cats=[],
|
||||||
@ -24,7 +24,7 @@ async def test_subs_export(app: App, init_scheduler):
|
|||||||
)
|
)
|
||||||
await config.add_subscribe(
|
await config.add_subscribe(
|
||||||
TargetQQGroup(group_id=2342),
|
TargetQQGroup(group_id=2342),
|
||||||
target=TTarget("weibo_id"),
|
target=TTarget(TTarget("weibo_id")),
|
||||||
target_name="weibo_name",
|
target_name="weibo_name",
|
||||||
platform_name="weibo",
|
platform_name="weibo",
|
||||||
cats=[],
|
cats=[],
|
||||||
@ -45,7 +45,7 @@ async def test_subs_export(app: App, init_scheduler):
|
|||||||
cookie_name="test cookie",
|
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()
|
data = await config.list_subs_with_all_info()
|
||||||
assert len(data) == 3
|
assert len(data) == 3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user