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
- Start the background monitor script
- 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:
CODEBLOCK0
Where:
- -
platform: "telegram" or "discord" - INLINECODE1 : Current channel identifier (platform prefix is optional, e.g.,
telegram_123 or 123 both work) - INLINECODE4 ,
token2, ...: Token numbers to monitor
Example:
CODEBLOCK1
Background Execution
Start the monitor as a background process so the agent responds immediately:
CODEBLOCK2
Agent Response
After starting the monitor, respond immediately with:
CODEBLOCK3
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 INLINECODE6
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-monitor
详细描述:
MRC食堂监控
监控MRC食堂订单令牌,并在订单准备好取餐时发送通知。
快速开始
当用户发送包含食堂令牌的命令时:
- 1. 从消息中提取所有令牌编号
- 启动后台监控脚本
- 立即回复确认信息
命令识别
用户可能使用各种前缀发送令牌:
- - mrc 73 或 mrc 73 97 42
- token 73 或 token 73 97
- monitor 73
- check 73(仅单次查询)
启动监控
从用户消息中提取所有数字并启动后台监控:
bash
python3 skills/mrc-monitor/scripts/monitor.py <平台> <频道ID> <令牌1> <令牌2> ...
其中:
- - 平台:telegram 或 discord
- 频道ID:当前频道标识符(平台前缀可选,例如 telegram_123 或 123 均可使用)
- 令牌1、令牌2、...:需要监控的令牌编号
示例:
bash
python3 skills/mrc-monitor/scripts/monitor.py telegram telegram_6046286675 73 97 42
或
python3 skills/mrc-monitor/scripts/monitor.py telegram 6046286675 73 97 42
后台执行
将监控作为后台进程启动,以便代理立即响应:
python
import subprocess
频道ID可以带或不带平台前缀(两者均可)
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)
代理响应
启动监控后,立即回复:
✅ 正在监控令牌:73, 97, 42
每15秒检查一次。
准备好后我会在这里通知您!🍕
单次查询
对于check 73命令,执行一次Firebase查询并返回状态,不启动后台监控。
监控行为
监控脚本:
- - 每15秒轮询Firebase Firestore
- 每次轮询检查所有监控中的令牌
- 当令牌状态变为Ready时发送🍕 订单X已准备好!通知
- 将已通知的令牌从监控列表中移除
- 当所有令牌都通知完毕时自动退出
- 优雅处理错误并重试
- 将所有活动记录到skills/mrc-monitor/logs/monitorYYYYMMDDHHMMSS.log
错误处理
脚本自动处理:
- - 网络超时(最多重试5次)
- HTTP错误(包括速率限制)
- 意外错误(连续5次失败后停止)
- 信号终止(SIGTERM、SIGINT)
发生致命错误时,脚本会在退出前发送通知。
Firebase详情
- - 项目:kanteen-mrc-blr-24cfa
- 集合:orders
- 文档字段:
- studentId(字符串):student-{令牌编号}
- status(字符串):Preparing、Ready、Completed