mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-29 05:02:46 +00:00
fix problems found by tests
This commit is contained in:
parent
e366633ebd
commit
31b3203483
16
bashbot.sh
16
bashbot.sh
@ -11,7 +11,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ 0.96-dev2-8-g46748ee
|
#### $$VERSION$$ 0.96-dev2-11-ge366633
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -105,12 +105,12 @@ if [ ! -w "." ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
#jsonDB is now mandatory
|
#jsonDB is now mandatory
|
||||||
if [ ! -r "${MODULEDIR:-./modules}"/jsonDB.sh ]; then
|
if [ ! -r "${MODULEDIR:-.}"/jsonDB.sh ]; then
|
||||||
echo -e "${RED}ERROR: Mandatory module ${MODULEDIR:-./modules}/jsonDB.sh is missing or not readable!"
|
echo -e "${RED}ERROR: Mandatory module ${MODULEDIR:-.}/jsonDB.sh is missing or not readable!"
|
||||||
exit 6
|
exit 6
|
||||||
fi
|
fi
|
||||||
# shellcheck source=./modules/jsonDB.sh
|
# shellcheck source=./modules/jsonDB.sh
|
||||||
source "${MODULEDIR:-./modules}"/jsonDB.sh
|
source "${MODULEDIR:-.}"/jsonDB.sh
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
# Setup and check environment if BOTTOKEN is NOT set
|
# Setup and check environment if BOTTOKEN is NOT set
|
||||||
@ -171,7 +171,7 @@ if [ -z "${BOTTOKEN}" ]; then
|
|||||||
# setup count file
|
# setup count file
|
||||||
if [ ! -f "${COUNTFILE}.jssh" ]; then
|
if [ ! -f "${COUNTFILE}.jssh" ]; then
|
||||||
jssh_newDB "${COUNTFILE}"
|
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
|
# conveqrt old file on creation
|
||||||
if [ -r "${COUNTFILE}" ];then
|
if [ -r "${COUNTFILE}" ];then
|
||||||
sed 's/COUNT/\[\"/;s/$/\"\]\t\"1\"/' < "${COUNTFILE}" >> "${COUNTFILE}.jssh"
|
sed 's/COUNT/\[\"/;s/$/\"\]\t\"1\"/' < "${COUNTFILE}" >> "${COUNTFILE}.jssh"
|
||||||
@ -184,7 +184,7 @@ if [ -z "${BOTTOKEN}" ]; then
|
|||||||
# setup blocked file
|
# setup blocked file
|
||||||
if [ ! -f "${BLOCKEDFILE}.jssh" ]; then
|
if [ ! -f "${BLOCKEDFILE}.jssh" ]; then
|
||||||
jssh_newDB "${BLOCKEDFILE}"
|
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
|
||||||
fi
|
fi
|
||||||
# cleanup (remove double entries) countfile on startup
|
# cleanup (remove double entries) countfile on startup
|
||||||
@ -238,8 +238,8 @@ if [ "${SOURCE}" != "yes" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
###############
|
###############
|
||||||
# load modules
|
# load
|
||||||
for modules in "${MODULEDIR:-./modules}"/*.sh ; do
|
for modules in "${MODULEDIR:-.}"/*.sh ; do
|
||||||
# shellcheck source=./modules/aliases.sh
|
# shellcheck source=./modules/aliases.sh
|
||||||
if ! _is_function "$(basename "${modules}")" && [ -r "${modules}" ]; then source "${modules}" "source"; fi
|
if ! _is_function "$(basename "${modules}")" && [ -r "${modules}" ]; then source "${modules}" "source"; fi
|
||||||
done
|
done
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ 0.96-dev2-6-gda98b09
|
#### $$VERSION$$ 0.96-dev2-11-ge366633
|
||||||
#
|
#
|
||||||
# source from commands.sh to use jsonDB functions
|
# source from commands.sh to use jsonDB functions
|
||||||
#
|
#
|
||||||
@ -208,18 +208,20 @@ jssh_newDB() {
|
|||||||
local DB; DB="$(jssh_checkDB "$1")"
|
local DB; DB="$(jssh_checkDB "$1")"
|
||||||
[ -z "${DB}" ] && return 1
|
[ -z "${DB}" ] && return 1
|
||||||
[ -f "${DB}" ] && return 2 # already exist, do not zero out
|
[ -f "${DB}" ] && return 2 # already exist, 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
|
# returns real path to DB file if everything is ok
|
||||||
jssh_checkDB(){
|
jssh_checkDB(){
|
||||||
|
local DB
|
||||||
[ -z "$1" ] && return 1
|
[ -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
|
[[ "$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}"
|
printf '%s\n' "${DB}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user