Skip to content

Commit

Permalink
✨ 将 cookie default_cd 移动到 CookieSite 内部
Browse files Browse the repository at this point in the history
  • Loading branch information
suyiiyii committed Oct 28, 2024
1 parent cdd671b commit 4b4c483
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nonebot_bison/platform/bilibili/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class BilibiliClientManager(CookieClientManager):
_inited: bool = False

_site_name: str = "bilibili.com"
_default_cd: int = timedelta(seconds=120)

def __init__(self) -> None:
self._client = http_client()
Expand Down Expand Up @@ -97,6 +96,7 @@ class BilibiliSite(CookieSite):
schedule_type = "interval"
client_mgr = BilibiliClientManager
require_browser = True
default_cd: int = timedelta(seconds=120)


class BililiveSite(Site):
Expand Down
3 changes: 2 additions & 1 deletion nonebot_bison/platform/weibo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import re
import json
from typing import Any
from datetime import datetime
from urllib.parse import unquote
from datetime import datetime, timedelta

from yarl import URL
from lxml.etree import HTML
Expand Down Expand Up @@ -41,6 +41,7 @@ class WeiboSite(CookieSite):
schedule_type = "interval"
schedule_setting = {"seconds": 3}
client_mgr = create_cookie_client_manager(name)
default_cd: int = timedelta(seconds=15)

@classmethod
async def _get_current_user_name(cls, cookies: dict) -> str:
Expand Down
4 changes: 2 additions & 2 deletions nonebot_bison/utils/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ async def refresh_client(self):

class CookieClientManager(ClientManager):
_site_name: str # 绑定的 site_name,需要使用 create_cookie_client_manager 创建 Client_mgr 时绑定
_default_cd: int = timedelta(seconds=10)

@classmethod
async def _generate_anonymous_cookie(cls) -> Cookie:
Expand Down Expand Up @@ -83,7 +82,7 @@ async def add_user_cookie(cls, content: str, cookie_name: str | None = None) ->
raise ValueError()
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.cd = cls._default_cd
cookie.cd = cookie_site.default_cd
cookie_id = await config.add_cookie(cookie)
return await config.get_cookie_by_id(cookie_id)

Expand Down Expand Up @@ -166,6 +165,7 @@ def __str__(self):

class CookieSite(Site):
client_mgr: type[CookieClientManager] = CookieClientManager
default_cd: int = timedelta(seconds=10)

@classmethod
async def get_cookie_name(cls, content: str) -> str:
Expand Down

0 comments on commit 4b4c483

Please sign in to comment.