prepare for release, start cleanup and optimizing

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2020-06-09 09:15:36 +02:00
parent eb4924122e
commit b01e3e91b6
3 changed files with 20 additions and 19 deletions

View File

@ -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-27-g78c066e #### $$VERSION$$ v0.96-pre-0-geb49241
# #
# Exit Codes: # Exit Codes:
# - 0 sucess (hopefully) # - 0 sucess (hopefully)
@ -361,7 +361,7 @@ else
sendJsonResult "${res}" "sendJson (wget)" "$@" sendJsonResult "${res}" "sendJson (wget)" "$@"
} }
sendUpload() { sendUpload() {
printf "%s: %s\n" "$(date)" "Sorry, wget does not support file upload" >>"${ERRORLOG}" printf "%s: %s\n" "$(date)" "Sorry, wget does not support file upload\n" >>"${ERRORLOG}"
BOTSENT[OK]="false" BOTSENT[OK]="false"
[ "${SOURCE}" != "yes" ] && [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" & [ "${SOURCE}" != "yes" ] && [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" &
} }
@ -380,7 +380,7 @@ sendJsonRetry(){
sendUpload "$@" sendUpload "$@"
;; ;;
*) *)
printf '%s: SendJsonRetry: unknown, cannot retry %s' "$(date)" "${retry}" >>"${ERRORLOG}" printf "%s: SendJsonRetry: unknown, cannot retry %s\n" "$(date)" "${retry}" >>"${ERRORLOG}"
;; ;;
esac esac
} }
@ -416,7 +416,7 @@ sendJsonResult(){
# throttled, telegram say we send to much messages # throttled, telegram say we send to much messages
if [ -n "${BOTSENT[RETRY]}" ]; then if [ -n "${BOTSENT[RETRY]}" ]; then
BOTSEND_RETRY="(( ${BOTSENT[RETRY]} * 15/10 ))" BOTSEND_RETRY="(( ${BOTSENT[RETRY]} * 15/10 ))"
echo "Retry ${2} in ${BOTSEND_RETRY} seconds ..." printf "Retry %s in %s seconds ...\n" "${2}" "${BOTSEND_RETRY}"
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}" sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}"
unset BOTSEND_RETRY unset BOTSEND_RETRY
return return
@ -425,20 +425,20 @@ 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
echo "BASHBOT IP Adress is blocked!" printf "BASHBOT IP Adress is blocked!\n"
# 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"
echo "Function bashbotBlockRecover returned true, retry ${2}." printf "Function bashbotBlockRecover returned true, retry %s.\n" "${2}"
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}" sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}"
unset BOTSEND_RETRY unset BOTSEND_RETRY
fi fi
return return
fi fi
# if we are not blocked, so default curl and args is working # we are not blocked, default curl and args are working
if [ -n "${BASHBOT_CURL_ARGS}" ] || [ -n "${BASHBOT_CURL}" ]; then if [ -n "${BASHBOT_CURL_ARGS}" ] || [ -n "${BASHBOT_CURL}" ]; then
BOTSEND_RETRY="2" BOTSEND_RETRY="2"
printf 'Possible Problem with "%s %s", retry %s with default curl config ...'\ printf "Possible Problem with \"%s %s\", retry %s with default curl config ...\n"\
"${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "${2}" "${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "${2}"
unset BASHBOT_CURL BASHBOT_CURL_ARGS unset BASHBOT_CURL BASHBOT_CURL_ARGS
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}" sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}"
@ -465,7 +465,7 @@ title2Json(){
[ -n "$3" ] && desc=',"description":"'$(JsonEscape "$3")'"' [ -n "$3" ] && desc=',"description":"'$(JsonEscape "$3")'"'
[ -n "$4" ] && markup=',"parse_mode":"'$(JsonEscape "$4")'"' [ -n "$4" ] && markup=',"parse_mode":"'$(JsonEscape "$4")'"'
[ -n "$5" ] && keyboard=',"reply_markup":"'$(JsonEscape "$5")'"' [ -n "$5" ] && keyboard=',"reply_markup":"'$(JsonEscape "$5")'"'
printf "%s\n" "${title}${caption}${desc}${markup}${keyboard}" printf '%s\n' "${title}${caption}${desc}${markup}${keyboard}"
} }
# get bot name # get bot name
@ -483,6 +483,7 @@ JsonDecode() {
remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}" remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}"
out="${BASH_REMATCH[1]}" out="${BASH_REMATCH[1]}"
done done
# this echo must stay for correct decoding!
echo -e "${out}${remain}" echo -e "${out}${remain}"
} }

