增加loading消息
This commit is contained in:
17
dowmd.py
17
dowmd.py
@@ -8,7 +8,7 @@ import plugins
|
|||||||
from bridge.reply import Reply, ReplyType
|
from bridge.reply import Reply, ReplyType
|
||||||
from common.log import logger
|
from common.log import logger
|
||||||
from plugins import *
|
from plugins import *
|
||||||
|
from lib import itchat
|
||||||
|
|
||||||
@plugins.register(
|
@plugins.register(
|
||||||
name="dow_markdown",
|
name="dow_markdown",
|
||||||
@@ -21,16 +21,26 @@ class dow_markdown(Plugin):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
try:
|
try:
|
||||||
|
self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
|
||||||
self.handlers[Event.ON_DECORATE_REPLY] = self.on_decorate_reply
|
self.handlers[Event.ON_DECORATE_REPLY] = self.on_decorate_reply
|
||||||
logger.info("[dow_markdown] inited.")
|
logger.info("[dow_markdown] inited.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("[dow_markdown] init failed, ignore.")
|
logger.warn("[dow_markdown] init failed, ignore.")
|
||||||
raise e
|
raise e
|
||||||
|
def on_handle_context(self,e_content:EventContext):
|
||||||
|
try:
|
||||||
|
send_msg = e_context["context"]
|
||||||
|
if send_msg["type"] == ReplyType.TEXT:
|
||||||
|
if any(word in send_msg["content"] for word in ["画"]):
|
||||||
|
receiver = send_msg.get("receiver")
|
||||||
|
itchat.send("我正在绘画中,可能需要多等待一会,请稍后...",toUserName=receiver)
|
||||||
|
e_content.action = EventAction.CONTINUE
|
||||||
|
finally:
|
||||||
|
e_content.action = EventAction.CONTINUE
|
||||||
def on_decorate_reply(self, e_context: EventContext):
|
def on_decorate_reply(self, e_context: EventContext):
|
||||||
if e_context["reply"].type != ReplyType.TEXT:
|
if e_context["reply"].type != ReplyType.TEXT:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
logger.info(f"获取到回复消息{e_context}")
|
|
||||||
channel = e_context["channel"]
|
channel = e_context["channel"]
|
||||||
context = e_context["context"]
|
context = e_context["context"]
|
||||||
content = e_context["reply"].content.strip()
|
content = e_context["reply"].content.strip()
|
||||||
@@ -38,10 +48,9 @@ class dow_markdown(Plugin):
|
|||||||
if content.startswith("[DOWNLOAD_ERROR]"):
|
if content.startswith("[DOWNLOAD_ERROR]"):
|
||||||
return
|
return
|
||||||
has_md = re.search(r'\!\[[^\]]+\]\(?',content)
|
has_md = re.search(r'\!\[[^\]]+\]\(?',content)
|
||||||
logger.info(f"{content}是否含有md语法==>{has_md}")
|
|
||||||
if has_md:
|
if has_md:
|
||||||
host = os.environ.get('DIFY_API_BASE', 'http://121.37.155.68:35801')
|
host = os.environ.get('DIFY_API_BASE', 'http://121.37.155.68:35801')
|
||||||
image_path = re.search(r'!\[.*\]\((.*?)\)',reply.content).group(1)
|
image_path = re.search(r'!\[.*\]\((.*?)\)',content).group(1)
|
||||||
logger.info(f"提取到的数据==>host:{host},url:{image_path}")
|
logger.info(f"提取到的数据==>host:{host},url:{image_path}")
|
||||||
reply = Reply(ReplyType.IMAGE_URL, f"{host}{image_path}")
|
reply = Reply(ReplyType.IMAGE_URL, f"{host}{image_path}")
|
||||||
e_context["reply"] = reply
|
e_context["reply"] = reply
|
||||||
|
|||||||
Reference in New Issue
Block a user