A-kirami / nonebot-plugin-chatgpt

MIT License
318 stars 37 forks source link

[FIX] 通过Playwright绕开cf盾 #45

Closed sena-nana closed 1 year ago

sena-nana commented 1 year ago

这个 PR 带来了什么样的更改?

这个 PR 是否存在破坏性变更?

描述

通过playwright绕开cf盾,方法修改自原issue中的大佬代码

44

同时修复了原本的程序中两个logger使用的bug,这个bug导致了报错被显示为原issue的标题而非正常的报错

动机和背景

resolve #44

其他信息

该方法引入了playwright依赖。但是由于该插件依赖的htmlrender本身就依赖了playwright,用户并不需要多装包 该方法仅对具有GUI的系统有效,未在Linux及无GUI系统上测试,理论上会在无GUI系统上出现问题 本来想着依照上游库的方式,但是上游库所使用的解决方法在我的环境报错强制断开链接,所以采用了playwright实现

检查工作

sourcery-ai[bot] commented 1 year ago

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 3.26%.

Quality metrics Before After Change
Complexity 3.49 ⭐ 4.20 ⭐ 0.71 👎
Method Length 52.81 ⭐ 59.57 ⭐ 6.76 👎
Working memory 6.49 🙂 6.77 🙂 0.28 👎
Quality 75.27% 72.01% 🙂 -3.26% 👎
Other metrics Before After Change
Lines 436 536 100
Changed files Quality Before Quality After Quality Change
nonebot_plugin_chatgpt/__init__.py 74.83% 🙂 73.41% 🙂 -1.42% 👎
nonebot_plugin_chatgpt/chatgpt.py 66.00% 🙂 62.31% 🙂 -3.69% 👎
nonebot_plugin_chatgpt/config.py 82.05% ⭐ 77.41% ⭐ -4.64% 👎
nonebot_plugin_chatgpt/data.py 94.50% ⭐ 94.41% ⭐ -0.09% 👎
nonebot_plugin_chatgpt/utils.py 83.23% ⭐ 81.72% ⭐ -1.51% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
nonebot_plugin_chatgpt/chatgpt.py Chatbot.login 13 🙂 138 😞 10 😞 51.86% 🙂 Try splitting into smaller methods. Extract out complex expressions
nonebot_plugin_chatgpt/__init__.py ai_chat 7 ⭐ 186 😞 10 😞 52.62% 🙂 Try splitting into smaller methods. Extract out complex expressions
nonebot_plugin_chatgpt/chatgpt.py Chatbot.refresh_session 9 🙂 156 😞 8 🙂 57.78% 🙂 Try splitting into smaller methods
nonebot_plugin_chatgpt/chatgpt.py Chatbot.get_chat_response 6 ⭐ 207 ⛔ 7 🙂 58.57% 🙂 Try splitting into smaller methods
nonebot_plugin_chatgpt/chatgpt.py Chatbot.get_cf_cookies 2 ⭐ 164 😞 9 🙂 61.56% 🙂 Try splitting into smaller methods

Legend and Explanation

The emojis denote the absolute quality of the code:

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

shoucandanghehe commented 1 year ago

cf我记得是可以用playwright的firefox直接穿的 只要不出验证码( 参考代码 和chromium比不需要改ua之类,也可以直接无头启动

sena-nana commented 1 year ago

cf我记得是可以用playwright的firefox直接穿的 只要不出验证码( 参考代码 和chromium比不需要改ua之类,也可以直接无头启动

我试一下,如果可行,无头启动确实挺好的

sena-nana commented 1 year ago

cf我记得是可以用playwright的firefox直接穿的 只要不出验证码( 参考代码 和chromium比不需要改ua之类,也可以直接无头启动

已经修改为无头firefox,但是没有在无GUI系统上测试,ua还是需要改的,不改不行

A-kirami commented 1 year ago

这个 PR 混杂了太多更改,应该拆分为独立的 PR

sena-nana commented 1 year ago

这个 PR 混杂了太多更改,应该拆分为独立的 PR

我拆分成了两个新的pr,我的另一个pr也准备拆分成新的pr,请把这两个pr关闭吧,之前不太会用git,给您带来麻烦了