iBUTTON: fix comamnds and mycommands processing

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-26 14:34:25 +01:00
parent 08a05242f9
commit b441384d4a
3 changed files with 14 additions and 16 deletions

View File

@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb
# 8 - curl/wget missing
# 10 - not bash!
#
#### $$VERSION$$ v1.35-dev-13-gbc414ee
#### $$VERSION$$ v1.35-dev-14-g08a0524
##################################################################
# emmbeded system may claim bash but it is not
@ -1134,9 +1134,9 @@ bot_init() {
fi
# check if mycommands exist
if [ ! -r "${BASHBOT_ETC:-.}/mycommands.sh" ]; then
printf "Mycommands.sh not found, copy ${GREY}mycommands.sh.dist${NC} to mycommands.sh? (y/N) N\b"
printf "Mycommands.sh not found, copy ${GREY}mycommands.sh.clean${NC} to mycommands.sh? (y/N) N\b"
read -r ANSWER
[[ "${ANSWER}" =~ ^[Yy] ]] && cp -f "${BASHBOT_ETC:-.}/mycommands.sh.dist" "${BASHBOT_ETC:-.}/mycommands.sh"
[[ "${ANSWER}" =~ ^[Yy] ]] && cp -f "${BASHBOT_ETC:-.}/mycommands.sh.clean" "${BASHBOT_ETC:-.}/mycommands.sh"
# offer to copy config also
if [ ! -r "${BASHBOT_ETC:-.}/mycommands.conf" ]; then
printf "Mycommands config file not found, copy ${GREY}mycommands.conf.dist${NC} to mycommands.conf? (y/N) N\b"

View File

@ -15,7 +15,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v1.35-dev-7-g9584068
#### $$VERSION$$ v1.35-dev-14-g08a0524
#
# bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed
@ -81,11 +81,11 @@ if [ -z "$1" ] || [[ "$1" == *"debug"* ]];then
# detect inline and callback query
if [ -n "${iQUERY[ID]}" ]; then
# forward inline query to optional dispatcher
[ "${INLINE:-0}" != "0" ] || _exec_if_function myinlines
[ "${INLINE:-0}" != "0" ] && _exec_if_function myinlines
elif [ -n "${iBUTTON[ID]}" ]; then
# forward inline query to optional dispatcher
[ "${CALLBACK:-0}" != "0" ] || _exec_if_function mycallbacks
[ "${CALLBACK:-0}" != "0" ] && _exec_if_function mycallbacks
#################
# regular command

View File

@ -13,7 +13,7 @@
# License: WTFPLv2 http://www.wtfpl.net/txt/copying/
# Author: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.35-dev-7-g9584068
#### $$VERSION$$ v1.35-dev-14-g08a0524
#######################################################
# shellcheck disable=SC1117
@ -183,22 +183,22 @@ else
#######################
# callbacks from buttons attached to messages will be processed here
# no standard use case for processing callbacks, let's log them for some users and chats
case "${USER[ID]}+${CHAT[ID]}" in
case "${iBUTTON[USER_ID]}+${iBUTTON[CHAT_ID]}" in
'USERID1+'*) # do something for all callbacks from USER
printf "%s: U=%s C=%s D=%s\n" "$(date)" "${iBOTTON[USER_ID]}" "${iBOTTON[CHAT_ID]}" "${iBUTTON[DATA]}"\
>>"${DATADIR}/${iBOTTON[USER_ID]}.log"
printf "%s: U=%s C=%s D=%s\n" "$(date)" "${iBUTTON[USER_ID]}" "${iBUTTON[CHAT_ID]}" "${iBUTTON[DATA]}"\
>>"${DATADIR}/${iBUTTON[USER_ID]}.log"
answer_callback_query "${iBUTTON[ID]}" "Request has been logged in your user log..."
return
;;
*'+CHATID1') # do something for all callbacks from CHAT
printf "%s: U=%s C=%s D=%s\n" "$(date)" "${iBOTTON[USER_ID]}" "${iBOTTON[CHAT_ID]}" "${iBUTTON[DATA]}"\
>>"${DATADIR}/${iBOTTON[CHAT_ID]}.log"
printf "%s: U=%s C=%s D=%s\n" "$(date)" "${iBUTTON[USER_ID]}" "${iBUTTON[CHAT_ID]}" "${iBUTTON[DATA]}"\
>>"${DATADIR}/${iBUTTON[CHAT_ID]}.log"
answer_callback_query "${iBUTTON[ID]}" "Request has been logged in chat log..."
return
;;
'USERID2+CHATID2') # do something only for callbacks form USER in CHAT
printf "%s: U=%s C=%s D=%s\n" "$(date)" "${iBOTTON[USER_ID]}" "${iBOTTON[CHAT_ID]}" "${iBUTTON[DATA]}"\
>>"${DATADIR}/${iBOTTON[USER_ID]}-${iBOTTON[CHAT_ID]}.log"
printf "%s: U=%s C=%s D=%s\n" "$(date)" "${iBUTTON[USER_ID]}" "${iBUTTON[CHAT_ID]}" "${iBUTTON[DATA]}"\
>>"${DATADIR}/${iBUTTON[USER_ID]}-${iBUTTON[CHAT_ID]}.log"
answer_callback_query "${iBUTTON[ID]}" "Request has been logged in user-chat log..."
return
;;
@ -209,8 +209,6 @@ else
answer_callback_query "${iBUTTON[ID]}" ""
;;
esac
}
myinlines() {