From 96fda449b53108bf002cb2a234a8525d5158485c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 16 May 2020 22:10:12 +0200 Subject: [PATCH] add admin checks to mycommands --- mycommands.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mycommands.sh b/mycommands.sh index ff64eec..5c486ce 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -8,7 +8,7 @@ # #### if you start to develop your own bot, use the clean version of this file: # #### mycommands.clean # -#### $$VERSION$$ v0.94-0-gaaa71c8 +#### $$VERSION$$ v0.94-2-g93f4966 # # uncomment the following lines to overwrite info and help messages @@ -32,6 +32,9 @@ export FILE_REGEX="${BASHBOT_ETC}/.*" # set to "yes" and give your bot admin privilegs to remove service messaes from groups export SILENCER="no" +# messages for admin only commands +NOTADMIN="Sorry, this command is allowed for admin or owner only" +NOTBOTADMIN="Sorry, this command is allowed for bot owner only" if [ "$1" = "startbot" ];then ################### @@ -63,6 +66,25 @@ else fi fi + # pre-check admin only commands + case "${MESSAGE}" in + # must be private, group admin, or botadmin + '/run_'*|'stop_'*) + send_action "${CHAT[ID]}" "typing" + if ! user_is_admin "${CHAT[ID]}" "${USER[ID]}" ; then + send_normal_message "${CHAT[ID]}" "${NOTADMIN}"; return 1 + fi + # ok, now lets process the real command + ;; + # must be botadmin + '/echo'*) + send_action "${CHAT[ID]}" "typing" + if ! user_is_botadmin "${USER[ID]}" ; then + send_markdown_message "${CHAT[ID]}" "*${NOTBOTADMIN}*"; return 1 + fi + ;; + esac + case "${MESSAGE}" in ################## # example commands, replace thm by your own