mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-27 20:44:53 +00:00
multiline printf
This commit is contained in:
parent
ed1cc4a37f
commit
9cca55b376
12
bashbot.sh
12
bashbot.sh
@ -30,7 +30,7 @@
|
||||
# 8 - curl/wget missing
|
||||
# 10 - not bash!
|
||||
#
|
||||
#### $$VERSION$$ v1.21-pre-11-g03c8c9d
|
||||
#### $$VERSION$$ v1.21-pre-12-ged1cc4a
|
||||
##################################################################
|
||||
|
||||
# emmbeded system may claim bash but it is not
|
||||
@ -279,16 +279,16 @@ fi
|
||||
|
||||
# BOTTOKEN format checks
|
||||
if ! check_token "${BOTTOKEN}"; then
|
||||
printf "\n${ORANGE}Warning: Your bot token is incorrect, it should have the following format:${NC}\n"
|
||||
printf "<your_bot_id>${RED}:${NC}<35_alphanumeric_characters-hash> ${RED}e.g. =>${NC} 123456789${RED}:${NC}Aa-Zz_0Aa-Zz_1Aa-Zz_2Aa-Zz_3Aa-Zz_4\n\n"
|
||||
printf "${GREY}Your bot token: '${NC}${BOTTOKEN//:/${RED}:${NC}}'\n"
|
||||
printf "\n${ORANGE}Warning: Your bot token is incorrect, it should have the following format:${NC}\n%b%b"\
|
||||
"<your_bot_id>${RED}:${NC}<35_alphanumeric_characters-hash> ${RED}e.g. =>${NC} 123456789${RED}:${NC}Aa-Zz_0Aa-Zz_1Aa-Zz_2Aa-Zz_3Aa-Zz_4\n\n"\
|
||||
"${GREY}Your bot token: '${NC}${BOTTOKEN//:/${RED}:${NC}}'\n"
|
||||
|
||||
if [[ ! "${BOTTOKEN}" =~ ^[0-9]{8,10}: ]]; then
|
||||
printf "${GREY}\tHint: Bot id len: ${NC}$(($(wc -c <<<"${BOTTOKEN%:*}")-1)) ${GREY}but should be${NC} 8-10\n"
|
||||
printf "${GREY}\tHint: Bot id not a number or wrong len: ${NC}$(($(wc -c <<<"${BOTTOKEN%:*}")-1)) ${GREY}but should be${NC} 8-10\n"
|
||||
[ -n "$(getConfigKey "botid")" ] && printf "\t${GREEN}Did you mean: \"${NC}$(getConfigKey "botid")${GREEN}\" ?${NN}"
|
||||
fi
|
||||
[[ ! "${BOTTOKEN}" =~ :[a-zA-Z0-9_-]{35}$ ]] &&\
|
||||
printf "${GREY}\tHint: Hash contains invalid character or is not${NC} 35 ${GREY}characters long, hash len is ${NC}$(($(wc -c <<<"${BOTTOKEN#*:}")-1))\n"
|
||||
printf "${GREY}\tHint: Hash contains invalid character or has not len${NC} 35 ${GREY}, hash len is ${NC}$(($(wc -c <<<"${BOTTOKEN#*:}")-1))\n"
|
||||
printf "\n"
|
||||
fi
|
||||
|
||||
|
53
xxx
53
xxx
@ -1,53 +0,0 @@
|
||||
# CREATE botconfig if not exist
|
||||
# assume everything already set up correctly if TOKEN is set
|
||||
if [ -z "${BOTTOKEN}" ]; then
|
||||
# BOTCONFIG does not exist, create
|
||||
[ ! -f "${BOTCONFIG}.jssh" ] && printf '["bot_config_key"]\t"config_key_value"\n' >>"${BOTCONFIG}.jssh"
|
||||
if [ -z "$(getConfigKey "bottoken")" ]; then
|
||||
# ask user for bot token
|
||||
if [ -z "${INTERACTIVE}" ] && [ "$1" != "init" ]; then
|
||||
printf "Running headless, set BOTTOKEN or run ${SCRIPT} init first!\n"
|
||||
exit 2
|
||||
else
|
||||
printf "${RED}ENTER BOT TOKEN...${NN}${ORANGE}PLEASE WRITE YOUR TOKEN HERE OR PRESS CTRL+C TO ABORT${NN}"
|
||||
read -r token
|
||||
printf "\n"
|
||||
fi
|
||||
[ -n "${token}" ] && printf '["bottoken"]\t"%s"\n' "${token}" >> "${BOTCONFIG}.jssh"
|
||||
fi
|
||||
# no botadmin, setup botadmin
|
||||
if [ -z "$(getConfigKey "botadmin")" ]; then
|
||||
# ask user for bot admin
|
||||
if [ -z "${INTERACTIVE}" ]; then
|
||||
printf "Running headless, set botadmin to AUTO MODE!\n"
|
||||
else
|
||||
printf "${RED}ENTER BOT ADMIN...${NN}${ORANGE}PLEASE WRITE YOUR TELEGRAM ID HERE OR PRESS ENTER\nTO MAKE FIRST USER TYPING '/start' BOT ADMIN${NN}?\b"
|
||||
read -r admin
|
||||
fi
|
||||
[ -z "${admin}" ] && admin='?'
|
||||
printf '["botadmin"]\t"%s"\n' "${admin}" >> "${BOTCONFIG}.jssh"
|
||||
fi
|
||||
# setup botacl file
|
||||
if [ ! -f "${BOTACL}" ]; then
|
||||
printf "${GREY}Create initial ${BOTACL} file.${NN}"
|
||||
printf '\n' >"${BOTACL}"
|
||||
fi
|
||||
# check data dir file
|
||||
if [ ! -w "${DATADIR}" ]; then
|
||||
printf "${RED}ERROR: ${DATADIR} does not exist or is not writeable!.${NN}"
|
||||
exit 2
|
||||
fi
|
||||
# setup count file
|
||||
if [ ! -f "${COUNTFILE}.jssh" ]; then
|
||||
printf '["counted_user_chat_id"]\t"num_messages_seen"\n' >> "${COUNTFILE}.jssh"
|
||||
elif [ ! -w "${COUNTFILE}.jssh" ]; then
|
||||
printf "${RED}ERROR: Can't write to ${COUNTFILE}!.${NN}"
|
||||
ls -l "${COUNTFILE}.jssh"
|
||||
exit 2
|
||||
fi
|
||||
# setup blocked file
|
||||
if [ ! -f "${BLOCKEDFILE}.jssh" ]; then
|
||||
printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >>"${BLOCKEDFILE}.jssh"
|
||||
fi
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user