调整异常扣分记录,如果是异常的数据,则不扣分

This commit is contained in:
liuwei
2025-04-17 14:42:47 +08:00
parent 05eb182e6a
commit 9579d3208f
10 changed files with 53 additions and 28 deletions

View File

@@ -135,7 +135,7 @@ class DifyPlugin(MessagePluginInterface):
if not query: if not query:
self.message_util.send_text_msg("请在@我的同时提供问题内容", roomid, sender) self.message_util.send_text_msg("请在@我的同时提供问题内容", roomid, sender)
return True, "没有提供问题内容" return False, "没有提供问题内容"
# self.message_util.send_text_msg("⏳AI 正在加油,请稍候… 😊", roomid, sender) # self.message_util.send_text_msg("⏳AI 正在加油,请稍候… 😊", roomid, sender)
@@ -157,12 +157,12 @@ class DifyPlugin(MessagePluginInterface):
return True, "发送成功" return True, "发送成功"
else: else:
self.message_util.send_text_msg("❌未能获取到回复,请稍后再试", roomid, sender) self.message_util.send_text_msg("❌未能获取到回复,请稍后再试", roomid, sender)
return True, "未获取到回复" return False, "未获取到回复"
except Exception as e: except Exception as e:
self.LOG.error(f"处理Dify聊天请求出错: {e}") self.LOG.error(f"处理Dify聊天请求出错: {e}")
self.message_util.send_text_msg(f"❌请求出错:{str(e)}", roomid, sender) self.message_util.send_text_msg(f"❌请求出错:{str(e)}", roomid, sender)
return True, f"处理出错: {e}" return False, f"处理出错: {e}"
# 原有的命令处理逻辑 # 原有的命令处理逻辑
parts = content.split(" ", 1) parts = content.split(" ", 1)
@@ -172,7 +172,7 @@ class DifyPlugin(MessagePluginInterface):
if len(parts) < 2 or not parts[1].strip(): if len(parts) < 2 or not parts[1].strip():
self.message_util.send_text_msg(f"{self.command_format}", self.message_util.send_text_msg(f"{self.command_format}",
(roomid if roomid else sender), sender) (roomid if roomid else sender), sender)
return True, "命令格式错误" return False, "命令格式错误"
# 检查权限 # 检查权限
if roomid and gbm.get_group_permission(roomid, Feature.AI_CAPABILITY) == PermissionStatus.DISABLED: if roomid and gbm.get_group_permission(roomid, Feature.AI_CAPABILITY) == PermissionStatus.DISABLED:
@@ -206,13 +206,13 @@ class DifyPlugin(MessagePluginInterface):
else: else:
self.message_util.send_text_msg("❌未能获取到回复,请稍后再试", (roomid if roomid else sender), self.message_util.send_text_msg("❌未能获取到回复,请稍后再试", (roomid if roomid else sender),
sender if roomid else "") sender if roomid else "")
return True, "未获取到回复" return False, "未获取到回复"
except Exception as e: except Exception as e:
self.LOG.error(f"处理Dify聊天请求出错: {e}") self.LOG.error(f"处理Dify聊天请求出错: {e}")
self.message_util.send_text_msg(f"❌请求出错:{str(e)}", (roomid if roomid else sender), self.message_util.send_text_msg(f"❌请求出错:{str(e)}", (roomid if roomid else sender),
sender if roomid else "") sender if roomid else "")
return True, f"处理出错: {e}" return False, f"处理出错: {e}"
def _chat_with_dify(self, session_id: str, user_id: str, query: str) -> Optional[str]: def _chat_with_dify(self, session_id: str, user_id: str, query: str) -> Optional[str]:
""" """

View File

