mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-29 05:02:46 +00:00
get/send Json: output debug messages to DEBUGLOG
This commit is contained in:
parent
1952610282
commit
6e0242368e
15
bashbot.sh
15
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.99-dev2-12-g2dc1f38
|
#### $$VERSION$$ v0.99-dev2-13-g1952610
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 success (hopefully)
|
# - 0 success (hopefully)
|
||||||
@ -381,7 +381,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
|||||||
[ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl"
|
[ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl"
|
||||||
# simple curl or wget call, output to stdout
|
# simple curl or wget call, output to stdout
|
||||||
getJson(){
|
getJson(){
|
||||||
[[ -n "${BASHBOTDEBUG}" && -n "${3}" ]] && printf "%s: getJson (curl) URL=%s\n" "$(date)" "${1##*/}" 1>&2
|
[[ -n "${BASHBOTDEBUG}" && -n "${3}" ]] && printf "%s: getJson (curl) URL=%s\n" "$(date)" "${1##*/}" >>"${DEBUGLOG}"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
"${BASHBOT_CURL}" -sL -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" "$1"
|
"${BASHBOT_CURL}" -sL -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" "$1"
|
||||||
}
|
}
|
||||||
@ -389,7 +389,8 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
|||||||
sendJson(){
|
sendJson(){
|
||||||
local chat="";
|
local chat="";
|
||||||
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
|
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
|
||||||
[ -n "${BASHBOTDEBUG}" ] && printf "%s: sendJson (curl) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" 1>&2
|
[ -n "${BASHBOTDEBUG}" ] &&\
|
||||||
|
printf "%s: sendJson (curl) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${DEBUGLOG}"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
|
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
|
||||||
-d '{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' -X POST "${3}" \
|
-d '{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' -X POST "${3}" \
|
||||||
@ -401,7 +402,8 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
|||||||
sendUpload() {
|
sendUpload() {
|
||||||
[ "$#" -lt 4 ] && return
|
[ "$#" -lt 4 ] && return
|
||||||
if [ -n "$5" ]; then
|
if [ -n "$5" ]; then
|
||||||
[ -n "${BASHBOTDEBUG}" ] && printf "%s: sendUpload CHAT=%s WHAT=%s FILE=%s CAPT=%s\n" "$(date)" "${1}" "${2}" "${3}" "${4}" 1>&2
|
[ -n "${BASHBOTDEBUG}" ] &&\
|
||||||
|
printf "%s: sendUpload CHAT=%s WHAT=%s FILE=%s CAPT=%s\n" "$(date)" "${1}" "${2}" "${3}" "${4}" >>"${DEBUGLOG}"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
|
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
|
||||||
-F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
|
-F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
|
||||||
@ -416,7 +418,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
|||||||
else
|
else
|
||||||
# simple curl or wget call outputs result to stdout
|
# simple curl or wget call outputs result to stdout
|
||||||
getJson(){
|
getJson(){
|
||||||
[[ -n "${BASHBOTDEBUG}" && -z "${3}" ]] && printf "%s: getJson (wget) URL=%s\n" "$(date)" "${1##*/}" 1>&2
|
[[ -n "${BASHBOTDEBUG}" && -z "${3}" ]] && printf "%s: getJson (wget) URL=%s\n" "$(date)" "${1##*/}" >>"${DEBUGLOG}"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - "$1"
|
wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - "$1"
|
||||||
}
|
}
|
||||||
@ -424,7 +426,8 @@ else
|
|||||||
sendJson(){
|
sendJson(){
|
||||||
local chat="";
|
local chat="";
|
||||||
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
|
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
|
||||||
[ -n "${BASHBOTDEBUG}" ] && printf "%s: sendJson (wget) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" 1>&2
|
[ -n "${BASHBOTDEBUG}" ] &&\
|
||||||
|
printf "%s: sendJson (wget) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${DEBUGLOG}"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$(wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - --post-data='{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' \
|
res="$(wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - --post-data='{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' \
|
||||||
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
|
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
|
||||||
|
Loading…
Reference in New Issue
Block a user