mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-31 22:01:46 +00:00
some small error message changes
This commit is contained in:
parent
de21079d2f
commit
f968c8b92d
20
bashbot.sh
20
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-pre-32-gd70656d
|
#### $$VERSION$$ v0.96-pre-33-gde21079
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -367,7 +367,6 @@ sendJsonRetry(){
|
|||||||
case "${retry}" in
|
case "${retry}" in
|
||||||
'sendJson'*)
|
'sendJson'*)
|
||||||
sendJson "$@"
|
sendJson "$@"
|
||||||
|
|
||||||
;;
|
;;
|
||||||
'sendUpload'*)
|
'sendUpload'*)
|
||||||
sendUpload "$@"
|
sendUpload "$@"
|
||||||
@ -388,7 +387,7 @@ sendJsonResult(){
|
|||||||
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${1}")"
|
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${1}")"
|
||||||
if [ "${BOTSENT[OK]}" = "true" ]; then
|
if [ "${BOTSENT[OK]}" = "true" ]; then
|
||||||
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "${1}")"
|
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "${1}")"
|
||||||
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@:2}"
|
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@:3}"
|
||||||
return
|
return
|
||||||
# hot path everthing OK!
|
# hot path everthing OK!
|
||||||
else
|
else
|
||||||
@ -402,7 +401,7 @@ sendJsonResult(){
|
|||||||
BOTSENT[DESCRIPTION]="Timeout or broken/no connection"
|
BOTSENT[DESCRIPTION]="Timeout or broken/no connection"
|
||||||
fi
|
fi
|
||||||
# log error
|
# log error
|
||||||
printf "%s: RESULT=%s FUNC=%s CHAT[ID]=%s ERROR=%s DESC=%s\n=ACTION=%s\n" "$(date)"\
|
printf "%s: RESULT=%s FUNC=%s CHAT[ID]=%s ERROR=%s DESC=%s ACTION=%s\n" "$(date)"\
|
||||||
"${BOTSENT[OK]}" "${2}" "${3}" "${BOTSENT[ERROR]}" "${BOTSENT[DESCRIPTION]}" "${4/[$'\n\r']*}"
|
"${BOTSENT[OK]}" "${2}" "${3}" "${BOTSENT[ERROR]}" "${BOTSENT[DESCRIPTION]}" "${4/[$'\n\r']*}"
|
||||||
# warm path, do not retry on error, also if we use wegt
|
# warm path, do not retry on error, also if we use wegt
|
||||||
[ -n "${BOTSEND_RETRY}${BASHBOT_WGET}" ] && return
|
[ -n "${BOTSEND_RETRY}${BASHBOT_WGET}" ] && return
|
||||||
@ -412,7 +411,7 @@ sendJsonResult(){
|
|||||||
if [ -n "${BOTSENT[RETRY]}" ]; then
|
if [ -n "${BOTSENT[RETRY]}" ]; then
|
||||||
BOTSEND_RETRY="$(( BOTSENT[RETRY]++ ))"
|
BOTSEND_RETRY="$(( BOTSENT[RETRY]++ ))"
|
||||||
printf "Retry %s in %s seconds ...\n" "${2}" "${BOTSEND_RETRY}"
|
printf "Retry %s in %s seconds ...\n" "${2}" "${BOTSEND_RETRY}"
|
||||||
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}"
|
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:3}"
|
||||||
unset BOTSEND_RETRY
|
unset BOTSEND_RETRY
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -420,29 +419,28 @@ sendJsonResult(){
|
|||||||
if [ "${BOTSENT[ERROR]}" == "999" ];then
|
if [ "${BOTSENT[ERROR]}" == "999" ];then
|
||||||
# check if default curl and args are OK
|
# check if default curl and args are OK
|
||||||
if ! curl -sL -k -m 2 "${URL}" >/dev/null 2>&1 ; then
|
if ! curl -sL -k -m 2 "${URL}" >/dev/null 2>&1 ; then
|
||||||
printf "BASHBOT IP Adress is blocked!\n"
|
printf "%s: BASHBOT IP Adress is blocked!\n" "$(date)"
|
||||||
# user provided function to recover or notify block
|
# user provided function to recover or notify block
|
||||||
if _exec_if_function bashbotBlockRecover; then
|
if _exec_if_function bashbotBlockRecover; then
|
||||||
BOTSEND_RETRY="2"
|
BOTSEND_RETRY="2"
|
||||||
printf "Function bashbotBlockRecover returned true, retry %s.\n" "${2}"
|
printf "bashbotBlockRecover returned true, retry %s. ...\n" "${2}"
|
||||||
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}"
|
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:3}"
|
||||||
unset BOTSEND_RETRY
|
unset BOTSEND_RETRY
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
# are not blocked, default curl and args are working
|
# are not blocked, default curl and args are working
|
||||||
if [ -n "${BASHBOT_CURL_ARGS}" ] || [ "${BASHBOT_CURL}" != "curl" ]; then
|
if [ -n "${BASHBOT_CURL_ARGS}" ] || [ "${BASHBOT_CURL}" != "curl" ]; then
|
||||||
printf "Possible Problem with \"%s %s\", retry %s with default curl config ...\n"\
|
printf "Problem with \"%s %s\"? retry %s with default config ...\n"\
|
||||||
"${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "${2}"
|
"${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "${2}"
|
||||||
BOTSEND_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS=""
|
BOTSEND_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS=""
|
||||||
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}"
|
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:3}"
|
||||||
unset BOTSEND_RETRY
|
unset BOTSEND_RETRY
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
} >>"${ERRORLOG}"
|
} >>"${ERRORLOG}"
|
||||||
|
|
||||||
|
|
||||||
# escape / remove text charaters for json strings, eg. " -> \"
|
# escape / remove text charaters for json strings, eg. " -> \"
|
||||||
# $1 string
|
# $1 string
|
||||||
# output escaped string
|
# output escaped string
|
||||||
|
Loading…
Reference in New Issue
Block a user