From f95b6c2e7df82c0f280b9983126a2502639afae3 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 19 Jan 2021 23:53:58 +0100 Subject: [PATCH] modules: _button_row empty button starts new row --- bin/send_buttons.sh | 2 +- modules/sendMessage.sh | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/send_buttons.sh b/bin/send_buttons.sh index fd6a024..070f84c 100755 --- a/bin/send_buttons.sh +++ b/bin/send_buttons.sh @@ -21,7 +21,7 @@ USAGE='send_message.sh [-h|--help] "CHAT[ID]" "message" "text|url" ...' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 18.01.2021 11:34 # -#### $$VERSION$$ v1.31-dev-8-g8854e03 +#### $$VERSION$$ v1.31-dev-9-g6c91a32 #=============================================================================== #### diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 7f55e75..55e997a 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.31-dev-8-g8854e03 +#### $$VERSION$$ v1.31-dev-9-g6c91a32 # will be automatically sourced from bashbot @@ -151,14 +151,15 @@ send_button() { } # helper function to create json for a button row -# buttons will specified as "text|url" ... "text|url" +# buttons will specified as "text|url" ... "text|url" empty arg starts new row _button_row() { [ -z "$1" ] && return 1 - local arg json + local arg json sep for arg in "$@" do - [ -n "${json}" ] && json+="," - json+='{"text":"'"$(JsonEscape "${arg%|*}")"'", "url":"'"${arg##*|}"'"}' + [ -z "${arg}" ] && sep="],[" && continue + json+="${sep}"'{"text":"'"$(JsonEscape "${arg%|*}")"'", "url":"'"${arg##*|}"'"}' + sep="," done printf "[%s]" "${json}" }