# shellcheck shell=sh disable=SC2154,SC2120,SC3043

___x_cmd_discord___curl(){
    ___x_cmd curl -sS "$@"
}

___x_cmd_discord_bot___send_json() {
    local req_json ; req_json="$(___x_cmd_cmds_cat)"
    discord:debug "$(printf "%s" "$req_json" | ___x_cmd jo fmt)"

    [ -n "$webhook" ] || {
        local webhook
        ___x_cmd_discord_cur webhook:= 2>/dev/null
        [ -n "$webhook" ] || N=discord M="Please setting up your webhook first ==> 'x discord --cfg webhook=<your webhook url>'" log:ret:1
    }

    local proxy
    ___x_cmd_discord_cur proxy:= 2>/dev/null

    ___x_cmd curl -X POST ${proxy:+-x} ${proxy:+"$proxy"}   \
                  -H 'Content-Type: application/json'       \
                  -d "$req_json"                            \
                  "$webhook?wait=true"
}

___x_cmd_discord_bot___send_file() {
    local file_path="$1"
    [ -n "$webhook" ] || {
        local webhook
        ___x_cmd_discord_cur webhook:= 2>/dev/null
        [ -n "$webhook" ] || N=discord M="Please setting up your webhook first ==> 'x discord --cfg webhook=<your webhook url>'" log:ret:1
    }

    local proxy
    ___x_cmd_discord_cur proxy:= 2>/dev/null

    [ -f "$file_path" ] || N=discord M="File not found ==> $file_path" log:ret:1
    ___x_cmd curl -X POST ${proxy:+-x} ${proxy:+"$proxy"}   \
                    -H 'Content-Type:multipart/form-data'   \
                    -F "file=@${file_path}"                         \
                    "$webhook"
}
