给9-群百科答题游戏加上权限,防止浪费资源

This commit is contained in:
liuwei
2025-02-28 17:14:35 +08:00
parent 050162cb0f
commit 43904ea33c
2 changed files with 23 additions and 14 deletions

View File

@@ -158,15 +158,19 @@ class Robot(Job):
# 所有人员都可以要求他撤回刚刚的信息 # 所有人员都可以要求他撤回刚刚的信息
if msg.from_group() and q.startswith("/"): if msg.from_group() and q.startswith("/"):
try: # 进行权限判断 加入权限防止tokens浪费
# 因为内容中存在空格指令所以不能使用q if self.gbm.get_group_permission(msg.roomid, Feature.TASK_GAME) == PermissionStatus.DISABLED:
game_message = re.sub(r"@.*?[\u2005|\s]", "", msg.content) return True
self.LOG.info(f"msg.content:{msg.content}\n game_message: {game_message}") else:
resp = game_process_message(group_id=msg.roomid, player_id=msg.sender, message=game_message, try:
player_name=self.allContacts.get(msg.sender, msg.sender)) # 因为内容中存在空格指令所以不能使用q
self.sendTextMsg(resp, msg.roomid, msg.sender) game_message = re.sub(r"@.*?[\u2005|\s]", "", msg.content)
except Exception as e: self.LOG.info(f"msg.content:{msg.content}\n game_message: {game_message}")
self.LOG.error(f"game_message_load error{e}") 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 return True
if q == "#今日百度新闻": if q == "#今日百度新闻":
self.newsBaiduReport((msg.roomid if msg.from_group() else msg.sender)) self.newsBaiduReport((msg.roomid if msg.from_group() else msg.sender))
@@ -268,11 +272,15 @@ class Robot(Job):
# 兼容不@ 直接/触发指令,回答问题。 # 兼容不@ 直接/触发指令,回答问题。
try: try:
if msg.content.startswith("/"): if msg.content.startswith("/"):
# 因为内容中存在空格指令,所以不能使用 # 进行权限判断 加入权限防止tokens浪费
self.LOG.info(f"msg.content:{msg.content}\n game_message: {msg.content}") if self.gbm.get_group_permission(msg.roomid, Feature.TASK_GAME) == PermissionStatus.DISABLED:
resp = game_process_message(group_id=msg.roomid, player_id=msg.sender, message=msg.content, return
player_name=self.allContacts.get(msg.sender, msg.sender)) else:
self.sendTextMsg(resp, msg.roomid, msg.sender) # 因为内容中存在空格指令,所以不能使用
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 return
except Exception as e: except Exception as e:
self.LOG.error(f"game_message_load error{e}") self.LOG.error(f"game_message_load error{e}")

View File

@@ -30,6 +30,7 @@ class Feature(Enum):
PDF_CAPABILITY = 6, "sehuatang PDF能力" PDF_CAPABILITY = 6, "sehuatang PDF能力"
EPIC = 7, "EPIC自动播报" # 新增的功能 EPIC = 7, "EPIC自动播报" # 新增的功能
PIC = 8, "图来能力" PIC = 8, "图来能力"
TASK_GAME = 9, "百科答题游戏"
def __new__(cls, value, description): def __new__(cls, value, description):
obj = object.__new__(cls) obj = object.__new__(cls)