🐛 B站蹲饼修复 (#525)

*  使用新接口

* ♻️ 调整刷新逻辑

* 🐛 调整刷新逻辑

* ♻️ 将单个哔哩哔哩文件拆开

* 🐛 修修补补边界情况

*  添加UID:xxx匹配

*  调整测试中的导入

*  调整测试的断言

* 🐛 添加unicode字符的escape

*  不再主动刷新cookies

* 🔀 适配新版Site

* 🐛 解析live_rcmd中的json string

* 🚨 make ruff happy

* 🐛 调整并测试bilibili retry函数

*  修正测试

* ♻️ 按review意见调整

* ♻️ 清理一些遗留的复杂写法

* ♻️ 移出函数内的NameTuple

* 🔇 删除不必要的日志输出

Co-authored-by: felinae98 <731499577@qq.com>

* Update nonebot_bison/platform/bilibili/scheduler.py

* Update scheduler.py

---------

Co-authored-by: felinae98 <731499577@qq.com>
This commit is contained in:
Azide
2024-06-17 13:24:04 +08:00
committed by GitHub
parent 9729d4b776
commit af72b6c3d0
15 changed files with 6387 additions and 7213 deletions
+11 -1
View File
@@ -91,10 +91,20 @@ if plugin_config.bison_filter_log:
default_filter.level = ("DEBUG" if config.debug else "INFO") if config.log_level is None else config.log_level
def text_similarity(str1, str2) -> float:
def text_similarity(str1: str, str2: str) -> float:
"""利用最长公共子序列的算法判断两个字符串是否相似,并返回0到1.0的相似度"""
if len(str1) == 0 or len(str2) == 0:
raise ValueError("The length of string can not be 0")
matcher = difflib.SequenceMatcher(None, str1, str2)
t = sum(temp.size for temp in matcher.get_matching_blocks())
return t / min(len(str1), len(str2))
def decode_unicode_escapes(s: str):
"""解码 \\r, \\n, \\t, \\uXXXX 等转义序列"""
def decode_match(match: re.Match[str]) -> str:
return bytes(match.group(0), "utf-8").decode("unicode_escape")
regex = re.compile(r"\\[rnt]|\\u[0-9a-fA-F]{4}")
return regex.sub(decode_match, s)