mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-02 09:26:12 +08:00
:refactor: 将 cookie default_cd 移动到 CookieSite 内部
This commit is contained in:
parent
cdd671b15f
commit
ac794efd18
@ -27,7 +27,6 @@ class BilibiliClientManager(CookieClientManager):
|
|||||||
_inited: bool = False
|
_inited: bool = False
|
||||||
|
|
||||||
_site_name: str = "bilibili.com"
|
_site_name: str = "bilibili.com"
|
||||||
_default_cd: int = timedelta(seconds=120)
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._client = http_client()
|
self._client = http_client()
|
||||||
@ -97,6 +96,7 @@ class BilibiliSite(CookieSite):
|
|||||||
schedule_type = "interval"
|
schedule_type = "interval"
|
||||||
client_mgr = BilibiliClientManager
|
client_mgr = BilibiliClientManager
|
||||||
require_browser = True
|
require_browser = True
|
||||||
|
default_cd: int = timedelta(seconds=120)
|
||||||
|
|
||||||
|
|
||||||
class BililiveSite(Site):
|
class BililiveSite(Site):
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from datetime import datetime
|
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from yarl import URL
|
from yarl import URL
|
||||||
from lxml.etree import HTML
|
from lxml.etree import HTML
|
||||||
@ -41,6 +41,7 @@ class WeiboSite(CookieSite):
|
|||||||
schedule_type = "interval"
|
schedule_type = "interval"
|
||||||
schedule_setting = {"seconds": 3}
|
schedule_setting = {"seconds": 3}
|
||||||
client_mgr = create_cookie_client_manager(name)
|
client_mgr = create_cookie_client_manager(name)
|
||||||
|
default_cd: int = timedelta(seconds=15)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def _get_current_user_name(cls, cookies: dict) -> str:
|
async def _get_current_user_name(cls, cookies: dict) -> str:
|
||||||
|
@ -44,7 +44,6 @@ class DefaultClientManager(ClientManager):
|
|||||||
|
|
||||||
class CookieClientManager(ClientManager):
|
class CookieClientManager(ClientManager):
|
||||||
_site_name: str # 绑定的 site_name,需要使用 create_cookie_client_manager 创建 Client_mgr 时绑定
|
_site_name: str # 绑定的 site_name,需要使用 create_cookie_client_manager 创建 Client_mgr 时绑定
|
||||||
_default_cd: int = timedelta(seconds=10)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def _generate_anonymous_cookie(cls) -> Cookie:
|
async def _generate_anonymous_cookie(cls) -> Cookie:
|
||||||
@ -83,7 +82,7 @@ class CookieClientManager(ClientManager):
|
|||||||
raise ValueError()
|
raise ValueError()
|
||||||
cookie = Cookie(site_name=cls._site_name, content=content)
|
cookie = Cookie(site_name=cls._site_name, content=content)
|
||||||
cookie.cookie_name = cookie_name if cookie_name else await cookie_site.get_cookie_name(content)
|
cookie.cookie_name = cookie_name if cookie_name else await cookie_site.get_cookie_name(content)
|
||||||
cookie.cd = cls._default_cd
|
cookie.cd = cookie_site.default_cd
|
||||||
cookie_id = await config.add_cookie(cookie)
|
cookie_id = await config.add_cookie(cookie)
|
||||||
return await config.get_cookie_by_id(cookie_id)
|
return await config.get_cookie_by_id(cookie_id)
|
||||||
|
|
||||||
@ -166,6 +165,7 @@ class Site(metaclass=RegistryMeta, base=True):
|
|||||||
|
|
||||||
class CookieSite(Site):
|
class CookieSite(Site):
|
||||||
client_mgr: type[CookieClientManager] = CookieClientManager
|
client_mgr: type[CookieClientManager] = CookieClientManager
|
||||||
|
default_cd: int = timedelta(seconds=10)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_cookie_name(cls, content: str) -> str:
|
async def get_cookie_name(cls, content: str) -> str:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user