diff --git a/bashbot.sh b/bashbot.sh index cec73dd..2e2a0ed 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-12-gaa93839 # # Exit Codes: # - 0 sucess (hopefully) @@ -36,7 +36,7 @@ RUNDIR="${BASHBOT_VAR:-${SCRIPTDIR}}" [ "${RUNDIR}" = "${SCRIPTDIR}" ] && SCRIPT="./$(basename "${SCRIPT}")" -RUNUSER="${USER}" # USER is overwritten by bashbot array, $USER may not work later on... +RUNUSER="${USER}" # USER is overwritten by bashbot array if [ "$1" != "source" ] && ! cd "${RUNDIR}" ; then echo -e "${RED}ERROR: Can't change to ${RUNDIR} ...${NC}" @@ -93,7 +93,7 @@ if [ ! -f "${BOTACL}" ]; then echo "" >"${BOTACL}" fi -TMPDIR="${BASHBOT_VAR:-.}/tmp-bot-bash" +TMPDIR="${BASHBOT_VAR:-.}/data-bot-bash" if [ ! -d "${TMPDIR}" ]; then mkdir "${TMPDIR}" elif [ ! -w "${TMPDIR}" ]; then @@ -155,7 +155,8 @@ GETMEMBER_URL=$URL'/getChatMember' FILE_URL='https://api.telegram.org/file/bot'$BOTTOKEN'/' UPD_URL=$URL'/getUpdates?offset=' GET_URL=$URL'/getFile' -OFFSET=0 + +unset USER declare -A USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO @@ -616,6 +617,7 @@ process_message() { # main get updates loop, should never terminate start_bot() { + local OFFSET=0 local mysleep="100" # ms local addsleep="100" local maxsleep="$(( ${BASHBOT_SLEEP:-5000} + 100 ))" @@ -643,6 +645,9 @@ start_bot() { # initialize bot environment, user and permissions bot_init() { + # move tmpdir to datadir + local OLDTMP="${BASHBOT_VAR:-.}/tmp-bot-bash" + [ -d "${OLDTMP}" ] && { mv -n "${OLDTMP}/"* "${TMPDIR}"; rmdir "${OLDTMP}"; } [[ "$(id -u)" -eq "0" ]] && RUNUSER="nobody" echo -n "Enter User to run basbot [$RUNUSER]: " read -r TOUSER diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index b695f77..0ea4597 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.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-12-gaa93839 # 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 892c605..2f5a2ae 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.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-12-gaa93839 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -26,8 +26,8 @@ echo "Check process_message ..." for i in 1 2 do [ "${i}" = "1" ] && ! which python >/dev/null 2>&1 && continue - [ "${i}" = "1" ] && echo " ... JsonDecode Phyton" && unset BASHBOT_DECODE - [ "${i}" = "2" ] && echo " ... JsonDecode Bash" && export BASHBOT_DECODE="yes" + [ "${i}" = "1" ] && echo " ... with JsonDecode Phyton" && unset BASHBOT_DECODE + [ "${i}" = "2" ] && echo " ... with JsonDecode Bash" && export BASHBOT_DECODE="yes" set -x { process_message "0"; set +x; } >>"${LOGFILE}" 2>&1; diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index a6e2bc8..e0b6b9b 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.70-dev2-11-g8549727 +#### $$VERSION$$ v0.70-dev2-12-gaa93839 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -16,7 +16,7 @@ source "${TESTDIR}/bashbot.sh" source # start writing your tests here ... # first user asking for botadmin will botadmin -echo " test \"user_is_botadmin\" ..." +echo "Check \"user_is_botadmin\" ..." echo '?' >"${ADMINFILE}" # auto mode @@ -32,7 +32,7 @@ fi echo "${SUCCESS}" # lets see If UAC works ... -echo " test \"user_is_allowed\" ..." +echo "Check \"user_is_allowed\" ..." echo " ... with not rules" user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should always fail because no rules exist