@@ -122,7 +122,7 @@ class DouyinParserPlugin(MessagePluginInterface):
video_info = self._parse_douyin(original_url) video_info = self._parse_douyin(original_url)
if not video_info: if not video_info:
print(f"❌无法解析抖音视频信息") print(f"❌无法解析抖音视频信息")
return True, "解析失败" return False, "解析失败"
video_url = video_info.get('video', '') video_url = video_info.get('video', '')
title = video_info.get('title', '无标题') title = video_info.get('title', '无标题')
@@ -131,7 +131,7 @@ class DouyinParserPlugin(MessagePluginInterface):
if not video_url: if not video_url:
print(f"❌无法获取视频地址") print(f"❌无法获取视频地址")
return True, "获取视频地址失败" return False, "获取视频地址失败"
# 根据模式选择发送方式 # 根据模式选择发送方式
if self.download_mode == "file": if self.download_mode == "file":
@@ -142,7 +142,7 @@ class DouyinParserPlugin(MessagePluginInterface):
return True, "发送视频文件成功" return True, "发送视频文件成功"
else: else:
print(f"❌下载视频失败") print(f"❌下载视频失败")
return True, "下载视频失败" return False, "下载视频失败"
else: else:
# 发送卡片 # 发送卡片
wcf.send_rich_text( wcf.send_rich_text(
@@ -159,11 +159,11 @@ class DouyinParserPlugin(MessagePluginInterface):
except DouyinParserError as e: except DouyinParserError as e:
self.LOG.error(f"抖音解析错误: {e}") self.LOG.error(f"抖音解析错误: {e}")
print(f"❌抖音解析失败: {str(e)}") print(f"❌抖音解析失败: {str(e)}")
return True, f"解析错误: {e}" return False, f"解析错误: {e}"
except Exception as e: except Exception as e:
self.LOG.error(f"处理抖音链接出错: {e}\n{traceback.format_exc()}") self.LOG.error(f"处理抖音链接出错: {e}\n{traceback.format_exc()}")
print(f"❌处理抖音链接出错: {str(e)}") print(f"❌处理抖音链接出错: {str(e)}")
return True, f"处理出错: {e}" return False, f"处理出错: {e}"
def _clean_url(self, url: str) -> str: def _clean_url(self, url: str) -> str:
"""清理URL""" """清理URL"""

View File

@@ -170,12 +170,12 @@ class GroupAutoInvitePlugin(MessagePluginInterface):
return True, "邀请发送成功" return True, "邀请发送成功"
else: else:
wcf.send_text(f"❌ 邀请发送失败,请稍后再试", sender) wcf.send_text(f"❌ 邀请发送失败,请稍后再试", sender)
return True, "邀请发送失败" return False, "邀请发送失败"
except Exception as e: except Exception as e:
self.LOG.error(f"处理加群请求出错: {e}") self.LOG.error(f"处理加群请求出错: {e}")
wcf.send_text(f"❌ 处理加群请求出错: {e}", sender) wcf.send_text(f"❌ 处理加群请求出错: {e}", sender)
return True, f"处理出错: {e}" return False, f"处理出错: {e}"
def add_mapping(self, key, group_id): def add_mapping(self, key, group_id):
"""添加群组ID到指定key""" """添加群组ID到指定key"""

View File

@@ -95,11 +95,11 @@ class MessageSummaryPlugin(MessagePluginInterface):
# 直接发送消息 # 直接发送消息
if wcf: if wcf:
wcf.send_text("只支持群聊消息总结", message.get("sender")) wcf.send_text("只支持群聊消息总结", message.get("sender"))
return True, None return False, None
# 权限判断 # 权限判断
gbm: GroupBotManager = message.get("gbm") gbm: GroupBotManager = message.get("gbm")
if gbm and gbm.get_group_permission(group_id, Feature.SUMMARY_CAPABILITY) == PermissionStatus.DISABLED: if gbm and gbm.get_group_permission(group_id, Feature.SUMMARY_CAPABILITY) == PermissionStatus.DISABLED:
return True, None return False, None
# 从消息历史中获取群聊记录 # 从消息历史中获取群聊记录
all_contacts: dict = message.get("all_contacts") all_contacts: dict = message.get("all_contacts")

View File

@@ -97,7 +97,7 @@ class MusicPlugin(MessagePluginInterface):
if len(content.split(" ")) == 1: if len(content.split(" ")) == 1:
wcf.send_text(f"❌命令格式错误!\n{self.command_format}", wcf.send_text(f"❌命令格式错误!\n{self.command_format}",
(roomid if roomid else sender), sender) (roomid if roomid else sender), sender)
return True, "命令格式错误" return False, "命令格式错误"
# 检查权限 # 检查权限
if roomid and gbm.get_group_permission(roomid, Feature.MUSIC) == PermissionStatus.DISABLED: if roomid and gbm.get_group_permission(roomid, Feature.MUSIC) == PermissionStatus.DISABLED:
@@ -112,7 +112,7 @@ class MusicPlugin(MessagePluginInterface):
if not song_info or not song_info.get("play_url"): if not song_info or not song_info.get("play_url"):
wcf.send_text(f"❌未找到歌曲:{user_song_name}", wcf.send_text(f"❌未找到歌曲:{user_song_name}",
(roomid if roomid else sender), sender) (roomid if roomid else sender), sender)
return True, "未找到歌曲" return False, "未找到歌曲"
# 发送音乐 # 发送音乐
self._send_music_message(wcf, song_info, roomid or sender) self._send_music_message(wcf, song_info, roomid or sender)
@@ -120,7 +120,7 @@ class MusicPlugin(MessagePluginInterface):
except Exception as e: except Exception as e:
self.LOG.error(f"处理音乐请求出错: {e}") self.LOG.error(f"处理音乐请求出错: {e}")
return True, f"处理出错: {e}" return False, f"处理出错: {e}"
def _search_song(self, song_name: str) -> Dict[str, Any]: def _search_song(self, song_name: str) -> Dict[str, Any]:
"""搜索歌曲信息""" """搜索歌曲信息"""

View File

@@ -245,7 +245,7 @@ class PointTradePlugin(MessagePluginInterface):
if not user_points: if not user_points:
wcf.send_text(f"❌未找到你的积分记录!请先参与积分活动[签到,答题/t]。", wcf.send_text(f"❌未找到你的积分记录!请先参与积分活动[签到,答题/t]。",
(roomid if roomid else sender), sender) (roomid if roomid else sender), sender)
return True, "未找到积分记录" return False, "未找到积分记录"
# 获取用户昵称 # 获取用户昵称
user_info = self._get_user_record(sender, roomid) user_info = self._get_user_record(sender, roomid)

View File

@@ -111,7 +111,7 @@ class VideoPlugin(MessagePluginInterface):
if not file_abspath or not file_abspath.endswith("mp4"): if not file_abspath or not file_abspath.endswith("mp4"):
wcf.send_text(f"\n❌视频下载失败,请稍后再试", wcf.send_text(f"\n❌视频下载失败,请稍后再试",
(roomid if roomid else sender), sender) (roomid if roomid else sender), sender)
return True, "视频下载失败" return False, "视频下载失败"
# 发送视频 # 发送视频
result = wcf.send_file(file_abspath, (roomid if roomid else sender)) result = wcf.send_file(file_abspath, (roomid if roomid else sender))
@@ -122,7 +122,7 @@ class VideoPlugin(MessagePluginInterface):
self.LOG.error(f"处理视频请求出错: {e}") self.LOG.error(f"处理视频请求出错: {e}")
wcf.send_text(f"\n❌请求出错:{e}", wcf.send_text(f"\n❌请求出错:{e}",
(roomid if roomid else sender), sender) (roomid if roomid else sender), sender)
return True, f"处理出错: {e}" return False, f"处理出错: {e}"
def _download_stream(self, url, save_path): def _download_stream(self, url, save_path):
""" """

View File

@@ -111,7 +111,7 @@ class VideoManPlugin(MessagePluginInterface):
if not file_abspath: if not file_abspath:
self.message_util.send_text_msg(f"\n❌视频下载失败,请稍后再试", self.message_util.send_text_msg(f"\n❌视频下载失败,请稍后再试",
(roomid if roomid else sender), sender) (roomid if roomid else sender), sender)
return True, "视频下载失败" return False, "视频下载失败"
# 发送视频 # 发送视频
result = wcf.send_file(file_abspath, (roomid if roomid else sender)) result = wcf.send_file(file_abspath, (roomid if roomid else sender))
@@ -120,7 +120,7 @@ class VideoManPlugin(MessagePluginInterface):
except Exception as e: except Exception as e:
self.LOG.error(f"处理视频请求出错: {e}") self.LOG.error(f"处理视频请求出错: {e}")
return True, f"处理出错: {e}" return False, f"处理出错: {e}"
def _download_video(self, api_url): def _download_video(self, api_url):
""" """

View File

@@ -108,7 +108,7 @@ class XiurenImagePlugin(MessagePluginInterface):
if not pic_path: if not pic_path:
wcf.send_text(f"❌未找到图片资源", wcf.send_text(f"❌未找到图片资源",
(roomid if roomid else sender), sender) (roomid if roomid else sender), sender)
return True, "未找到图片资源" return False, "未找到图片资源"
# 发送图片 # 发送图片
result = wcf.send_file(pic_path, (roomid if roomid else sender)) result = wcf.send_file(pic_path, (roomid if roomid else sender))
@@ -117,7 +117,7 @@ class XiurenImagePlugin(MessagePluginInterface):
except Exception as e: except Exception as e:
self.LOG.error(f"处理图片请求出错: {e}") self.LOG.error(f"处理图片请求出错: {e}")
return True, f"处理出错: {e}" return False, f"处理出错: {e}"
def _get_random_pic(self) -> Optional[str]: def _get_random_pic(self) -> Optional[str]:
"""获取随机图片路径""" """获取随机图片路径"""

View File

@@ -61,7 +61,7 @@ def plugin_stats_decorator(plugin_name: str) -> Callable:
logger.debug(f"[{plugin_name}] 记录插件调用统计") logger.debug(f"[{plugin_name}] 记录插件调用统计")
stats_db.record_plugin_call( stats_db.record_plugin_call(
plugin_name=plugin_name, plugin_name=plugin_name,
command=command, # 使用提取的指令而不是完整内容 command=command,
user_id=sender, user_id=sender,
group_id=roomid, group_id=roomid,
success=success, success=success,
@@ -69,6 +69,30 @@ def plugin_stats_decorator(plugin_name: str) -> Callable:
) )
logger.info(f"[{plugin_name}] 成功记录插件调用: {command}, 耗时: {process_time_ms:.2f}ms") logger.info(f"[{plugin_name}] 成功记录插件调用: {command}, 耗时: {process_time_ms:.2f}ms")
# 定义不需要记录错误的正常业务状态
normal_responses = {
"没有权限",
"命令格式错误",
"请先开启功能",
# 可以添加其他正常的业务状态返回
}
# 新增:如果业务代码返回失败,且不属于正常业务状态,则记录错误信息
if not success and response and response not in normal_responses:
logger.debug(f"[{plugin_name}] 业务代码返回失败,记录错误信息: {response}")
try:
stats_db.record_error(
plugin_name=plugin_name,
command=command,
user_id=sender,
group_id=roomid,
error_message=f"业务返回失败: {response}",
stack_trace="业务代码捕获的错误,无堆栈信息"
)
logger.info(f"[{plugin_name}] 成功记录业务失败信息: {response}")
except Exception as err_record_error:
logger.error(f"[{plugin_name}] 记录业务失败信息出错: {err_record_error}")
return success, response return success, response
except Exception as e: except Exception as e:
# 计算执行时间(毫秒) # 计算执行时间(毫秒)
@@ -100,12 +124,13 @@ def plugin_stats_decorator(plugin_name: str) -> Callable:
command=command, # 使用提取的指令而不是完整内容 command=command, # 使用提取的指令而不是完整内容
user_id=sender, user_id=sender,
group_id=roomid, group_id=roomid,
error_message=error_message, error_message=error_message[:500] if error_message else "未知错误", # 限制长度并确保不为空
stack_trace=stack_trace stack_trace=stack_trace[:2000] if stack_trace else "无堆栈信息" # 限制长度并确保不为空
) )
logger.info(f"[{plugin_name}] 成功记录插件错误: {command}, 错误: {error_message}") logger.info(f"[{plugin_name}] 成功记录插件错误: {command}, 错误: {error_message}")
except Exception as db_error: except Exception as db_error:
logger.error(f"[{plugin_name}] 记录插件统计数据失败: {db_error}") logger.error(f"[{plugin_name}] 记录插件统计数据失败: {db_error}")
logger.error(traceback.format_exc())
# 重新抛出异常,让上层处理 # 重新抛出异常,让上层处理
raise raise