mirror of
https://github.com/anten-ka/go_warp_pro.git
synced 2026-05-20 15:36:17 +00:00
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:
77
warp.sh
77
warp.sh
@@ -1618,52 +1618,41 @@ bot_daemon() {
|
|||||||
if has_awg_mode && [ -n "$CONTAINER" ]; then awg_load_container_data 2>/dev/null; fi
|
if has_awg_mode && [ -n "$CONTAINER" ]; then awg_load_container_data 2>/dev/null; fi
|
||||||
local offset=0
|
local offset=0
|
||||||
while true; do
|
while true; do
|
||||||
bot_poll_cycle
|
source "$WARP_CONF" 2>/dev/null
|
||||||
done
|
local response
|
||||||
}
|
response=$(curl -s --max-time 35 \
|
||||||
|
"https://api.telegram.org/bot${BOT_TOKEN}/getUpdates?offset=${offset}&timeout=30" 2>/dev/null)
|
||||||
bot_poll_cycle() {
|
[ -z "$response" ] && sleep 2 && continue
|
||||||
source "$WARP_CONF" 2>/dev/null
|
local ok; ok=$(echo "$response" | jq -r '.ok // "false"')
|
||||||
local response
|
[ "$ok" != "true" ] && sleep 5 && continue
|
||||||
response=$(curl -s --max-time 35 \
|
local cnt; cnt=$(echo "$response" | jq '.result | length')
|
||||||
"https://api.telegram.org/bot${BOT_TOKEN}/getUpdates?offset=${offset}&timeout=30" 2>/dev/null)
|
for (( i=0; i<cnt; i++ )); do
|
||||||
[ -z "$response" ] && sleep 2 && return
|
local upd; upd=$(echo "$response" | jq ".result[$i]")
|
||||||
|
local uid; uid=$(echo "$upd" | jq -r '.update_id')
|
||||||
local header
|
offset=$((uid + 1))
|
||||||
header=$(echo "$response" | jq -r '[.ok // "false", (.result | length)] | @tsv' 2>/dev/null) || true
|
local cbd; cbd=$(echo "$upd" | jq -r '.callback_query.data // empty')
|
||||||
local ok cnt
|
if [ -n "$cbd" ]; then
|
||||||
IFS=$'\t' read -r ok cnt <<< "$header"
|
local cbi cci cmi
|
||||||
[ "$ok" != "true" ] && sleep 5 && return
|
cbi=$(echo "$upd" | jq -r '.callback_query.id')
|
||||||
[ "$cnt" -eq 0 ] 2>/dev/null && return
|
cci=$(echo "$upd" | jq -r '.callback_query.message.chat.id')
|
||||||
|
cmi=$(echo "$upd" | jq -r '.callback_query.message.message_id')
|
||||||
local updates_tsv
|
if ! is_bot_admin "$cci"; then tg_answer_cb "$cbi" "Нет доступа" > /dev/null; continue; fi
|
||||||
updates_tsv=$(echo "$response" | jq -r '
|
bot_handle_callback "$cci" "$cmi" "$cbi" "$cbd"
|
||||||
.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"
|
|
||||||
else
|
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
|
||||||
fi
|
done
|
||||||
done <<< "$updates_tsv"
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─── Bot menu (SSH) ──────────────────────────────────────────
|
# ─── Bot menu (SSH) ──────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user