diff --git a/bashbot.sh b/bashbot.sh index 0ad316a..631215e 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$$ v1.2-dev2-66-gc93c9ae +#### $$VERSION$$ v1.2-dev2-74-g0b7cd8a # # Exit Codes: # - 0 success (hopefully) diff --git a/bin/bashbot_env.inc.sh b/bin/bashbot_env.inc.sh index f551153..90a4c05 100644 --- a/bin/bashbot_env.inc.sh +++ b/bin/bashbot_env.inc.sh @@ -13,31 +13,46 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 18.12.2020 12:27 # -#### $$VERSION$$ v1.2-dev2-73-gf281ae0 +#### $$VERSION$$ v1.2-dev2-74-g0b7cd8a #=============================================================================== +############ # set where your bashbot lives # default: one dir up BASHBOT_HOME="$(cd "${BASH_SOURCE[0]%/*}" >/dev/null 2>&1 && pwd)/../" +[ "${BASHBOT_HOME}" = "/../" ] && BASHBOT_HOME="../" + +# set you own BASHBOT_HOME if different, e.g. +# BASHBOT_HOME="/usr/local/telegram-bot-bash" +BASHBOT_ETC="${BASHBOT_HOME}" +BASHBOT_VAR="${BASHBOT_HOME}" ##### # if files are not readable, eviroment is wrong or bashbot is not initialized +# source bashbot +if [ ! -r "${BASHBOT_HOME}/bashbot.sh" ]; then + echo "Bashbot.sh not found in \"${BASHBOT_HOME}\"" + exit 4 +else + # shellcheck disable=SC1090 + source "${BASHBOT_HOME}/bashbot.sh" source "$1" +fi + # check for botconfig.jssh readable -if [ ! -r "${BASHBOT_HOME}/botconfig.jssh" ]; then - echo "Bashbot config file in \"${BASHBOT_HOME}\" does not exist or is not readable." +if [ ! -r "${BASHBOT_ETC}/botconfig.jssh" ]; then + echo "Bashbot config file in \"${BASHBOT_ETC}\" does not exist or is not readable." exit 3 fi # check for count.jssh readable -if [ ! -r "${BASHBOT_HOME}/count.jssh" ]; then - echo "Bashbot count file in \"${BASHBOT_HOME}\" does not exist or is not readable" +if [ ! -r "${BASHBOT_VAR}/count.jssh" ]; then + echo "Bashbot count file in \"${BASHBOT_VAR}\" does not exist or is not readable. Did you run bashbot init?" exit 3 fi -# source bashbot and check for ADMIN -# shellcheck disable=SC1090 -source "${BASHBOT_HOME}/bashbot.sh" source "$1" - -ADMIN="$(getConfigKey "botadmin")" -[ "${ADMIN}" = "?" ] && echo -e "${ORANGE}Warning: Botadmin not set, did you forget to sent command${NC} /start?" +# get and check ADMIN and NAME +BOT_ADMIN="$(getConfigKey "botadmin")" +BOT_NAME="$(getConfigKey "botname")" +[[ -z "${BOT_ADMIN}" || "${BOT_ADMIN}" == "?" ]] && echo -e "${ORANGE}Warning: Botadmin not set, did you forget to sent command${NC} /start" +[[ -z "${BOT_NAME}" ]] && echo -e "${ORANGE}Warning: Botname not set, did you ever run bashbot?" diff --git a/bin/bashbot_stats.sh b/bin/bashbot_stats.sh index 80f5587..be2c835 100755 --- a/bin/bashbot_stats.sh +++ b/bin/bashbot_stats.sh @@ -16,7 +16,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 20:34 # -#### $$VERSION$$ v1.2-dev2-73-gf281ae0 +#### $$VERSION$$ v1.2-dev2-74-g0b7cd8a #=============================================================================== #### @@ -39,8 +39,7 @@ source "${0%/*}/bashbot_env.inc.sh" "$1" #### # ready, do stuff here ----- -ME="$(getConfigKey "botname")" -echo -e "${GREEN}Hi I'm ${ME}.${NC}" +echo -e "${GREEN}Hi I'm ${BOT_NAME}.${NC}" declare -A STATS jssh_readDB_async "STATS" "${COUNTFILE}" for MSG in ${!STATS[*]} diff --git a/bin/send_broadcast.sh b/bin/send_broadcast.sh index 846dceb..525d8f7 100755 --- a/bin/send_broadcast.sh +++ b/bin/send_broadcast.sh @@ -24,7 +24,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 16:14 # -#### $$VERSION$$ v1.2-dev2-73-gf281ae0 +#### $$VERSION$$ v1.2-dev2-74-g0b7cd8a #=============================================================================== #### @@ -88,7 +88,7 @@ if [ -z "${SENDALL[*]}" ]; then fi # loop over users - echo -e "${GREEN}Sending broadcast message to all users of $(getConfigKey "botname")${NC}${GREY}\c" + echo -e "${GREEN}Sending broadcast message to all users of ${BOT_NAME}${NC}${GREY}\c" { # dry run [ -z "${DOIT}" ] && echo -e "${NC}\n${ORANGE}DRY RUN! use --doit as first argument to execute broadcast...${NC}" diff --git a/bin/send_edit_message.sh b/bin/send_edit_message.sh index 9a47942..a4419ad 100755 --- a/bin/send_edit_message.sh +++ b/bin/send_edit_message.sh @@ -22,7 +22,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 16:52 # -#### $$VERSION$$ v1.2-dev2-73-gf281ae0 +#### $$VERSION$$ v1.2-dev2-74-g0b7cd8a #=============================================================================== #### @@ -63,7 +63,7 @@ source "${0%/*}/bashbot_env.inc.sh" "$4" # $4 debug #### # ready, do stuff here ----- if [ "$1" == "BOTADMIN" ]; then - CHAT="${ADMIN}" + CHAT="${BOT_ADMIN}" else CHAT="$1" fi diff --git a/bin/send_message.sh b/bin/send_message.sh index bbf6395..418c4bb 100755 --- a/bin/send_message.sh +++ b/bin/send_message.sh @@ -21,7 +21,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 11:34 # -#### $$VERSION$$ v1.2-dev2-73-gf281ae0 +#### $$VERSION$$ v1.2-dev2-74-g0b7cd8a #=============================================================================== @@ -61,7 +61,7 @@ source "${0%/*}/bashbot_env.inc.sh" "$3" # $3 debug #### # ready, do stuff here ----- if [ "$1" == "BOTADMIN" ]; then - CHAT="${ADMIN}" + CHAT="${BOT_ADMIN}" else CHAT="$1" fi