From 43904ea33ce8fb8e1c92608592cab41181f4d787 Mon Sep 17 00:00:00 2001 From: liuwei Date: Fri, 28 Feb 2025 17:14:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=999-=E7=BE=A4=E7=99=BE=E7=A7=91=E7=AD=94?= =?UTF-8?q?=E9=A2=98=E6=B8=B8=E6=88=8F=E5=8A=A0=E4=B8=8A=E6=9D=83=E9=99=90?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E6=B5=AA=E8=B4=B9=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robot.py | 36 ++++++++++++++++++++++-------------- robot_cmd/robot_command.py | 1 + 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/robot.py b/robot.py index da05a08..5887018 100644 --- a/robot.py +++ b/robot.py @@ -158,15 +158,19 @@ class Robot(Job): # 所有人员都可以要求他撤回刚刚的信息 if msg.from_group() and q.startswith("/"): - try: - # 因为内容中存在空格指令,所以不能使用q - game_message = re.sub(r"@.*?[\u2005|\s]", "", msg.content) - self.LOG.info(f"msg.content:{msg.content}\n game_message: {game_message}") - resp = game_process_message(group_id=msg.roomid, player_id=msg.sender, message=game_message, - player_name=self.allContacts.get(msg.sender, msg.sender)) - self.sendTextMsg(resp, msg.roomid, msg.sender) - except Exception as e: - self.LOG.error(f"game_message_load error:{e}") + # 进行权限判断 加入权限,防止tokens浪费 + if self.gbm.get_group_permission(msg.roomid, Feature.TASK_GAME) == PermissionStatus.DISABLED: + return True + else: + try: + # 因为内容中存在空格指令,所以不能使用q + game_message = re.sub(r"@.*?[\u2005|\s]", "", msg.content) + self.LOG.info(f"msg.content:{msg.content}\n game_message: {game_message}") + resp = game_process_message(group_id=msg.roomid, player_id=msg.sender, message=game_message, + player_name=self.allContacts.get(msg.sender, msg.sender)) + self.sendTextMsg(resp, msg.roomid, msg.sender) + except Exception as e: + self.LOG.error(f"game_message_load error:{e}") return True if q == "#今日百度新闻": self.newsBaiduReport((msg.roomid if msg.from_group() else msg.sender)) @@ -268,11 +272,15 @@ class Robot(Job): # 兼容不@ 直接/触发指令,回答问题。 try: if msg.content.startswith("/"): - # 因为内容中存在空格指令,所以不能使用 - self.LOG.info(f"msg.content:{msg.content}\n game_message: {msg.content}") - resp = game_process_message(group_id=msg.roomid, player_id=msg.sender, message=msg.content, - player_name=self.allContacts.get(msg.sender, msg.sender)) - self.sendTextMsg(resp, msg.roomid, msg.sender) + # 进行权限判断 加入权限,防止tokens浪费 + if self.gbm.get_group_permission(msg.roomid, Feature.TASK_GAME) == PermissionStatus.DISABLED: + return + else: + # 因为内容中存在空格指令,所以不能使用 + self.LOG.info(f"msg.content:{msg.content}\n game_message: {msg.content}") + resp = game_process_message(group_id=msg.roomid, player_id=msg.sender, message=msg.content, + player_name=self.allContacts.get(msg.sender, msg.sender)) + self.sendTextMsg(resp, msg.roomid, msg.sender) return except Exception as e: self.LOG.error(f"game_message_load error:{e}") diff --git a/robot_cmd/robot_command.py b/robot_cmd/robot_command.py index 3334635..b1a0c2e 100644 --- a/robot_cmd/robot_command.py +++ b/robot_cmd/robot_command.py @@ -30,6 +30,7 @@ class Feature(Enum): PDF_CAPABILITY = 6, "sehuatang PDF能力" EPIC = 7, "EPIC自动播报" # 新增的功能 PIC = 8, "图来能力" + TASK_GAME = 9, "百科答题游戏" def __new__(cls, value, description): obj = object.__new__(cls)