fix problems found by tests

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2020-06-01 11:50:42 +02:00
parent e366633ebd
commit 31b3203483
2 changed files with 17 additions and 15 deletions

View File

@ -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$$ 0.96-dev2-8-g46748ee
#### $$VERSION$$ 0.96-dev2-11-ge366633
#
# Exit Codes:
# - 0 sucess (hopefully)
@ -105,12 +105,12 @@ if [ ! -w "." ]; then
fi
#jsonDB is now mandatory
if [ ! -r "${MODULEDIR:-./modules}"/jsonDB.sh ]; then
echo -e "${RED}ERROR: Mandatory module ${MODULEDIR:-./modules}/jsonDB.sh is missing or not readable!"
if [ ! -r "${MODULEDIR:-.}"/jsonDB.sh ]; then
echo -e "${RED}ERROR: Mandatory module ${MODULEDIR:-.}/jsonDB.sh is missing or not readable!"
exit 6
fi
# shellcheck source=./modules/jsonDB.sh
source "${MODULEDIR:-./modules}"/jsonDB.sh
source "${MODULEDIR:-.}"/jsonDB.sh
#####################
# Setup and check environment if BOTTOKEN is NOT set
@ -171,7 +171,7 @@ if [ -z "${BOTTOKEN}" ]; then
# setup count file
if [ ! -f "${COUNTFILE}.jssh" ]; then
jssh_newDB "${COUNTFILE}"
jssh_insertDB 'counted_user_chat_id' "num_messages_seen" "${COUNTFILE}"
jssh_insertKeyDB 'counted_user_chat_id' "num_messages_seen" "${COUNTFILE}"
# conveqrt old file on creation
if [ -r "${COUNTFILE}" ];then
sed 's/COUNT/\[\"/;s/$/\"\]\t\"1\"/' < "${COUNTFILE}" >> "${COUNTFILE}.jssh"
@ -184,7 +184,7 @@ if [ -z "${BOTTOKEN}" ]; then
# setup blocked file
if [ ! -f "${BLOCKEDFILE}.jssh" ]; then
jssh_newDB "${BLOCKEDFILE}"
jssh_insertDB 'blocked_user_or_chat_id' "name and reason" "${BLOCKEDFILE}"
jssh_insertKeyDB 'blocked_user_or_chat_id' "name and reason" "${BLOCKEDFILE}"
fi
fi
# cleanup (remove double entries) countfile on startup
@ -238,8 +238,8 @@ if [ "${SOURCE}" != "yes" ]; then
fi
###############
# load modules
for modules in "${MODULEDIR:-./modules}"/*.sh ; do
# load
for modules in "${MODULEDIR:-.}"/*.sh ; do
# shellcheck source=./modules/aliases.sh
if ! _is_function "$(basename "${modules}")" && [ -r "${modules}" ]; then source "${modules}" "source"; fi
done

View File

@ -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-6-gda98b09
#### $$VERSION$$ 0.96-dev2-11-ge366633
#
# source from commands.sh to use jsonDB functions
#
@ -208,18 +208,20 @@ jssh_newDB() {
local DB; DB="$(jssh_checkDB "$1")"
[ -z "${DB}" ] && return 1
[ -f "${DB}" ] && return 2 # already exist, do not zero out
printf '\n' >"${DB}"
printf '' >"${DB}"
}
# $1 filename, check filename, it must be relative to BASHBOT_ETC, and not contain '..'
# $1 filename, check filename, it must be relative to BASHBOT_VAR, and not contain '..'
# returns real path to DB file if everything is ok
jssh_checkDB(){
local DB
[ -z "$1" ] && return 1
local DB="${BASHBOT_ETC:-.}/$1.jssh"
if [[ "$1" = "${BASHBOT_ETC:-.}"* ]] || [[ "$1" = "${BASHBOT_DATA:-.}"* ]]; then
DB="$1.jssh"
fi
[[ "$1" = *'..'* ]] && return 2
if [[ "$1" == "${BASHBOT_VAR:-.}"* ]] || [[ "$1" == "${BASHBOT_DATA:-.}"* ]]; then
DB="$1.jssh"
else
DB="${BASHBOT_VAR:-.}/$1.jssh"
fi
printf '%s\n' "${DB}"
}