fix running commands.sh in subshell

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-27 11:54:48 +01:00
parent 5a0a5712dd
commit 079eb1c289
4 changed files with 59 additions and 12 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-21-gcbf3945
#### $$VERSION$$ v1.35-dev-24-g5a0a571
##################################################################
# emmbeded system may claim bash but it is not
@ -707,7 +707,7 @@ process_client() {
# process inline and message events
# first classic command dispatcher
# shellcheck source=./commands.sh
"${COMMANDS}" "${debug}" &
{ source "${COMMANDS}" "${debug}"; } &
# then all registered addons
if [ -z "${iQUERY[ID]}" ]; then

View File

@ -249,7 +249,7 @@ If `"url"` without text is given, `url` is shown on the button and opened on but
*example:*
```bash
# one button, same as send_button
send_inline_keyboard "${CHAT[ID]}" "Best Dealz!" "Visit my Shop|https://dealz.rrr.de"
send_inline_buttons "${CHAT[ID]}" "Best Dealz!" "Visit my Shop|https://dealz.rrr.de"
# result
Best Dealz!
@ -258,7 +258,7 @@ send_inline_keyboard "${CHAT[ID]}" "Best Dealz!" "Visit my Shop|https://dealz.rr
+----------------------------+
# one button row
send_inline_keyboard "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|http://rrr.de"
send_inline_buttons "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|http://rrr.de"
# result
message ...
@ -267,7 +267,7 @@ send_inline_keyboard "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|
+----------------------------+
# multiple button rows
send_inline_keyboard "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|http://rrr.de" "" "Button on second row|http://rrr.de"
send_inline_buttons "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|http://rrr.de" "" "Button on second row|http://rrr.de"
# result
message ...
@ -276,6 +276,7 @@ send_inline_keyboard "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|
|----------------------------|
| Button on second row |
+----------------------------+
```
##### edit_inline_buttons
@ -316,6 +317,42 @@ answer_callback_query "${iBUTTON[ID]}" "Button data is: ${iBUTTON[DATA]}"
answer_callback_query "${iBUTTON[ID]}" "Alert: Button pressed!" "alert"
```
```bash
# CALLBACK button example
send_inline_buttons "${CHAT[ID]}" "Press Button ..." " Button |RANDOM-BUTTON"
# result
Press Button ...
+----------------------------+
| Button |
+----------------------------+
# react on button press from mycommands
CALLBACK="1" # enable callbacks
...
mycallbacks() {
local answer
#######################
# callbacks from buttons attached to messages will be processed here
if [ "${iBUTTON[DATA]}" = "RANDOM-BUTTON" ]; then
answer="Button pressed"
edit_inline_buttons "${iBUTTON[CHAT_ID]}" "${iBUTTON[MESSAGE_ID]}" " Button ${RANDOM}|RANDOM-BUTTON"
fi
# Telegram needs an ack each callback query, default empty
answer_callback_query "${iBUTTON[ID]}" "${answer}"
;;
}
# result, XXXXX: random number changed on each press
Press Button ...
+----------------------------+
| Button XXXXXX |
+----------------------------+
```
----
#### Inline keyboards
@ -1451,5 +1488,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca
#### [Prev Best Practice](5_practice.md)
#### [Next Notes for Developers](7_develop.md)
#### $$VERSION$$ v1.35-dev-23-g5192212
#### $$VERSION$$ v1.35-dev-24-g5a0a571

View File

@ -13,7 +13,7 @@
# License: WTFPLv2 http://www.wtfpl.net/txt/copying/
# Author: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.35-dev-20-gfa0cb75
#### $$VERSION$$ v1.35-dev-24-g5a0a571
#######################################################
# shellcheck disable=SC1117
@ -131,6 +131,9 @@ else
'/echo'*) # example echo command
send_normal_message "${CHAT[ID]}" "${MESSAGE}"
;;
'/button'*)# inline button, set CALLBACK=1 for processing callbacks
send_inline_buttons "${CHAT[ID]}" "Press Button ..." " Button |RANDOM-BUTTON"
;;
'/question'*) # start interactive questions
checkproc
if [ "${res}" -gt 0 ] ; then
@ -203,13 +206,19 @@ else
return
;;
*) # all other callbacks are processed here
local callback_answer
# your processing here ...
# message available?
if [[ -n "${iBUTTON[CHAT_ID]}" && -n "${iBUTTON[MESSAGE_ID]}" ]]; then
# output random button if message data is available
edit_inline_buttons "${iBUTTON[CHAT_ID]}" "${iBUTTON[MESSAGE_ID]}" "Button ${RANDOM}|${RANDOM}"
if [ "${iBUTTON[DATA]}" = "RANDOM-BUTTON" ]; then
callback_answer="Button pressed"
edit_inline_buttons "${iBUTTON[CHAT_ID]}" "${iBUTTON[MESSAGE_ID]}" "Button ${RANDOM}|RANDOM-BUTTON"
fi
else
callback_answer="Button to old, sorry."
fi
# Telegram needs an ack each callback query, default empty
answer_callback_query "${iBUTTON[ID]}" ""
answer_callback_query "${iBUTTON[ID]}" "${callback_answer}"
;;
esac
}

View File

@ -10,7 +10,7 @@
# License: WTFPLv2 http://www.wtfpl.net/txt/copying/
# Author: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.35-dev-18-ge4ee880
#### $$VERSION$$ v1.35-dev-24-g5a0a571
#######################################################
# shellcheck disable=SC1117
@ -82,10 +82,11 @@ else
# callbacks from buttons attached to messages will be processed here
case "${iBUTTON[USER_ID]}+${iBUTTON[CHAT_ID]}" in
*) # all other callbacks are processed here
local callback_answer
: # your processing here ...
:
# Telegram needs an ack each callback query, default empty
answer_callback_query "${iBUTTON[ID]}" ""
answer_callback_query "${iBUTTON[ID]}" "${callback_answer}"
;;
esac
}