From 3c968906b4c91206c046cc7b2b90bdaa9c5876bf Mon Sep 17 00:00:00 2001 From: Kubbo <390378816@qq.com> Date: Tue, 6 Aug 2024 21:53:31 +0800 Subject: [PATCH] =?UTF-8?q?v0.5=20=E5=85=BC=E5=AE=B9coze,=E5=B9=B6?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=9B=B4=E5=B9=BF=E6=B3=9B=E7=9A=84md?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- dowmd.py | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3b8f56f..ffaf8f5 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ + 针对触发绘画的有loading消息触发 + 支持图文消息拆分发送,Dify兼容性更好了 + 增加对视频的支持 ++ 兼容coze和更广泛的md格式 **安装方法:** @@ -22,4 +23,4 @@ **更新方法:** ```sh #updatep dow_markdown -``` \ No newline at end of file +``` diff --git a/dowmd.py b/dowmd.py index 0974829..c041037 100644 --- a/dowmd.py +++ b/dowmd.py @@ -6,13 +6,14 @@ import plugins from bridge.reply import Reply, ReplyType from lib import itchat from plugins import * +from config import conf @plugins.register( name="dow_markdown", desire_priority=66, desc="优化markdown返回结果中的图片和网址链接。", - version="0.4", + version="0.5", author="Kubbo", hidden=False ) @@ -64,10 +65,12 @@ class dow_markdown(Plugin): return "优化返回结果中的图片和网址链接。" def handle_send(self, content, e_context, is_last): - host = os.environ.get('DIFY_API_BASE', 'http://121.37.155.68:35801') + host = os.environ.get('DIFY_API_BASE', '') if host.endswith('/v1'): host = host[:-3] - parts = re.split(r'\!\[[^\]]+\]\(', content) + if 'coze' == conf().get('model'): + host = "https://s.coze.cn/t/" + parts = re.split(r'\!\[[^\]]+\]\(?', content) parts = [p for p in parts if p.strip()] channel = e_context["channel"] context = e_context["context"] @@ -77,16 +80,22 @@ class dow_markdown(Plugin): reply = Reply(content=part.strip(), type=ReplyType.TEXT) if re.search(r"\.(gif|jpg|png|jpeg|webp)", part): reply.type = ReplyType.IMAGE_URL - reply.content = part[:-1].strip() - if not part.startswith('http'): - reply.content = host + reply.content + reply.content = self.extract_url(part.strip(), host) elif re.search(r"\.(mp4)", part): reply.type = ReplyType.VIDEO_URL - reply.content = part[:-1].strip() - if not part.startswith('http'): - reply.content = host + reply.content + reply.content = self.extract_url(part.strip(), host) if index == len(parts) - 1 and is_last: e_context["reply"] = reply e_context.action = EventAction.BREAK_PASS else: channel.send(reply, context) + + def extract_url(self, text, host): + text = text.strip() + if text.endswith(")"): + text = text[:-1] + if not text.startswith('http'): + if text.startswith('/t/') and 'coze' == conf().get('model'): + text = text[3:] + text = host + text + return text