mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-25 16:57:33 +00:00
final _exec_if_function, fix env_test
This commit is contained in:
parent
3c6b2d3b35
commit
cfdcb41a38
23
bashbot.sh
23
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.90-dev2-4-gb60f33a
|
||||
#### $$VERSION$$ v0.90-dev2-6-g3c6b2d3
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
@ -136,6 +136,7 @@ unset USER
|
||||
declare -A UPD BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY
|
||||
export res UPD BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY CAPTION
|
||||
|
||||
|
||||
COMMANDS="${BASHBOT_ETC:-.}/commands.sh"
|
||||
if [ "${SOURCE}" = "yes" ]; then
|
||||
for modules in ${MODULEDIR:-.}/*.sh ; do
|
||||
@ -199,8 +200,8 @@ _exists()
|
||||
}
|
||||
|
||||
# execute function if exists
|
||||
_execute_function() {
|
||||
[ "$(LC_ALL=C type -t "${1}")" = "function" ] && "$@"
|
||||
_exec_if_function() {
|
||||
[ "$(LC_ALL=C type -t "${1}")" != "function" ] || "$@"
|
||||
}
|
||||
# returns true if function exist
|
||||
_is_function()
|
||||
@ -332,7 +333,7 @@ process_client() {
|
||||
process_message "${num}" "${debug}"
|
||||
else
|
||||
[[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"INLINE.log"
|
||||
[ "$INLINE" != "0" ] && _is_function process_inline && process_inline "${num}" "${debug}"
|
||||
[ "$INLINE" != "0" ] && _exec_if_function process_inline "${num}" "${debug}"
|
||||
fi
|
||||
#####
|
||||
# process inline and message events
|
||||
@ -357,7 +358,7 @@ event_inline() {
|
||||
# shellcheck disable=SC2153
|
||||
for event in "${!BASHBOT_EVENT_INLINE[@]}"
|
||||
do
|
||||
_is_function "${BASHBOT_EVENT_INLINE[${event}]}" && "${BASHBOT_EVENT_INLINE[${event}]}" "inline" "${debug}"
|
||||
_exec_if_function "${BASHBOT_EVENT_INLINE[${event}]}" "inline" "${debug}"
|
||||
done
|
||||
}
|
||||
event_message() {
|
||||
@ -366,7 +367,7 @@ event_message() {
|
||||
# shellcheck disable=SC2153
|
||||
for event in "${!BASHBOT_EVENT_MESSAGE[@]}"
|
||||
do
|
||||
_is_function "${BASHBOT_EVENT_MESSAGE[${event}]}" && "${BASHBOT_EVENT_MESSAGE[${event}]}" "messsage" "${debug}"
|
||||
_exec_if_function "${BASHBOT_EVENT_MESSAGE[${event}]}" "messsage" "${debug}"
|
||||
done
|
||||
|
||||
# ${REPLYTO[*]} event_replyto
|
||||
@ -374,7 +375,7 @@ event_message() {
|
||||
# shellcheck disable=SC2153
|
||||
for event in "${!BASHBOT_EVENT_REPLYTO[@]}"
|
||||
do
|
||||
_is_function "${BASHBOT_EVENT_REPLYTO[${event}]}" && "${BASHBOT_EVENT_REPLYTO[${event}]}" "replyto" "${debug}"
|
||||
_exec_if_function "${BASHBOT_EVENT_REPLYTO[${event}]}" "replyto" "${debug}"
|
||||
done
|
||||
fi
|
||||
|
||||
@ -383,7 +384,7 @@ event_message() {
|
||||
# shellcheck disable=SC2153
|
||||
for event in "${!BASHBOT_EVENT_FORWARD[@]}"
|
||||
do
|
||||
_is_function "${BASHBOT_EVENT_FORWARD[${event}]}" && "${BASHBOT_EVENT_FORWARD[${event}]}" "forward" "${debug}"
|
||||
_exec_if_function && "${BASHBOT_EVENT_FORWARD[${event}]}" "forward" "${debug}"
|
||||
done
|
||||
fi
|
||||
|
||||
@ -392,7 +393,7 @@ event_message() {
|
||||
# shellcheck disable=SC2153
|
||||
for event in "${!BASHBOT_EVENT_CONTACT[@]}"
|
||||
do
|
||||
_is_function "${BASHBOT_EVENT_CONTACT[${event}]}" && "${BASHBOT_EVENT_CONTACT[${event}]}" "contact" "${debug}"
|
||||
_exec_if_function "${BASHBOT_EVENT_CONTACT[${event}]}" "contact" "${debug}"
|
||||
done
|
||||
fi
|
||||
|
||||
@ -402,7 +403,7 @@ event_message() {
|
||||
# shellcheck disable=SC2153
|
||||
for event in "${!BASHBOT_EVENT_LOCATION[@]}"
|
||||
do
|
||||
_is_function "${BASHBOT_EVENT_LOCATION[${event}]}" && "${BASHBOT_EVENT_LOCATION[${event}]}" "location" "${debug}"
|
||||
_exec_if_function "${BASHBOT_EVENT_LOCATION[${event}]}" "location" "${debug}"
|
||||
done
|
||||
fi
|
||||
|
||||
@ -411,7 +412,7 @@ event_message() {
|
||||
# shellcheck disable=SC2153
|
||||
for event in "${!BASHBOT_EVENT_FILE[@]}"
|
||||
do
|
||||
_is_function "${BASHBOT_EVENT_FILE[${event}]}" && "${BASHBOT_EVENT_FILE[${event}]}" "file" "${debug}"
|
||||
_exec_if_function "${BASHBOT_EVENT_FILE[${event}]}" "file" "${debug}"
|
||||
done
|
||||
fi
|
||||
|
||||
|
10
commands.sh
10
commands.sh
@ -5,7 +5,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.90-dev2-0-gec85636
|
||||
#### $$VERSION$$ v0.90-dev2-6-g3c6b2d3
|
||||
#
|
||||
|
||||
# adjust your language setting here, e.g.when run from other user or cron.
|
||||
@ -61,7 +61,7 @@ if [ "${1}" != "source" ];then
|
||||
if [ "$INLINE" != "0" ] && [ "${iQUERY[ID]}" != "" ]; then
|
||||
if _is_function process_inline; then
|
||||
# forward iinline query to optional dispatcher
|
||||
_is_function myinlines && myinlines
|
||||
_exec_if_function myinlines
|
||||
fi
|
||||
|
||||
# regular (gobal) commands ...
|
||||
@ -69,8 +69,8 @@ if [ "${1}" != "source" ];then
|
||||
else
|
||||
|
||||
###################
|
||||
# user defined commands must plaed in mycommands
|
||||
! _is_function mycommands || mycommands # return true if not exist!
|
||||
# user defined commands must placed in mycommands
|
||||
_exec_if_function mycommands
|
||||
|
||||
# run commands if true (0) is returned or if mycommands dose not exist
|
||||
# shellcheck disable=SC2181
|
||||
@ -111,7 +111,7 @@ if [ "${1}" != "source" ];then
|
||||
if [ "$res" -eq 0 ] ; then killproc && _message "Command canceled.";else _message "No command is currently running.";fi
|
||||
;;
|
||||
*) # forward messages to optional dispatcher
|
||||
_is_function send_interactive && send_interactive "${CHAT[ID]}" "${MESSAGE}"
|
||||
_exec_if_function send_interactive "${CHAT[ID]}" "${MESSAGE}"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.90-dev2-0-gec85636
|
||||
#### $$VERSION$$ v0.90-dev2-6-g3c6b2d3
|
||||
|
||||
# common variables
|
||||
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
||||
@ -54,6 +54,6 @@ echo "............................"
|
||||
[ "${TESTDIR}" = "" ] && echo "${NOSUCCESS} not called from testsuite, exit" && exit 1
|
||||
|
||||
# reset env for test
|
||||
unset IFS; set -f
|
||||
unset IFS;
|
||||
export TERM=""
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.90-dev2-0-gec85636
|
||||
#### $$VERSION$$ v0.90-dev2-6-g3c6b2d3
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
@ -38,6 +38,7 @@ echo "Test if $JSONSHFILE exists ..."
|
||||
echo "Test Sourcing of bashbot.sh ..."
|
||||
# shellcheck source=./bashbot.sh
|
||||
source "${TESTDIR}/bashbot.sh" source
|
||||
echo "Test Sourcing of commands.sh ..."
|
||||
source "${TESTDIR}/commands.sh" source
|
||||
|
||||
trap '' EXIT
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.90-dev2-0-gec85636
|
||||
#### $$VERSION$$ v0.90-dev2-6-g3c6b2d3
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
@ -31,7 +31,7 @@ set +f
|
||||
# shellcheck disable=SC2086
|
||||
cp ${TESTDIR}/*commands.sh "${BASHBOT_ETC}" || exit 1
|
||||
set -f
|
||||
cp "${TESTDIR}/bashbot.sh" "${BASHBOT_BIN}" || exit 1
|
||||
cp -r "${TESTDIR}/bashbot.sh" "${TESTDIR}/modules" "${BASHBOT_BIN}" || exit 1
|
||||
|
||||
TESTTOKEN="bashbottestscript"
|
||||
TESTFILES="${TOKENFILE} ${ACLFILE} ${ADMINFILE}"
|
||||
|
Loading…
Reference in New Issue
Block a user