From dc5be6c7283e4808db27cb27a8cba025c6c85440 Mon Sep 17 00:00:00 2001 From: liuwei Date: Mon, 17 Feb 2025 15:34:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E9=AA=8C=E8=AF=81=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BB=A5=E4=B8=BA=E6=98=AF?= =?UTF-8?q?true=EF=BC=8C=E7=BB=93=E6=9E=9C=E6=98=AF=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E3=80=82=E5=AF=BC=E8=87=B4=E6=89=80=E6=9C=89=E7=BE=A4=E9=83=BD?= =?UTF-8?q?=E6=94=B6=E5=88=B0=E4=BA=86=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robot.py | 38 +++++++++++++++++++++----------------- robot_cmd/robot_command.py | 9 +++++++++ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/robot.py b/robot.py index a0521b5..9d50792 100644 --- a/robot.py +++ b/robot.py @@ -26,6 +26,7 @@ from constants import ChatType from robot_cmd.robot_command import GroupBotManager from job_mgmt import Job from robot_cmd.robot_command import Feature +from robot_cmd.robot_command import PermissionStatus __version__ = "39.2.4.0" @@ -327,7 +328,7 @@ class Robot(Job): if not receivers: return for r in receivers: - if self.gbm.get_group_permission(r, feature): + if self.gbm.get_group_permission(r, feature) == PermissionStatus.ENABLED: self.sendTextMsg(msg, r) except Exception as e: self.LOG.error(f"send_group_txt_message:{feature.description} error:{e}") @@ -338,7 +339,7 @@ class Robot(Job): if not receivers: return for r in receivers: - if self.gbm.get_group_permission(r, feature): + if self.gbm.get_group_permission(r, feature) == PermissionStatus.ENABLED: self.wcf.send_file(path, r) except Exception as e: self.LOG.error(f"send_group_file_message:{feature.description} error:{e}") @@ -414,17 +415,6 @@ class Robot(Job): except Exception as e: self.LOG.error(f"write_to_db error:{e}") - def generateAndSendRanking(self): - try: - receivers = self.gbm.get_group_list() - if not receivers: - return - for r in receivers: - if self.gbm.get_group_permission(r, Feature.DAILY_SUMMARY): - self.sendTextMsg(generate_and_send_ranking(r, self.allContacts), r) - except Exception as e: - self.LOG.error(f"SendRanking error:{e}") - def generateSehuatangPdf(self): try: path = pdf_file_path() @@ -433,11 +423,25 @@ class Robot(Job): except Exception as e: self.LOG.error(f"generateSehuatangPdf error:{e}") + def generateAndSendRanking(self): + try: + receivers = self.gbm.get_group_list() + if not receivers: + return + for r in receivers: + if self.gbm.get_group_permission(r, Feature.DAILY_SUMMARY) == PermissionStatus.ENABLED: + self.sendTextMsg(generate_and_send_ranking(r, self.allContacts), r) + except Exception as e: + self.LOG.error(f"SendRanking error:{e}") + def message_summary_robot(self, sender: str = None): try: - self.LOG.info(f"群: {sender} 消息总结开始执行!") - content = get_messages(sender, self.allContacts) - summary = message_summary(content) - self.sendTextMsg(summary, sender) + if self.gbm.get_group_permission(sender, Feature.DAILY_SUMMARY) == PermissionStatus.ENABLED: + self.LOG.info(f"群: {sender} 消息总结开始执行!") + content = get_messages(sender, self.allContacts) + summary = message_summary(content) + self.sendTextMsg(summary, sender) + else: + self.sendTextMsg("群发言总结功能未开启", sender) except Exception as e: self.LOG.error(f"message_summary_robot error:{e}") diff --git a/robot_cmd/robot_command.py b/robot_cmd/robot_command.py index c24e11a..358d139 100644 --- a/robot_cmd/robot_command.py +++ b/robot_cmd/robot_command.py @@ -100,6 +100,14 @@ class GroupBotManager: else: return PermissionStatus.DISABLED + @staticmethod + def check_permission(group_id, feature: Feature): + """检查某个功能是否启用,若未启用则返回提示信息""" + status = GroupBotManager.get_group_permission(group_id, feature) + if status == PermissionStatus.DISABLED: + return f"该功能未启用,请开启 {feature.description}。" + return None # 如果已启用,则返回 None,不做处理 + @staticmethod def handle_command(group_id, command_str): """统一处理群功能指令""" @@ -246,6 +254,7 @@ def simulate_commands(): # 保存到 Redis GroupBotManager.save_to_redis() + if __name__ == '__main__': # 执行模拟命令 simulate_commands()