mirror of https://github.com/Mai-with-u/MaiBot.git
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
parent
681814f7d1
commit
cdebc31ef6
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue