fix delete of empty messages for keyboards

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-04-25 15:17:35 +02:00
parent 96aae9d40e
commit 0f220bdbc8
2 changed files with 19 additions and 19 deletions

View File

@ -320,44 +320,44 @@ old_send_keyboard() {
res="$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"keyboard\": [$keyboard],\"one_time_keyboard\": true}")" res="$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"keyboard\": [$keyboard],\"one_time_keyboard\": true}")"
} }
TEXTISEMPTY="MyTextIsEmpty" TEXTISEMPTY="ThisTextIsEmptyAndWillBeDeleted"
send_keyboard() { send_keyboard() {
if [[ "$3" != *'['* ]]; then old_send_keyboard "$@"; return; fi if [[ "$3" != *'['* ]]; then old_send_keyboard "$@"; return; fi
local chat='"chat_id":'"${1}" local chat="${1}"
local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"'
local one_time=', "one_time_keyboard":true' && [ "$4" != "" ] && one_time="" local one_time=', "one_time_keyboard":true' && [ "$4" != "" ] && one_time=""
local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"' } }' local JSON="${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"'}'
# '{"chat_id":$1, "text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true} }' # '"text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true}'
sendJson "$JSON" "$MSG_URL" sendJson "${chat}" "$JSON" "$MSG_URL"
[ "${text}" = '"text":"'"${TEXTISEMPTY}"'"' ] && delete_message "${1}" "${2}"
} }
remove_keyboard() { remove_keyboard() {
local chat='"chat_id":'"${1}" local chat="${1}"
local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"'
local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"remove_keyboard":true} }' local JSON="${text}"', "reply_markup": {"remove_keyboard":true}'
#JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"remove_keyboard":true} }' #JSON='"text":"$2", "reply_markup": {"remove_keyboard":true}'
sendJson "$JSON" "$MSG_URL" sendJson "${chat}" "$JSON" "$MSG_URL"
[ "${text}" = '"text":"'"${TEXTISEMPTY}"'"' ] && delete_message "${1}" "${2}"
} }
send_inline_keyboard() { send_inline_keyboard() {
local chat='"chat_id":'"${1}" local chat="${1}"
local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"'
local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]} }' local JSON="${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]}'
# JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]} }' # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}'
sendJson "$JSON" "$MSG_URL" sendJson "${chat}" "$JSON" "$MSG_URL"
[ "${text}" = '"text":"'"${TEXTISEMPTY}"'"' ] && delete_message "${1}" "${2}"
} }
send_inline_button() { send_inline_button() {
send_inline_keyboard "${1}" "${2}" '[ {"text":"'"${3}"'", "url":"'"${4}"'"}]' send_inline_keyboard "${1}" "${2}" '[ {"text":"'"${3}"'", "url":"'"${4}"'"}]'
# JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"inline_keyboard": [[ {"text":"$3", "url":"$4"} ... ]]} }' # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [[ {"text":"$3", "url":"$4"} ... ]]}'
} }
# this will be the only send interface to telegram! # this will be the only send interface to telegram!
# usage: sendJson "chat" "JSON" "URL"
sendJson(){ sendJson(){
res="$(curl -d "${1}" -H "Content-Type: application/json" -X POST "${2}" | "${JSONSHFILE}" -s -b -n )" res="$(curl -d '{"chat_id":'"${1}"', '"$2"'}' -H "Content-Type: application/json" \
-X POST "${3}" | "${JSONSHFILE}" -s -b -n )"
BOTSENT[OK]="$(echo "$res" | JsonGetLine '"ok"')" BOTSENT[OK]="$(echo "$res" | JsonGetLine '"ok"')"
BOTSENT[ID]="$(echo "$res" | JsonGetValue '"result","message_id"')" BOTSENT[ID]="$(echo "$res" | JsonGetValue '"result","message_id"')"
[[ "${2}" = *"${TEXTISEMPTY}"* ]] && delete_message "${1}" "${BOTSENT[ID]}"
} }

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# file: git-add.sh # file: git-add.sh
# #
# works together with git pre-push.sh and add all changed files sind last push # works together with git pre-push.sh and ADD all changed files since last push
#### $$VERSION$$ v0.70-dev3-1-g55dab95 #### $$VERSION$$ v0.70-dev3-1-g55dab95