From 601128b8561c1b5d112eba8cf28878f25440b0e1 Mon Sep 17 00:00:00 2001 From: celso Date: Mon, 27 Mar 2023 00:34:40 -0300 Subject: [PATCH] prevented empty messages from ending up in updates or sentmsgs --- bashbot-lib.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bashbot-lib.sh b/bashbot-lib.sh index f736213..bd01fe3 100755 --- a/bashbot-lib.sh +++ b/bashbot-lib.sh @@ -159,8 +159,8 @@ sendmsg() { || sentmsg="$(curl -sX GET "${api_url}sendMessage" -d "chat_id=${1}" \ -d "text=${2}" \ -d "reply_markup=${3}")" - [ ! -z "${sentmsg}" ] && sed 's/^{"ok":false.*\|^{"ok":true,"result":{\|}$//g'\ - <<< "${sentmsg}" >> "${bot_tmpdir}sentmsgs.txt" + sentmsg="$(sed 's/^{"ok":false.*\|^{"ok":true,"result":{\|}$//g' <<< "${sentmsg}")" + [ ! -z "${sentmsg}" ] && printf "%s\n" "${sentmsg}" >> "${bot_tmpdir}sentmsgs.txt" } # $1 is target chat_id @@ -174,8 +174,8 @@ replymsg() { -d "text=${3}")" || sentmsg="$(curl -sX GET "${api_url}sendMessage" -d "chat_id=${1}" -d "reply_to_message_id=${2}"\ -d "text=${3}" -d "reply_markup=${4}")" - [ ! -z "${sentmsg}" ] && sed 's/^{"ok":false.*\|^{"ok":true,"result":{\|}$//g'\ - <<< "${sentmsg}" >> "${bot_tmpdir}sentmsgs.txt" + sentmsg="$(sed 's/^{"ok":false.*\|^{"ok":true,"result":{\|}$//g' <<< "${sentmsg}")" + [ ! -z "${sentmsg}" ] && printf "%s\n" "${sentmsg}" >> "${bot_tmpdir}sentmsgs.txt" } # $1 is target chat_id @@ -184,11 +184,11 @@ replymsg() { # $4 is inline keyboard (optional) editmsg() { local editmsg - [ -z "${3}" ] && editmsg="$(curl -sX GET "${api_url}editMessageText" -d "chat_id=${1}" -d "message_id=${2}" \ + [ -z "${4}" ] && editmsg="$(curl -sX GET "${api_url}editMessageText" -d "chat_id=${1}" -d "message_id=${2}" \ -d "text=${3}")" || editmsg="$(curl -sX GET "${api_url}editMessageText" -d "chat_id=${1}" -d "message_id=${2}" \ -d "text=${3}" -d "reply_markup=${4}")" - [ ! -z "${editmsg}" ] && sed 's/^{"ok":false.*\|^{"ok":true,"result":{\|}$//g'\ - <<< "${editmsg}" >> "${bot_tmpdir}sentmsgs.txt" + editmsg="$(sed 's/^{"ok":false.*\|^{"ok":true,"result":{\|}$//g' <<< "${editmsg}")" + [ ! -z "${editmsg}" ] && printf "%s\n" "${editmsg}" >> "${bot_tmpdir}sentmsgs.txt" } # $1 is target chat_id