mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-29 13:12:36 +00:00
fix problems found by tests
This commit is contained in:
parent
eace5e18a4
commit
a792048dfe
59
bashbot.sh
59
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$$ v0.96-pre-14-g4fd6f98
|
#### $$VERSION$$ v0.96-pre-15-geace5e1
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -77,9 +77,6 @@ MODULEDIR="${SCRIPTDIR}/modules"
|
|||||||
# adjust locations based on source and real name
|
# adjust locations based on source and real name
|
||||||
if [ "${SCRIPT}" != "${REALME}" ] || [ "$1" = "source" ]; then
|
if [ "${SCRIPT}" != "${REALME}" ] || [ "$1" = "source" ]; then
|
||||||
SOURCE="yes"
|
SOURCE="yes"
|
||||||
else
|
|
||||||
SCRIPT="./$(basename "${SCRIPT}")"
|
|
||||||
MODULEDIR="./$(basename "${MODULEDIR}")"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$BASHBOT_HOME" ]; then
|
if [ -n "$BASHBOT_HOME" ]; then
|
||||||
@ -106,28 +103,6 @@ if [ ! -w "." ]; then
|
|||||||
ls -ld .
|
ls -ld .
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###############
|
|
||||||
# load modules
|
|
||||||
for modules in "${MODULEDIR:-.}"/*.sh ; do
|
|
||||||
# shellcheck source=./modules/aliases.sh
|
|
||||||
if ! _is_function "$(basename "${modules}")" && [ -r "${modules}" ]; then source "${modules}" "source"; fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# shellcheck source=./modules/jsonDB.sh
|
|
||||||
source "${MODULEDIR:-.}"/jsonDB.sh
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#####################
|
|
||||||
# BASHBOT INTERNAL functions
|
|
||||||
#
|
|
||||||
|
|
||||||
#jsonDB is now mandatory
|
|
||||||
if ! _is_function jssh_newDB ; then
|
|
||||||
echo -e "${RED}ERROR: Mandatory module jsonDB is missing or not readable!"
|
|
||||||
exit 6
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Setup and check environment if BOTTOKEN is NOT set
|
# Setup and check environment if BOTTOKEN is NOT set
|
||||||
TOKENFILE="${BASHBOT_ETC:-.}/token"
|
TOKENFILE="${BASHBOT_ETC:-.}/token"
|
||||||
BOTADMIN="${BASHBOT_ETC:-.}/botadmin"
|
BOTADMIN="${BASHBOT_ETC:-.}/botadmin"
|
||||||
@ -191,8 +166,7 @@ if [ -z "${BOTTOKEN}" ]; then
|
|||||||
fi
|
fi
|
||||||
# setup count file
|
# setup count file
|
||||||
if [ ! -f "${COUNTFILE}.jssh" ]; then
|
if [ ! -f "${COUNTFILE}.jssh" ]; then
|
||||||
jssh_newDB_async "${COUNTFILE}"
|
printf '["counted_user_chat_id"]\t"num_messages_seen"\n' > "${COUNTFILE}.jssh"
|
||||||
jssh_insertKeyDB_async 'counted_user_chat_id' "num_messages_seen" "${COUNTFILE}"
|
|
||||||
# convert old file on creation
|
# convert 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"
|
||||||
@ -204,12 +178,9 @@ if [ -z "${BOTTOKEN}" ]; then
|
|||||||
fi
|
fi
|
||||||
# setup blocked file
|
# setup blocked file
|
||||||
if [ ! -f "${BLOCKEDFILE}.jssh" ]; then
|
if [ ! -f "${BLOCKEDFILE}.jssh" ]; then
|
||||||
jssh_newDB_async "${BLOCKEDFILE}"
|
printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >"${BLOCKEDFILE}.jssh"
|
||||||
jssh_insertKeyDB_async 'blocked_user_or_chat_id' "name and reason" "${BLOCKEDFILE}"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# cleanup (remove double entries) countfile on startup
|
|
||||||
[ "${SOURCE}" != "yes" ] && jssh_deleteKeyDB_async "CLEAN_COUNTER_DATABASE_ON_STARTUP" "${COUNTFILE}"
|
|
||||||
|
|
||||||
# do we have BSD sed
|
# do we have BSD sed
|
||||||
if ! sed '1ia' </dev/null 2>/dev/null; then
|
if ! sed '1ia' </dev/null 2>/dev/null; then
|
||||||
@ -230,9 +201,9 @@ fi
|
|||||||
|
|
||||||
##################
|
##################
|
||||||
# here we start with the real stuff
|
# here we start with the real stuff
|
||||||
URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}"
|
|
||||||
BOTSEND_RETRY="no" # do not retry by default
|
BOTSEND_RETRY="no" # do not retry by default
|
||||||
|
|
||||||
|
URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}"
|
||||||
ME_URL=$URL'/getMe'
|
ME_URL=$URL'/getMe'
|
||||||
|
|
||||||
UPD_URL=$URL'/getUpdates?offset='
|
UPD_URL=$URL'/getUpdates?offset='
|
||||||
@ -259,6 +230,25 @@ if [ "${SOURCE}" != "yes" ]; then
|
|||||||
source "${COMMANDS}" "source"
|
source "${COMMANDS}" "source"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
###############
|
||||||
|
# load modules
|
||||||
|
for modules in "${MODULEDIR:-.}"/*.sh ; do
|
||||||
|
# shellcheck source=./modules/aliases.sh
|
||||||
|
if ! _is_function "$(basename "${modules}")" && [ -r "${modules}" ]; then source "${modules}" "source"; fi
|
||||||
|
done
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# BASHBOT INTERNAL functions
|
||||||
|
#
|
||||||
|
|
||||||
|
#jsonDB is now mandatory
|
||||||
|
if ! _is_function jssh_newDB ; then
|
||||||
|
echo -e "${RED}ERROR: Mandatory module jsonDB is missing or not readable!"
|
||||||
|
exit 6
|
||||||
|
fi
|
||||||
|
|
||||||
|
# cleanup (remove double entries) countfile on startup
|
||||||
|
[ "${SOURCE}" != "yes" ] && jssh_deleteKeyDB_async "CLEAN_COUNTER_DATABASE_ON_STARTUP" "${COUNTFILE}"
|
||||||
|
|
||||||
#################
|
#################
|
||||||
# BASHBOT COMMON functions
|
# BASHBOT COMMON functions
|
||||||
@ -890,7 +880,8 @@ JSONSHFILE="${BASHBOT_JSONSH:-${SCRIPTDIR}/JSON.sh/JSON.sh}"
|
|||||||
|
|
||||||
if [ ! -f "${JSONSHFILE}" ]; then
|
if [ ! -f "${JSONSHFILE}" ]; then
|
||||||
echo "Seems to be first run, Downloading ${JSONSHFILE}..."
|
echo "Seems to be first run, Downloading ${JSONSHFILE}..."
|
||||||
mkdir "${SCRIPTDIR}/JSON.sh" 2>/dev/null && chmod +w "${SCRIPTDIR}/JSON.sh"
|
[ "${SCRIPTDIR}/JSON.sh/JSON.sh" = "${JSONSHFILE}" ] &&\
|
||||||
|
mkdir "${SCRIPTDIR}/JSON.sh" 2>/dev/null && chmod +w "${SCRIPTDIR}/JSON.sh"
|
||||||
getJson "https://cdn.jsdelivr.net/gh/dominictarr/JSON.sh/JSON.sh" >"${JSONSHFILE}"
|
getJson "https://cdn.jsdelivr.net/gh/dominictarr/JSON.sh/JSON.sh" >"${JSONSHFILE}"
|
||||||
chmod +x "${JSONSHFILE}"
|
chmod +x "${JSONSHFILE}"
|
||||||
fi
|
fi
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# this has to run once atfer git clone
|
# this has to run once atfer git clone
|
||||||
# and every time we create new hooks
|
# and every time we create new hooks
|
||||||
#### $$VERSION$$ v0.96-dev3-1-g2a66ee9
|
#### $$VERSION$$ v0.96-pre-15-geace5e1
|
||||||
|
|
||||||
# magic to ensure that we're always inside the root of our application,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
Loading…
Reference in New Issue
Block a user