From fa1e965fba72a1c61bfd8c4df8c04173359040b3 Mon Sep 17 00:00:00 2001 From: Saboteur7 Date: Tue, 4 Jun 2024 11:23:45 +0800 Subject: [PATCH] feat: add dingtalk card switch --- channel/dingtalk/dingtalk_channel.py | 37 ++++++++++++++++------------ config.py | 3 ++- plugins/source.json | 8 +++--- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/channel/dingtalk/dingtalk_channel.py b/channel/dingtalk/dingtalk_channel.py index 33e73d8..cbe522f 100644 --- a/channel/dingtalk/dingtalk_channel.py +++ b/channel/dingtalk/dingtalk_channel.py @@ -176,24 +176,29 @@ class DingTalkChanel(ChatChannel, dingtalk_stream.ChatbotHandler): receiver = context["receiver"] isgroup = context.kwargs['msg'].is_group incoming_message = context.kwargs['msg'].incoming_message - logger.info("[Dingtalk] sendMsg={}, receiver={}".format(reply, receiver)) - def reply_with_text(): - self.reply_text(reply.content, incoming_message) - def reply_with_at_text(): - self.reply_text("📢 您有一条新的消息,请查看。", incoming_message) - def reply_with_ai_markdown(): - button_list, markdown_content = self.generate_button_markdown_content(context, reply) - self.reply_ai_markdown_button(incoming_message, markdown_content, button_list, "", "📌 内容由AI-Bot生成", "",[incoming_message.sender_staff_id]) - - if reply.type in [ReplyType.IMAGE_URL, ReplyType.IMAGE, ReplyType.TEXT]: - if isgroup: - reply_with_ai_markdown() - reply_with_at_text() + + if conf().get("dingtalk_card_enabled"): + logger.info("[Dingtalk] sendMsg={}, receiver={}".format(reply, receiver)) + def reply_with_text(): + self.reply_text(reply.content, incoming_message) + def reply_with_at_text(): + self.reply_text("📢 您有一条新的消息,请查看。", incoming_message) + def reply_with_ai_markdown(): + button_list, markdown_content = self.generate_button_markdown_content(context, reply) + self.reply_ai_markdown_button(incoming_message, markdown_content, button_list, "", "📌 内容由AI生成", "",[incoming_message.sender_staff_id]) + + if reply.type in [ReplyType.IMAGE_URL, ReplyType.IMAGE, ReplyType.TEXT]: + if isgroup: + reply_with_ai_markdown() + reply_with_at_text() + else: + reply_with_ai_markdown() else: - reply_with_ai_markdown() + # 暂不支持其它类型消息回复 + reply_with_text() else: - # 暂不支持其它类型消息回复 - reply_with_text() + self.reply_text(reply.content, incoming_message) + def generate_button_markdown_content(self, context, reply): image_url = context.kwargs.get("image_url") diff --git a/config.py b/config.py index 2b70305..01edf10 100644 --- a/config.py +++ b/config.py @@ -146,7 +146,8 @@ available_setting = { # 钉钉配置 "dingtalk_client_id": "", # 钉钉机器人Client ID - "dingtalk_client_secret": "", # 钉钉机器人Client Secret + "dingtalk_client_secret": "", # 钉钉机器人Client Secret + "dingtalk_card_enabled": False, # chatgpt指令自定义触发词 "clear_memory_commands": ["#清除记忆"], # 重置会话指令,必须以#开头 diff --git a/plugins/source.json b/plugins/source.json index 44b4023..293a342 100644 --- a/plugins/source.json +++ b/plugins/source.json @@ -1,9 +1,5 @@ { "repo": { - "midjourney": { - "url": "https://github.com/baojingyu/midjourney.git", - "desc": "利用midjourney实现ai绘图的的插件" - }, "sdwebui": { "url": "https://github.com/lanvent/plugin_sdwebui.git", "desc": "利用stable-diffusion画图的插件" @@ -31,6 +27,10 @@ "Blackroom": { "url": "https://github.com/dividduang/blackroom.git", "desc": "小黑屋插件,被拉进小黑屋的人将不能使用@bot的功能的插件" + }, + "midjourney": { + "url": "https://github.com/baojingyu/midjourney.git", + "desc": "利用midjourney实现ai绘图的的插件" } } }