From 68bee463838446a1ca8c70b863b64b2bd34bcf2f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 25 May 2019 13:31:36 +0200 Subject: [PATCH] allow overwriting of standard commands --- commands.sh | 17 ++++++++++++----- mycommands.sh | 14 +++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/commands.sh b/commands.sh index 8ced63e..b70aa39 100644 --- a/commands.sh +++ b/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.80-18-g6b88656 +#### $$VERSION$$ v0.80-23-g25c9b62 # # 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() 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 '/info'*) @@ -105,8 +112,8 @@ if [ "${1}" != "source" ];then ;; *) # forward messages to optional dispatcher _is_function send_interactive && send_interactive "${CHAT[ID]}" "${MESSAGE}" - _is_function mycommands && mycommands ;; - esac - fi + esac + fi + fi fi diff --git a/mycommands.sh b/mycommands.sh index 8a673f6..5c6f7a2 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # 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 @@ -26,6 +26,8 @@ if [ "$1" != "source" ];then mycommands() { case "${MESSAGE}" in + ################## + # example commands, replace thm by your own '/echo'*) # example echo command send_normal_message "${CHAT[ID]}" "$MESSAGE" ;; @@ -56,6 +58,16 @@ if [ "$1" != "source" ];then 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 }