final _exec_if_function, fix env_test

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-26 21:25:01 +02:00
parent 3c6b2d3b35
commit cfdcb41a38
5 changed files with 23 additions and 21 deletions

View File

@ -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.90-dev2-4-gb60f33a #### $$VERSION$$ v0.90-dev2-6-g3c6b2d3
# #
# Exit Codes: # Exit Codes:
# - 0 sucess (hopefully) # - 0 sucess (hopefully)
@ -136,6 +136,7 @@ unset USER
declare -A UPD BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY 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 export res UPD BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY CAPTION
COMMANDS="${BASHBOT_ETC:-.}/commands.sh" COMMANDS="${BASHBOT_ETC:-.}/commands.sh"
if [ "${SOURCE}" = "yes" ]; then if [ "${SOURCE}" = "yes" ]; then
for modules in ${MODULEDIR:-.}/*.sh ; do for modules in ${MODULEDIR:-.}/*.sh ; do
@ -199,8 +200,8 @@ _exists()
} }
# execute function if exists # execute function if exists
_execute_function() { _exec_if_function() {
[ "$(LC_ALL=C type -t "${1}")" = "function" ] && "$@" [ "$(LC_ALL=C type -t "${1}")" != "function" ] || "$@"
} }
# returns true if function exist # returns true if function exist
_is_function() _is_function()
@ -332,7 +333,7 @@ process_client() {
process_message "${num}" "${debug}" process_message "${num}" "${debug}"
else else
[[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"INLINE.log" [[ "${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 fi
##### #####
# process inline and message events # process inline and message events
@ -357,7 +358,7 @@ event_inline() {
# shellcheck disable=SC2153 # shellcheck disable=SC2153
for event in "${!BASHBOT_EVENT_INLINE[@]}" for event in "${!BASHBOT_EVENT_INLINE[@]}"
do do
_is_function "${BASHBOT_EVENT_INLINE[${event}]}" && "${BASHBOT_EVENT_INLINE[${event}]}" "inline" "${debug}" _exec_if_function "${BASHBOT_EVENT_INLINE[${event}]}" "inline" "${debug}"
done done
} }
event_message() { event_message() {
@ -366,7 +367,7 @@ event_message() {
# shellcheck disable=SC2153 # shellcheck disable=SC2153
for event in "${!BASHBOT_EVENT_MESSAGE[@]}" for event in "${!BASHBOT_EVENT_MESSAGE[@]}"
do do
_is_function "${BASHBOT_EVENT_MESSAGE[${event}]}" && "${BASHBOT_EVENT_MESSAGE[${event}]}" "messsage" "${debug}" _exec_if_function "${BASHBOT_EVENT_MESSAGE[${event}]}" "messsage" "${debug}"
done done
# ${REPLYTO[*]} event_replyto # ${REPLYTO[*]} event_replyto
@ -374,7 +375,7 @@ event_message() {
# shellcheck disable=SC2153 # shellcheck disable=SC2153
for event in "${!BASHBOT_EVENT_REPLYTO[@]}" for event in "${!BASHBOT_EVENT_REPLYTO[@]}"
do do
_is_function "${BASHBOT_EVENT_REPLYTO[${event}]}" && "${BASHBOT_EVENT_REPLYTO[${event}]}" "replyto" "${debug}" _exec_if_function "${BASHBOT_EVENT_REPLYTO[${event}]}" "replyto" "${debug}"
done done
fi fi
@ -383,7 +384,7 @@ event_message() {
# shellcheck disable=SC2153 # shellcheck disable=SC2153
for event in "${!BASHBOT_EVENT_FORWARD[@]}" for event in "${!BASHBOT_EVENT_FORWARD[@]}"
do do
_is_function "${BASHBOT_EVENT_FORWARD[${event}]}" && "${BASHBOT_EVENT_FORWARD[${event}]}" "forward" "${debug}" _exec_if_function && "${BASHBOT_EVENT_FORWARD[${event}]}" "forward" "${debug}"
done done
fi fi
@ -392,7 +393,7 @@ event_message() {
# shellcheck disable=SC2153 # shellcheck disable=SC2153
for event in "${!BASHBOT_EVENT_CONTACT[@]}" for event in "${!BASHBOT_EVENT_CONTACT[@]}"
do do
_is_function "${BASHBOT_EVENT_CONTACT[${event}]}" && "${BASHBOT_EVENT_CONTACT[${event}]}" "contact" "${debug}" _exec_if_function "${BASHBOT_EVENT_CONTACT[${event}]}" "contact" "${debug}"
done done
fi fi
@ -402,7 +403,7 @@ event_message() {
# shellcheck disable=SC2153 # shellcheck disable=SC2153
for event in "${!BASHBOT_EVENT_LOCATION[@]}" for event in "${!BASHBOT_EVENT_LOCATION[@]}"
do do
_is_function "${BASHBOT_EVENT_LOCATION[${event}]}" && "${BASHBOT_EVENT_LOCATION[${event}]}" "location" "${debug}" _exec_if_function "${BASHBOT_EVENT_LOCATION[${event}]}" "location" "${debug}"
done done
fi fi
@ -411,7 +412,7 @@ event_message() {
# shellcheck disable=SC2153 # shellcheck disable=SC2153
for event in "${!BASHBOT_EVENT_FILE[@]}" for event in "${!BASHBOT_EVENT_FILE[@]}"
do do
_is_function "${BASHBOT_EVENT_FILE[${event}]}" && "${BASHBOT_EVENT_FILE[${event}]}" "file" "${debug}" _exec_if_function "${BASHBOT_EVENT_FILE[${event}]}" "file" "${debug}"
done done
fi fi

View File

@ -5,7 +5,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.90-dev2-0-gec85636 #### $$VERSION$$ v0.90-dev2-6-g3c6b2d3
# #
# 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.
@ -61,7 +61,7 @@ if [ "${1}" != "source" ];then
if [ "$INLINE" != "0" ] && [ "${iQUERY[ID]}" != "" ]; then if [ "$INLINE" != "0" ] && [ "${iQUERY[ID]}" != "" ]; then
if _is_function process_inline; then if _is_function process_inline; then
# forward iinline query to optional dispatcher # forward iinline query to optional dispatcher
_is_function myinlines && myinlines _exec_if_function myinlines
fi fi
# regular (gobal) commands ... # regular (gobal) commands ...
@ -69,8 +69,8 @@ if [ "${1}" != "source" ];then
else else
################### ###################
# user defined commands must plaed in mycommands # user defined commands must placed in mycommands
! _is_function mycommands || mycommands # return true if not exist! _exec_if_function mycommands
# run commands if true (0) is returned or if mycommands dose not exist # run commands if true (0) is returned or if mycommands dose not exist
# shellcheck disable=SC2181 # 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 if [ "$res" -eq 0 ] ; then killproc && _message "Command canceled.";else _message "No command is currently running.";fi
;; ;;
*) # forward messages to optional dispatcher *) # forward messages to optional dispatcher
_is_function send_interactive && send_interactive "${CHAT[ID]}" "${MESSAGE}" _exec_if_function send_interactive "${CHAT[ID]}" "${MESSAGE}"
;; ;;
esac esac
fi fi

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.90-dev2-0-gec85636 #### $$VERSION$$ v0.90-dev2-6-g3c6b2d3
# common variables # common variables
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
@ -54,6 +54,6 @@ echo "............................"
[ "${TESTDIR}" = "" ] && echo "${NOSUCCESS} not called from testsuite, exit" && exit 1 [ "${TESTDIR}" = "" ] && echo "${NOSUCCESS} not called from testsuite, exit" && exit 1
# reset env for test # reset env for test
unset IFS; set -f unset IFS;
export TERM="" export TERM=""

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.90-dev2-0-gec85636 #### $$VERSION$$ v0.90-dev2-6-g3c6b2d3
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh
@ -38,6 +38,7 @@ echo "Test if $JSONSHFILE exists ..."
echo "Test Sourcing of bashbot.sh ..." echo "Test Sourcing of bashbot.sh ..."
# shellcheck source=./bashbot.sh # shellcheck source=./bashbot.sh
source "${TESTDIR}/bashbot.sh" source source "${TESTDIR}/bashbot.sh" source
echo "Test Sourcing of commands.sh ..."
source "${TESTDIR}/commands.sh" source source "${TESTDIR}/commands.sh" source
trap '' EXIT trap '' EXIT

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.90-dev2-0-gec85636 #### $$VERSION$$ v0.90-dev2-6-g3c6b2d3
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh
@ -31,7 +31,7 @@ set +f
# shellcheck disable=SC2086 # shellcheck disable=SC2086
cp ${TESTDIR}/*commands.sh "${BASHBOT_ETC}" || exit 1 cp ${TESTDIR}/*commands.sh "${BASHBOT_ETC}" || exit 1
set -f set -f
cp "${TESTDIR}/bashbot.sh" "${BASHBOT_BIN}" || exit 1 cp -r "${TESTDIR}/bashbot.sh" "${TESTDIR}/modules" "${BASHBOT_BIN}" || exit 1
TESTTOKEN="bashbottestscript" TESTTOKEN="bashbottestscript"
TESTFILES="${TOKENFILE} ${ACLFILE} ${ADMINFILE}" TESTFILES="${TOKENFILE} ${ACLFILE} ${ADMINFILE}"