加入验证判断逻辑,以为是true,结果是文本。导致所有群都收到了消息

This commit is contained in:
liuwei
2025-02-17 15:34:13 +08:00
parent cceecc21fc
commit dc5be6c728
2 changed files with 30 additions and 17 deletions

View File

@@ -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}")

View File

@@ -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()