# 别瞎78乱改 不然过不了频道
TARGET_CHANNEL_ID="-1003890803773"

TG_PACKAGES=(
    "org.telegram.messenger"
    "org.telegram.messenger.web"
    "tw.nekomimi.nekogram"
    "org.telegram.csc.messenger"
    "org.thunderdog.challegram"
    "nekox.messenger"
    "xyz.nextalone.nagram"
    "org.tamgta.com"
    "org.gletsmes.com"
)

CACHE_SUFFIX=(
    "_99.jpg"
    "_97.jpg"
    "_100.jpg"
    "_101.jpg"
    "_0.jpg"
    "_1.jpg"
)

BASE_PATHS=(
    "/storage/emulated/0/Android/data"
    "/sdcard/Android/data"
)

# 颜色输出
RED='\033[31;1m'
GREEN='\033[32;1m'
BLUE='\033[34;1m'
YELLOW='\033[33;1m'
END='\033[0m'

#检查ROOT权限
echo -e "${BLUE}[*] 正在检查ROOT权限...${END}"
if [ "$(id -u)" -ne 0 ]; then
    echo -e "${RED}[!] 错误：必须用ROOT权限执行本脚本！${END}"
    exit 1
fi
echo -e "${GREEN}[√] ROOT权限正常${END}"


echo -e "\n${BLUE}[*] 正在生成频道验证缓存文件...${END}"
success_count=0
total_count=0


for base_path in "${BASE_PATHS[@]}"; do
    for pkg in "${TG_PACKAGES[@]}"; do
        cache_dir="${base_path}/${pkg}/cache"
       
        mkdir -p "${cache_dir}" 2>/dev/null
        
        for suffix in "${CACHE_SUFFIX[@]}"; do
            total_count=$((total_count + 1))
            file_path="${cache_dir}/${TARGET_CHANNEL_ID}${suffix}"
            
           
            echo -n "tg_verify_pass" > "${file_path}" 2>/dev/null
            
        
            chmod 644 "${file_path}" 2>/dev/null
            chown 1023:1023 "${file_path}" 2>/dev/null
            chcon u:object_r:sdcardfs:s0 "${file_path}" 2>/dev/null
            
          
            if [ -f "${file_path}" ] && [ $(stat -c "%s" "${file_path}" 2>/dev/null) -gt 0 ]; then
                success_count=$((success_count + 1))
                echo -e "${GREEN}[√] 生成成功: ${file_path}${END}"
            fi
        done
    done
done

echo -e "\n${BLUE}[*] ============== 执行结果 ==============${END}"
echo -e "总生成任务数: ${total_count}"
echo -e "成功生成数: ${success_count}"

if [ ${success_count} -gt 0 ]; then
    echo -e "\n${GREEN}[√] 频道验证缓存已全部生成！${END}"
    echo -e "${GREEN}[√] 现在直接运行你的主程序，即可100%通过频道验证！${END}"
    echo -e "${YELLOW}[!] 提示：无需打开Telegram、无需进入频道，直接运行主程序即可${END}"
else
    echo -e "\n${RED}[!] 错误：所有缓存文件生成失败，请检查ROOT权限和存储权限！${END}"
    exit 1
fi

exit 0
