From 5642cbcfbf78640ebfd1fbe28c7c3383109f814e Mon Sep 17 00:00:00 2001 From: hotyue Date: Mon, 10 Aug 2026 07:30:24 +0000 Subject: [PATCH] =?UTF-8?q?feat(master):=20=E5=BC=95=E5=85=A5=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E8=BF=BD=E8=B8=AA=E4=B8=8E=E6=8C=87=E4=BB=A4=E6=B0=94?= =?UTF-8?q?=E6=B3=A1=E6=8A=B9=E6=9D=80=E6=9C=BA=E5=88=B6=EF=BC=8C=E5=BD=BB?= =?UTF-8?q?=E5=BA=95=E8=A7=A3=E5=86=B3=E7=BA=AF=E6=96=87=E6=9C=AC=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E8=A7=A6=E5=8F=91=E7=9A=84=E9=9D=A2=E6=9D=BF=E5=A0=86?= =?UTF-8?q?=E7=A7=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- master/tg_master.sh | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/master/tg_master.sh b/master/tg_master.sh index 2b1ccc59..ee3b9306 100755 --- a/master/tg_master.sh +++ b/master/tg_master.sh @@ -60,7 +60,7 @@ render_ui() { local buttons="$4" if [ -n "$msg_id" ]; then - # 1. 尝试物理删除旧面板,实现完美沉底转移 + # 1. 按钮触发:尝试物理删除旧面板,实现完美沉底转移 local del_res=$(curl -s --connect-timeout 5 -m 10 -X POST "https://api.telegram.org/bot${TG_TOKEN}/deleteMessage" \ -d "chat_id=$chat_id" -d "message_id=$msg_id") @@ -70,9 +70,24 @@ render_ui() { -H "Content-Type: application/json" \ -d "{\"chat_id\":\"$chat_id\",\"message_id\":\"$msg_id\",\"reply_markup\":{\"inline_keyboard\":[]}}" > /dev/null fi + else + # 3. [新增] 文本触发 (如输入/start):尝试抹除全局记录的上一个遗留面板 + if [ -f "${MASTER_DIR}/.last_ui_id" ]; then + local last_ui=$(cat "${MASTER_DIR}/.last_ui_id") + curl -s --connect-timeout 5 -m 10 -X POST "https://api.telegram.org/bot${TG_TOKEN}/deleteMessage" \ + -d "chat_id=$chat_id" -d "message_id=$last_ui" > /dev/null + fi + fi + + # 4. 无论如何,在最底部发送全新面板,并捕获最新 message_id 记录下来 + local res=$(curl -s --connect-timeout 5 -m 10 -X POST "https://api.telegram.org/bot${TG_TOKEN}/sendMessage" \ + -H "Content-Type: application/json" \ + -d "{\"chat_id\":\"$chat_id\",\"text\":\"$text\",\"parse_mode\":\"Markdown\",\"reply_markup\":{\"inline_keyboard\":$buttons}}") + + local new_id=$(echo "$res" | jq -r '.result.message_id // empty') + if [ -n "$new_id" ] && [ "$new_id" != "null" ]; then + echo "$new_id" > "${MASTER_DIR}/.last_ui_id" fi - # 3. 无论如何,在最底部发送全新面板,杜绝视线跳跃 - send_ui "$chat_id" "$text" "$buttons" } # [核心重构] 文本沉底重绘引擎 @@ -204,6 +219,10 @@ while true; do # [安全漏洞 #106 修复] 严格区分消息文本与按钮回调源 MSG_TEXT=$(echo "$UPDATE" | jq -r '.message.text // empty') + + # 👇 --- 新增这一行:提取用户的文本气泡 ID --- 👇 + USER_MSG_ID=$(echo "$UPDATE" | jq -r '.message.message_id // empty') + CB_DATA=$(echo "$UPDATE" | jq -r '.callback_query.data // empty') CB_ID=$(echo "$UPDATE" | jq -r '.callback_query.id // empty') MSG_ID=$(echo "$UPDATE" | jq -r '.callback_query.message.message_id // empty') @@ -347,6 +366,13 @@ while true; do # ---------------------------------------------------------- case "$TEXT" in "/start"|"/menu") + # 👇 --- 新增这段逻辑:抹杀用户发送的 /start 文本指令 --- 👇 + if [ -n "$USER_MSG_ID" ] && [ -z "$CB_ID" ]; then + curl -s -X POST "https://api.telegram.org/bot${TG_TOKEN}/deleteMessage" \ + -d "chat_id=$CHAT_ID" -d "message_id=$USER_MSG_ID" > /dev/null + fi + # 👆 ----------------------------------------------------- 👆 + REMOTE_VER=$(curl -s -m 2 "${REPO_RAW_URL}/version.txt" | grep "^MASTER_VERSION=" | cut -d'=' -f2 | tr -d '[:space:]') VER_INFO="当前版本: \`v${MASTER_VERSION}\`"