View File

@ -5,7 +5,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-pre-0-geb49241
# source from commands.sh if you want ro use interactive or background jobs # source from commands.sh if you want ro use interactive or background jobs
@ -130,16 +130,16 @@ job_control() {
fifo="$(procname "${CHAT}" "${job}")" fifo="$(procname "${CHAT}" "${job}")"
case "$1" in case "$1" in
"resumeb"*|"backgr"*) "resumeb"*|"backgr"*)
echo "Restart Job: ${proc} ${fifo}" printf "Restart Job: %s %s\n" "${proc}" " ${fifo}"
restart_back "${CHAT}" "${proc}" "${job}" restart_back "${CHAT}" "${proc}" "${job}"
;; ;;
"suspendb"*) "suspendb"*)
echo "Suspend Job: ${proc} ${fifo}" printf "Suspend Job: %s %s\n" "${proc}" " ${fifo}"
kill_proc "${CHAT}" "${job}" kill_proc "${CHAT}" "${job}"
killall="y" killall="y"
;; ;;
"killb"*) "killb"*)
echo "Kill Job: ${proc} ${fifo}" printf "Kill Job: %s %s\n" "${proc}" " ${fifo}"
kill_proc "${CHAT}" "${job}" kill_proc "${CHAT}" "${job}"
rm -f "${FILE}" # remove job rm -f "${FILE}" # remove job
killall="y" killall="y"

View File

@ -5,7 +5,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-20-gbd22e2a #### $$VERSION$$ v0.96-pre-0-geb49241
# #
# source from commands.sh to use jsonDB functions # source from commands.sh to use jsonDB functions
# #
@ -130,7 +130,7 @@ if _exists flock; then
{ flock -s -w 1 200 { flock -s -w 1 200
Json2Array "oldARR" <"${DB}" Json2Array "oldARR" <"${DB}"
} 200>"${DB}${BASHBOT_LOCKNAME}" } 200>"${DB}${BASHBOT_LOCKNAME}"
echo "${oldARR["$1"]}" printf '%f' "${oldARR["$1"]}"
} }
@ -208,8 +208,8 @@ jssh_newDB_async() { jssh_newDB "$@"; }
jssh_newDB() { jssh_newDB() {
local DB; DB="$(jssh_checkDB "$1")" local DB; DB="$(jssh_checkDB "$1")"
[ -z "${DB}" ] && return 1 [ -z "${DB}" ] && return 1
[ -f "${DB}" ] && return 2 # already exist, do not zero out [ -f "${DB}" ] && return 2 # already exist
printf '' >"${DB}" touch "${DB}"
} }
# $1 filename, check filename, it must be relative to BASHBOT_VAR, and not contain '..' # $1 filename, check filename, it must be relative to BASHBOT_VAR, and not contain '..'
@ -224,7 +224,7 @@ jssh_checkDB(){
else else
DB="${BASHBOT_VAR:-.}/$1.jssh" DB="${BASHBOT_VAR:-.}/$1.jssh"
fi fi
printf '%s\n' "${DB}" printf '%s' "${DB}"
} }
@ -290,7 +290,7 @@ jssh_getKeyDB_async() {
local DB; DB="$(jssh_checkDB "$2")" local DB; DB="$(jssh_checkDB "$2")"
declare -A oldARR declare -A oldARR
Json2Array "oldARR" <"${DB}" Json2Array "oldARR" <"${DB}"
echo "${oldARR["$1"]}" printf '%s' "${oldARR["$1"]}"
} }
jssh_countKeyDB_async() { jssh_countKeyDB_async() {