新增robot_menu指令清单展示能力
变更项: 1. 新增“菜单 指令清单、菜单 指令、菜单 命令清单”入口,返回本群可用触发指令。 2. 从功能描述方括号中自动提取命令并去重,生成可直接复制的指令列表。 3. 优化主菜单文案,增加“常用指令清单”区块,帮助用户快速上手。 4. 扩展@语义关键词,支持“指令清单、命令清单”等问法触发菜单。
This commit is contained in:
@@ -24,6 +24,10 @@ class RobotMenuPlugin(MessagePluginInterface):
|
|||||||
"功能清单",
|
"功能清单",
|
||||||
"功能菜单",
|
"功能菜单",
|
||||||
"功能列表",
|
"功能列表",
|
||||||
|
"指令清单",
|
||||||
|
"命令清单",
|
||||||
|
"指令",
|
||||||
|
"命令",
|
||||||
"菜单",
|
"菜单",
|
||||||
"怎么用",
|
"怎么用",
|
||||||
"如何用",
|
"如何用",
|
||||||
@@ -145,6 +149,31 @@ class RobotMenuPlugin(MessagePluginInterface):
|
|||||||
first = first.split("-", 1)[0].strip()
|
first = first.split("-", 1)[0].strip()
|
||||||
return first or "请发送“菜单”查看"
|
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
|
@staticmethod
|
||||||
def _extract_brief_from_description(description: str) -> str:
|
def _extract_brief_from_description(description: str) -> str:
|
||||||
desc = str(description or "")
|
desc = str(description or "")
|
||||||
@@ -196,6 +225,37 @@ class RobotMenuPlugin(MessagePluginInterface):
|
|||||||
result += f"{feature['id']}. {feature['name']} | 触发:{usage} | {brief}\n"
|
result += f"{feature['id']}. {feature['name']} | 触发:{usage} | {brief}\n"
|
||||||
return result.strip()
|
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:
|
def build_user_friendly_menu(self, group_id: str) -> str:
|
||||||
"""构建给普通群成员看的直观功能菜单"""
|
"""构建给普通群成员看的直观功能菜单"""
|
||||||
if group_id not in GroupBotManager.local_cache["group_list"]:
|
if group_id not in GroupBotManager.local_cache["group_list"]:
|
||||||
@@ -205,11 +265,19 @@ class RobotMenuPlugin(MessagePluginInterface):
|
|||||||
if not enabled_features:
|
if not enabled_features:
|
||||||
return "当前群暂无可用功能。"
|
return "当前群暂无可用功能。"
|
||||||
|
|
||||||
|
command_list = self._collect_group_commands(group_id)
|
||||||
|
|
||||||
lines = [
|
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):
|
for idx, feature in enumerate(enabled_features, start=1):
|
||||||
usage = self._extract_usage_from_description(feature["description"])
|
usage = self._extract_usage_from_description(feature["description"])
|
||||||
brief = self._extract_brief_from_description(feature["description"])
|
brief = self._extract_brief_from_description(feature["description"])
|
||||||
@@ -298,6 +366,12 @@ class RobotMenuPlugin(MessagePluginInterface):
|
|||||||
revoke.add_message_to_revoke(target, client_msg_id, create_time, new_msg_id, 90)
|
revoke.add_message_to_revoke(target, client_msg_id, create_time, new_msg_id, 90)
|
||||||
return True, "显示功能状态"
|
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() == "群列表":
|
if cmd_name.upper() == "群列表":
|
||||||
group_list_text = self.get_group_list()
|
group_list_text = self.get_group_list()
|
||||||
|
|||||||
Reference in New Issue
Block a user