Add files via upload
This commit is contained in:
222
Xbox-bot使用教程.md
Normal file
222
Xbox-bot使用教程.md
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
# Xbox Bot 部署手册
|
||||||
|
|
||||||
|
## 架构概览
|
||||||
|
|
||||||
|
```
|
||||||
|
Telegram / Surge 脚本
|
||||||
|
↓
|
||||||
|
Cloudflare Worker(故障转移)
|
||||||
|
/ \
|
||||||
|
服务器 A 服务器 B
|
||||||
|
locvps tkarm1
|
||||||
|
(主) (备)
|
||||||
|
\ /
|
||||||
|
Redis Cloud(共享数据)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、文件清单
|
||||||
|
|
||||||
|
| 文件 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| `server.js` | Bot 主程序 |
|
||||||
|
| `package.json` | Node.js 依赖 |
|
||||||
|
| `Dockerfile` | Docker 镜像构建 |
|
||||||
|
| `docker-compose.yml` | 容器编排(含 Redis,迁移到 Redis Cloud 后 Redis 容器可移除) |
|
||||||
|
| `.env` | 环境变量配置 |
|
||||||
|
| `worker.js` | Cloudflare Worker 故障转移脚本 |
|
||||||
|
| `NewAddToCart_Web.js` | Surge 加购脚本(GitHub) |
|
||||||
|
| `SyncXboxCloud.js` | Surge 同步脚本(GitHub) |
|
||||||
|
| `XboxWebController.sgmodule` | Surge 模块(GitHub) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、Redis Cloud 配置
|
||||||
|
|
||||||
|
### 创建数据库
|
||||||
|
1. 注册 [Redis Cloud](https://redis.io/try-free/)
|
||||||
|
2. 创建免费数据库:**GCP + AP East (Hong Kong)**
|
||||||
|
3. 进入数据库详情 → Configuration
|
||||||
|
4. 获取 **Public endpoint** 和 **Default user password**
|
||||||
|
5. 拼接连接地址:
|
||||||
|
```
|
||||||
|
redis://default:密码@redis-xxxxx.c1.ap-east-1-1.ec2.redns.redis-cloud.com:端口
|
||||||
|
```
|
||||||
|
|
||||||
|
### 测试连接
|
||||||
|
```bash
|
||||||
|
docker run --rm redis redis-cli -u "redis://default:密码@地址:端口" ping
|
||||||
|
# 返回 PONG 即成功
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、服务器部署(A 和 B 步骤相同)
|
||||||
|
|
||||||
|
### 1. 上传文件
|
||||||
|
```bash
|
||||||
|
scp server.js package.json Dockerfile docker-compose.yml .env \
|
||||||
|
user@服务器IP:/opt/1panel/apps/xbox-bot/
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 配置 .env
|
||||||
|
```env
|
||||||
|
BOT_TOKEN=8755879992:AAFLp9ZSD-n6ynT9X9pwyVTB1MN43H3AZNw
|
||||||
|
ALLOWED_USER_ID=1732587552
|
||||||
|
VIEW_TOKEN=xbox123
|
||||||
|
WEBHOOK_SECRET=
|
||||||
|
REDIS_URL=redis://default:密码@redis-xxxxx地址:端口 # ← Redis Cloud 地址
|
||||||
|
PORT=3000
|
||||||
|
```
|
||||||
|
|
||||||
|
> ⚠️ 两台服务器的 REDIS_URL 必须指向同一个 Redis Cloud 实例
|
||||||
|
|
||||||
|
### 3. 启动服务
|
||||||
|
```bash
|
||||||
|
cd /opt/1panel/apps/xbox-bot
|
||||||
|
docker compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 查看日志
|
||||||
|
```bash
|
||||||
|
docker compose logs -f bot
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、1Panel 反向代理配置
|
||||||
|
|
||||||
|
两台服务器都需要配置,将域名流量转发到 bot 的 3000 端口。
|
||||||
|
|
||||||
|
### 服务器 A(locvps)
|
||||||
|
- 域名:`locvps.dragonisheep.com`
|
||||||
|
- 类型:反向代理
|
||||||
|
- 代理地址:`http://127.0.0.1:3000`
|
||||||
|
|
||||||
|
### 服务器 B(tkarm1)
|
||||||
|
- 域名:`tkarm1xboxbot.dragonisheep.com`
|
||||||
|
- 类型:反向代理
|
||||||
|
- 代理地址:`http://127.0.0.1:3000`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、Cloudflare Worker 部署
|
||||||
|
|
||||||
|
### 1. 修改 worker.js
|
||||||
|
```js
|
||||||
|
const SERVER_A = 'https://locvps.dragonisheep.com'; // 主服务器
|
||||||
|
const SERVER_B = 'https://tkarm1xboxbot.dragonisheep.com'; // 备用服务器
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 部署
|
||||||
|
1. 登录 [Cloudflare Dashboard](https://dash.cloudflare.com)
|
||||||
|
2. Workers & Pages → Create Application → Create Worker
|
||||||
|
3. 粘贴 `worker.js` 内容 → 部署
|
||||||
|
4. 记录 Worker 地址,如 `xbox-bot.yourname.workers.dev`
|
||||||
|
5. 可在 Worker 设置里绑定自定义域名
|
||||||
|
|
||||||
|
### 3. 设置 Telegram Webhook
|
||||||
|
```bash
|
||||||
|
curl "https://api.telegram.org/bot8755879992:AAFLp9ZSD-n6ynT9X9pwyVTB1MN43H3AZNw/setWebhook?url=https://Worker地址/webhook"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 验证 Webhook
|
||||||
|
```bash
|
||||||
|
curl "https://api.telegram.org/bot8755879992:AAFLp9ZSD-n6ynT9X9pwyVTB1MN43H3AZNw/getWebhookInfo"
|
||||||
|
# 确认 url 字段是 Worker 地址,last_error_message 为空
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 六、Surge 脚本配置
|
||||||
|
|
||||||
|
> 脚本托管在 GitHub,修改后推送即可自动生效。
|
||||||
|
|
||||||
|
### NewAddToCart_Web.js
|
||||||
|
```js
|
||||||
|
const REMOTE_READ_URL = 'https://Worker地址/surge?token=xbox123';
|
||||||
|
const REMOTE_COMMIT_URL = 'https://Worker地址/surge/commit?token=xbox123';
|
||||||
|
```
|
||||||
|
|
||||||
|
### SyncXboxCloud.js
|
||||||
|
```js
|
||||||
|
const readUrl = 'https://Worker地址/surge?token=xbox123';
|
||||||
|
const commitUrl = 'https://Worker地址/surge/commit?token=xbox123';
|
||||||
|
```
|
||||||
|
|
||||||
|
### XboxWebController.sgmodule
|
||||||
|
无需修改,脚本地址已指向 GitHub raw 链接。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 七、BotFather 指令设置
|
||||||
|
|
||||||
|
发送给 @BotFather → `/setcommands` → 粘贴:
|
||||||
|
|
||||||
|
```
|
||||||
|
run - 执行链接队列解析
|
||||||
|
us - 获取队列链接的美区 Surge 参数
|
||||||
|
view_list - 查看待处理链接队列
|
||||||
|
view_product - 查看当前 Surge 分组队列
|
||||||
|
update_product - 覆盖更新 Surge 分组数据
|
||||||
|
force_stop - 强制停止当前执行任务
|
||||||
|
clear - 清空所有队列与记录
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 八、故障排查
|
||||||
|
|
||||||
|
### Bot 无响应
|
||||||
|
```bash
|
||||||
|
# 检查容器状态
|
||||||
|
docker compose ps
|
||||||
|
|
||||||
|
# 查看错误日志
|
||||||
|
docker compose logs --tail=50 bot
|
||||||
|
|
||||||
|
# 检查 Webhook 状态
|
||||||
|
curl "https://api.telegram.org/bot<TOKEN>/getWebhookInfo"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Redis 连接失败
|
||||||
|
```bash
|
||||||
|
# 测试连接
|
||||||
|
docker run --rm redis redis-cli -u "redis://default:密码@地址:端口" ping
|
||||||
|
```
|
||||||
|
|
||||||
|
### 主服务器宕机切换验证
|
||||||
|
访问 Worker 地址的 `/surge?token=xbox123`,能返回 JSON 说明 Worker 正常工作。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 九、日常维护
|
||||||
|
|
||||||
|
### 更新 server.js
|
||||||
|
```bash
|
||||||
|
scp server.js user@服务器IP:/opt/1panel/apps/xbox-bot/server.js
|
||||||
|
cd /opt/1panel/apps/xbox-bot && docker compose up -d --build
|
||||||
|
```
|
||||||
|
> ⚠️ A 和 B 两台服务器都需要更新
|
||||||
|
|
||||||
|
### 更新 Surge 脚本
|
||||||
|
推送到 GitHub 即可,Surge 会自动拉取最新版本。
|
||||||
|
|
||||||
|
### 查看 Redis 用量
|
||||||
|
Redis Cloud Dashboard → 数据库详情 → Memory used
|
||||||
|
> 超过 20MB 时 bot 会在每天凌晨 3 点自动清理旧缓存
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 十、关键配置速查
|
||||||
|
|
||||||
|
| 项目 | 值 |
|
||||||
|
|------|-----|
|
||||||
|
| Bot Token | `8755879992:AAFLp9ZSD-n6ynT9X9pwyVTB1MN43H3AZNw` |
|
||||||
|
| Allowed User ID | `1732587552` |
|
||||||
|
| View Token | `xbox123` |
|
||||||
|
| 服务器 A | `locvps.dragonisheep.com` |
|
||||||
|
| 服务器 B | `tkarm1xboxbot.dragonisheep.com` |
|
||||||
|
| Bot 端口 | `3000` |
|
||||||
|
| Redis Cloud | GCP + AP East (Hong Kong) |
|
||||||
Reference in New Issue
Block a user