Revert bot_daemon to proven working loop (no poll_cycle/TSV), keep multi-admin and config re-source

Made-with: Cursor
This commit is contained in:
anten-ka
2026-03-22 16:38:34 +03:00
parent 9fcee1d985
commit d25da45fcd

77
warp.sh
View File

@@ -1618,52 +1618,41 @@ bot_daemon() {
if has_awg_mode && [ -n "$CONTAINER" ]; then awg_load_container_data 2>/dev/null; fi
local offset=0
while true; do
bot_poll_cycle
done
}
bot_poll_cycle() {
source "$WARP_CONF" 2>/dev/null
local response
response=$(curl -s --max-time 35 \
"https://api.telegram.org/bot${BOT_TOKEN}/getUpdates?offset=${offset}&timeout=30" 2>/dev/null)
[ -z "$response" ] && sleep 2 && return
local header
header=$(echo "$response" | jq -r '[.ok // "false", (.result | length)] | @tsv' 2>/dev/null) || true
local ok cnt
IFS=$'\t' read -r ok cnt <<< "$header"
[ "$ok" != "true" ] && sleep 5 && return
[ "$cnt" -eq 0 ] 2>/dev/null && return
local updates_tsv
updates_tsv=$(echo "$response" | jq -r '
.result[] | [
.update_id,
(.callback_query.data // ""),
(.callback_query.id // ""),
(.callback_query.message.chat.id // ""),
(.callback_query.message.message_id // ""),
(.message.chat.id // ""),
(.message.text // "")
] | @tsv
' 2>/dev/null) || true
while IFS=$'\t' read -r uid cbd cbi cci cmi mci mtx; do
[ -z "$uid" ] && continue
offset=$((uid + 1))
if [ -n "$cbd" ]; then
if ! is_bot_admin "$cci"; then tg_answer_cb "$cbi" "Нет доступа" > /dev/null; continue; fi
bot_handle_callback "$cci" "$cmi" "$cbi" "$cbd"
elif [ -n "$mci" ] && [ -n "$mtx" ]; then
if ! is_bot_admin "$mci"; then tg_send "$mci" "⛔ Нет доступа.\nChat ID: <code>$mci</code>" "" > /dev/null; continue; fi
if [[ "$mtx" == "/start" || "$mtx" == "/menu" ]]; then
bot_main_menu "$mci"
source "$WARP_CONF" 2>/dev/null
local response
response=$(curl -s --max-time 35 \
"https://api.telegram.org/bot${BOT_TOKEN}/getUpdates?offset=${offset}&timeout=30" 2>/dev/null)
[ -z "$response" ] && sleep 2 && continue
local ok; ok=$(echo "$response" | jq -r '.ok // "false"')
[ "$ok" != "true" ] && sleep 5 && continue
local cnt; cnt=$(echo "$response" | jq '.result | length')
for (( i=0; i<cnt; i++ )); do
local upd; upd=$(echo "$response" | jq ".result[$i]")
local uid; uid=$(echo "$upd" | jq -r '.update_id')
offset=$((uid + 1))
local cbd; cbd=$(echo "$upd" | jq -r '.callback_query.data // empty')
if [ -n "$cbd" ]; then
local cbi cci cmi
cbi=$(echo "$upd" | jq -r '.callback_query.id')
cci=$(echo "$upd" | jq -r '.callback_query.message.chat.id')
cmi=$(echo "$upd" | jq -r '.callback_query.message.message_id')
if ! is_bot_admin "$cci"; then tg_answer_cb "$cbi" "Нет доступа" > /dev/null; continue; fi
bot_handle_callback "$cci" "$cmi" "$cbi" "$cbd"
else
tg_send "$mci" "Используйте /start или /menu" "" > /dev/null
local mci mtx
mci=$(echo "$upd" | jq -r '.message.chat.id // empty')
mtx=$(echo "$upd" | jq -r '.message.text // empty')
if [ -n "$mci" ] && [ -n "$mtx" ]; then
if ! is_bot_admin "$mci"; then tg_send "$mci" "⛔ Нет доступа.\nChat ID: <code>$mci</code>" "" > /dev/null; continue; fi
if [[ "$mtx" == "/start" || "$mtx" == "/menu" ]]; then
bot_main_menu "$mci"
else
tg_send "$mci" "Используйте /start или /menu" "" > /dev/null
fi
fi
fi
fi
done <<< "$updates_tsv"
done
done
}
# ─── Bot menu (SSH) ──────────────────────────────────────────