diff --git a/plugins/dify/main.py b/plugins/dify/main.py index 6589236..2481419 100644 --- a/plugins/dify/main.py +++ b/plugins/dify/main.py @@ -10,6 +10,7 @@ from pathlib import Path from plugin_common.message_plugin_interface import MessagePluginInterface from plugin_common.plugin_interface import PluginStatus from utils.decorator.plugin_decorators import plugin_stats_decorator +from utils.markdown_to_image import convert_md_str_to_image from utils.revoke.message_auto_revoke import MessageAutoRevoke from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager from utils.decorator.points_decorator import plugin_points_cost @@ -148,10 +149,16 @@ class DifyPlugin(MessagePluginInterface): # 判断是否为本地文件路径 if os.path.isfile(response): # 如果是文件路径,使用发送文件方法 - await bot.send_image_message(roomid, Path(response)) + await bot.send_image_message((roomid if roomid else sender), Path(response)) else: - # 如果是普通文本,使用发送文本方法 - await bot.send_at_message((roomid if roomid else sender), response, [sender]) + # 如果是普通文本,则在长度大于100字时,转为图片发送 + if len(response) > 100: + # 转图片 + respath = await convert_md_str_to_image(response, "dify_output.jpg") + await bot.send_image_message((roomid if roomid else sender), Path(respath)) + else: + # 如果是普通文本,使用发送文本方法 + await bot.send_at_message((roomid if roomid else sender), response, [sender]) return True, "发送成功" else: await bot.send_text_message((roomid if roomid else sender), "❌未能获取到回复,请稍后再试", sender) @@ -162,7 +169,7 @@ class DifyPlugin(MessagePluginInterface): client_msg_id, create_time, new_msg_id = await bot.send_text_message((roomid if roomid else sender), "❌未能获取到回复,请稍后再试", sender) - revoke.add_message_to_revoke(roomid, client_msg_id, create_time, new_msg_id, 5) + revoke.add_message_to_revoke((roomid if roomid else sender), client_msg_id, create_time, new_msg_id, 5) return False, f"处理出错: {e}" @@ -176,14 +183,14 @@ class DifyPlugin(MessagePluginInterface): return False, "命令格式错误" # 检查权限 - if roomid and gbm.get_group_permission(roomid, Feature.AI_CAPABILITY) == PermissionStatus.DISABLED: + if roomid and gbm.get_group_permission((roomid if roomid else sender), Feature.AI_CAPABILITY) == PermissionStatus.DISABLED: return False, "没有权限" client_msg_id, create_time, new_msg_id = await bot.send_text_message((roomid if roomid else sender), "⏳AI 正在加油,请稍候… 😊", sender if roomid else "") - revoke.add_message_to_revoke(roomid, client_msg_id, create_time, new_msg_id, 3) + revoke.add_message_to_revoke((roomid if roomid else sender), client_msg_id, create_time, new_msg_id, 3) # 获取查询内容 query = parts[1].strip() @@ -205,16 +212,21 @@ class DifyPlugin(MessagePluginInterface): # 如果是文件路径,使用发送文件方法 await bot.send_image_message((roomid if roomid else sender), Path(response)) else: - # 如果是普通文本,使用发送文本方法 - await bot.send_at_message((roomid if roomid else sender), response, - [sender if roomid else ""]) + # 如果是普通文本,则在长度大于100字时,转为图片发送 + if len(response) > 100: + # 转图片 + respath = await convert_md_str_to_image(response, "dify_output.jpg") + await bot.send_image_message((roomid if roomid else sender), Path(respath)) + else: + # 如果是普通文本,使用发送文本方法 + await bot.send_at_message((roomid if roomid else sender), response, [sender]) return True, "发送成功" else: client_msg_id, create_time, new_msg_id = await bot.send_text_message((roomid if roomid else sender), "❌未能获取到回复,请稍后再试", sender if roomid else "") - revoke.add_message_to_revoke(roomid, client_msg_id, create_time, new_msg_id, 5) + revoke.add_message_to_revoke((roomid if roomid else sender), client_msg_id, create_time, new_msg_id, 5) return False, "未获取到回复" except Exception as e: @@ -223,7 +235,7 @@ class DifyPlugin(MessagePluginInterface): f"❌请求出错:{str(e)}", sender if roomid else "") - revoke.add_message_to_revoke(roomid, client_msg_id, create_time, new_msg_id, 5) + revoke.add_message_to_revoke((roomid if roomid else sender), client_msg_id, create_time, new_msg_id, 5) return False, f"处理出错: {e}" def _chat_with_dify(self, session_id: str, user_id: str, query: str) -> Optional[str]: diff --git a/plugins/game_task/main.py b/plugins/game_task/main.py index 5dfb734..a6a2a2d 100644 --- a/plugins/game_task/main.py +++ b/plugins/game_task/main.py @@ -13,7 +13,6 @@ from utils.decorator.points_decorator import points_reward_decorator from utils.ai.game_chatgpt_qa import game_question_json, game_answer_json from db.connection import DBConnectionManager from db.encyclopedia import EncyclopediaDB -from wechat_ipad import WechatAPIClient class GameTaskPlugin(MessagePluginInterface):