From b01e3e91b6c9a51eeaef8223a20182ed35e25ec6 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 9 Jun 2020 09:15:36 +0200 Subject: [PATCH] prepare for release, start cleanup and optimizing --- bashbot.sh | 19 ++++++++++--------- modules/background.sh | 8 ++++---- modules/jsonDB.sh | 12 ++++++------ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 5394146..ed7c527 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-dev3-27-g78c066e +#### $$VERSION$$ v0.96-pre-0-geb49241 # # Exit Codes: # - 0 sucess (hopefully) @@ -361,7 +361,7 @@ else sendJsonResult "${res}" "sendJson (wget)" "$@" } 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" [ "${SOURCE}" != "yes" ] && [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" & } @@ -380,7 +380,7 @@ sendJsonRetry(){ sendUpload "$@" ;; *) - printf '%s: SendJsonRetry: unknown, cannot retry %s' "$(date)" "${retry}" >>"${ERRORLOG}" + printf "%s: SendJsonRetry: unknown, cannot retry %s\n" "$(date)" "${retry}" >>"${ERRORLOG}" ;; esac } @@ -416,7 +416,7 @@ sendJsonResult(){ # throttled, telegram say we send to much messages if [ -n "${BOTSENT[RETRY]}" ]; then 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}" unset BOTSEND_RETRY return @@ -425,20 +425,20 @@ sendJsonResult(){ if [ "${BOTSENT[ERROR]}" == "999" ];then # check if default curl and args are OK 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 if _exec_if_function bashbotBlockRecover; then BOTSEND_RETRY="2" - echo "Function bashbotBlockRecover returned true, retry ${2}." + printf "Function bashbotBlockRecover returned true, retry %s.\n" "${2}" sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}" unset BOTSEND_RETRY fi return 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 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}" unset BASHBOT_CURL BASHBOT_CURL_ARGS sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}" @@ -465,7 +465,7 @@ title2Json(){ [ -n "$3" ] && desc=',"description":"'$(JsonEscape "$3")'"' [ -n "$4" ] && markup=',"parse_mode":"'$(JsonEscape "$4")'"' [ -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 @@ -483,6 +483,7 @@ JsonDecode() { remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}" out="${BASH_REMATCH[1]}" done + # this echo must stay for correct decoding! echo -e "${out}${remain}" } diff --git a/modules/background.sh b/modules/background.sh index e624bca..4bc93d3 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -5,7 +5,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-0-geb49241 # source from commands.sh if you want ro use interactive or background jobs @@ -130,16 +130,16 @@ job_control() { fifo="$(procname "${CHAT}" "${job}")" case "$1" in "resumeb"*|"backgr"*) - echo "Restart Job: ${proc} ${fifo}" + printf "Restart Job: %s %s\n" "${proc}" " ${fifo}" restart_back "${CHAT}" "${proc}" "${job}" ;; "suspendb"*) - echo "Suspend Job: ${proc} ${fifo}" + printf "Suspend Job: %s %s\n" "${proc}" " ${fifo}" kill_proc "${CHAT}" "${job}" killall="y" ;; "killb"*) - echo "Kill Job: ${proc} ${fifo}" + printf "Kill Job: %s %s\n" "${proc}" " ${fifo}" kill_proc "${CHAT}" "${job}" rm -f "${FILE}" # remove job killall="y" diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index a77189e..8da70b4 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,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-20-gbd22e2a +#### $$VERSION$$ v0.96-pre-0-geb49241 # # source from commands.sh to use jsonDB functions # @@ -130,7 +130,7 @@ if _exists flock; then { flock -s -w 1 200 Json2Array "oldARR" <"${DB}" } 200>"${DB}${BASHBOT_LOCKNAME}" - echo "${oldARR["$1"]}" + printf '%f' "${oldARR["$1"]}" } @@ -208,8 +208,8 @@ jssh_newDB_async() { jssh_newDB "$@"; } jssh_newDB() { local DB; DB="$(jssh_checkDB "$1")" [ -z "${DB}" ] && return 1 - [ -f "${DB}" ] && return 2 # already exist, do not zero out - printf '' >"${DB}" + [ -f "${DB}" ] && return 2 # already exist + touch "${DB}" } # $1 filename, check filename, it must be relative to BASHBOT_VAR, and not contain '..' @@ -224,7 +224,7 @@ jssh_checkDB(){ else DB="${BASHBOT_VAR:-.}/$1.jssh" fi - printf '%s\n' "${DB}" + printf '%s' "${DB}" } @@ -290,7 +290,7 @@ jssh_getKeyDB_async() { local DB; DB="$(jssh_checkDB "$2")" declare -A oldARR Json2Array "oldARR" <"${DB}" - echo "${oldARR["$1"]}" + printf '%s' "${oldARR["$1"]}" } jssh_countKeyDB_async() {