Merge pull request #1143 from sofia-riese/patch-1

refactor(set_bot_tg): replace recursion with while loop
This commit is contained in:
juewuy
2026-01-17 20:09:10 +08:00
committed by GitHub

View File

@@ -192,7 +192,9 @@ set_bot_tg_service(){
fi fi
setconfig bot_tg_service "$bot_tg_service" setconfig bot_tg_service "$bot_tg_service"
} }
set_bot_tg(){
set_bot_tg() {
while true; do
[ -n "$ts_auth_key" ] && ts_auth_key_info='已设置' [ -n "$ts_auth_key" ] && ts_auth_key_info='已设置'
[ -n "$TG_CHATID" ] && TG_CHATID_info='已绑定' [ -n "$TG_CHATID" ] && TG_CHATID_info='已绑定'
echo "-----------------------------------------------" echo "-----------------------------------------------"
@@ -202,36 +204,37 @@ set_bot_tg(){
echo -e " 2 TG-BOT绑定设置 \033[32m$TG_CHATID_info\033[0m" echo -e " 2 TG-BOT绑定设置 \033[32m$TG_CHATID_info\033[0m"
echo -e " 0 返回上级菜单 \033[0m" echo -e " 0 返回上级菜单 \033[0m"
echo "-----------------------------------------------" echo "-----------------------------------------------"
read -p "请输入对应数字 > " num read -pr "请输入对应数字 > " num
case "$num" in case "$num" in
0) ;; "" | 0)
break
;;
1) 1)
. "$GT_CFG_PATH" . "$GT_CFG_PATH"
if [ -n "$TG_CHATID" ];then if [ -n "$TG_CHATID" ]; then
set_bot_tg_service set_bot_tg_service
else else
echo -e "\033[31m请先绑定TG-BOT\033[0m" echo -e "\033[31m请先绑定TG-BOT\033[0m"
fi fi
sleep 1 sleep 1
set_bot_tg
;; ;;
2) 2)
if [ -n "$chat_ID" ] && [ -n "$push_TG" ] && [ "$push_TG" != 'publictoken' ]; then if [ -n "$chat_ID" ] && [ -n "$push_TG" ] && [ "$push_TG" != 'publictoken' ]; then
read -p "检测到已经绑定了TG推送BOT是否直接使用(1/0) > " res read -pr "检测到已经绑定了TG推送BOT是否直接使用(1/0) > " res
if [ "$res" = 1 ]; then if [ "$res" = 1 ]; then
TOKEN="$push_TG" TOKEN="$push_TG"
set_bot_tg_config set_bot_tg_config
set_bot_tg continue
return
fi fi
fi fi
set_bot_tg_init set_bot_tg_init
set_bot_tg
;; ;;
*) *)
errornum errornum
sleep 1
;; ;;
esac esac
done
} }
# 自定义入站 # 自定义入站