v0.5 兼容coze,并兼容更广泛的md格式
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
+ 针对触发绘画的有loading消息触发
|
+ 针对触发绘画的有loading消息触发
|
||||||
+ 支持图文消息拆分发送,Dify兼容性更好了
|
+ 支持图文消息拆分发送,Dify兼容性更好了
|
||||||
+ 增加对视频的支持
|
+ 增加对视频的支持
|
||||||
|
+ 兼容coze和更广泛的md格式
|
||||||
|
|
||||||
**安装方法:**
|
**安装方法:**
|
||||||
|
|
||||||
|
|||||||
27
dowmd.py
27
dowmd.py
@@ -6,13 +6,14 @@ import plugins
|
|||||||
from bridge.reply import Reply, ReplyType
|
from bridge.reply import Reply, ReplyType
|
||||||
from lib import itchat
|
from lib import itchat
|
||||||
from plugins import *
|
from plugins import *
|
||||||
|
from config import conf
|
||||||
|
|
||||||
|
|
||||||
@plugins.register(
|
@plugins.register(
|
||||||
name="dow_markdown",
|
name="dow_markdown",
|
||||||
desire_priority=66,
|
desire_priority=66,
|
||||||
desc="优化markdown返回结果中的图片和网址链接。",
|
desc="优化markdown返回结果中的图片和网址链接。",
|
||||||
version="0.4",
|
version="0.5",
|
||||||
author="Kubbo",
|
author="Kubbo",
|
||||||
hidden=False
|
hidden=False
|
||||||
)
|
)
|
||||||
@@ -64,10 +65,12 @@ class dow_markdown(Plugin):
|
|||||||
return "优化返回结果中的图片和网址链接。"
|
return "优化返回结果中的图片和网址链接。"
|
||||||
|
|
||||||
def handle_send(self, content, e_context, is_last):
|
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'):
|
if host.endswith('/v1'):
|
||||||
host = host[:-3]
|
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()]
|
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"]
|
||||||
@@ -77,16 +80,22 @@ class dow_markdown(Plugin):
|
|||||||
reply = Reply(content=part.strip(), type=ReplyType.TEXT)
|
reply = Reply(content=part.strip(), type=ReplyType.TEXT)
|
||||||
if re.search(r"\.(gif|jpg|png|jpeg|webp)", part):
|
if re.search(r"\.(gif|jpg|png|jpeg|webp)", part):
|
||||||
reply.type = ReplyType.IMAGE_URL
|
reply.type = ReplyType.IMAGE_URL
|
||||||
reply.content = part[:-1].strip()
|
reply.content = self.extract_url(part.strip(), host)
|
||||||
if not part.startswith('http'):
|
|
||||||
reply.content = host + reply.content
|
|
||||||
elif re.search(r"\.(mp4)", part):
|
elif re.search(r"\.(mp4)", part):
|
||||||
reply.type = ReplyType.VIDEO_URL
|
reply.type = ReplyType.VIDEO_URL
|
||||||
reply.content = part[:-1].strip()
|
reply.content = self.extract_url(part.strip(), host)
|
||||||
if not part.startswith('http'):
|
|
||||||
reply.content = host + reply.content
|
|
||||||
if index == len(parts) - 1 and is_last:
|
if index == len(parts) - 1 and is_last:
|
||||||
e_context["reply"] = reply
|
e_context["reply"] = reply
|
||||||
e_context.action = EventAction.BREAK_PASS
|
e_context.action = EventAction.BREAK_PASS
|
||||||
else:
|
else:
|
||||||
channel.send(reply, context)
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user