@@ -24,10 +24,6 @@ class RobotMenuPlugin(MessagePluginInterface):
|
||||
"功能清单",
|
||||
"功能菜单",
|
||||
"功能列表",
|
||||
"指令清单",
|
||||
"命令清单",
|
||||
"指令",
|
||||
"命令",
|
||||
"菜单",
|
||||
"怎么用",
|
||||
"如何用",
|
||||
@@ -149,31 +145,6 @@ class RobotMenuPlugin(MessagePluginInterface):
|
||||
first = first.split("-", 1)[0].strip()
|
||||
return first or "请发送“菜单”查看"
|
||||
|
||||
@staticmethod
|
||||
def _extract_command_candidates(description: str) -> List[str]:
|
||||
"""
|
||||
从 Feature.description 中提取可触发命令列表
|
||||
例如: [菜单 - 显示功能菜单 | 菜单 状态 - 显示功能状态]
|
||||
-> ["菜单", "菜单 状态"]
|
||||
"""
|
||||
desc = str(description or "")
|
||||
match = re.search(r"\[(.*?)\]", desc)
|
||||
if not match:
|
||||
return []
|
||||
inner = match.group(1).strip()
|
||||
if not inner:
|
||||
return []
|
||||
commands: List[str] = []
|
||||
for part in inner.split("|"):
|
||||
item = part.strip()
|
||||
if not item:
|
||||
continue
|
||||
if "-" in item:
|
||||
item = item.split("-", 1)[0].strip()
|
||||
if item:
|
||||
commands.append(item)
|
||||
return commands
|
||||
|
||||
@staticmethod
|
||||
def _extract_brief_from_description(description: str) -> str:
|
||||
desc = str(description or "")
|
||||
@@ -225,37 +196,6 @@ class RobotMenuPlugin(MessagePluginInterface):
|
||||
result += f"{feature['id']}. {feature['name']} | 触发:{usage} | {brief}\n"
|
||||
return result.strip()
|
||||
|
||||
def _collect_group_commands(self, group_id: str) -> List[str]:
|
||||
enabled_features = self._get_enabled_feature_items(group_id)
|
||||
if not enabled_features:
|
||||
return []
|
||||
ordered: List[str] = []
|
||||
seen = set()
|
||||
for feature in enabled_features:
|
||||
for cmd in self._extract_command_candidates(feature.get("description", "")):
|
||||
key = self._normalize_text(cmd)
|
||||
if not key or key in seen:
|
||||
continue
|
||||
seen.add(key)
|
||||
ordered.append(cmd)
|
||||
return ordered
|
||||
|
||||
def build_command_list_text(self, group_id: str) -> str:
|
||||
"""仅输出本群可用的触发指令清单"""
|
||||
if group_id not in GroupBotManager.local_cache["group_list"]:
|
||||
return "当前群未开通机器人功能,请联系管理员开启。"
|
||||
|
||||
commands = self._collect_group_commands(group_id)
|
||||
if not commands:
|
||||
return "当前群暂无可用指令。"
|
||||
|
||||
lines = ["本群指令清单:", "复制以下任一指令发送即可触发。", ""]
|
||||
for idx, cmd in enumerate(commands, start=1):
|
||||
lines.append(f"{idx}. {cmd}")
|
||||
lines.append("")
|
||||
lines.append("提示:发送“菜单”查看功能说明。")
|
||||
return "\n".join(lines).strip()
|
||||
|
||||
def build_user_friendly_menu(self, group_id: str) -> str:
|
||||
"""构建给普通群成员看的直观功能菜单"""
|
||||
if group_id not in GroupBotManager.local_cache["group_list"]:
|
||||
@@ -265,19 +205,11 @@ class RobotMenuPlugin(MessagePluginInterface):
|
||||
if not enabled_features:
|
||||
return "当前群暂无可用功能。"
|
||||
|
||||
command_list = self._collect_group_commands(group_id)
|
||||
|
||||
lines = [
|
||||
"本群已开通功能:",
|
||||
"直接复制“触发”里的命令发送即可。",
|
||||
"",
|
||||
]
|
||||
if command_list:
|
||||
lines.append("常用指令清单:")
|
||||
for idx, cmd in enumerate(command_list, start=1):
|
||||
lines.append(f"{idx}. {cmd}")
|
||||
lines.append("")
|
||||
|
||||
for idx, feature in enumerate(enabled_features, start=1):
|
||||
usage = self._extract_usage_from_description(feature["description"])
|
||||
brief = self._extract_brief_from_description(feature["description"])
|
||||
@@ -366,12 +298,6 @@ class RobotMenuPlugin(MessagePluginInterface):
|
||||
revoke.add_message_to_revoke(target, client_msg_id, create_time, new_msg_id, 90)
|
||||
return True, "显示功能状态"
|
||||
|
||||
if cmd_name in ["指令", "指令清单", "命令", "命令清单"]:
|
||||
list_text = self.build_command_list_text(roomid if roomid else sender)
|
||||
client_msg_id, create_time, new_msg_id = await bot.send_text_message(target, list_text, sender)
|
||||
revoke.add_message_to_revoke(target, client_msg_id, create_time, new_msg_id, 120)
|
||||
return True, "显示指令清单"
|
||||
|
||||
# 处理群列表命令
|
||||
if cmd_name.upper() == "群列表":
|
||||
group_list_text = self.get_group_list()
|
||||
|
||||
Reference in New Issue
Block a user