mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2025-02-11 06:28:48 +00:00
make curl location configurable
This commit is contained in:
parent
3fcb8547e8
commit
d11598e082
14
bashbot.sh
14
bashbot.sh
@ -11,7 +11,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
#### $$VERSION$$ v0.96-dev3-15-g3fcb854
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -306,17 +306,19 @@ TIMEOUT="${BASHBOT_TIMEOUT}"
|
|||||||
[[ "$TIMEOUT" =~ ^[0-9]+$ ]] || TIMEOUT="20"
|
[[ "$TIMEOUT" =~ ^[0-9]+$ ]] || TIMEOUT="20"
|
||||||
|
|
||||||
if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
||||||
|
[ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl"
|
||||||
# simple curl or wget call, output to stdout
|
# simple curl or wget call, output to stdout
|
||||||
getJson(){
|
getJson(){
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
curl -sL -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" "$1"
|
"${BASHBOT_CURL}" -sL -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" "$1"
|
||||||
}
|
}
|
||||||
# usage: sendJson "chat" "JSON" "URL"
|
# usage: sendJson "chat" "JSON" "URL"
|
||||||
sendJson(){
|
sendJson(){
|
||||||
local chat="";
|
local chat="";
|
||||||
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
|
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$(curl -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" -d '{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' -X POST "${3}" \
|
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
|
||||||
|
-d '{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' -X POST "${3}" \
|
||||||
-H "Content-Type: application/json" | "${JSONSHFILE}" -s -b -n )"
|
-H "Content-Type: application/json" | "${JSONSHFILE}" -s -b -n )"
|
||||||
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${res}")"
|
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${res}")"
|
||||||
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "${res}")"
|
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "${res}")"
|
||||||
@ -329,10 +331,12 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
|||||||
[ "$#" -lt 4 ] && return
|
[ "$#" -lt 4 ] && return
|
||||||
if [ -n "$5" ]; then
|
if [ -n "$5" ]; then
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$(curl -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1" -F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -s -b -n )"
|
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
|
||||||
|
-F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -s -b -n )"
|
||||||
else
|
else
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$(curl -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1" -F "$2=@$3;${3##*/}" | "${JSONSHFILE}" -s -b -n )"
|
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
|
||||||
|
-F "$2=@$3;${3##*/}" | "${JSONSHFILE}" -s -b -n )"
|
||||||
fi
|
fi
|
||||||
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${res}")"
|
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${res}")"
|
||||||
[ "${SOURCE}" != "yes" ] && [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" &
|
[ "${SOURCE}" != "yes" ] && [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" &
|
||||||
|
Loading…
x
Reference in New Issue
Block a user