feat(help): 重构帮助菜单界面并优化样式
refactor(bili_parser): 修复 API 响应 content-type 问题 fix(command_manager): 添加帮助图片获取的错误处理 docs(deployment): 简化部署文档并移除 JIT 相关内容
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 136 KiB |
@@ -202,17 +202,20 @@ class CommandManager:
|
|||||||
内置的 `/help` 命令的实现。
|
内置的 `/help` 命令的实现。
|
||||||
直接从 Redis 获取缓存的图片。
|
直接从 Redis 获取缓存的图片。
|
||||||
"""
|
"""
|
||||||
# 1. 尝试从 Redis 获取
|
try:
|
||||||
help_pic = await redis_manager.get("neobot:core:help_pic")
|
# 1. 尝试从 Redis 获取
|
||||||
|
|
||||||
if not help_pic:
|
|
||||||
await bot.send(event, "帮助图片缓存缺失,正在重新生成...")
|
|
||||||
await self.sync_help_pic()
|
|
||||||
help_pic = await redis_manager.get("neobot:core:help_pic")
|
help_pic = await redis_manager.get("neobot:core:help_pic")
|
||||||
|
|
||||||
if help_pic:
|
if not help_pic:
|
||||||
await bot.send(event, MessageSegment.image(help_pic))
|
await bot.send(event, "帮助图片缓存缺失,正在重新生成...")
|
||||||
return
|
await self.sync_help_pic()
|
||||||
|
help_pic = await redis_manager.get("neobot:core:help_pic")
|
||||||
|
|
||||||
|
if help_pic:
|
||||||
|
await bot.send(event, MessageSegment.image(help_pic))
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取或生成帮助图片失败: {e}")
|
||||||
|
|
||||||
# 2. 最后的兜底:发送纯文本
|
# 2. 最后的兜底:发送纯文本
|
||||||
help_text = "--- 可用指令列表 ---\n"
|
help_text = "--- 可用指令列表 ---\n"
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ pip install -r requirements.txt
|
|||||||
|
|
||||||
### c. 编译核心模块 (可选,但为获得最佳性能强烈建议)
|
### c. 编译核心模块 (可选,但为获得最佳性能强烈建议)
|
||||||
|
|
||||||
为了最大化性能,我们提供了两层级性能优化方案:
|
为了最大化性能,你可以将项目中的核心 Python 模块编译成 C 语言扩展。这将大幅提升机器人的响应速度和处理效率。
|
||||||
|
|
||||||
#### 1. Mypyc 编译 (AOT - Ahead-of-Time)
|
|
||||||
将核心 Python 模块编译成 C 语言扩展。这将大幅提升机器人的响应速度和处理效率。
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 确保你在虚拟环境中
|
# 确保你在虚拟环境中
|
||||||
@@ -38,16 +35,6 @@ python setup_mypyc.py
|
|||||||
|
|
||||||
> **注意**: 编译产物是平台相关的(例如,在 Windows 上编译的 `.pyd` 文件不能在 Linux 上使用)。因此,**请务必在你最终部署的服务器环境(例如 Linux)上执行此编译步骤**。更多关于 Mypyc 编译的细节,请参考 [性能优化详解](core-concepts/performance.md)。
|
> **注意**: 编译产物是平台相关的(例如,在 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. 使用进程管理器
|
## 2. 使用进程管理器
|
||||||
|
|
||||||
你想直接 `python main.py` 然后关掉 SSH?那机器人也跟着停了。必须用进程管理器来守护它。
|
你想直接 `python main.py` 然后关掉 SSH?那机器人也跟着停了。必须用进程管理器来守护它。
|
||||||
@@ -71,7 +58,6 @@ module.exports = {
|
|||||||
name : "neobot",
|
name : "neobot",
|
||||||
script : "main.py",
|
script : "main.py",
|
||||||
interpreter: "/path/to/your/bot/venv/bin/python", // 指定虚拟环境里的 python
|
interpreter: "/path/to/your/bot/venv/bin/python", // 指定虚拟环境里的 python
|
||||||
args: "-X jit", // 启用 Python 3.14 JIT 编译器
|
|
||||||
max_memory_restart: "500M", // 内存超过 500M 自动重启
|
max_memory_restart: "500M", // 内存超过 500M 自动重启
|
||||||
env: {
|
env: {
|
||||||
"PYTHONUNBUFFERED": "1" // 禁用 python 输出缓冲,日志能实时看
|
"PYTHONUNBUFFERED": "1" // 禁用 python 输出缓冲,日志能实时看
|
||||||
|
|||||||
@@ -126,7 +126,9 @@ async def get_direct_video_url(video_url: str) -> Optional[str]:
|
|||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get(api_url, headers=HEADERS, timeout=10) as response:
|
async with session.get(api_url, headers=HEADERS, timeout=10) as response:
|
||||||
response.raise_for_status()
|
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"):
|
if data.get("code") == 200 and data.get("data"):
|
||||||
return data["data"][0].get("video_url")
|
return data["data"][0].get("video_url")
|
||||||
except (aiohttp.ClientError, json.JSONDecodeError, KeyError, IndexError) as e:
|
except (aiohttp.ClientError, json.JSONDecodeError, KeyError, IndexError) as e:
|
||||||
|
|||||||
@@ -3,131 +3,234 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<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>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
--primary-color: #4a90e2;
|
/* 调整为更深邃、高对比度的配色 */
|
||||||
--bg-color: #f5f7fa;
|
--bg-color: #0f172a; /* 深蓝黑背景 */
|
||||||
--card-bg: #ffffff;
|
--window-bg: rgba(30, 41, 59, 0.85); /* 窗口背景,增加不透明度以提高文字可读性 */
|
||||||
--text-color: #333333;
|
--border-color: rgba(255, 255, 255, 0.08);
|
||||||
--secondary-text: #666666;
|
|
||||||
--border-radius: 12px;
|
--accent: #6366f1; /* 核心强调色 - 靛蓝 */
|
||||||
--shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
--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 {
|
body {
|
||||||
font-family: 'Microsoft YaHei', 'Segoe UI', Roboto, sans-serif;
|
font-family: 'Noto Sans SC', system-ui, sans-serif;
|
||||||
background-color: var(--bg-color);
|
background-color: var(--bg-color);
|
||||||
color: var(--text-color);
|
color: var(--text-title);
|
||||||
margin: 0;
|
/* 居中布局 */
|
||||||
padding: 20px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
padding: 40px;
|
||||||
|
min-height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
/* 窗口容器 */
|
||||||
width: 600px;
|
.window {
|
||||||
background-color: var(--bg-color);
|
width: 800px; /* 稍微收窄一点,更像手机/卡片比例 */
|
||||||
}
|
background: var(--window-bg);
|
||||||
|
backdrop-filter: blur(20px);
|
||||||
.header {
|
-webkit-backdrop-filter: blur(20px);
|
||||||
text-align: center;
|
border-radius: 20px;
|
||||||
margin-bottom: 30px;
|
border: 1px solid var(--border-color);
|
||||||
padding: 20px 0;
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
|
||||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
overflow: hidden;
|
||||||
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 {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 15px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.plugin-card {
|
/* 顶部标题栏 */
|
||||||
background-color: var(--card-bg);
|
.header {
|
||||||
border-radius: var(--border-radius);
|
padding: 24px 32px;
|
||||||
padding: 20px;
|
border-bottom: 1px solid var(--border-color);
|
||||||
box-shadow: var(--shadow);
|
background: rgba(255, 255, 255, 0.02);
|
||||||
transition: transform 0.2s;
|
|
||||||
border-left: 5px solid var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.plugin-header {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
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;
|
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 {
|
.plugin-name {
|
||||||
font-size: 1.2em;
|
font-size: 18px;
|
||||||
font-weight: bold;
|
font-weight: 700;
|
||||||
color: var(--primary-color);
|
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 {
|
.plugin-desc {
|
||||||
color: var(--secondary-text);
|
font-size: 13px;
|
||||||
margin-bottom: 15px;
|
color: var(--text-desc);
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
|
margin-top: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.plugin-usage {
|
/* 指令代码块 - 核心修改区域 */
|
||||||
background-color: #f8f9fa;
|
.cmd-block {
|
||||||
padding: 10px;
|
background: var(--cmd-bg);
|
||||||
border-radius: 6px;
|
border-radius: 8px;
|
||||||
font-family: 'Consolas', monospace;
|
padding: 16px;
|
||||||
font-size: 0.9em;
|
border: 1px solid var(--border-color);
|
||||||
color: #d63384;
|
font-family: 'JetBrains Mono', monospace;
|
||||||
border: 1px solid #e9ecef;
|
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 {
|
.footer {
|
||||||
text-align: center;
|
padding: 20px 32px;
|
||||||
margin-top: 30px;
|
border-top: 1px solid var(--border-color);
|
||||||
color: var(--secondary-text);
|
color: rgba(255, 255, 255, 0.2);
|
||||||
font-size: 0.8em;
|
font-size: 12px;
|
||||||
|
text-align: right;
|
||||||
|
background: rgba(0,0,0,0.1);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="window">
|
||||||
|
<!-- 窗口栏 -->
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h1>NeoBot</h1>
|
<div class="dots">
|
||||||
<p>功能插件列表</p>
|
<div class="dot red"></div>
|
||||||
|
<div class="dot yellow"></div>
|
||||||
|
<div class="dot green"></div>
|
||||||
|
</div>
|
||||||
|
<div class="title">NeoBot System</div>
|
||||||
</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 %}
|
{% for plugin in plugins %}
|
||||||
<div class="plugin-card">
|
<div class="plugin-card">
|
||||||
<div class="plugin-header">
|
<div class="card-top">
|
||||||
<span class="plugin-name">{{ plugin.name }}</span>
|
<div class="plugin-name">
|
||||||
</div>
|
{{ plugin.name }}
|
||||||
<div class="plugin-desc">{{ plugin.description }}</div>
|
<span class="plugin-tag">Plugin</span>
|
||||||
<div class="plugin-usage">
|
</div>
|
||||||
{{ plugin.usage }}
|
<div class="plugin-desc">
|
||||||
|
{{ plugin.description }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 代码块:宽度占满容器,高度自适应 -->
|
||||||
|
<div class="cmd-block">{{ plugin.usage }}</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
Generated by NeoBot • Playwright Rendering
|
Generated by NeoBot Render Engine
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user