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