菜单改为小卡片形态并在功能卡片展示开启关闭状态
This commit is contained in:
@@ -10,7 +10,7 @@ from loguru import logger as default_logger
|
||||
|
||||
from utils.markdown_to_image import convert_md_str_to_image, html_to_image
|
||||
from utils.revoke.message_auto_revoke import MessageAutoRevoke
|
||||
from utils.robot_cmd.robot_command import Feature
|
||||
from utils.robot_cmd.robot_command import Feature, GroupBotManager, PermissionStatus
|
||||
from wechat_ipad import WechatAPIClient
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ class RobotMenuRenderTool:
|
||||
return result
|
||||
|
||||
def build_feature_status_markdown(self, group_id: str) -> str:
|
||||
"""构建紧凑菜单 Markdown(强调“怎么用”,不展示启停状态/管理命令)。"""
|
||||
"""构建紧凑菜单 Markdown(强调“怎么用”,并显示开启/关闭状态)。"""
|
||||
user_features = self._iter_user_command_features()
|
||||
lines = [
|
||||
"# 机器人功能菜单",
|
||||
@@ -133,7 +133,10 @@ class RobotMenuRenderTool:
|
||||
"## 功能与指令",
|
||||
]
|
||||
for feature in user_features:
|
||||
status = GroupBotManager.get_group_permission(group_id, feature)
|
||||
status_text = "开启" if status == PermissionStatus.ENABLED else "关闭"
|
||||
lines.extend(self._build_feature_usage_lines(feature))
|
||||
lines.append(f" 状态:{status_text}")
|
||||
lines.append("")
|
||||
return "\n".join(lines)
|
||||
|
||||
@@ -161,6 +164,10 @@ class RobotMenuRenderTool:
|
||||
for feature in user_features:
|
||||
title, _ = self._split_feature_description(feature.description)
|
||||
command_examples = self._get_feature_command_examples(feature)
|
||||
status = GroupBotManager.get_group_permission(group_id, feature)
|
||||
is_enabled = status == PermissionStatus.ENABLED
|
||||
status_text = "开启" if is_enabled else "关闭"
|
||||
status_class = "status-on" if is_enabled else "status-off"
|
||||
# 为纵向卡片增加轻量色彩分组,提升视觉节奏感,避免纯白卡片过于单调。
|
||||
try:
|
||||
tone_idx = int(feature.value) % 4
|
||||
@@ -175,6 +182,7 @@ class RobotMenuRenderTool:
|
||||
<h3>{html.escape(title)}</h3>
|
||||
<p class="feature-key">功能键:<code>{html.escape(feature.name)}</code></p>
|
||||
</div>
|
||||
<span class="status-badge {status_class}">{status_text}</span>
|
||||
</div>
|
||||
<div class="feature-body">
|
||||
<p>{command_examples}</p>
|
||||
@@ -279,19 +287,37 @@ class RobotMenuRenderTool:
|
||||
.feature-card.tone-3 {{ border-left-color: #ef4444; }}
|
||||
.feature-top {{ display: flex; align-items: center; gap: 8px; }}
|
||||
.feature-index {{
|
||||
min-width: 26px;
|
||||
text-align: center;
|
||||
font-weight: 700;
|
||||
min-width: 26px;
|
||||
text-align: center;
|
||||
font-weight: 700;
|
||||
color: #0f5fb7;
|
||||
background: var(--brand-soft);
|
||||
border: 1px solid #cfe1fb;
|
||||
border-radius: 6px;
|
||||
padding: 2px 4px;
|
||||
font-size: 10px;
|
||||
padding: 2px 4px;
|
||||
font-size: 10px;
|
||||
}}
|
||||
.feature-meta {{ flex: 1; }}
|
||||
.feature-meta h3 {{ margin: 0 0 1px 0; font-size: 12px; }}
|
||||
.feature-key {{ margin: 0; font-size: 10px; color: var(--muted); }}
|
||||
.status-badge {{
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
padding: 2px 8px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid transparent;
|
||||
white-space: nowrap;
|
||||
}}
|
||||
.status-on {{
|
||||
color: #0f7a4f;
|
||||
background: #e9f9f1;
|
||||
border-color: #bde8d2;
|
||||
}}
|
||||
.status-off {{
|
||||
color: #9f2f2f;
|
||||
background: #feefef;
|
||||
border-color: #f3c7c7;
|
||||
}}
|
||||
.feature-body {{
|
||||
margin-top: 5px;
|
||||
padding: 5px 7px;
|
||||
@@ -322,10 +348,32 @@ class RobotMenuRenderTool:
|
||||
<main class="content">
|
||||
<section class="block">
|
||||
<h2>快速上手</h2>
|
||||
<ul>
|
||||
<li><code>菜单</code>:查看可用功能和指令</li>
|
||||
<li>以下仅保留可直接输入的用户指令(共 {len(user_features)} 项)</li>
|
||||
</ul>
|
||||
<div class="feature-list">
|
||||
<section class="feature-card tone-0">
|
||||
<div class="feature-top">
|
||||
<div class="feature-index">A</div>
|
||||
<div class="feature-meta">
|
||||
<h3>查看菜单</h3>
|
||||
<p class="feature-key"><code>菜单</code></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="feature-body">
|
||||
<p><span class="line-main">发送一次即可查看全部功能卡片</span></p>
|
||||
</div>
|
||||
</section>
|
||||
<section class="feature-card tone-1">
|
||||
<div class="feature-top">
|
||||
<div class="feature-index">B</div>
|
||||
<div class="feature-meta">
|
||||
<h3>展示范围</h3>
|
||||
<p class="feature-key">用户直接可用指令</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="feature-body">
|
||||
<p><span class="line-main">当前共 {len(user_features)} 项</span></p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
<section class="block">
|
||||
<h2>功能与指令</h2>
|
||||
|
||||
Reference in New Issue
Block a user