From 81c87718988bfb1f8da6c2a862298ad0aa0879d4 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 11 Jun 2020 08:33:59 +0200 Subject: [PATCH] enable retry by default --- bashbot.sh | 26 +++++++++++++------------- commands.sh | 6 ++++-- mycommands.sh | 10 +++++----- mycommands.sh.clean | 10 +++++----- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 3723102..9301f0a 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.96-pre-34-gf968c8b +#### $$VERSION$$ v0.96-pre-35-g2bc8f39 # # Exit Codes: # - 0 sucess (hopefully) @@ -205,7 +205,7 @@ fi ################## # here we start with the real stuff -BOTSEND_RETRY="no" # do not retry by default +BASHBOT_RETRY="" # retry by default URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}" ME_URL=$URL'/getMe' @@ -404,15 +404,15 @@ sendJsonResult(){ 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:0:60}" # warm path, do not retry on error, also if we use wegt - [ -n "${BOTSEND_RETRY}${BASHBOT_WGET}" ] && return + [ -n "${BASHBOT_RETRY}${BASHBOT_WGET}" ] && return # OK, we can retry sendJson, let's see what's failed # throttled, telegram say we send to much messages if [ -n "${BOTSENT[RETRY]}" ]; then - BOTSEND_RETRY="$(( BOTSENT[RETRY]++ ))" - printf "Retry %s in %s seconds ...\n" "${2}" "${BOTSEND_RETRY}" - sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:3}" - unset BOTSEND_RETRY + BASHBOT_RETRY="$(( BOTSENT[RETRY]++ ))" + printf "Retry %s in %s seconds ...\n" "${2}" "${BASHBOT_RETRY}" + sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}" + unset BASHBOT_RETRY return fi # timeout, failed connection or blocked @@ -422,10 +422,10 @@ sendJsonResult(){ printf "%s: BASHBOT IP Adress is blocked!\n" "$(date)" # user provided function to recover or notify block if _exec_if_function bashbotBlockRecover; then - BOTSEND_RETRY="2" + BASHBOT_RETRY="2" printf "bashbotBlockRecover returned true, retry %s ...\n" "${2}" - sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:3}" - unset BOTSEND_RETRY + sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}" + unset BASHBOT_RETRY fi return fi @@ -433,9 +433,9 @@ sendJsonResult(){ if [ -n "${BASHBOT_CURL_ARGS}" ] || [ "${BASHBOT_CURL}" != "curl" ]; then printf "Problem with \"%s %s\"? retry %s with default config ...\n"\ "${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "${2}" - BOTSEND_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS="" - sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:3}" - unset BOTSEND_RETRY + BASHBOT_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS="" + sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}" + unset BASHBOT_RETRY fi fi fi diff --git a/commands.sh b/commands.sh index 5628a99..ca23cdc 100644 --- a/commands.sh +++ b/commands.sh @@ -15,7 +15,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.96-dev3-12-g3f85134 +#### $$VERSION$$ v0.96-pre-35-g2bc8f39 # # adjust your language setting here, e.g.when run from other user or cron. @@ -38,7 +38,9 @@ It currently can send, recieve and forward messages, custom keyboards, photos, a # # this file *MUST* not edited! # copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there -bashbot_help='*Available commands*: +bashbot_help='Place your own commands and messages in mycommands.sh + +*Available commands*: *• /start*: _Start bot and get this message_. *• /help*: _Get this message_. *• /info*: _Get shorter info message about this bot_. diff --git a/mycommands.sh b/mycommands.sh index 1cf5dd4..8a9f34a 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -8,7 +8,7 @@ # #### if you start to develop your own bot, use the clean version of this file: # #### mycommands.clean # -#### $$VERSION$$ v0.96-pre-13-ga71d68e +#### $$VERSION$$ v0.96-pre-35-g2bc8f39 # # uncomment the following lines to overwrite info and help messages @@ -29,10 +29,10 @@ export FILE_REGEX="${BASHBOT_ETC}/.*" # example: run bashbot over TOR # export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050" -# unset BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling -# see logs/ERROR.log for information why send_messages etc. fail -export BOTSEND_RETRY="no" -#unset BOTSEND_RETRY +# set BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling +# problems with send_,´message etc are looged to logs/ERROR.log +unset BASHBOT_RETRY +#export BASHBOT_RETRY="yes" # set value for adaptive sleeping while waitingnfor uodates in millisconds # max slepp between polling updates 10s (default 5s) diff --git a/mycommands.sh.clean b/mycommands.sh.clean index 1902803..a8b2905 100644 --- a/mycommands.sh.clean +++ b/mycommands.sh.clean @@ -4,7 +4,7 @@ # files: mycommands.sh.clean # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.96-pre-13-ga71d68e +#### $$VERSION$$ v0.96-pre-35-g2bc8f39 # ########## @@ -27,10 +27,10 @@ export INLINE="0" # do NOT set to .* as this allow sending files from all locations! export FILE_REGEX="${BASHBOT_ETC}/.*" -# unset BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling -# see logs/ERROR.log for information why send_messages etc. fail -export BOTSEND_RETRY="no" -#unset BOTSEND_RETRY +# set BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling +# problems with send_,´message etc are looged to logs/ERROR.log +unset BASHBOT_RETRY +#export BASHBOT_RETRY="yes" # set value for adaptive sleeping while waitingnfor uodates in millisconds # max slepp between polling updates 10s (default 5s)