allow overwriting of standard commands

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-25 13:31:36 +02:00
parent 25c9b62a76
commit 68bee46383
2 changed files with 25 additions and 6 deletions

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.80-18-g6b88656 #### $$VERSION$$ v0.80-23-g25c9b62
# #
# 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.
@ -68,7 +68,14 @@ if [ "${1}" != "source" ];then
# your commands are in mycommands() # your commands are in mycommands()
else else
case "${MESSAGE}" in ###################
# user defined commands must plaed in mycommands
! _is_function mycommands || mycommands # return true if not exist!
# run commands if true (0) is returned or if mycommands dose not exist
# shellcheck disable=SC2181
if [ "$?" = "0" ]; then
case "${MESSAGE}" in
################################################ ################################################
# GLOBAL commands start here, edit messages only # GLOBAL commands start here, edit messages only
'/info'*) '/info'*)
@ -105,8 +112,8 @@ if [ "${1}" != "source" ];then
;; ;;
*) # forward messages to optional dispatcher *) # forward messages to optional dispatcher
_is_function send_interactive && send_interactive "${CHAT[ID]}" "${MESSAGE}" _is_function send_interactive && send_interactive "${CHAT[ID]}" "${MESSAGE}"
_is_function mycommands && mycommands
;; ;;
esac esac
fi fi
fi
fi fi

View File

@ -2,7 +2,7 @@
# files: mycommands.sh.dist # files: mycommands.sh.dist
# copy to mycommands.sh and add all your commands and functions here ... # copy to mycommands.sh and add all your commands and functions here ...
# #
#### $$VERSION$$ v0.80-18-g6b88656 #### $$VERSION$$ v0.80-23-g25c9b62
# #
# uncomment the following lines to overwrite info and help messages # uncomment the following lines to overwrite info and help messages
@ -26,6 +26,8 @@ if [ "$1" != "source" ];then
mycommands() { mycommands() {
case "${MESSAGE}" in case "${MESSAGE}" in
##################
# example commands, replace thm by your own
'/echo'*) # example echo command '/echo'*) # example echo command
send_normal_message "${CHAT[ID]}" "$MESSAGE" send_normal_message "${CHAT[ID]}" "$MESSAGE"
;; ;;
@ -56,6 +58,16 @@ if [ "$1" != "source" ];then
fi fi
;; ;;
##########
# command overwrite examples
'info'*) # output date in front of regular info
send_normal_message "${CHAT[ID]}" "$(date)"
return 0
;;
'/kickme'*) # this will replace the /kickme command
send_markdown_mesage "${CHAT[ID]}" "*This bot will not kick you!*"
return 1
;;
esac esac
} }