From b61bde6e3fcd76018c1e0fbe4017503c7206e93a Mon Sep 17 00:00:00 2001 From: suyiiyii Date: Fri, 6 Sep 2024 00:39:57 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=85=B3=E8=81=94cookie=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=8F=AA=E6=98=BE=E7=A4=BA=E6=94=AF=E6=8C=81=E7=9A=84?= =?UTF-8?q?=E8=AE=A2=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_bison/apis.py | 3 ++- nonebot_bison/sub_manager/add_cookie_target.py | 4 +++- nonebot_bison/sub_manager/utils.py | 14 +++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/nonebot_bison/apis.py b/nonebot_bison/apis.py index c4f247a..fb44654 100644 --- a/nonebot_bison/apis.py +++ b/nonebot_bison/apis.py @@ -1,4 +1,5 @@ from .types import Target +from .utils import text_fletten from .config.db_model import Cookie from .scheduler import scheduler_dict from .platform import platform_manager @@ -20,4 +21,4 @@ async def check_sub_target_cookie(platform_name: str, target: Target, cookie: st async def get_cookie_friendly_name(cookie: Cookie): # TODO - return f"{cookie.platform_name} [{cookie.content[:10]}]" + return text_fletten(f"{cookie.platform_name} [{cookie.content[:10]}]") diff --git a/nonebot_bison/sub_manager/add_cookie_target.py b/nonebot_bison/sub_manager/add_cookie_target.py index 5a1a4d0..be3fe89 100644 --- a/nonebot_bison/sub_manager/add_cookie_target.py +++ b/nonebot_bison/sub_manager/add_cookie_target.py @@ -15,7 +15,9 @@ def do_add_cookie_target(add_cookie_target_matcher: type[Matcher]): @add_cookie_target_matcher.handle() async def init_promote(state: T_State): - res = await generate_sub_list_text(add_cookie_target_matcher, state, is_index=True, is_show_cookie=True) + res = await generate_sub_list_text( + add_cookie_target_matcher, state, is_index=True, is_show_cookie=True, is_hide_no_cookie_platfrom=True + ) res += "请输入要关联 cookie 的订阅的序号\n输入'取消'中止" await MessageFactory(await parse_text(res)).send() diff --git a/nonebot_bison/sub_manager/utils.py b/nonebot_bison/sub_manager/utils.py index 4b7dd6f..8edf7f8 100644 --- a/nonebot_bison/sub_manager/utils.py +++ b/nonebot_bison/sub_manager/utils.py @@ -16,6 +16,7 @@ from ..types import Category from ..platform import platform_manager from ..plugin_config import plugin_config from ..apis import get_cookie_friendly_name +from ..utils.site import is_cookie_client_manager def _configurable_to_me(to_me: bool = EventToMe()): @@ -68,7 +69,12 @@ def admin_permission(): async def generate_sub_list_text( - matcher: type[Matcher], state: T_State, user_info: PlatformTarget = None, is_index=False, is_show_cookie=False + matcher: type[Matcher], + state: T_State, + user_info: PlatformTarget = None, + is_index=False, + is_show_cookie=False, + is_hide_no_cookie_platfrom=False, ): if user_info: sub_list = await config.list_subscribe(user_info) @@ -78,6 +84,12 @@ async def generate_sub_list_text( next(group) for key, group in groupby(sorted(sub_list, key=attrgetter("target_id")), key=attrgetter("target_id")) ] + if is_hide_no_cookie_platfrom: + sub_list = [ + sub + for sub in sub_list + if is_cookie_client_manager(platform_manager.get(sub.target.platform_name).site.client_mgr) + ] if not sub_list: await matcher.finish("暂无已订阅账号\n请使用“添加订阅”命令添加订阅") res = "订阅的帐号为:\n"