mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-28 12:50:44 +00:00
optimze sourcing of modules
This commit is contained in:
parent
4aa7561f7c
commit
c0a633f42d
19
bashbot.sh
19
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$$ v0.94-pre-0-gac2ec02
|
||||
#### $$VERSION$$ v0.94-pre-1-g4aa7561
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
@ -39,7 +39,7 @@ RUNDIR="$(dirname "$0")"
|
||||
|
||||
MODULEDIR="${SCRIPTDIR}/modules"
|
||||
|
||||
|
||||
# adjust locations based on source and real name
|
||||
if [ "${SCRIPT}" != "${REALME}" ] || [ "$1" = "source" ]; then
|
||||
SOURCE="yes"
|
||||
else
|
||||
@ -69,20 +69,21 @@ if [ ! -w "." ]; then
|
||||
ls -ld .
|
||||
fi
|
||||
|
||||
|
||||
# if BOTTOKEN is empty read from file
|
||||
TOKENFILE="${BASHBOT_ETC:-.}/token"
|
||||
if [ ! -f "${TOKENFILE}" ]; then
|
||||
if [ -z "${BOTTOKEN}" ] && [ ! -f "${TOKENFILE}" ]; then
|
||||
if [ "${CLEAR}" = "" ] && [ "$1" != "init" ]; then
|
||||
echo "Running headless, run ${SCRIPT} init first!"
|
||||
echo "Running headless, set BOTTOKEN or run ${SCRIPT} init first!"
|
||||
exit 2
|
||||
else
|
||||
${CLEAR}
|
||||
echo -e "${RED}TOKEN MISSING.${NC}"
|
||||
echo -e "${ORANGE}PLEASE WRITE YOUR TOKEN HERE OR PRESS CTRL+C TO ABORT${NC}"
|
||||
read -r token
|
||||
printf '%s\n' "${token}" > "${TOKENFILE}"
|
||||
read -r BOTTOKEN
|
||||
printf '%s\n' "${BOTTOKEN}" > "${TOKENFILE}"
|
||||
fi
|
||||
fi
|
||||
[ -z "${BOTTOKEN}" ] && BOTTOKEN="$(< "${TOKENFILE}")"
|
||||
|
||||
BOTADMIN="${BASHBOT_ETC:-.}/botadmin"
|
||||
if [ ! -f "${BOTADMIN}" ]; then
|
||||
@ -124,7 +125,6 @@ elif [ ! -w "${COUNTFILE}" ]; then
|
||||
exit 2
|
||||
fi
|
||||
|
||||
BOTTOKEN="$(< "${TOKENFILE}")"
|
||||
URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}"
|
||||
|
||||
ME_URL=$URL'/getMe'
|
||||
@ -155,7 +155,7 @@ fi
|
||||
# load modules
|
||||
for modules in "${MODULEDIR:-.}"/*.sh ; do
|
||||
# shellcheck source=./modules/aliases.sh
|
||||
[ -r "${modules}" ] && source "${modules}" "source"
|
||||
if ! _is_function "$(basename "${modules}")" && [ -r "${modules}" ]; then source "${modules}" "source"; fi
|
||||
done
|
||||
|
||||
#################
|
||||
@ -677,6 +677,7 @@ bot_init() {
|
||||
# upgrade from old version
|
||||
local OLDTMP="${BASHBOT_VAR:-.}/tmp-bot-bash"
|
||||
[ -d "${OLDTMP}" ] && { mv -n "${OLDTMP}/"* "${DATADIR}"; rmdir "${OLDTMP}"; }
|
||||
# no more existing modules
|
||||
[ -f "modules/inline.sh" ] && rm -f "modules/inline.sh"
|
||||
# load addons on startup
|
||||
for addons in "${ADDONDIR:-.}"/*.sh ; do
|
||||
|
12
commands.sh
12
commands.sh
@ -15,7 +15,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-0-gac2ec02
|
||||
#### $$VERSION$$ v0.94-pre-1-g4aa7561
|
||||
#
|
||||
|
||||
# adjust your language setting here, e.g.when run from other user or cron.
|
||||
@ -51,12 +51,14 @@ Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash)
|
||||
'
|
||||
|
||||
# load modues on startup and always on on debug
|
||||
if [ "${1}" = "startbot" ] || [[ "${1}" = *"debug"* ]] ; then
|
||||
# load all readable modules
|
||||
for modules in "${MODULEDIR:-.}"/*.sh ; do
|
||||
if [ "${1}" != "" ]; then
|
||||
# load all readable modules
|
||||
for modules in "${MODULEDIR:-.}"/*.sh ; do
|
||||
if [[ "${1}" == *"debug"* ]] || ! _is_function "$(basename "${modules}")"; then
|
||||
# shellcheck source=./modules/aliases.sh
|
||||
[ -r "${modules}" ] && source "${modules}" "${1}"
|
||||
done
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
#
|
||||
|
@ -5,10 +5,13 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ v0.94-pre-1-g4aa7561
|
||||
#
|
||||
# source from commands.sh to use the aliases
|
||||
|
||||
# source once magic, function named like file
|
||||
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
|
||||
|
||||
# easy handling of users:
|
||||
_is_botadmin() {
|
||||
user_is_botadmin "${USER[ID]}"
|
||||
|
@ -5,10 +5,13 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ v0.94-pre-1-g4aa7561
|
||||
|
||||
# source from commands.sh to use the inline functions
|
||||
|
||||
# source once magic, function named like file
|
||||
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
|
||||
|
||||
INLINE_QUERY=$URL'/answerInlineQuery'
|
||||
|
||||
answer_inline_query() {
|
||||
|
@ -5,10 +5,13 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ v0.94-pre-1-g4aa7561
|
||||
|
||||
# source from commands.sh if you want ro use interactive or background jobs
|
||||
|
||||
# source once magic, function named like file
|
||||
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
|
||||
|
||||
######
|
||||
# interactive and background functions
|
||||
|
||||
|
@ -5,7 +5,10 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ v0.94-pre-1-g4aa7561
|
||||
|
||||
# source once magic, function named like file
|
||||
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
|
||||
|
||||
# source from commands.sh to use the member functions
|
||||
|
||||
|
@ -5,13 +5,16 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ v0.94-pre-1-g4aa7561
|
||||
#
|
||||
# source from commands.sh to use jsonDB functions
|
||||
#
|
||||
# jsonDB provides simple functions to read and store bash Arrays
|
||||
# from to file in JSON.sh output format, its a simple key/value storage.
|
||||
|
||||
# source once magic, function named like file
|
||||
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
|
||||
|
||||
# read content of a file in JSON.sh format into given ARRAY
|
||||
# $1 ARRAY name, must be delared with "declare -A ARRAY" upfront
|
||||
# $2 filename, must be relative to BASHBOT_ETC, and not contain '..'
|
||||
|
@ -5,7 +5,10 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ v0.94-pre-1-g4aa7561
|
||||
|
||||
# source once magic, function named like file
|
||||
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
|
||||
|
||||
# source from commands.sh to use the sendMessage functions
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user