chore: initial commit

This commit is contained in:
你的用户名
2025-11-01 21:58:31 +08:00
commit 0406b5664f
101 changed files with 20458 additions and 0 deletions

44
auto_restart_on_error.sh Executable file
View File

@@ -0,0 +1,44 @@
#\!/bin/bash
# 检测连接错误并自动重启机器人
LOG_FILE="logs/auto_restart.log"
ERROR_LOG="logs/integrated_bot_errors.log"
CHECK_MINUTES=10 # 检查最近10分钟的错误
log() {
echo "[$(date "+%Y-%m-%d %H:%M:%S")] $1" | tee -a "$LOG_FILE"
}
# 检查最近的 "Connection lost" 错误
RECENT_ERRORS=$(tail -200 "$ERROR_LOG" 2>/dev/null | grep -c "Connection lost")
if [ "$RECENT_ERRORS" -gt 3 ]; then
log "⚠️ 检测到 $RECENT_ERRORS 个连接丢失错误"
# 检查是否是最近10分钟的错误
TIMESTAMP=$(date -d "$CHECK_MINUTES minutes ago" "+%Y-%m-%d %H:%M" 2>/dev/null || date -v-${CHECK_MINUTES}M "+%Y-%m-%d %H:%M")
VERY_RECENT=$(tail -100 "$ERROR_LOG" 2>/dev/null | grep "Connection lost" | grep "$TIMESTAMP" | wc -l)
if [ "$VERY_RECENT" -gt 2 ]; then
log "❌ 检测到最近的连接错误,准备重启..."
# 重启机器人
./manage_bot.sh restart >> "$LOG_FILE" 2>&1
log "✅ 机器人已重启"
# 等待几秒让它初始化
sleep 10
# 验证是否启动成功
if grep -q "✅ Pyrogram客户端已启动" logs/integrated_bot_detailed.log 2>/dev/null; then
log "✅ Pyrogram 客户端重连成功"
else
log "⚠️ 警告: Pyrogram 客户端状态未知"
fi
else
log "✅ 错误较旧,不需要重启"
fi
else
log "✅ 连接正常,无需操作"
fi