From e64d066db44f8a97130a195cb0793100fc41a531 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Jun 2020 17:24:23 +0200 Subject: [PATCH 01/16] fix argment list on help --- bashbot.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index a3043d1..2998f0a 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-29-gaec4e71 +#### $$VERSION$$ v0.96-pre-30-g769d07d # # Exit Codes: # - 0 sucess (hopefully) @@ -1022,7 +1022,7 @@ if [ "${SOURCE}" != "yes" ]; then ;; *) echo -e "${RED}${REALME}: BAD REQUEST${NC}" - echo -e "${RED}Available arguments: ${GREY}start, stop, kill, status, status, broadcast, help, suspendback, resumeback, killback${NC}" + echo -e "${ORANGE}Available arguments: ${GREY}start, stop, kill, status, stats, broadcast, help, suspendback, resumeback, killback${NC}" exit 4 ;; esac From d70656db68d4c01f15b641638a86fab1586e752a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Jun 2020 17:42:54 +0200 Subject: [PATCH 02/16] make diff tests more stable --- bashbot.sh | 2 +- test/d-process_inline-test.sh | 6 ++- .../d-process_inline-test.result.sort | 5 ++ test/d-process_message-test.sh | 6 ++- .../d-process_message-test.result.sort | 50 +++++++++++++++++++ 5 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 test/d-process_inline-test/d-process_inline-test.result.sort create mode 100644 test/d-process_message-test/d-process_message-test.result.sort diff --git a/bashbot.sh b/bashbot.sh index 2998f0a..9d63932 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-30-g769d07d +#### $$VERSION$$ v0.96-pre-31-ge64d066 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh index 71ebc24..ed7dd74 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-pre-31-ge64d066 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -37,7 +37,9 @@ do # output processed input print_array "iQUERY" >"${OUTPUTFILE}" - diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1 + sort -d -o "${OUTPUTFILE}.sort" "${OUTPUTFILE}" + sort -d -o "${REFFILE}.sort" "${REFFILE}" + diff -c "${REFFILE}.sort" "${OUTPUTFILE}.sort" || exit 1 echo "${SUCCESS}" done diff --git a/test/d-process_inline-test/d-process_inline-test.result.sort b/test/d-process_inline-test/d-process_inline-test.result.sort new file mode 100644 index 0000000..2922977 --- /dev/null +++ b/test/d-process_inline-test/d-process_inline-test.result.sort @@ -0,0 +1,5 @@ +iQUERY: 0 message +iQUERY: FIRST_NAME Kay +iQUERY: LAST_NAME M +iQUERY: USER_ID 123456789 +iQUERY: USERNAME Gnadelwartz diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index fad677e..2e7896f 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-dev3-0-gdddd1ce +#### $$VERSION$$ v0.96-pre-31-ge64d066 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -35,7 +35,9 @@ CHAT[ID]="123456789" # output processed input print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" "SERVICE">"${OUTPUTFILE}" -diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1 +sort -d -o "${OUTPUTFILE}.sort" "${OUTPUTFILE}" +sort -d -o "${REFFILE}.sort" "${REFFILE}" +diff -c "${REFFILE}.sort" "${OUTPUTFILE}.sort" || exit 1 echo "${SUCCESS}" cd "${DIRME}" || exit 1 diff --git a/test/d-process_message-test/d-process_message-test.result.sort b/test/d-process_message-test/d-process_message-test.result.sort new file mode 100644 index 0000000..e940fff --- /dev/null +++ b/test/d-process_message-test/d-process_message-test.result.sort @@ -0,0 +1,50 @@ +CAPTION: 0 +CHAT: ALL_ADMIN +CHAT: ALL_MEMBERS_ARE_ADMINISTRATORS +CHAT: FIRST_NAME Test +CHAT: ID 123456789 +CHAT: LAST_NAME Bot +CHAT: TITLE BotTestTitle +CHAT: TYPE private +CHAT: USERNAME BotTest +CONTACT: FIRST_NAME ADAC +CONTACT: LAST_NAME Pannenhilfe +CONTACT: NUMBER 222222 +CONTACT: USER_ID +CONTACT: VCARD BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD +FORWARD: FIRST_NAME Kay +FORWARD: ID 6541 +FORWARD: LAST_NAME M +FORWARD: UID 123456789 +FORWARD: USERNAME Gnadelwartz +LOCATION: LATITUDE 49.631824 +LOCATION: LONGITUDE 8.377072 +MESSAGE: 0 πŸ˜‚πŸ˜πŸ‘Œβ˜Ίβ€πŸ˜•πŸ˜ˆ#βƒ£πŸŒπŸŽ‰πŸ™ŠπŸ™‰β˜•πŸš€βœˆπŸš‚πŸ’―βœ”γ€½πŸ”š +MESSAGE: ID 6541 +REPLYTO: 0 Ich bin der Deal-O-Mat Bot. FΓΌr eine Liste der Befehle sende /help +REPLYTO: FIRST_NAME dealzbot +REPLYTO: ID 6542 +REPLYTO: LAST_NAME +REPLYTO: UID 987654321 +REPLYTO: USERNAME Deal_O_Mat_bot +SERVICE: 0 yes +SERVICE: LEFTMEMBER 123456789 +SERVICE: NEWMEMBER 123456789 +SERVICE: NEWPHOTO +SERVICE: NEWTILE +SERVICE: PINNED +URLS: AUDIO audio-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +URLS: DOCUMENT document-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +URLS: PHOTO photo-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +URLS: STICKER sticker-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +URLS: VIDEO video-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +URLS: VOICE voice-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +USER: FIRST_NAME Kay +USER: ID 123456789 +USER: LAST_NAME M +USER: USERNAME Gnadelwartz +VENUE: ADDRESS Am Rhein 1 +VENUE: FOURSQUARE 4c4321afce54e21eee980d1a +VENUE: LATITUDE 49.631824 +VENUE: LONGITUDE 8.377072 +VENUE: TITLE Kolb's Biergarten From de21079d2ff993cad0f6950555ec239d17acc82c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Jun 2020 18:07:12 +0200 Subject: [PATCH 03/16] create and use compare_sorted test --- bashbot.sh | 2 +- test/ALL-tests.inc.sh | 11 +++- test/d-process_inline-test.sh | 6 +-- .../d-process_inline-test.result.sort | 5 -- test/d-process_message-test.sh | 6 +-- .../d-process_message-test.result.sort | 50 ------------------- test/d-send_message-test.sh | 7 +-- 7 files changed, 17 insertions(+), 70 deletions(-) delete mode 100644 test/d-process_inline-test/d-process_inline-test.result.sort delete mode 100644 test/d-process_message-test/d-process_message-test.result.sort diff --git a/bashbot.sh b/bashbot.sh index 9d63932..0d9e87d 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-31-ge64d066 +#### $$VERSION$$ v0.96-pre-32-gd70656d # # Exit Codes: # - 0 sucess (hopefully) diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 9d78bd0..ef61510 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-dev3-0-gdddd1ce +#### $$VERSION$$ v0.96-pre-32-gd70656d # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME @@ -49,6 +49,15 @@ print_array() { } +compare_sorted() { + local ret=0 + sort -d -o "${1}.sort" "${1}" + sort -d -o "${2}.sort" "${2}" + diff -c "${1}.sort" "${2}.sort" || ret=1 + rm -f "${1}.sort" "${2}.sort" + return "$ret" +} + ###### # lets go ... echo "Running ${TESTNAME#? } ..." diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh index ed7dd74..8656982 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-pre-31-ge64d066 +#### $$VERSION$$ v0.96-pre-32-gd70656d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -37,9 +37,7 @@ do # output processed input print_array "iQUERY" >"${OUTPUTFILE}" - sort -d -o "${OUTPUTFILE}.sort" "${OUTPUTFILE}" - sort -d -o "${REFFILE}.sort" "${REFFILE}" - diff -c "${REFFILE}.sort" "${OUTPUTFILE}.sort" || exit 1 + compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1 echo "${SUCCESS}" done diff --git a/test/d-process_inline-test/d-process_inline-test.result.sort b/test/d-process_inline-test/d-process_inline-test.result.sort deleted file mode 100644 index 2922977..0000000 --- a/test/d-process_inline-test/d-process_inline-test.result.sort +++ /dev/null @@ -1,5 +0,0 @@ -iQUERY: 0 message -iQUERY: FIRST_NAME Kay -iQUERY: LAST_NAME M -iQUERY: USER_ID 123456789 -iQUERY: USERNAME Gnadelwartz diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 2e7896f..34e69db 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-pre-31-ge64d066 +#### $$VERSION$$ v0.96-pre-32-gd70656d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -35,9 +35,7 @@ CHAT[ID]="123456789" # output processed input print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" "SERVICE">"${OUTPUTFILE}" -sort -d -o "${OUTPUTFILE}.sort" "${OUTPUTFILE}" -sort -d -o "${REFFILE}.sort" "${REFFILE}" -diff -c "${REFFILE}.sort" "${OUTPUTFILE}.sort" || exit 1 +compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1 echo "${SUCCESS}" cd "${DIRME}" || exit 1 diff --git a/test/d-process_message-test/d-process_message-test.result.sort b/test/d-process_message-test/d-process_message-test.result.sort deleted file mode 100644 index e940fff..0000000 --- a/test/d-process_message-test/d-process_message-test.result.sort +++ /dev/null @@ -1,50 +0,0 @@ -CAPTION: 0 -CHAT: ALL_ADMIN -CHAT: ALL_MEMBERS_ARE_ADMINISTRATORS -CHAT: FIRST_NAME Test -CHAT: ID 123456789 -CHAT: LAST_NAME Bot -CHAT: TITLE BotTestTitle -CHAT: TYPE private -CHAT: USERNAME BotTest -CONTACT: FIRST_NAME ADAC -CONTACT: LAST_NAME Pannenhilfe -CONTACT: NUMBER 222222 -CONTACT: USER_ID -CONTACT: VCARD BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD -FORWARD: FIRST_NAME Kay -FORWARD: ID 6541 -FORWARD: LAST_NAME M -FORWARD: UID 123456789 -FORWARD: USERNAME Gnadelwartz -LOCATION: LATITUDE 49.631824 -LOCATION: LONGITUDE 8.377072 -MESSAGE: 0 πŸ˜‚πŸ˜πŸ‘Œβ˜Ίβ€πŸ˜•πŸ˜ˆ#βƒ£πŸŒπŸŽ‰πŸ™ŠπŸ™‰β˜•πŸš€βœˆπŸš‚πŸ’―βœ”γ€½πŸ”š -MESSAGE: ID 6541 -REPLYTO: 0 Ich bin der Deal-O-Mat Bot. FΓΌr eine Liste der Befehle sende /help -REPLYTO: FIRST_NAME dealzbot -REPLYTO: ID 6542 -REPLYTO: LAST_NAME -REPLYTO: UID 987654321 -REPLYTO: USERNAME Deal_O_Mat_bot -SERVICE: 0 yes -SERVICE: LEFTMEMBER 123456789 -SERVICE: NEWMEMBER 123456789 -SERVICE: NEWPHOTO -SERVICE: NEWTILE -SERVICE: PINNED -URLS: AUDIO audio-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa -URLS: DOCUMENT document-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa -URLS: PHOTO photo-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa -URLS: STICKER sticker-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa -URLS: VIDEO video-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa -URLS: VOICE voice-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa -USER: FIRST_NAME Kay -USER: ID 123456789 -USER: LAST_NAME M -USER: USERNAME Gnadelwartz -VENUE: ADDRESS Am Rhein 1 -VENUE: FOURSQUARE 4c4321afce54e21eee980d1a -VENUE: LATITUDE 49.631824 -VENUE: LONGITUDE 8.377072 -VENUE: TITLE Kolb's Biergarten diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index 45a083d..2f87ac9 100755 --- a/test/d-send_message-test.sh +++ b/test/d-send_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-dev3-1-g2a66ee9 +#### $$VERSION$$ v0.96-pre-32-gd70656d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -54,10 +54,7 @@ done < "${INPUTFILE}" 2>>"${LOGFILE}" echo " done." -sort -d -o "${OUTPUTFILE}.sort" "${OUTPUTFILE}" -sort -d -o "${REFFILE}.sort" "${REFFILE}" - -{ diff -c "${REFFILE}.sort" "${OUTPUTFILE}.sort" || exit 1; } | cat -v +{ compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1; } | cat -v rm -f "${REFFILE}.sort" echo " ... all \"send_message\" functions seems to work as expected." From f968c8b92d053b08e2c2333b7449bec2cf2be1e2 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Jun 2020 18:26:51 +0200 Subject: [PATCH 04/16] some small error message changes --- bashbot.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 0d9e87d..6b26816 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-32-gd70656d +#### $$VERSION$$ v0.96-pre-33-gde21079 # # Exit Codes: # - 0 sucess (hopefully) @@ -367,7 +367,6 @@ sendJsonRetry(){ case "${retry}" in 'sendJson'*) sendJson "$@" - ;; 'sendUpload'*) sendUpload "$@" @@ -388,7 +387,7 @@ sendJsonResult(){ BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${1}")" if [ "${BOTSENT[OK]}" = "true" ]; then BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "${1}")" - [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@:2}" + [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@:3}" return # hot path everthing OK! else @@ -402,7 +401,7 @@ sendJsonResult(){ BOTSENT[DESCRIPTION]="Timeout or broken/no connection" fi # 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']*}" # warm path, do not retry on error, also if we use wegt [ -n "${BOTSEND_RETRY}${BASHBOT_WGET}" ] && return @@ -412,7 +411,7 @@ sendJsonResult(){ if [ -n "${BOTSENT[RETRY]}" ]; then BOTSEND_RETRY="$(( BOTSENT[RETRY]++ ))" printf "Retry %s in %s seconds ...\n" "${2}" "${BOTSEND_RETRY}" - sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}" + sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:3}" unset BOTSEND_RETRY return fi @@ -420,29 +419,28 @@ 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 - printf "BASHBOT IP Adress is blocked!\n" + 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" - printf "Function bashbotBlockRecover returned true, retry %s.\n" "${2}" - sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}" + printf "bashbotBlockRecover returned true, retry %s. ...\n" "${2}" + sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:3}" unset BOTSEND_RETRY fi return fi # are not blocked, default curl and args are working 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}" BOTSEND_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS="" - sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}" + sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:3}" unset BOTSEND_RETRY fi fi fi } >>"${ERRORLOG}" - # escape / remove text charaters for json strings, eg. " -> \" # $1 string # output escaped string From 2bc8f398c025a118abaa8265c05db4ef72d90316 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Jun 2020 18:52:26 +0200 Subject: [PATCH 05/16] shorten action in error messages --- bashbot.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 6b26816..3723102 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-33-gde21079 +#### $$VERSION$$ v0.96-pre-34-gf968c8b # # Exit Codes: # - 0 sucess (hopefully) @@ -363,7 +363,7 @@ fi sendJsonRetry(){ local retry="${1}"; shift [[ "${1}" =~ ^\ *[0-9.]+\ *$ ]] && sleep "${1}"; shift - printf "%s: RETRY %s %s %s\n" "$(date)" "${retry}" "${1}" "${2/[$'\n\r']*}" + printf "%s: RETRY %s %s %s\n" "$(date)" "${retry}" "${1}" "${2:0:60}" case "${retry}" in 'sendJson'*) sendJson "$@" @@ -376,7 +376,7 @@ sendJsonRetry(){ return ;; esac - [ "${BOTSENT[OK]}" = "true" ] && printf "%s: Retry OK: %s %s\n" "$(date)" "${retry}" "${1}" + [ "${BOTSENT[OK]}" = "true" ] && printf "%s: Retry OK: %s %s %s\n" "$(date)" "${retry}" "${1}" "${2:0:60}" } >>"${ERRORLOG}" # process sendJson result @@ -402,7 +402,7 @@ sendJsonResult(){ fi # log error 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:0:60}" # warm path, do not retry on error, also if we use wegt [ -n "${BOTSEND_RETRY}${BASHBOT_WGET}" ] && return @@ -423,7 +423,7 @@ sendJsonResult(){ # user provided function to recover or notify block if _exec_if_function bashbotBlockRecover; then BOTSEND_RETRY="2" - printf "bashbotBlockRecover returned true, retry %s. ...\n" "${2}" + printf "bashbotBlockRecover returned true, retry %s ...\n" "${2}" sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:3}" unset BOTSEND_RETRY fi From 81c87718988bfb1f8da6c2a862298ad0aa0879d4 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 11 Jun 2020 08:33:59 +0200 Subject: [PATCH 06/16] 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) From 6c02bab1bd9cb3fad0e4d6bf3faab749e4bc0355 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 11 Jun 2020 09:23:03 +0200 Subject: [PATCH 07/16] document timer tick disabled by default --- addons/antiFlood.sh | 4 +-- addons/example.sh | 4 +-- bashbot.sh | 8 ++--- commands.sh | 4 +-- doc/2_usage.md | 6 ++-- doc/4_expert.md | 6 ++-- doc/6_reference.md | 4 +-- doc/7_develop.md | 74 ++++++++++++++++++++++++--------------------- mycommands.sh | 6 ++-- mycommands.sh.clean | 6 ++-- 10 files changed, 63 insertions(+), 59 deletions(-) diff --git a/addons/antiFlood.sh b/addons/antiFlood.sh index e4a8a3f..87224b9 100644 --- a/addons/antiFlood.sh +++ b/addons/antiFlood.sh @@ -4,12 +4,12 @@ # this addon counts how many files, e.g. stickers, are sent to # a chat and takes actions if threshold is reached # -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-pre-36-g81c8771 # used events: # # BASHBOT_EVENT_TEXT message containing message text received -# BASHBOT_EVENT_CMD a command is recieved +# BASHBOT_EVENT_CMD a command is received # BASHBOT_EVENT_FILE file received # # all global variables and functions can be used in registered functions. diff --git a/addons/example.sh b/addons/example.sh index bb08160..ee22ca2 100644 --- a/addons/example.sh +++ b/addons/example.sh @@ -4,7 +4,7 @@ # Addons can register to bashbot events at statup # by providing their name and a callback per event # -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-pre-36-g81c8771 # # If an event occours each registered event function is called. # @@ -22,7 +22,7 @@ # BASHBOT_EVENT_INLINE inline query received # BASHBOT_EVENT_MESSAGE any type of message received # BASHBOT_EVENT_TEXT message containing message text received -# BASHBOT_EVENT_CMD a command is recieved +# BASHBOT_EVENT_CMD a command is received # BASHBOT_EVENT_REPLYTO reply to message received # BASHBOT_EVENT_FORWARD forwarded message received # BASHBOT_EVENT_CONTACT contact received diff --git a/bashbot.sh b/bashbot.sh index 9301f0a..aa799c0 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-35-g2bc8f39 +#### $$VERSION$$ v0.96-pre-36-g81c8771 # # Exit Codes: # - 0 sucess (hopefully) @@ -669,7 +669,7 @@ process_message() { MESSAGE[0]="$(JsonDecode "${UPD["result",${num},"message","text"]}" | sed 's#\\/#/#g')" MESSAGE[ID]="${UPD["result",${num},"message","message_id"]}" - # Chat ID is now parsed when update isrecieved + # Chat ID is now parsed when update isreceived #CHAT[ID]="${UPD["result",${num},"message","chat","id"]}" CHAT[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","chat","last_name"]}")" CHAT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","chat","first_name"]}")" @@ -679,7 +679,7 @@ process_message() { CHAT[ALL_ADMIN]="${UPD["result",${num},"message","chat","all_members_are_administrators"]}" CHAT[ALL_MEMBERS_ARE_ADMINISTRATORS]="${CHAT[ALL_ADMIN]}" # backward compatibility - # user ID is now parsed when update isrecieved + # user ID is now parsed when update isreceived #USER[ID]="${UPD["result",${num},"message","from","id"]}" USER[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","first_name"]}")" USER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","last_name"]}")" @@ -760,7 +760,7 @@ process_message() { SERVICE[NEWTILE]="${UPD["result",${num},"message","new_chat_title"]}" SERVICE[NEWPHOTO]="${UPD["result",${num},"message","new_chat_photo"]}" SERVICE[PINNED]="${UPD["result",${num},"message","pinned_message"]}" - # set SSERVICE to yes if a service message was recieved + # set SSERVICE to yes if a service message was received [[ "${SERVICE[*]}" =~ ^[[:blank:]]+$ ]] || SERVICE[0]="yes" diff --git a/commands.sh b/commands.sh index ca23cdc..f39cfeb 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-pre-35-g2bc8f39 +#### $$VERSION$$ v0.96-pre-36-g81c8771 # # adjust your language setting here, e.g.when run from other user or cron. @@ -32,7 +32,7 @@ unset IFS # copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there bashbot_info='This is bashbot, the Telegram bot written entirely in bash. It features background tasks and interactive chats, and can serve as an interface for CLI programs. -It currently can send, recieve and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files. +It currently can send, receive and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files. ' # diff --git a/doc/2_usage.md b/doc/2_usage.md index f3df000..ba5f7e8 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -96,7 +96,7 @@ To send a broadcast to all of users that ever used the bot run the following com ---- ## Recieve data -Evertime a Message is recieved, you can read incoming data using the following variables: +Evertime a Message is received, you can read incoming data using the following variables: ### Regular Messages @@ -169,7 +169,7 @@ Evertime a Message is recieved, you can read incoming data using the following v ### Inline queries -Evertime a Message is recieved, you can read incoming data using the following variables: +Evertime a Message is received, you can read incoming data using the following variables: * ```${iQUERY}```: Current inline query * ```$iQUERY```: This array contains the ID, First name, last name, username and user id of the sender of the current inline query. @@ -256,5 +256,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.96-dev3-14-g5fc4d01a +#### $$VERSION$$ v0.96-pre-36-g81c8771 diff --git a/doc/4_expert.md b/doc/4_expert.md index db7e8a7..7428719 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -40,7 +40,7 @@ To display all availible locales on your system run ```locale -a | more```. [Gen #### Bashbot UTF-8 Support Bashbot handles all messages transparently, regardless of the charset in use. The only exception is when converting from JSON data to strings. -Telegram use JSON to send / recieve data. JSON encodes strings as follow: Characters not ASCII *(>127)* are escaped as sequences of ```\uxxxx``` to be regular ASCII. In addition multibyte characters, *e.g. Emoticons or Arabic characters*, are send in double byte UTF-16 notation. +Telegram use JSON to send / receive data. JSON encodes strings as follow: Characters not ASCII *(>127)* are escaped as sequences of ```\uxxxx``` to be regular ASCII. In addition multibyte characters, *e.g. Emoticons or Arabic characters*, are send in double byte UTF-16 notation. The Emoticons ``` 😁 😘 ❀️ 😊 πŸ‘ ``` are encoded as: ``` \uD83D\uDE01 \uD83D\uDE18 \u2764\uFE0F \uD83D\uDE0A \uD83D\uDC4D ``` **This "mixed" JSON encoding needs special handling and can not decoded from** ```echo -e``` or ```printf '%s\\n'``` @@ -326,7 +326,7 @@ BASHBOT_TIMEOUT to a numeric value between 1 and 999. Any non numeric or negativ ##### BASHBOT_SLEEP Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling. -If messages are recieved bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay +If messages are received bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay for every poll until the maximum of BASHBOT_SLEEP ms. ```bash unset BASHBOT_SLEEP # 5000ms (default) @@ -382,5 +382,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Advanced Use](3_advanced.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.96-dev3-17-g720dc59 +#### $$VERSION$$ v0.96-pre-36-g81c8771 diff --git a/doc/6_reference.md b/doc/6_reference.md index bb4338a..10da99d 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -404,7 +404,7 @@ fi ##### start_back Starts a script as a background job and attaches a jobname to it. All output from a background job is sent to the associated chat. -In contrast to interactive chats, background jobs do not recieve user input and can run forever. In addition you can suspend and restart running jobs, e.g. after reboot. +In contrast to interactive chats, background jobs do not receive user input and can run forever. In addition you can suspend and restart running jobs, e.g. after reboot. *usage:* start_back "${CHAT[ID]}" "script" "jobname" @@ -1035,5 +1035,5 @@ The name of your bot is availible as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.96-dev3-5-g407e147 +#### $$VERSION$$ v0.96-pre-36-g81c8771 diff --git a/doc/7_develop.md b/doc/7_develop.md index f8e5751..68de0f3 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -31,7 +31,7 @@ you can the change the level of verbosity of the debug argument: to keep 'bashbot.sh' small, while extending functionality. In addition not every funtion is needed by all bots, so you can disable modules, e.g. by rename the respective module file to 'module.sh.off'. -Modules must use functions provided by 'bahsbot.sh' or the module itself and sould not depend on other modules or addons. +Modules must use only functions provided by 'bahsbot.sh' or the module itself and sould not depend on other modules or addons. The only mandatory module is 'module/sendMessage.sh'. If a not mandatory module is used in 'bashbot.sh' or 'commands.sh', the use of ```_is_function``` or @@ -40,11 +40,11 @@ If a not mandatory module is used in 'bashbot.sh' or 'commands.sh', the use of ` **Addons** resides in ```addons/*.sh.dist``` and are not endabled by default. To activate an addon rename it to end with '.sh', e.g. by ```cp addons/example.sh.dist addons/example.sh```. -Addons must register themself to BASHBOT_EVENTS at startup, e.g. to call a function everytime a message is recieved. +Addons must register themself to BASHBOT_EVENTS at startup, e.g. to call a function everytime a message is received. Addons works similar as 'commands.sh' and 'mycommands.sh' but are much more flexible on when functions/commands are triggered. -Another major difference is: **Addons are executed in the context of the main script**, while 'commands.sh' and 'macommands.sh' are executed as a seperate process. -This is why event functions are time critical and must return as fast as possible. +Another major difference is: **Addons are executed in the context of the main script**, while 'commands.sh' and 'mycommands.sh' are executed new child process on efery execution. +This is why event functions are time critical and must finish as fast as possible. #### Bashbot Events Addons must register functions to bashbot events by providing their name, and internal identifier and a callback function. @@ -54,13 +54,15 @@ Registered functions run in the same process as bashbot, not as a sub process, s Note: For the same reason event function MUST return immediately! Time consuming tasks must be run as a background process, e.g. "long running &" -##### MESSAGE events (all iQuery and/or Message variables are avalible): +##### SEND RECEIVE events + +executed when a Message is received, same iQuery / Message variables are avalible as in commands.sh * BASHBOT_EVENT_INLINE an inline query is received * BASHBOT_EVENT_MESSAGE any of the following message types is received - * BASHBOT_EVENT_TEXT a message containing text is recieved - * BASHBOT_EVENT_CMD a message containing a command is recieved (starts with /) + * BASHBOT_EVENT_TEXT a message containing text is received + * BASHBOT_EVENT_CMD a message containing a command is received (starts with /) * BASHBOT_EVENT_REPLYTO a reply to a message is received * BASHBOT_EVENT_FORWARD a forwarded message is received * BASHBOT_EVENT_CONTACT a contact is received @@ -87,7 +89,35 @@ example_echo() { } ``` -##### Other types of events +* BASHBOT_EVENT_SEND is exceuted if data is send or uploaded to Telegram server + +In contrast to other events, BASHBOT_EVENT_SEND is excecuted in a subshell, so there is no need to spawn +a background process for longer running commands and changes to variables are not persistent! + +BASHBOT_EVENT_SEND is for logging purposes, you must not send messages while processing this event. +To avoid wrong use of EVENT_SEND, e.g. fork bomb, event processing is suspended if recursion is detected. + +*usage*: BASHBOT_EVENT_SEND[ "unique-name" ]="callback" + +"callback" is called with paramter "send" or "upload", followed by the arguments used for 'sendJson' or 'upload' functions. + +*Example:* +```bash +# register callback: +BAHSBOT_EVENT_SEND["example_log","1"]="example_log" +EXAMPLE_LOG="${BASHBOT_ETC:-.}/addons/${EXAMPLE_ME}.log" + +# Note: do not call any send message functions from EVENT_SEND! +example_log(){ + local send="$1"; shift + echo "$(date): Type: ${send} Args: $*" >>"${EXAMPLE_LOG}" +} + +``` + +##### TIMER events + +Important: The timer tick is diabled by default and must be enabled by setting BASHBOT_START_TIMER to any value not zero. * BAHSBOT_EVENT_TIMER executed every minute and can be used in 3 variants: oneshot, once a minute, every X minutes. @@ -129,32 +159,6 @@ BAHSBOT_EVENT_TIMER["example_10min","$(( (EVENT_TIMER+10) * -1 ))"]="example_in1 ``` -* BASHBOT_EVENT_SEND is exceuted if data is send or uploaded to Telegram server - -In contrast to other events, BASHBOT_EVENT_SEND is excecuted in a subshell, so there is no need to spawn -a background process for longer running commands and changes to variables are not persistent! - -BASHBOT_EVENT_SEND is for logging purposes, you must not send messages while processing this event. -To avoid wrong use of EVENT_SEND, e.g. fork bomb, event processing is suspended if recursion is detected. - -*usage*: BASHBOT_EVENT_SEND[ "unique-name" ]="callback" - -"callback" is called with paramter "send" or "upload", followed by the arguments used for 'sendJson' or 'upload' functions. - -*Example:* -```bash -# register callback: -BAHSBOT_EVENT_SEND["example_log","1"]="example_log" -EXAMPLE_LOG="${BASHBOT_ETC:-.}/addons/${EXAMPLE_ME}.log" - -# Note: do not call any send message functions from EVENT_SEND! -example_log(){ - local send="$1"; shift - echo "$(date): Type: ${send} Args: $*" >>"${EXAMPLE_LOG}" -} - -``` - ---- #### Create a stripped down Version of your Bot @@ -332,5 +336,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v0.96-pre-9-gb23aadd +#### $$VERSION$$ v0.96-pre-36-g81c8771 diff --git a/mycommands.sh b/mycommands.sh index 8a9f34a..e39befd 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-35-g2bc8f39 +#### $$VERSION$$ v0.96-pre-36-g81c8771 # # uncomment the following lines to overwrite info and help messages @@ -54,7 +54,7 @@ NOTBOTADMIN="Sorry, this command is allowed for bot owner only" if [ "$1" = "startbot" ];then ################### - # this function is run once after startup when the first message is recieved + # this function is run once after startup when the first message is received my_startup(){ # send message ito first user on startup send_normal_message "${CHAT[ID]}" "Hi, you was the first one after startup!" @@ -72,7 +72,7 @@ else mycommands() { ############## - # a service Message was recieved + # a service Message was received # add your own stuff here if [ -n "${SERVICE}" ]; then diff --git a/mycommands.sh.clean b/mycommands.sh.clean index a8b2905..f6fb58e 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-35-g2bc8f39 +#### $$VERSION$$ v0.96-pre-36-g81c8771 # ########## @@ -53,7 +53,7 @@ export SILENCER="no" # export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1" # regular SOCKS if [ "$1" = "startbot" ];then - # run once after startup when the first message is recieved + # run once after startup when the first message is received my_startup(){ : } @@ -69,7 +69,7 @@ else mycommands() { ############## - # a service Message was recieved + # a service Message was received # add your own stuff here if [ -n "${SERVICE}" ]; then From 15928bd58f6aa38b4168064dac52fc29c4ada55d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 11 Jun 2020 11:00:16 +0200 Subject: [PATCH 08/16] update doc for error processing --- doc/3_advanced.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 1f2bbea..095018a 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -203,8 +203,72 @@ answer_inline_query "${iQUERY[ID]}" "cached_sticker" "identifier for the sticker ``` See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inline_multi) and [mycommands.sh](../mycommands.sh) for more information. + +### Handle send message errors + +Usually the exmaples do not care if an error happen while sending a message, this is because bashbot detects if a message is +not sent and try to recover when possible, e.g. resend on throttling. + +In addition on every transmission to telegram the results are provided as bash in bash variables. + +#### Trasmission results + +**Note**: the values of the variables contains always the result of the LAST transmission to telegram, +everey send action will overwrite them! + +* ```$BOTSENT```: This array contains the parsed results from the last transmission to telegram. + * ```${BOTSENT[OK]}```: contain's the string 'true' after a successful transmission + * ```${BOTSENT[ERROR]}```: Error code if OK is not true + * ```${BOTSENT[DESC]}```: Description text for error + * ```${BOTSENT[RETRY]}```: Seconds to wait ifntelegram requests throtteling. +* ```$res```: temporary variable containing the full transmission result, may be overwritten by any bashbot function. + +By default you don't have to care about retry, as bashbot resend the message after the requested time automatically. +Only if the retry fails also an error is returned. The downside is that send_message functions will wait until resend is done. + +If you want to disbale all automtic error processing and handle all errors manually (or don't care) +set ```BASHBOT_RETRY``` to any no zero value. + +[Telegram API error codes](https://core.telegram.org/api/errors) + + +#### Detect bot blocked + +If the we can't connect to telegram, e.g. blocked from telegram server but also any other reason, +bashbot set ```BOTSENT[ERROR]``` to '999'. + +To get a notification on every connection problem create a function named ```bashbotBlockRecover``` and handle blocks there. +If the function returns true (0 or no value) bashbot will retry once and then return to the calling function. +In case you return any non 0 value bashbot will return to the calling function without retry. + + +```bash + # somewhere in myfunctions.sh ... + MYBLOCKED="0" + + function bashbotBlockRecover() { + # ups, we are blocked! + (( MYBLOCKED++ )) + # log what we gotr + printf "%s: Blocked %d times: %s\n" "$(date)" "${MYBLOCKED}" "$*" >>"${ERRORLOG}" + + if [ "${MYBLOCKED}" -gt 10 ]; then + printf "Permanent problem abort current command: %s\n" "${MESSAGE}">>"${ERRORLOG}" + exit + fi + if do_something_to_unblock; then + # may be we removed block, e.g. changed IP address, try again + return 0 + fi + # do not retry if we cant recover + return 1 + } + +``` + + #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.96-dev3-13-g601fe0e +#### $$VERSION$$ v0.96-pre-37-g6c02bab From b6e9f9ed16df8778b61027708358948338490566 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 11 Jun 2020 11:32:52 +0200 Subject: [PATCH 09/16] log updates received on debug --- bashbot.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index aa799c0..eaa648d 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-36-g81c8771 +#### $$VERSION$$ v0.96-pre-38-g15928bd # # Exit Codes: # - 0 sucess (hopefully) @@ -501,11 +501,15 @@ process_updates() { } process_client() { local num="$1" debug="$2" - CMD=( ); iQUERY=( ) - [[ "${debug}" = *"debug"* ]] && printf "\n%s: New Message ==========\n%s\n" "$(date)" "$UPDATE" >>"${LOGDIR}/MESSAGE.log" + CMD=( ); iQUERY=( ); MESSAGE=() iQUERY[ID]="${UPD["result",${num},"inline_query","id"]}" CHAT[ID]="${UPD["result",${num},"message","chat","id"]}" USER[ID]="${UPD["result",${num},"message","from","id"]}" + # log message on debug + if [[ "${debug}" = *"debug"* ]]; then + printf "%s: update received FROM=%s CHAT=%s iQEUERY=%s\n" "$(date)" "${USER[ID]}" "${CHAT[ID]}" "${iQUERY[ID]}" + printf "\n%s: New Message ==========\n%s\n" "$(date)" "$UPDATE" >>"${LOGDIR}/MESSAGE.log" + fi # check for uers / groups to ignore if [ -n "${USER[ID]}" ]; then From e663979206e002a79a46b1a0162d00179df1a3af Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 11 Jun 2020 12:17:07 +0200 Subject: [PATCH 10/16] improve doc --- README.html | 3 ++- README.md | 3 ++- README.txt | 3 ++- doc/3_advanced.md | 26 +++++++++++++++----------- doc/7_develop.md | 16 +++++++++------- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/README.html b/README.html index 703421c..504bf27 100644 --- a/README.html +++ b/README.html @@ -118,6 +118,7 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadel
  • Interactive Chats
  • Background Jobs
  • Inline queries
  • +
  • Send message errors
  • Expert Use
      @@ -245,6 +246,6 @@ It features background tasks and interactive chats, and can serve as an interfac

      @Gnadelwartz

      That's it!

      If you feel that there's something missing or if you found a bug, feel free to submit a pull request!

      -

      $$VERSION$$ v0.96-pre-13-ga71d68e

      +

      $$VERSION$$ v0.96-pre-39-gb6e9f9e

      diff --git a/README.md b/README.md index 4f481a4..4bd8192 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do * Interactive Chats * Background Jobs * Inline queries + * Send message errors * [Expert Use](doc/4_expert.md) * Handling UTF-8 character sets * Run as other user or system service @@ -218,4 +219,4 @@ This may happen if to many wrong requests are sent to api.telegram.org, e.g. usi If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.96-pre-13-ga71d68e +#### $$VERSION$$ v0.96-pre-39-gb6e9f9e diff --git a/README.txt b/README.txt index c3b5a90..50bf470 100644 --- a/README.txt +++ b/README.txt @@ -50,6 +50,7 @@ availible on www.github.com * Interactive Chats * Background Jobs * Inline queries + * Send message errors * [Expert Use](doc/4_expert.md) * Handling UTF-8 character sets * Run as other user or system service @@ -304,4 +305,4 @@ in 'mycommands.sh' as example. If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.96-pre-13-ga71d68e +#### $$VERSION$$ v0.96-pre-39-gb6e9f9e diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 095018a..6d5213f 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -206,27 +206,30 @@ See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inli ### Handle send message errors -Usually the exmaples do not care if an error happen while sending a message, this is because bashbot detects if a message is -not sent and try to recover when possible, e.g. resend on throttling. +Our examples usually do not care about errors happening while sending a message, this is OK as long your bot does not send an +massive aoumnt of messages. By default bashbot detects if a message is not sent and try to recover when possible, +e.g. resend on throttling. In addtion every send error is logged in logs/ERROR.log -In addition on every transmission to telegram the results are provided as bash in bash variables. #### Trasmission results +On every message send to telgram (transmission) the results are provided in bash variables, like its done when a new message +is received. + **Note**: the values of the variables contains always the result of the LAST transmission to telegram, -everey send action will overwrite them! +every send action will overwrite them! * ```$BOTSENT```: This array contains the parsed results from the last transmission to telegram. - * ```${BOTSENT[OK]}```: contain's the string 'true' after a successful transmission - * ```${BOTSENT[ERROR]}```: Error code if OK is not true + * ```${BOTSENT[OK]}```: contains the string ```true```: after a successful transmission + * ```${BOTSENT[ERROR]}```: Error code if an error occured * ```${BOTSENT[DESC]}```: Description text for error - * ```${BOTSENT[RETRY]}```: Seconds to wait ifntelegram requests throtteling. + * ```${BOTSENT[RETRY]}```: Seconds to wait if telegram requests throtteling. * ```$res```: temporary variable containing the full transmission result, may be overwritten by any bashbot function. By default you don't have to care about retry, as bashbot resend the message after the requested time automatically. Only if the retry fails also an error is returned. The downside is that send_message functions will wait until resend is done. -If you want to disbale all automtic error processing and handle all errors manually (or don't care) +If you want to disable automtic error processing and handle all errors manually (or don't care) set ```BASHBOT_RETRY``` to any no zero value. [Telegram API error codes](https://core.telegram.org/api/errors) @@ -235,12 +238,13 @@ set ```BASHBOT_RETRY``` to any no zero value. #### Detect bot blocked If the we can't connect to telegram, e.g. blocked from telegram server but also any other reason, -bashbot set ```BOTSENT[ERROR]``` to '999'. +bashbot set ```BOTSENT[ERROR]``` to ```999```. To get a notification on every connection problem create a function named ```bashbotBlockRecover``` and handle blocks there. If the function returns true (0 or no value) bashbot will retry once and then return to the calling function. In case you return any non 0 value bashbot will return to the calling function without retry. +Note: If you disable automatic retry, se above, you disable also connection problem notification. ```bash # somewhere in myfunctions.sh ... @@ -249,7 +253,7 @@ In case you return any non 0 value bashbot will return to the calling function w function bashbotBlockRecover() { # ups, we are blocked! (( MYBLOCKED++ )) - # log what we gotr + # log what we got printf "%s: Blocked %d times: %s\n" "$(date)" "${MYBLOCKED}" "$*" >>"${ERRORLOG}" if [ "${MYBLOCKED}" -gt 10 ]; then @@ -270,5 +274,5 @@ In case you return any non 0 value bashbot will return to the calling function w #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.96-pre-37-g6c02bab +#### $$VERSION$$ v0.96-pre-39-gb6e9f9e diff --git a/doc/7_develop.md b/doc/7_develop.md index 68de0f3..07ca51c 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -56,7 +56,7 @@ Note: For the same reason event function MUST return immediately! Time consuming ##### SEND RECEIVE events -executed when a Message is received, same iQuery / Message variables are avalible as in commands.sh +An RECEIVE event is executed when a Message is received, same iQuery / Message variables are avalible as in commands.sh * BASHBOT_EVENT_INLINE an inline query is received @@ -89,6 +89,8 @@ example_echo() { } ``` +An SEND event is executed when a Message is send tomtelegram. + * BASHBOT_EVENT_SEND is exceuted if data is send or uploaded to Telegram server In contrast to other events, BASHBOT_EVENT_SEND is excecuted in a subshell, so there is no need to spawn @@ -117,7 +119,7 @@ example_log(){ ##### TIMER events -Important: The timer tick is diabled by default and must be enabled by setting BASHBOT_START_TIMER to any value not zero. +Important: Bashbot timer tick is diabled by default and must be enabled by setting BASHBOT_START_TIMER to any value not zero. * BAHSBOT_EVENT_TIMER executed every minute and can be used in 3 variants: oneshot, once a minute, every X minutes. @@ -133,9 +135,9 @@ This means if you register an every 5 minutes callback first execution may < 5 M * 0 ignored * 1 execute once every minute * x execute every x minutes - * -x execute ONCE in (next) x minutes * + * -x execute once WHITHIN the next x Minutes (10=between now and 10 Minutes) -*\* if you really want "in x minutes" you must use ```-(EVENT_TIMER+x)```* +Note: If you want exact "in x minutes" use "EVENT_TIMER plus x" as time: ```-(EVENT_TIMER + x)``` *Example:* ```bash @@ -151,10 +153,10 @@ example_everymin() { # register other callback: BAHSBOT_EVENT_TIMER["example_every5","5"]="example_every5min" -# execute once in the next 10 minutes +# execute once in the next 1 to 10 minutes BAHSBOT_EVENT_TIMER["example_10min","-10"]="example_in10min" -# once in 10 minutes +# once in exact 10 minutes BAHSBOT_EVENT_TIMER["example_10min","$(( (EVENT_TIMER+10) * -1 ))"]="example_in10min" ``` @@ -336,5 +338,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v0.96-pre-36-g81c8771 +#### $$VERSION$$ v0.96-pre-39-gb6e9f9e From 15f6da85dcb8dd8d4af2c77d0edd2fe78f6322fc Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 11 Jun 2020 12:37:36 +0200 Subject: [PATCH 11/16] remove count.jssh.flock after cleanup --- bashbot.sh | 3 ++- doc/3_advanced.md | 6 +++--- doc/7_develop.md | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index eaa648d..a90c7e2 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-38-g15928bd +#### $$VERSION$$ v0.96-pre-40-ge663979 # # Exit Codes: # - 0 sucess (hopefully) @@ -812,6 +812,7 @@ start_bot() { fi # cleanup countfile on startup jssh_deleteKeyDB "CLEAN_COUNTER_DATABASE_ON_STARTUP" "${COUNTFILE}" + [ -f "${COUNTFILE}.jssh.flock" ] && rm -f "${COUNTFILE}.jssh.flock" ########## # bot is ready, start processing updates ... diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 6d5213f..d8bdfbf 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -213,7 +213,7 @@ e.g. resend on throttling. In addtion every send error is logged in logs/ERROR.l #### Trasmission results -On every message send to telgram (transmission) the results are provided in bash variables, like its done when a new message +On every message send to telegram (transmission) the results are provided in bash variables, like its done when a new message is received. **Note**: the values of the variables contains always the result of the LAST transmission to telegram, @@ -229,7 +229,7 @@ every send action will overwrite them! By default you don't have to care about retry, as bashbot resend the message after the requested time automatically. Only if the retry fails also an error is returned. The downside is that send_message functions will wait until resend is done. -If you want to disable automtic error processing and handle all errors manually (or don't care) +If you want to disable automatic error processing and handle all errors manually (or don't care) set ```BASHBOT_RETRY``` to any no zero value. [Telegram API error codes](https://core.telegram.org/api/errors) @@ -274,5 +274,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.96-pre-39-gb6e9f9e +#### $$VERSION$$ v0.96-pre-40-ge663979 diff --git a/doc/7_develop.md b/doc/7_develop.md index 07ca51c..53c141b 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -89,7 +89,7 @@ example_echo() { } ``` -An SEND event is executed when a Message is send tomtelegram. +An SEND event is executed when a Message is send to telegram. * BASHBOT_EVENT_SEND is exceuted if data is send or uploaded to Telegram server @@ -338,5 +338,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v0.96-pre-39-gb6e9f9e +#### $$VERSION$$ v0.96-pre-40-ge663979 From 38164ba9a2cd7a60f9cfb975ee4e0f28962c42a2 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 11 Jun 2020 15:55:15 +0200 Subject: [PATCH 12/16] dispose JSON.sh complaint about empty input --- bashbot.sh | 10 +++++----- doc/3_advanced.md | 4 ++-- doc/7_develop.md | 19 +++++++++++++------ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index a90c7e2..4f6c2a0 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-40-ge663979 +#### $$VERSION$$ v0.96-pre-41-g15f6da8 # # Exit Codes: # - 0 sucess (hopefully) @@ -319,7 +319,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then # 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}" \ - -H "Content-Type: application/json" | "${JSONSHFILE}" -s -b -n )" + -H "Content-Type: application/json" | "${JSONSHFILE}" -s -b -n 2>/dev/null )" sendJsonResult "${res}" "sendJson (curl)" "$@" } #$1 Chat, $2 what , $3 file, $4 URL, $5 caption @@ -348,7 +348,7 @@ else [ -n "${1}" ] && chat='"chat_id":'"${1}"',' # 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 )" + --header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n 2>/dev/null )" sendJsonResult "${res}" "sendJson (wget)" "$@" } sendUpload() { @@ -462,7 +462,7 @@ title2Json(){ # get bot name getBotName() { - getJson "$ME_URL" | "${JSONSHFILE}" -s -b -n | JsonGetString '"result","username"' + getJson "$ME_URL" | "${JSONSHFILE}" -s -b -n 2>/dev/null | JsonGetString '"result","username"' } # pure bash implementaion, done by KayM (@gnadelwartz) @@ -821,7 +821,7 @@ start_bot() { sleep "$(_round_float "${nextsleep}e-3" "1")" ((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep)) # get next update - UPDATE="$(getJson "$UPD_URL$OFFSET" 2>/dev/null | "${JSONSHFILE}" -s -b -n | iconv -f utf-8 -t utf-8 -c)" + UPDATE="$(getJson "$UPD_URL$OFFSET" 2>/dev/null | "${JSONSHFILE}" -s -b -n 2>/dev/null | iconv -f utf-8 -t utf-8 -c)" # did we ge an responsn0r if [ -n "${UPDATE}" ]; then # we got something, do processing diff --git a/doc/3_advanced.md b/doc/3_advanced.md index d8bdfbf..2b5e432 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -232,7 +232,7 @@ Only if the retry fails also an error is returned. The downside is that send_mes If you want to disable automatic error processing and handle all errors manually (or don't care) set ```BASHBOT_RETRY``` to any no zero value. -[Telegram API error codes](https://core.telegram.org/api/errors) +[Telegram Bot API error codes](https://github.com/TelegramBotAPI/errors) #### Detect bot blocked @@ -274,5 +274,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.96-pre-40-ge663979 +#### $$VERSION$$ v0.96-pre-41-g15f6da8 diff --git a/doc/7_develop.md b/doc/7_develop.md index 53c141b..054e931 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -43,10 +43,15 @@ If a not mandatory module is used in 'bashbot.sh' or 'commands.sh', the use of ` Addons must register themself to BASHBOT_EVENTS at startup, e.g. to call a function everytime a message is received. Addons works similar as 'commands.sh' and 'mycommands.sh' but are much more flexible on when functions/commands are triggered. -Another major difference is: **Addons are executed in the context of the main script**, while 'commands.sh' and 'mycommands.sh' are executed new child process on efery execution. -This is why event functions are time critical and must finish as fast as possible. +Another major difference is: While regular command processing is done in as a new sub shell for every command, +**Addons are executed in the context of bashbot event loop!**, This is why event functions are (time) critical +and must return as fast as possible. **If an event function call exit, also bashbot exits!** + +*Important*: If an event function e.g. send_messages or need longer time for processing spawn a sub shell! +This prevents blocking or exiting bashbots event loop. #### Bashbot Events + Addons must register functions to bashbot events by providing their name, and internal identifier and a callback function. If an event occours each registered function for the event is called. @@ -85,7 +90,9 @@ BASHBOT_EVENT_TEXT["example_1"]="example_echo" example_echo() { local event="$1" key="$2" # all availible bashbot functions and variables can be used - send_normal_message "${CHAT[ID]}" "Event: ${event} Key: ${key} : ${MESSAGE[0]}" & # note the &! + send_normal_message "${CHAT[ID]}" "Event: ${event} Key: ${key} : ${MESSAGE[0]}" & # NOTE the & for sub shell!!! + + do_more_processing & # NOTE the & for sub shell!!! } ``` @@ -135,7 +142,7 @@ This means if you register an every 5 minutes callback first execution may < 5 M * 0 ignored * 1 execute once every minute * x execute every x minutes - * -x execute once WHITHIN the next x Minutes (10=between now and 10 Minutes) + * -x execute once WHITHIN the next x Minutes (next 10 Minutes since start "event") Note: If you want exact "in x minutes" use "EVENT_TIMER plus x" as time: ```-(EVENT_TIMER + x)``` @@ -153,7 +160,7 @@ example_everymin() { # register other callback: BAHSBOT_EVENT_TIMER["example_every5","5"]="example_every5min" -# execute once in the next 1 to 10 minutes +# execute once on the next 10 minutes since start "event" BAHSBOT_EVENT_TIMER["example_10min","-10"]="example_in10min" # once in exact 10 minutes @@ -338,5 +345,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v0.96-pre-40-ge663979 +#### $$VERSION$$ v0.96-pre-41-g15f6da8 From 471ad21e90a4e4071c6e85837d8e1024277ec89c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 11 Jun 2020 23:00:14 +0200 Subject: [PATCH 13/16] update background job doc --- doc/3_advanced.md | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 2b5e432..23ab32f 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -64,13 +64,17 @@ You must use the function ```user_is_allowed``` to check if a user has the capab **See also [Bashbot User Access Control functions](6_reference.md#User-Access-Control)** ### Interactive Chats -Interactive chats are scripts, reading user input and echo data to the user. +Interactive chats are short running scripts, reading user input and echo data to the user. To create a new interactive chat script copy 'scripts/interactive.sh.clean' to e.g. 'scripts/mynewinteractive.sh', make it executeable and then use 'start_proc' function from your bot, it's possible to pass two arguments. You find more examples for interactive scripts in 'examples' *usage*: start_proc chat_id script arg1 arg2 +*usage*: kill_proc chat_id + +*usage*: check_prog chat_id + **Note:** From Version 0.96 on scripts must read user input from '$3' instead of stdin! ```bash @@ -137,15 +141,26 @@ echo "$out" ### Background Jobs -A background job is similar to an interactive chat, but runs in the background and does only output massages and does not get user input. In contrast to interactive chats it's possible to run multiple background jobs. To create a background job write a script or edit 'examples/notify.sh' script and use the funtion ```background``` to start it: +A background job is similar to an interactive chat, but can be a long running job and does only output massages, user input is ignored. +It's possible to run multiple background jobs from the same chat. + +To create a new interactive chat script copy 'scripts/interactive.sh.clean' to e.g. 'scripts/mynewbackground.sh', make it executeable +and then use 'start_back' function from your bot, it's possible to pass two arguments. You find more examples for background scripts in 'examples' + +*usage*: start_back chat_id script jobname arg1 arg2 + +*usage*: kill_back chat_id jobname + +*usage*: check_back chat_id jobname + ```bash -background "examples/notify.sh" "jobname" +start_back "examples/notify.sh" "${CHAT[ID]}" "jobname" ``` All output of the script will be sent to the user, to stop a background job use: ```bash -killback "jobname" +kill_back "${CHAT[ID]}" "jobname" ``` -You can also suspend and resume the last running background jobs from outside bashbot, e.g. in your startup schripts: +You can also suspend and resume currently running background jobs from outside bashbot, e.g. in your startup schripts: ```bash ./bashbot.sh suspendback ./bashbot.sh resumeback @@ -156,7 +171,7 @@ If you want to kill all background jobs permantly run: ./bashbot.sh killback ``` -Note: Background Jobs run independent from main bot and continue running until your script exits or you stop if from your Bot. Backgound Jobs will continue running if your Bot is stopeda and must be terminated, e.g. by ```bashbot.sh killback``` +Note: Background jobs run independent from main bot and continue running until your script exits or you stop it. Backgound jobs will continue running if your Bot is stoped and must be terminated seperatly e.g. by ```bashbot.sh killback``` ### Inline queries **Inline queries** allow users to send commands to your bot from every chat without going to a private chat. An inline query is started if the user type the bots name, e.g. @myBot. Everything after @myBot is immediatly send to the bot. From 737d54d3652a14e32e251edad2a49eac34883ce8 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 12 Jun 2020 01:17:15 +0200 Subject: [PATCH 14/16] improved logging, error handling on update --- bashbot.sh | 36 +++++++++++++++++++++--------------- doc/3_advanced.md | 2 +- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 4f6c2a0..dec142d 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-41-g15f6da8 +#### $$VERSION$$ v0.96-pre-43-g471ad21 # # Exit Codes: # - 0 sucess (hopefully) @@ -398,7 +398,7 @@ sendJsonResult(){ BOTSENT[RETRY]="$(JsonGetValue '"parameters","retry_after"' <<< "${1}")" else BOTSENT[ERROR]="999" - BOTSENT[DESCRIPTION]="Timeout or broken/no connection" + BOTSENT[DESCRIPTION]="Send to telegram not possible, timeout/broken/no connection" fi # log error printf "%s: RESULT=%s FUNC=%s CHAT[ID]=%s ERROR=%s DESC=%s ACTION=%s\n" "$(date)"\ @@ -506,20 +506,22 @@ process_client() { CHAT[ID]="${UPD["result",${num},"message","chat","id"]}" USER[ID]="${UPD["result",${num},"message","from","id"]}" # log message on debug - if [[ "${debug}" = *"debug"* ]]; then - printf "%s: update received FROM=%s CHAT=%s iQEUERY=%s\n" "$(date)" "${USER[ID]}" "${CHAT[ID]}" "${iQUERY[ID]}" - printf "\n%s: New Message ==========\n%s\n" "$(date)" "$UPDATE" >>"${LOGDIR}/MESSAGE.log" - fi + [[ -n "${debug}" ]] && printf "\n%s: New Message ==========\n%s\n" "$(date)" "$UPDATE" >>"${LOGDIR}/MESSAGE.log" # check for uers / groups to ignore - if [ -n "${USER[ID]}" ]; then - [[ " ${!BASHBOT_BLOCKED[*]} " == *" ${USER[ID]} "* ]] && return - jssh_readDB_async "BASHBOT_BLOCKED" "${BLOCKEDFILE}" - fi + [ -n "${USER[ID]}" ] && [[ " ${!BASHBOT_BLOCKED[*]} " == *" ${USER[ID]} "* ]] && return + jssh_readDB_async "BASHBOT_BLOCKED" "${BLOCKEDFILE}" + + # process per message type if [ -z "${iQUERY[ID]}" ]; then + MESSAGE[0]="$(JsonDecode "${UPD["result",${num},"message","text"]}" | sed 's#\\/#/#g')" process_message "${num}" "${debug}" + [[ -n "${debug}" ]] && printf "%s: update received FROM=%s CHAT=%s CMD=%s\n"\ + "$(date)" "${USER[USERNAME]} (${USER[ID]})" "${CHAT[USERNAME]}${CHAT[TITLE]} (${CHAT[ID]})" "${MESSAGE%% *}" else process_inline "${num}" "${debug}" + [[ -n "${debug}" ]] && printf "%s: iQuery received FROM=%s iQUERY=%s\n"\ + "$(date)" "${iQUERY[USERNAME]} (${iQUERY[USER_ID]})" "${iQUERY[0]}" fi ##### # process inline and message events @@ -670,7 +672,6 @@ process_inline() { process_message() { local num="$1" # Message - MESSAGE[0]="$(JsonDecode "${UPD["result",${num},"message","text"]}" | sed 's#\\/#/#g')" MESSAGE[ID]="${UPD["result",${num},"message","message_id"]}" # Chat ID is now parsed when update isreceived @@ -819,27 +820,32 @@ start_bot() { while true; do # adaptive sleep in ms rounded to next 0.1 s sleep "$(_round_float "${nextsleep}e-3" "1")" - ((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep)) # get next update UPDATE="$(getJson "$UPD_URL$OFFSET" 2>/dev/null | "${JSONSHFILE}" -s -b -n 2>/dev/null | iconv -f utf-8 -t utf-8 -c)" # did we ge an responsn0r if [ -n "${UPDATE}" ]; then # we got something, do processing + [ "${OFFSET}" = "-999" ] &&\ + printf "%s: Recovered from timeout/broken/no connection, continue with telegram updates\n"\ + "$(date)" >>"${ERRORLOG}" # escape bash $ expansion bug UPDATE="${UPDATE//$/\\$}" # Offset OFFSET="$(grep <<< "${UPDATE}" '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)" ((OFFSET++)) + ((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep)) if [ "$OFFSET" != "1" ]; then nextsleep="100" process_updates "${DEBUG}" fi else - # ups, something bad happend, wait maxsleep - (( nextsleep=maxsleep*2 )) - printf "%s: Timeout or broken/no connection on telegram update, sleep %ds\n"\ + # ups, something bad happend, wait maxsleep*10 + (( nextsleep=nextsleep*2 , nextsleep= nextsleep>maxsleep*10 ?maxsleep*10:nextsleep )) + [ "${OFFSET}" = "-999" ] &&\ + printf "%s: Repeated timeout/broken/no connection on telegram update, sleep %ds\n"\ "$(date)" "$(_round_float "${nextsleep}e-3")" >>"${ERRORLOG}" + OFFSET="-999" fi done } diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 23ab32f..ebc18d7 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -289,5 +289,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.96-pre-41-g15f6da8 +#### $$VERSION$$ v0.96-pre-42-g38164ba From 3871ca9656279f0d35bfc649c36f4fc55be62e1a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 12 Jun 2020 10:00:52 +0200 Subject: [PATCH 15/16] finalize error logs, update events doc --- bashbot.sh | 9 +++++---- doc/7_develop.md | 14 ++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index dec142d..f6f9dca 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-43-g471ad21 +#### $$VERSION$$ v0.96-pre-44-g737d54d # # Exit Codes: # - 0 sucess (hopefully) @@ -517,7 +517,8 @@ process_client() { MESSAGE[0]="$(JsonDecode "${UPD["result",${num},"message","text"]}" | sed 's#\\/#/#g')" process_message "${num}" "${debug}" [[ -n "${debug}" ]] && printf "%s: update received FROM=%s CHAT=%s CMD=%s\n"\ - "$(date)" "${USER[USERNAME]} (${USER[ID]})" "${CHAT[USERNAME]}${CHAT[TITLE]} (${CHAT[ID]})" "${MESSAGE%% *}" + "$(date)" "${USER[USERNAME]:0:20} (${USER[ID]})"\ + "${CHAT[USERNAME]:0:20}${CHAT[TITLE]:0:30} (${CHAT[ID]})" "${MESSAGE%%[ \?]*}" else process_inline "${num}" "${debug}" [[ -n "${debug}" ]] && printf "%s: iQuery received FROM=%s iQUERY=%s\n"\ @@ -825,16 +826,16 @@ start_bot() { # did we ge an responsn0r if [ -n "${UPDATE}" ]; then # we got something, do processing - [ "${OFFSET}" = "-999" ] &&\ + [ "${OFFSET}" = "-999" ] && [ "${nextsleep}" -gt "${maxsleep}" ] &&\ printf "%s: Recovered from timeout/broken/no connection, continue with telegram updates\n"\ "$(date)" >>"${ERRORLOG}" # escape bash $ expansion bug + ((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep)) UPDATE="${UPDATE//$/\\$}" # Offset OFFSET="$(grep <<< "${UPDATE}" '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)" ((OFFSET++)) - ((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep)) if [ "$OFFSET" != "1" ]; then nextsleep="100" process_updates "${DEBUG}" diff --git a/doc/7_develop.md b/doc/7_develop.md index 054e931..1203196 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -43,11 +43,11 @@ If a not mandatory module is used in 'bashbot.sh' or 'commands.sh', the use of ` Addons must register themself to BASHBOT_EVENTS at startup, e.g. to call a function everytime a message is received. Addons works similar as 'commands.sh' and 'mycommands.sh' but are much more flexible on when functions/commands are triggered. -Another major difference is: While regular command processing is done in as a new sub shell for every command, +Another major difference is: While regular command processing is done in a new sub shell for every command, **Addons are executed in the context of bashbot event loop!**, This is why event functions are (time) critical and must return as fast as possible. **If an event function call exit, also bashbot exits!** -*Important*: If an event function e.g. send_messages or need longer time for processing spawn a sub shell! +*Important*: Spawn a new sub shell in background for your procssing and when calling bashbot functions, e.g. send_messages. This prevents blocking or exiting bashbots event loop. #### Bashbot Events @@ -90,9 +90,11 @@ BASHBOT_EVENT_TEXT["example_1"]="example_echo" example_echo() { local event="$1" key="$2" # all availible bashbot functions and variables can be used - send_normal_message "${CHAT[ID]}" "Event: ${event} Key: ${key} : ${MESSAGE[0]}" & # NOTE the & for sub shell!!! + send_normal_message "${CHAT[ID]}" "Event: ${event} Key: ${key} : ${MESSAGE[0]}" & # run in background! - do_more_processing & # NOTE the & for sub shell!!! + ( MYTEXT="${MESSAGE[0]}" + do_more_processing + ) & # run as sub shell in background! } ``` @@ -100,7 +102,7 @@ An SEND event is executed when a Message is send to telegram. * BASHBOT_EVENT_SEND is exceuted if data is send or uploaded to Telegram server -In contrast to other events, BASHBOT_EVENT_SEND is excecuted in a subshell, so there is no need to spawn +In contrast to other events, BASHBOT_EVENT_SEND is excecuted in a sub shell, so there is no need to spawn a background process for longer running commands and changes to variables are not persistent! BASHBOT_EVENT_SEND is for logging purposes, you must not send messages while processing this event. @@ -345,5 +347,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v0.96-pre-41-g15f6da8 +#### $$VERSION$$ v0.96-pre-44-g737d54d From 15e6c7bcbe861a2d57f52c557039b7125dabe279 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 12 Jun 2020 11:11:17 +0200 Subject: [PATCH 16/16] Version 0.96 --- README.html | 2 +- README.md | 2 +- README.txt | 2 +- addons/antiFlood.sh | 2 +- addons/example.sh | 2 +- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/all-tests.sh | 2 +- dev/git-add.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-distribution.sh | 2 +- dev/make-standalone.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 4 ++-- examples/README.md | 2 +- examples/background-scripts/run_diskusage.sh | 2 +- examples/background-scripts/run_filecontent.sh | 2 +- examples/background-scripts/run_filename.sh | 2 +- examples/background-scripts/run_notify.sh | 2 +- examples/bash2env.sh | 2 +- examples/bashbot-multi.sh | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question.sh | 2 +- examples/send-system-status/botacl | 2 +- examples/send-system-status/mycommands.sh | 2 +- modules/aliases.sh | 2 +- modules/answerInline.sh | 2 +- modules/background.sh | 2 +- modules/chatMember.sh | 2 +- modules/jsonDB.sh | 2 +- modules/sendMessage.sh | 2 +- mycommands.sh | 2 +- mycommands.sh.clean | 2 +- scripts/interactive.sh.clean | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/a-commit-test.sh | 2 +- test/b-example-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_inline-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- test/e-env-test.sh | 2 +- 58 files changed, 59 insertions(+), 59 deletions(-) diff --git a/README.html b/README.html index 504bf27..502abca 100644 --- a/README.html +++ b/README.html @@ -246,6 +246,6 @@ It features background tasks and interactive chats, and can serve as an interfac

      @Gnadelwartz

      That's it!

      If you feel that there's something missing or if you found a bug, feel free to submit a pull request!

      -

      $$VERSION$$ v0.96-pre-39-gb6e9f9e

      +

      $$VERSION$$ v0.96-0-g3871ca9

      diff --git a/README.md b/README.md index 4bd8192..207d974 100644 --- a/README.md +++ b/README.md @@ -219,4 +219,4 @@ This may happen if to many wrong requests are sent to api.telegram.org, e.g. usi If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.96-pre-39-gb6e9f9e +#### $$VERSION$$ v0.96-0-g3871ca9 diff --git a/README.txt b/README.txt index 50bf470..b5f2360 100644 --- a/README.txt +++ b/README.txt @@ -305,4 +305,4 @@ in 'mycommands.sh' as example. If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.96-pre-39-gb6e9f9e +#### $$VERSION$$ v0.96-0-g3871ca9 diff --git a/addons/antiFlood.sh b/addons/antiFlood.sh index 87224b9..ff90c65 100644 --- a/addons/antiFlood.sh +++ b/addons/antiFlood.sh @@ -4,7 +4,7 @@ # this addon counts how many files, e.g. stickers, are sent to # a chat and takes actions if threshold is reached # -#### $$VERSION$$ v0.96-pre-36-g81c8771 +#### $$VERSION$$ v0.96-0-g3871ca9 # used events: # diff --git a/addons/example.sh b/addons/example.sh index ee22ca2..1478bd6 100644 --- a/addons/example.sh +++ b/addons/example.sh @@ -4,7 +4,7 @@ # Addons can register to bashbot events at statup # by providing their name and a callback per event # -#### $$VERSION$$ v0.96-pre-36-g81c8771 +#### $$VERSION$$ v0.96-0-g3871ca9 # # If an event occours each registered event function is called. # diff --git a/bashbot.rc b/bashbot.rc index e2d1569..f09e946 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.96-dev3-12-g3f85134 +#### $$VERSION$$ v0.96-0-g3871ca9 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index f6f9dca..5c7f090 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-44-g737d54d +#### $$VERSION$$ v0.96-0-g3871ca9 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index f39cfeb..2b509ac 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-pre-36-g81c8771 +#### $$VERSION$$ v0.96-0-g3871ca9 # # adjust your language setting here, e.g.when run from other user or cron. diff --git a/dev/all-tests.sh b/dev/all-tests.sh index c06ea03..f293453 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.96-pre-15-geace5e1 +#### $$VERSION$$ v0.96-0-g3871ca9 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/git-add.sh b/dev/git-add.sh index b3a0a59..68470a6 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 95d024a..b71cecf 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-dev3-20-gbd22e2a +#### $$VERSION$$ v0.96-0-g3871ca9 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index c3b3489..ee0158b 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 6c62a23..e1cc112 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index 4bc4c55..cb87687 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -2,7 +2,7 @@ # file: make-distribution.sh # creates files and arcchives to dirtribute bashbot # -#### $$VERSION$$ 0.96-dev2-6-gda98b09 +#### $$VERSION$$ v0.96-0-g3871ca9 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index 353f21b..d979cf3 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -5,7 +5,7 @@ # If you your bot is finished you can use make-standalone.sh to create the # the old all-in-one bashbot: bashbot.sh and commands.sh only! # -#### $$VERSION$$ v0.96-dev3-22-g19c45c4 +#### $$VERSION$$ v0.96-0-g3871ca9 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 167d5c2..6432c79 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,4 +1,4 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 bashbot.rc mycommands.sh.clean diff --git a/dev/version.sh b/dev/version.sh index 892b220..c78c8db 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index d391955..6376b15 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -101,5 +101,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 26e6a30..2289457 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -65,5 +65,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 diff --git a/doc/2_usage.md b/doc/2_usage.md index ba5f7e8..7b099c8 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -256,5 +256,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.96-pre-36-g81c8771 +#### $$VERSION$$ v0.96-0-g3871ca9 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index ebc18d7..deafadc 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -289,5 +289,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.96-pre-42-g38164ba +#### $$VERSION$$ v0.96-0-g3871ca9 diff --git a/doc/4_expert.md b/doc/4_expert.md index 7428719..11caee9 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -382,5 +382,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Advanced Use](3_advanced.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.96-pre-36-g81c8771 +#### $$VERSION$$ v0.96-0-g3871ca9 diff --git a/doc/5_practice.md b/doc/5_practice.md index 468f886..0731e75 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -152,5 +152,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 diff --git a/doc/6_reference.md b/doc/6_reference.md index 10da99d..b5c7825 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -1035,5 +1035,5 @@ The name of your bot is availible as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.96-pre-36-g81c8771 +#### $$VERSION$$ v0.96-0-g3871ca9 diff --git a/doc/7_develop.md b/doc/7_develop.md index 1203196..a3324f3 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -47,7 +47,7 @@ Another major difference is: While regular command processing is done in a new s **Addons are executed in the context of bashbot event loop!**, This is why event functions are (time) critical and must return as fast as possible. **If an event function call exit, also bashbot exits!** -*Important*: Spawn a new sub shell in background for your procssing and when calling bashbot functions, e.g. send_messages. +*Important*: Spawn a new sub shell in background for your processing commands and when calling bashbot functions, e.g. send_messages. This prevents blocking or exiting bashbots event loop. #### Bashbot Events @@ -347,5 +347,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v0.96-pre-44-g737d54d +#### $$VERSION$$ v0.96-0-g3871ca9 diff --git a/examples/README.md b/examples/README.md index d9b2870..60f7fd3 100644 --- a/examples/README.md +++ b/examples/README.md @@ -55,6 +55,6 @@ convert existing bots. **external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users. -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 diff --git a/examples/background-scripts/run_diskusage.sh b/examples/background-scripts/run_diskusage.sh index 1d897d0..62bc58d 100755 --- a/examples/background-scripts/run_diskusage.sh +++ b/examples/background-scripts/run_diskusage.sh @@ -4,7 +4,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-0-g3871ca9 ###### # parameters diff --git a/examples/background-scripts/run_filecontent.sh b/examples/background-scripts/run_filecontent.sh index 80c7260..0282ca8 100755 --- a/examples/background-scripts/run_filecontent.sh +++ b/examples/background-scripts/run_filecontent.sh @@ -2,7 +2,7 @@ # file: run_filename # background job to display content of all new files in WATCHDIR # -#### $$VERSION$$ v0.96-dev3-12-g3f85134 +#### $$VERSION$$ v0.96-0-g3871ca9 ###### # parameters diff --git a/examples/background-scripts/run_filename.sh b/examples/background-scripts/run_filename.sh index e6f1434..7f342a0 100755 --- a/examples/background-scripts/run_filename.sh +++ b/examples/background-scripts/run_filename.sh @@ -2,7 +2,7 @@ # file: run_filename # background job to display all new files in WATCHDIR # -#### $$VERSION$$ v0.96-dev3-12-g3f85134 +#### $$VERSION$$ v0.96-0-g3871ca9 ###### # parameters diff --git a/examples/background-scripts/run_notify.sh b/examples/background-scripts/run_notify.sh index 20433d9..e5889c1 100755 --- a/examples/background-scripts/run_notify.sh +++ b/examples/background-scripts/run_notify.sh @@ -4,7 +4,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-0-g3871ca9 ###### # parameters diff --git a/examples/bash2env.sh b/examples/bash2env.sh index d770aed..728dd24 100755 --- a/examples/bash2env.sh +++ b/examples/bash2env.sh @@ -6,7 +6,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-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/bashbot-multi.sh b/examples/bashbot-multi.sh index 43f3a2a..afc41c9 100755 --- a/examples/bashbot-multi.sh +++ b/examples/bashbot-multi.sh @@ -2,7 +2,7 @@ # file. multibot.sh # description: run multiple telegram bots from one installation # -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then echo "Usage: $0 botname command" diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 6a28210..feb7ab6 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 40f4ea4..06eb080 100755 --- a/examples/calc.sh +++ b/examples/calc.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-0-g3871ca9 ###### # parameters diff --git a/examples/notify.sh b/examples/notify.sh index 6254ec9..a3912a5 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -4,7 +4,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-0-g3871ca9 ###### # parameters diff --git a/examples/question.sh b/examples/question.sh index a860292..6df3720 100755 --- a/examples/question.sh +++ b/examples/question.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-14-g5fc4d01a +#### $$VERSION$$ v0.96-0-g3871ca9 ###### # parameters diff --git a/examples/send-system-status/botacl b/examples/send-system-status/botacl index 392b5d5..058ab92 100644 --- a/examples/send-system-status/botacl +++ b/examples/send-system-status/botacl @@ -1,7 +1,7 @@ # file: botacl # a user not listed here, will return false from 'user_is_allowed' # -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # Format: # user:ressource:chat diff --git a/examples/send-system-status/mycommands.sh b/examples/send-system-status/mycommands.sh index 6616f8c..34e3361 100644 --- a/examples/send-system-status/mycommands.sh +++ b/examples/send-system-status/mycommands.sh @@ -5,7 +5,7 @@ # to show how you can customize bashbot by only editing mycommands.sh # NOTE: this is not tested, simply copied from original source and reworked! # -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/modules/aliases.sh b/modules/aliases.sh index 6c87266..d0795b3 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # # source from commands.sh to use the aliases diff --git a/modules/answerInline.sh b/modules/answerInline.sh index 976dc08..8a20057 100644 --- a/modules/answerInline.sh +++ b/modules/answerInline.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-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # source from commands.sh to use the inline functions diff --git a/modules/background.sh b/modules/background.sh index 4bc93d3..622d114 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-pre-0-geb49241 +#### $$VERSION$$ v0.96-0-g3871ca9 # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 12e3cd3..0915133 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.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-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # source once magic, function named like file eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index 14b5d96..88a6a8d 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-pre-24-g5b25821 +#### $$VERSION$$ v0.96-0-g3871ca9 # # source from commands.sh to use jsonDB functions # diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 61f8dac..8474d87 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.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$$ 0.96-dev2-7-g6d1e7cc +#### $$VERSION$$ v0.96-0-g3871ca9 # source once magic, function named like file eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" diff --git a/mycommands.sh b/mycommands.sh index e39befd..120c204 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-36-g81c8771 +#### $$VERSION$$ v0.96-0-g3871ca9 # # uncomment the following lines to overwrite info and help messages diff --git a/mycommands.sh.clean b/mycommands.sh.clean index f6fb58e..6fe948e 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-36-g81c8771 +#### $$VERSION$$ v0.96-0-g3871ca9 # ########## diff --git a/scripts/interactive.sh.clean b/scripts/interactive.sh.clean index e6e72c0..8dbe9c3 100755 --- a/scripts/interactive.sh.clean +++ b/scripts/interactive.sh.clean @@ -6,7 +6,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-0-g3871ca9 ###### # parameters diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 0e6b0dd..2761cc3 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index ef61510..df2eccc 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-pre-32-gd70656d +#### $$VERSION$$ v0.96-0-g3871ca9 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 4742d8d..20319b1 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 ../dev/hooks/pre-commit.sh diff --git a/test/b-example-test.sh b/test/b-example-test.sh index ed39d3f..6e29ca6 100644 --- a/test/b-example-test.sh +++ b/test/b-example-test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # file: b-example-test.sh -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 8a43419..cb4157a 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-dev3-1-g2a66ee9 +#### $$VERSION$$ v0.96-0-g3871ca9 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 638b788..c2c1a5e 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh index 8656982..ac45aaa 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-pre-32-gd70656d +#### $$VERSION$$ v0.96-0-g3871ca9 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 34e69db..c3c8b11 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-pre-32-gd70656d +#### $$VERSION$$ v0.96-0-g3871ca9 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index 2f87ac9..16b6e17 100755 --- a/test/d-send_message-test.sh +++ b/test/d-send_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-pre-32-gd70656d +#### $$VERSION$$ v0.96-0-g3871ca9 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 2558a07..d004b70 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-dev-7-g0153928 +#### $$VERSION$$ v0.96-0-g3871ca9 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/e-env-test.sh b/test/e-env-test.sh index 8aeeb73..b89652c 100755 --- a/test/e-env-test.sh +++ b/test/e-env-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.96-dev3-0-gdddd1ce +#### $$VERSION$$ v0.96-0-g3871ca9 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh