mrc-monitor

TotalClaw 作者 totalclaw

MRC食堂点餐系统实时令牌监控。监控 Firebase Firestore 的令牌状态并在订单准备就绪时发出通知。当用户发送“mrc 73”、“token 97”或“monitor 42”等命令来监控一个或多个食堂令牌时使用。同时处理多个令牌,为每个令牌发送独立的通知,并在所有令牌准备就绪时自动退出。

安装 / 下载方式

TotalClaw CLI推荐
totalclaw install totalclaw:totalclaw~wysh3-mrc-monitor
cURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~wysh3-mrc-monitor/file -o wysh3-mrc-monitor.md
# MRC Canteen Monitor

Monitor MRC canteen order tokens and notify when they're ready for pickup.

## Quick Start

When user sends any command containing canteen tokens:

1. Extract all token numbers from the message
2. Start the background monitor script
3. Respond immediately with confirmation

## Command Recognition

Users may send tokens with various prefixes:
- "mrc 73" or "mrc 73 97 42"
- "token 73" or "token 73 97"
- "monitor 73"
- "check 73" (one-time check only)

## Starting the Monitor

Extract all numbers from the user message and start the background monitor:

```bash
python3 skills/mrc-monitor/scripts/monitor.py <platform> <channel_id> <token1> <token2> ...
```

Where:
- `platform`: "telegram" or "discord"
- `channel_id`: Current channel identifier (platform prefix is optional, e.g., `telegram_123` or `123` both work)
- `token1`, `token2`, ...: Token numbers to monitor

Example:
```bash
python3 skills/mrc-monitor/scripts/monitor.py telegram telegram_6046286675 73 97 42
# or
python3 skills/mrc-monitor/scripts/monitor.py telegram 6046286675 73 97 42
```

## Background Execution

Start the monitor as a background process so the agent responds immediately:

```python
import subprocess

# channel_id can be with or without platform prefix (both work)
cmd = ['python3', 'skills/mrc-monitor/scripts/monitor.py',
       platform, channel_id] + [str(t) for t in tokens]
subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
```

## Agent Response

After starting the monitor, respond immediately with:

```
✅ Monitoring tokens: 73, 97, 42
Checking every 15 seconds.
I'll notify you here when they're ready! 🍕
```

## One-Time Check

For "check 73" commands, perform a single Firebase query and respond with status without starting a background monitor.

## Monitor Behavior

The monitor script:
- Polls Firebase Firestore every 15 seconds
- Checks all monitored tokens in each poll
- Sends "🍕 Order X is ready!" notification when a token's status is "Ready"
- Removes notified tokens from the watch list
- Exits automatically when all tokens are notified
- Handles errors gracefully with retries
- Logs all activity to `skills/mrc-monitor/logs/monitor_YYYYMMDD_HHMMSS.log`

## Error Handling

The script automatically handles:
- Network timeouts (retries up to 5 times)
- HTTP errors (including rate limits)
- Unexpected errors (stops after 5 consecutive failures)
- Signal termination (SIGTERM, SIGINT)

On fatal errors, the script sends a notification before exiting.

## Firebase Details

- **Project**: kanteen-mrc-blr-24cfa
- **Collection**: orders
- **Document fields**:
  - `studentId` (string): "student-{token_number}"
  - `status` (string): "Preparing", "Ready", "Completed"

---

## 中文说明

# MRC Canteen Monitor

监控 MRC 食堂订单令牌,并在可取餐时发出通知。

## 快速开始

当用户发送任何包含食堂令牌的命令时:

1. 从消息中提取所有令牌号
2. 启动后台监控脚本
3. 立即回复确认

## 命令识别

用户发送令牌时可能带有多种前缀:
- "mrc 73" 或 "mrc 73 97 42"
- "token 73" 或 "token 73 97"
- "monitor 73"
- "check 73"(仅做一次性检查)

## 启动监控

从用户消息中提取所有数字,并启动后台监控:

```bash
python3 skills/mrc-monitor/scripts/monitor.py <platform> <channel_id> <token1> <token2> ...
```

其中:
- `platform`:"telegram" 或 "discord"
- `channel_id`:当前频道标识符(平台前缀可选,例如 `telegram_123` 或 `123` 都可用)
- `token1`, `token2`, ...:要监控的令牌号

示例:
```bash
python3 skills/mrc-monitor/scripts/monitor.py telegram telegram_6046286675 73 97 42
# or
python3 skills/mrc-monitor/scripts/monitor.py telegram 6046286675 73 97 42
```

## 后台执行

将监控作为后台进程启动,以便 agent 能立即回复:

```python
import subprocess

# channel_id can be with or without platform prefix (both work)
cmd = ['python3', 'skills/mrc-monitor/scripts/monitor.py',
       platform, channel_id] + [str(t) for t in tokens]
subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
```

## Agent 回复

启动监控后,立即回复:

```
✅ Monitoring tokens: 73, 97, 42
Checking every 15 seconds.
I'll notify you here when they're ready! 🍕
```

## 一次性检查

对于 "check 73" 命令,执行单次 Firebase 查询并回复状态,不启动后台监控。

## 监控行为

监控脚本会:
- 每 15 秒轮询一次 Firebase Firestore
- 在每次轮询中检查所有被监控的令牌
- 当某个令牌状态为 "Ready" 时发送 "🍕 Order X is ready!" 通知
- 将已通知的令牌从监控列表中移除
- 在所有令牌都已通知后自动退出
- 优雅地处理错误并重试
- 将所有活动记录到 `skills/mrc-monitor/logs/monitor_YYYYMMDD_HHMMSS.log`

## 错误处理

脚本会自动处理:
- 网络超时(最多重试 5 次)
- HTTP 错误(包括速率限制)
- 意外错误(连续失败 5 次后停止)
- 信号终止(SIGTERM、SIGINT)

发生致命错误时,脚本会在退出前发送一条通知。

## Firebase 详情

- **Project**:kanteen-mrc-blr-24cfa
- **Collection**:orders
- **Document fields**:
  - `studentId`(string):"student-{token_number}"
  - `status`(string):"Preparing"、"Ready"、"Completed"