Skip to content

Commit

Permalink
✏️ 改改变量名
Browse files Browse the repository at this point in the history
  • Loading branch information
suyiiyii committed Oct 21, 2024
1 parent f5d30b9 commit 8d32145
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions nonebot_bison/utils/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ class CookieClientManager(ClientManager):
@classmethod
async def refresh_anonymous_cookie(cls):
"""移除已有的匿名cookie,添加一个新的匿名cookie"""
anonymous_cookies = await config.get_cookie(cls._site_name, is_anonymous=True)
anonymous_cookie = Cookie(site_name=cls._site_name, content="{}", is_universal=True, is_anonymous=True)
for cookie in anonymous_cookies:
if not cookie.is_anonymous:
continue
existing_anonymous_cookies = await config.get_cookie(cls._site_name, is_anonymous=True)
new_anonymous_cookie = Cookie(site_name=cls._site_name, content="{}", is_universal=True, is_anonymous=True)
for cookie in existing_anonymous_cookies:
await config.delete_cookie_by_id(cookie.id)
anonymous_cookie.id = cookie.id # 保持原有的id
anonymous_cookie.last_usage = datetime.now() # 使得第一次请求优先使用用户 cookie
await config.add_cookie(anonymous_cookie)
new_anonymous_cookie.id = cookie.id # 保持原有的id
new_anonymous_cookie.last_usage = datetime.now() # 使得第一次请求优先使用用户 cookie
await config.add_cookie(new_anonymous_cookie)

@classmethod
async def add_user_cookie(cls, content: str):
Expand All @@ -81,7 +79,7 @@ async def _response_hook(resp: httpx.Response):
logger.trace(f"请求成功: {cookie.id} {resp.request.url}")
cookie.status = "success"
else:
logger.warning(f"请求失败:{cookie.id} {resp.request.url}, 状态码: {resp.status_code}")
logger.warning(f"请求失败: {cookie.id} {resp.request.url}, 状态码: {resp.status_code}")
cookie.status = "failed"
cookie.last_usage = datetime.now()
await config.update_cookie(cookie)
Expand Down

0 comments on commit 8d32145

Please sign in to comment.