Update src/plugins/group_nickname/nickname_mapper.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
pull/914/head
未來星織 2025-05-02 07:09:28 +08:00 committed by GitHub
parent 681814f7d1
commit cdebc31ef6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 5 deletions

View File

@ -102,11 +102,12 @@ async def analyze_chat_for_nicknames(
# 清理可能的 Markdown 代码块标记
response_content = response_content.strip()
if response_content.startswith("```json"):
response_content = response_content[7:]
if response_content.endswith("```"):
response_content = response_content[:-3]
response_content = response_content.strip()
# 使用正则表达式处理各种 Markdown 代码块情况
import re
markdown_code_regex = re.compile(r"^```(?:\w+)?\s*\n(.*?)\n\s*```$", re.DOTALL)
match = markdown_code_regex.match(response_content)
if match:
response_content = match.group(1).strip()
try:
result = json.loads(response_content)