From 19615186daad6841ff57b4b7956f32d0410f3f8b Mon Sep 17 00:00:00 2001 From: celso Date: Thu, 25 Jul 2024 16:44:09 -0300 Subject: [PATCH] added getreplytext and fixed gettimestamp to account for replies --- bashbot-lib.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bashbot-lib.sh b/bashbot-lib.sh index f6e964b..ee47c34 100755 --- a/bashbot-lib.sh +++ b/bashbot-lib.sh @@ -113,10 +113,19 @@ getcbk_data() { gettimestamp() { local timestamp="$(tail -n 1 "${bot_tmpdir}${1}"\ - | grep "\"date\"" | grep -om1 "\"date\":[0-9]\+,")" + | grep "\"date\"" | grep -om1 "\"date\":[0-9]\+," | head -n1)" [ ! -z "${timestamp}" ] && date "+%D %H:%M" -d "@${timestamp:7:-1}" } +getreplytext() { + grep reply_to_message "${bot_tmpdir}${1}" && local replytext="$(tail -n 1 "${bot_tmpdir}${1}" | grep -om1\ + '{\?\("text"\|"caption"\):"\(\\"\|[^"]*\)*"\(,\|}\)' | grep -v "^{" | head -n1)" + grep "^\"text\"" <<< "${text}" >/dev/null && utf-16-surrogate-pair-decode "${replytext:8:-2}"\ + || { + grep "^\"caption\"" <<< "${text}" >/dev/null && utf-16-surrogate-pair-decode "${replytext:11:-2}" + } +} + # $1 is name of a bash array with the number of columns in every row such as ( 1 1 3 ) for a 3 row keyboard in which the first and second row have 1 column, and the third has 3 # $2 is name of a bash array with as many text entries as there are columns, they are added left to right, up to down, to the rows/columns configuration passed as first arg # $3 is name of a bash array with as many data entries as there are columns, they are added left to right, up to down, to the rows/columns configuration passed as first arg @@ -220,4 +229,5 @@ getmsg_content(){ _REF[text]="$(gettext "${2}")" _REF[callback]="$(getcbk_data "${2}")" _REF[timestamp]="$(gettimestamp "${2}")" + local replytext="$(getreplytext "${2}")"; [ ! -z "${replytext}" ] && _REF[replytext]="$(getreplytext "${2}")" }