优化代码,删除无效代码

This commit is contained in:
liuwei
2025-05-19 17:58:49 +08:00
parent 28f02b58e0
commit fb752c084e
23 changed files with 83 additions and 503 deletions

View File

@@ -1,4 +1,3 @@
import logging
import os
import requests
import json
@@ -6,9 +5,6 @@ import time
import re # 添加re模块导入
from typing import Dict, Any, List, Optional, Tuple
from loguru import logger
from message_util import MessageUtil
from plugin_common.message_plugin_interface import MessagePluginInterface
from plugin_common.plugin_interface import PluginStatus
from utils.decorator.plugin_decorators import plugin_stats_decorator
@@ -65,7 +61,6 @@ class DifyPlugin(MessagePluginInterface):
# 保存上下文对象
self.event_system = context.get("event_system")
self.message_util: MessageUtil = context.get("message_util")
self.gbm = context.get("gbm")
# 从配置中获取参数
@@ -140,8 +135,6 @@ class DifyPlugin(MessagePluginInterface):
await bot.send_at_message(roomid, "请在@我的同时提供问题内容", [sender])
return False, "没有提供问题内容"
# self.message_util.send_text_msg("⏳AI 正在加油,请稍候… 😊", roomid, sender)
try:
# 调用Dify API获取回复
response = self._chat_with_dify((roomid if roomid else sender), sender, query)
@@ -153,7 +146,7 @@ class DifyPlugin(MessagePluginInterface):
# 判断是否为本地文件路径
if os.path.isfile(response):
# 如果是文件路径,使用发送文件方法
self.message_util.send_file(response, roomid)
await bot.send_image_message(roomid, response)
else:
# 如果是普通文本,使用发送文本方法
await bot.send_at_message((roomid if roomid else sender), response, [sender])
@@ -184,7 +177,11 @@ class DifyPlugin(MessagePluginInterface):
if roomid and gbm.get_group_permission(roomid, Feature.AI_CAPABILITY) == PermissionStatus.DISABLED:
return False, "没有权限"
# self.message_util.send_text_msg("⏳AI 正在加油,请稍候… 😊", (roomid if roomid else sender),sender if roomid else "")
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)
# 获取查询内容
query = parts[1].strip()