feat(help): 重构帮助菜单界面并优化样式

refactor(bili_parser): 修复 API 响应 content-type 问题
fix(command_manager): 添加帮助图片获取的错误处理
docs(deployment): 简化部署文档并移除 JIT 相关内容
This commit is contained in:
2026-01-14 23:05:31 +08:00
parent 7868fb2b41
commit 520462b4c6
5 changed files with 200 additions and 106 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 116 KiB

After

Width:  |  Height:  |  Size: 136 KiB

View File

@@ -202,6 +202,7 @@ class CommandManager:
内置的 `/help` 命令的实现。
直接从 Redis 获取缓存的图片。
"""
try:
# 1. 尝试从 Redis 获取
help_pic = await redis_manager.get("neobot:core:help_pic")
@@ -213,6 +214,8 @@ class CommandManager:
if help_pic:
await bot.send(event, MessageSegment.image(help_pic))
return
except Exception as e:
logger.error(f"获取或生成帮助图片失败: {e}")
# 2. 最后的兜底:发送纯文本
help_text = "--- 可用指令列表 ---\n"

View File

@@ -24,10 +24,7 @@ pip install -r requirements.txt
### c. 编译核心模块 (可选,但为获得最佳性能强烈建议)
为了最大化性能,我们提供了两层级性能优化方案:
#### 1. Mypyc 编译 (AOT - Ahead-of-Time)
将核心 Python 模块编译成 C 语言扩展。这将大幅提升机器人的响应速度和处理效率。
为了最大化性能,你可以将项目中的核心 Python 模块编译成 C 语言扩展。这将大幅提升机器人的响应速度和处理效率。
```bash
# 确保你在虚拟环境中
@@ -38,16 +35,6 @@ python setup_mypyc.py
> **注意**: 编译产物是平台相关的(例如,在 Windows 上编译的 `.pyd` 文件不能在 Linux 上使用)。因此,**请务必在你最终部署的服务器环境(例如 Linux上执行此编译步骤**。更多关于 Mypyc 编译的细节,请参考 [性能优化详解](core-concepts/performance.md)。
#### 2. Python 3.14 JIT (Just-In-Time)
即使不编译核心模块,你也可以通过启用 Python 3.14 自带的 JIT 编译器来获得性能提升。JIT 会在运行时将热点代码编译为机器码。
**如何启用**: 在启动命令中添加 `-X jit` 参数,或者在下面的 pm2 配置中添加 JIT 参数。
**性能策略**:
- **AOT (Mypyc)**: 负责静态、类型明确的核心模块WebSocket、管理器、工具函数
- **JIT**: 负责动态、灵活的插件代码B站解析、代码沙箱等业务逻辑
- **两者结合**: 可获得最佳性能,全面覆盖所有代码路径
## 2. 使用进程管理器
你想直接 `python main.py` 然后关掉 SSH那机器人也跟着停了。必须用进程管理器来守护它。
@@ -71,7 +58,6 @@ module.exports = {
name : "neobot",
script : "main.py",
interpreter: "/path/to/your/bot/venv/bin/python", // 指定虚拟环境里的 python
args: "-X jit", // 启用 Python 3.14 JIT 编译器
max_memory_restart: "500M", // 内存超过 500M 自动重启
env: {
"PYTHONUNBUFFERED": "1" // 禁用 python 输出缓冲,日志能实时看

View File

@@ -126,7 +126,9 @@ async def get_direct_video_url(video_url: str) -> Optional[str]:
async with aiohttp.ClientSession() as session:
async with session.get(api_url, headers=HEADERS, timeout=10) as response:
response.raise_for_status()
data = await response.json()
# 使用 content_type=None 来忽略 Content-Type 检查
# 因为 API 返回 text/json 而不是标准的 application/json
data = await response.json(content_type=None)
if data.get("code") == 200 and data.get("data"):
return data["data"][0].get("video_url")
except (aiohttp.ClientError, json.JSONDecodeError, KeyError, IndexError) as e:

View File

@@ -3,131 +3,234 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NeoBot 帮助菜单</title>
<title>CalglauBot Menu</title>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #4a90e2;
--bg-color: #f5f7fa;
--card-bg: #ffffff;
--text-color: #333333;
--secondary-text: #666666;
--border-radius: 12px;
--shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
/* 调整为更深邃、高对比度的配色 */
--bg-color: #0f172a; /* 深蓝黑背景 */
--window-bg: rgba(30, 41, 59, 0.85); /* 窗口背景,增加不透明度以提高文字可读性 */
--border-color: rgba(255, 255, 255, 0.08);
--accent: #6366f1; /* 核心强调色 - 靛蓝 */
--accent-glow: rgba(99, 102, 241, 0.4);
--text-title: #f8fafc;
--text-desc: #94a3b8;
--text-cmd: #a5f3fc; /* 指令高亮色 - 浅青 */
--card-bg: rgba(0, 0, 0, 0.2);
--cmd-bg: #0b1120; /* 代码块深色背景 */
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Microsoft YaHei', 'Segoe UI', Roboto, sans-serif;
font-family: 'Noto Sans SC', system-ui, sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
margin: 0;
padding: 20px;
color: var(--text-title);
/* 居中布局 */
display: flex;
justify-content: center;
padding: 40px;
min-height: auto;
}
.container {
width: 600px;
background-color: var(--bg-color);
}
.header {
text-align: center;
margin-bottom: 30px;
padding: 20px 0;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: var(--border-radius);
color: white;
box-shadow: var(--shadow);
}
.header h1 {
margin: 0;
font-size: 2.5em;
letter-spacing: 2px;
}
.header p {
margin: 10px 0 0;
opacity: 0.9;
}
.plugin-list {
/* 窗口容器 */
.window {
width: 800px; /* 稍微收窄一点,更像手机/卡片比例 */
background: var(--window-bg);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border-radius: 20px;
border: 1px solid var(--border-color);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
overflow: hidden;
display: flex;
flex-direction: column;
gap: 15px;
}
.plugin-card {
background-color: var(--card-bg);
border-radius: var(--border-radius);
padding: 20px;
box-shadow: var(--shadow);
transition: transform 0.2s;
border-left: 5px solid var(--primary-color);
}
.plugin-header {
/* 顶部标题栏 */
.header {
padding: 24px 32px;
border-bottom: 1px solid var(--border-color);
background: rgba(255, 255, 255, 0.02);
display: flex;
justify-content: space-between;
align-items: center;
}
.dots { display: flex; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; }
.red { background: #ef4444; }
.yellow { background: #f59e0b; }
.green { background: #10b981; }
.title {
font-size: 14px;
font-weight: 700;
letter-spacing: 1px;
color: var(--text-desc);
text-transform: uppercase;
}
/* 内容区域 */
.content {
padding: 32px;
display: flex;
flex-direction: column;
gap: 24px; /* 卡片之间的间距 */
}
.page-title {
margin-bottom: 10px;
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}
.page-title h1 {
font-size: 32px;
background: linear-gradient(to right, #fff, #94a3b8);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.page-title p {
color: var(--text-desc);
font-size: 14px;
margin-top: 8px;
}
/* 插件卡片 - 改为单列宽卡片 */
.plugin-card {
background: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 20px;
display: flex;
flex-direction: column; /* 垂直排列 */
gap: 16px;
transition: transform 0.2s;
position: relative;
overflow: hidden;
}
/* 左侧装饰线 */
.plugin-card::before {
content: '';
position: absolute;
left: 0; top: 0; bottom: 0;
width: 4px;
background: var(--accent);
opacity: 0.6;
}
/* 插件头部信息 */
.card-info {
display: flex;
justify-content: space-between;
align-items: baseline;
}
.plugin-name {
font-size: 1.2em;
font-weight: bold;
color: var(--primary-color);
font-size: 18px;
font-weight: 700;
color: #fff;
display: flex;
align-items: center;
gap: 10px;
}
/* 装饰性Tag */
.plugin-tag {
font-size: 10px;
background: rgba(99, 102, 241, 0.2);
color: #818cf8;
padding: 2px 6px;
border-radius: 4px;
font-weight: 600;
text-transform: uppercase;
}
.plugin-desc {
color: var(--secondary-text);
margin-bottom: 15px;
font-size: 13px;
color: var(--text-desc);
line-height: 1.5;
margin-top: 4px;
}
.plugin-usage {
background-color: #f8f9fa;
padding: 10px;
border-radius: 6px;
font-family: 'Consolas', monospace;
font-size: 0.9em;
color: #d63384;
border: 1px solid #e9ecef;
/* 指令代码块 - 核心修改区域 */
.cmd-block {
background: var(--cmd-bg);
border-radius: 8px;
padding: 16px;
border: 1px solid var(--border-color);
font-family: 'JetBrains Mono', monospace;
font-size: 13px;
line-height: 1.6;
color: var(--text-cmd);
/* 处理长文本的关键 CSS */
white-space: pre-wrap; /* 保留换行符,且允许自动换行 */
word-wrap: break-word; /* 允许长单词换行 */
overflow-wrap: break-word; /* 标准写法 */
word-break: break-word; /* 兼容性写法 */
}
/* 模拟终端提示符 */
.cmd-block::before {
content: '$ ';
color: #64748b;
user-select: none;
}
/* 页脚 */
.footer {
text-align: center;
margin-top: 30px;
color: var(--secondary-text);
font-size: 0.8em;
padding: 20px 32px;
border-top: 1px solid var(--border-color);
color: rgba(255, 255, 255, 0.2);
font-size: 12px;
text-align: right;
background: rgba(0,0,0,0.1);
}
</style>
</head>
<body>
<div class="container">
<div class="window">
<!-- 窗口栏 -->
<div class="header">
<h1>NeoBot</h1>
<p>功能插件列表</p>
<div class="dots">
<div class="dot red"></div>
<div class="dot yellow"></div>
<div class="dot green"></div>
</div>
<div class="title">NeoBot System</div>
</div>
<div class="plugin-list">
<div class="content">
<!-- 标题 -->
<div class="page-title">
<h1>功能中心</h1>
<p>Dashboard & Command List · {{ plugins|length }} Modules Loaded</p>
</div>
<!-- 插件列表 - 单列流式布局 -->
{% for plugin in plugins %}
<div class="plugin-card">
<div class="plugin-header">
<span class="plugin-name">{{ plugin.name }}</span>
<div class="card-top">
<div class="plugin-name">
{{ plugin.name }}
<span class="plugin-tag">Plugin</span>
</div>
<div class="plugin-desc">{{ plugin.description }}</div>
<div class="plugin-usage">
{{ plugin.usage }}
<div class="plugin-desc">
{{ plugin.description }}
</div>
</div>
<!-- 代码块:宽度占满容器,高度自适应 -->
<div class="cmd-block">{{ plugin.usage }}</div>
</div>
{% endfor %}
</div>
<div class="footer">
Generated by NeoBot • Playwright Rendering
Generated by NeoBot Render Engine
</div>
</div>
</body>