给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("/"):
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}")

View File

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