mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-05-31 16:16:11 +08:00
✏️ small fixs
This commit is contained in:
parent
3f7a9bf8a3
commit
d6b8d3b44e
@ -24,9 +24,8 @@ B = TypeVar("B", bound="Bilibili")
|
||||
|
||||
class BilibiliClientManager(CookieClientManager):
|
||||
|
||||
_default_cookie_cd: int = timedelta(seconds=120)
|
||||
_default_cookie_cd = timedelta(seconds=120)
|
||||
|
||||
@classmethod
|
||||
async def _get_cookies(self) -> list[Cookie]:
|
||||
browser = await get_browser()
|
||||
async with await browser.new_page() as page:
|
||||
@ -38,7 +37,6 @@ class BilibiliClientManager(CookieClientManager):
|
||||
|
||||
return cookies
|
||||
|
||||
@classmethod
|
||||
def _gen_json_cookie(self, cookies: list[Cookie]):
|
||||
cookie_dict = {}
|
||||
for cookie in cookies:
|
||||
|
@ -40,8 +40,8 @@ class Scheduler:
|
||||
logger.error(f"scheduler config [{self.name}] not found, exiting")
|
||||
raise RuntimeError(f"{self.name} not found")
|
||||
self.scheduler_config = scheduler_config
|
||||
self.scheduler_config_obj = self.scheduler_config()
|
||||
self.client_mgr = scheduler_config.client_mgr()
|
||||
self.scheduler_config_obj = self.scheduler_config()
|
||||
|
||||
self.schedulable_list = []
|
||||
self.batch_platform_name_targets_cache = defaultdict(list)
|
||||
|
@ -30,10 +30,12 @@ add_sub_matcher = on_command(
|
||||
add_sub_matcher.handle()(set_target_user_info)
|
||||
do_add_sub(add_sub_matcher)
|
||||
|
||||
|
||||
query_sub_matcher = on_command("查询订阅", rule=configurable_to_me, priority=5, block=True)
|
||||
query_sub_matcher.handle()(set_target_user_info)
|
||||
do_query_sub(query_sub_matcher)
|
||||
|
||||
|
||||
del_sub_matcher = on_command(
|
||||
"删除订阅",
|
||||
rule=configurable_to_me,
|
||||
|
@ -70,7 +70,7 @@ def admin_permission():
|
||||
async def generate_sub_list_text(
|
||||
matcher: type[Matcher],
|
||||
state: T_State,
|
||||
user_info: PlatformTarget = None,
|
||||
user_info: PlatformTarget | None = None,
|
||||
is_index=False,
|
||||
is_show_cookie=False,
|
||||
is_hide_no_cookie_platfrom=False,
|
||||
|
@ -2,6 +2,7 @@ import json
|
||||
from typing import Literal
|
||||
from json import JSONDecodeError
|
||||
from abc import ABC, abstractmethod
|
||||
from collections.abc import Callable
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import httpx
|
||||
@ -42,8 +43,14 @@ class DefaultClientManager(ClientManager):
|
||||
pass
|
||||
|
||||
|
||||
class SkipRequestException(Exception):
|
||||
"""跳过请求异常,如果需要在选择 Cookie 时跳过此次请求,可以抛出此异常"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class CookieClientManager(ClientManager):
|
||||
_default_cookie_cd: int = timedelta(seconds=15)
|
||||
_default_cookie_cd = timedelta(seconds=15)
|
||||
_site_name: str = ""
|
||||
|
||||
async def _generate_anonymous_cookie(self) -> Cookie:
|
||||
@ -98,7 +105,7 @@ class CookieClientManager(ClientManager):
|
||||
return False
|
||||
return True
|
||||
|
||||
def _generate_hook(self, cookie: Cookie) -> callable:
|
||||
def _generate_hook(self, cookie: Cookie) -> Callable:
|
||||
"""hook 函数生成器,用于回写请求状态到数据库"""
|
||||
|
||||
async def _response_hook(resp: httpx.Response):
|
||||
@ -132,7 +139,7 @@ class CookieClientManager(ClientManager):
|
||||
return await self._assemble_client(client, cookie)
|
||||
|
||||
async def _assemble_client(self, client, cookie) -> AsyncClient:
|
||||
"""组装 client,可以自定义 cookie 对象的 content 装配到 client 中的方式"""
|
||||
"""组装 client,可以自定义 cookie 对象装配到 client 中的方式"""
|
||||
cookies = httpx.Cookies()
|
||||
if cookie:
|
||||
cookies.update(json.loads(cookie.content))
|
||||
@ -185,7 +192,3 @@ def anonymous_site(schedule_type: Literal["date", "interval", "cron"], schedule_
|
||||
"client_mgr": DefaultClientManager,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class SkipRequestException(Exception):
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user