Files
my-project/config/openclaw/scripts/sleep-detector.sh
T

43 lines
824 B
Bash
Executable File

#!/bin/bash
# 检测用户是否在睡觉(1小时无对话)
LAST_ACTIVE_FILE="/tmp/openclaw-last-active.txt"
THRESHOLD_MINUTES=60
# 更新最后活动时间
update_active() {
date +%s > "$LAST_ACTIVE_FILE"
}
# 检查是否在睡眠(超过阈值无活动)
check_sleep() {
if [ ! -f "$LAST_ACTIVE_FILE" ]; then
# 首次运行,初始化
update_active
return 1
fi
last_active=$(cat "$LAST_ACTIVE_FILE")
now=$(date +%s)
diff=$(( (now - last_active) / 60 ))
if [ $diff -ge $THRESHOLD_MINUTES ]; then
return 0 # 在睡眠
else
return 1 # 醒着
fi
}
# 主逻辑
case "$1" in
"update")
update_active
;;
"check")
check_sleep
;;
*)
echo "Usage: $0 {update|check}"
;;
esac