调整注解位置
This commit is contained in:
@@ -58,7 +58,7 @@ class GameTaskPlugin(MessagePluginInterface):
|
||||
|
||||
# 初始化配置
|
||||
self._commands = self._config.get("GameTask", {}).get("command",
|
||||
["game", "任务", "/t", "/a", "/s", "/r", "/l", "/h"])
|
||||
["game", "任务", "/t", "/a", "/s", "/r", "/l", "/h"])
|
||||
self.command_format = self._config.get("GameTask", {}).get("command-format", """
|
||||
🎮 百科问答指令:
|
||||
/s - 加入游戏
|
||||
@@ -99,13 +99,17 @@ class GameTaskPlugin(MessagePluginInterface):
|
||||
|
||||
return command in self._commands
|
||||
|
||||
def calculate_reward_points(self, message: Dict[str, Any], success: bool, response: str) -> int:
|
||||
"""计算奖励积分"""
|
||||
def calculate_game_points(self, message: Dict[str, Any], success: bool, response: str) -> int:
|
||||
"""计算游戏积分"""
|
||||
if not success:
|
||||
return 0
|
||||
return int(response)
|
||||
try:
|
||||
return int(response)
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
@plugin_stats_decorator(plugin_name="百科问答")
|
||||
@points_reward_decorator(calculate_game_points, "game", "百科答题奖励")
|
||||
def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
|
||||
"""处理消息"""
|
||||
content = str(message.get("content", "")).strip()
|
||||
@@ -133,8 +137,9 @@ class GameTaskPlugin(MessagePluginInterface):
|
||||
self._handle_get_task(sender, roomid)
|
||||
return True, "获取任务成功"
|
||||
elif command == "/a":
|
||||
# 修改这里,传入整个 message 对象
|
||||
points = self._handle_submit_answer(message)
|
||||
# 修改这里,不要直接传递 message 对象
|
||||
content = str(message.get("content", "")).strip()
|
||||
points = self._handle_submit_answer(content, sender, roomid)
|
||||
return True, str(points)
|
||||
elif command == "/r":
|
||||
self._handle_show_rank(sender, roomid)
|
||||
@@ -147,7 +152,7 @@ class GameTaskPlugin(MessagePluginInterface):
|
||||
return True, "列举未完成任务成功"
|
||||
else:
|
||||
self.message_util.send_text_msg(f"❌未知命令!\n{self.command_format}",
|
||||
(roomid if roomid else sender), sender)
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, "未知命令"
|
||||
|
||||
except Exception as e:
|
||||
@@ -247,25 +252,9 @@ class GameTaskPlugin(MessagePluginInterface):
|
||||
sender
|
||||
)
|
||||
|
||||
|
||||
def calculate_game_points(self, message: Dict[str, Any], success: bool, response: str) -> int:
|
||||
"""计算游戏积分"""
|
||||
if not success:
|
||||
return 0
|
||||
try:
|
||||
return int(response)
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
# 修复参数问题,确保方法签名与调用方式匹配
|
||||
@points_reward_decorator(calculate_game_points, "game", "百科答题奖励")
|
||||
def _handle_submit_answer(self, message: Dict[str, Any]) -> int:
|
||||
def _handle_submit_answer(self, content: str, sender: str, roomid: str) -> int:
|
||||
"""处理提交答案请求"""
|
||||
try:
|
||||
content = str(message.get("content", "")).strip()
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
|
||||
parts = content.split(" ", 2)
|
||||
if len(parts) < 3:
|
||||
self.message_util.send_text_msg(
|
||||
@@ -547,4 +536,4 @@ class GameTaskPlugin(MessagePluginInterface):
|
||||
group_id
|
||||
)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"定时任务出错: {e}")
|
||||
self.LOG.error(f"定时任务出错: {e}")
|
||||
|
||||
Reference in New Issue
Block a user