v0.6 修复插件异常,优化md格式转化
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
一款用来适配Dify的chatbot的返回的markdown格式返回的消息处理
|
一款用来适配Dify的chatbot的返回的markdown格式返回的消息处理
|
||||||
|
|
||||||
|
**最新更新**
|
||||||
|
+ 图文混排异常修复
|
||||||
|
+ 增加对换行的转化修复
|
||||||
|
|
||||||
|
**实现功能:**
|
||||||
|
|
||||||
+ 提取Dify返回的Markdown图片链接中的网址,并修改ReplyType为IMAGE_URL,以便DoW自动下载Markdown链接中的图片;
|
+ 提取Dify返回的Markdown图片链接中的网址,并修改ReplyType为IMAGE_URL,以便DoW自动下载Markdown链接中的图片;
|
||||||
+ 提取Dify返回的包含网址的Markdown链接中的图片网址,并修改ReplyType为IMAGE_URL,以便CoW自动下载Markdown链接中的图片;
|
+ 提取Dify返回的包含网址的Markdown链接中的图片网址,并修改ReplyType为IMAGE_URL,以便CoW自动下载Markdown链接中的图片;
|
||||||
+ 去掉每行结尾的Markdown链接中网址部分的小括号,避免微信误以为“)”是网址的一部分导致微信中无法打开该页面。
|
+ 去掉每行结尾的Markdown链接中网址部分的小括号,避免微信误以为“)”是网址的一部分导致微信中无法打开该页面。
|
||||||
|
|||||||
26
dowmd.py
26
dowmd.py
@@ -13,7 +13,7 @@ from config import conf
|
|||||||
name="dow_markdown",
|
name="dow_markdown",
|
||||||
desire_priority=66,
|
desire_priority=66,
|
||||||
desc="优化markdown返回结果中的图片和网址链接。",
|
desc="优化markdown返回结果中的图片和网址链接。",
|
||||||
version="0.5",
|
version="0.6",
|
||||||
author="Kubbo",
|
author="Kubbo",
|
||||||
hidden=False
|
hidden=False
|
||||||
)
|
)
|
||||||
@@ -70,7 +70,8 @@ class dow_markdown(Plugin):
|
|||||||
host = host[:-3]
|
host = host[:-3]
|
||||||
if 'coze' == conf().get('model'):
|
if 'coze' == conf().get('model'):
|
||||||
host = "https://s.coze.cn/t/"
|
host = "https://s.coze.cn/t/"
|
||||||
parts = re.split(r'\!\[[^\]]+\]\(?', content)
|
format_content = self.format_content(content)
|
||||||
|
parts = re.split(r'&分块&', format_content)
|
||||||
parts = [p for p in parts if p.strip()]
|
parts = [p for p in parts if p.strip()]
|
||||||
channel = e_context["channel"]
|
channel = e_context["channel"]
|
||||||
context = e_context["context"]
|
context = e_context["context"]
|
||||||
@@ -84,11 +85,16 @@ class dow_markdown(Plugin):
|
|||||||
elif re.search(r"\.(mp4)", part):
|
elif re.search(r"\.(mp4)", part):
|
||||||
reply.type = ReplyType.VIDEO_URL
|
reply.type = ReplyType.VIDEO_URL
|
||||||
reply.content = self.extract_url(part.strip(), host)
|
reply.content = self.extract_url(part.strip(), host)
|
||||||
if index == len(parts) - 1 and is_last:
|
try:
|
||||||
e_context["reply"] = reply
|
if index == len(parts) - 1 and is_last:
|
||||||
e_context.action = EventAction.BREAK_PASS
|
e_context["reply"] = reply
|
||||||
else:
|
e_context.action = EventAction.BREAK_PASS
|
||||||
channel.send(reply, context)
|
else:
|
||||||
|
channel.send(reply, context)
|
||||||
|
except Exception as e:
|
||||||
|
source_type = {ReplyType.IMAGE_URL: "图片", ReplyType.VIDEO_URL: "视频"}[reply.type]
|
||||||
|
itchat.send(f"[{source_type}]加载失败", toUserName=context.get("receiver"))
|
||||||
|
logger.warn("[dow_markdown] handle_send failed, error={}".format(e))
|
||||||
|
|
||||||
def extract_url(self, text, host):
|
def extract_url(self, text, host):
|
||||||
text = text.strip()
|
text = text.strip()
|
||||||
@@ -98,4 +104,10 @@ class dow_markdown(Plugin):
|
|||||||
if text.startswith('/t/') and 'coze' == conf().get('model'):
|
if text.startswith('/t/') and 'coze' == conf().get('model'):
|
||||||
text = text[3:]
|
text = text[3:]
|
||||||
text = host + text
|
text = host + text
|
||||||
|
logger.info("[extract_url] text={}".format(text))
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
def format_content(self, content):
|
||||||
|
content = re.sub(r"\!\[([^\]]+)\]\(([^)\\\s]+)\)", r"&分块&\2&分块&", content)
|
||||||
|
content = re.sub(r"\\n", "\n", content)
|
||||||
|
return content
|
||||||
|
|||||||
Reference in New Issue
Block a user