diff --git a/bashbot.sh b/bashbot.sh index 92d089e..b21bfd0 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.99-dev2-12-g2dc1f38 +#### $$VERSION$$ v0.99-dev2-13-g1952610 # # Exit Codes: # - 0 success (hopefully) @@ -381,7 +381,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then [ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl" # simple curl or wget call, output to stdout 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 "${BASHBOT_CURL}" -sL -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" "$1" } @@ -389,7 +389,8 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then sendJson(){ local chat=""; [ -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 res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\ -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() { [ "$#" -lt 4 ] && return 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 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 )" @@ -416,7 +418,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then else # simple curl or wget call outputs result to stdout 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 wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - "$1" } @@ -424,7 +426,8 @@ else sendJson(){ local chat=""; [ -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 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 )"