From 2faa8b1b4b2f8336a07c22df0295f4f43cbe52ad Mon Sep 17 00:00:00 2001 From: celso Date: Wed, 12 Mar 2025 01:21:19 -0300 Subject: [PATCH] refactored getusr_name to take last_name into account --- bashbot-lib.sh | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/bashbot-lib.sh b/bashbot-lib.sh index 6abe9f0..60aee6c 100755 --- a/bashbot-lib.sh +++ b/bashbot-lib.sh @@ -80,15 +80,35 @@ gettext() { } } -getusr_name(){ - local user_name="$(tail -n 1 "${bot_tmpdir}${1}" | grep -om1\ - '"first_name":"\(\\"\|[^"]*\)*",\("username"\|"language_code"\)' | head -n1)" - grep "\"username\"$" <<< "${user_name}" >/dev/null && utf-16-surrogate-pair-decode "${user_name:14:-12}"\ +getfirst_name(){ + local first_name="$(tail -n 1 "${bot_tmpdir}${1}" | grep -om1\ + '"first_name":"\(\\"\|[^"]*\)*"\(,\("username"\|"language_code"\|"last_name"\)\|},"chat"\)' | head -n1)" + grep "\"username\"$" <<< "${first_name}" >/dev/null && utf-16-surrogate-pair-decode "${first_name:14:-12}"\ || { - grep "\"language_code\"$" <<< "${user_name}" >/dev/null && utf-16-surrogate-pair-decode "${user_name:14:-17}" + grep "\"language_code\"$" <<< "${first_name}" >/dev/null && utf-16-surrogate-pair-decode "${first_name:14:-17}" + } || { + grep "\"last_name\"$" <<< "${first_name}" >/dev/null && utf-16-surrogate-pair-decode "${first_name:14:-13}" + } || { + grep "},\"chat\"$" <<< "${first_name}" >/dev/null && utf-16-surrogate-pair-decode "${first_name:14:-9}" } } +getlast_name(){ + local last_name="$(tail -n 1 "${bot_tmpdir}${1}" | grep -om1\ + '"last_name":"\(\\"\|[^"]*\)*"\(,\("username"\|"language_code"\)\|},"chat"\)' | head -n1)" + grep "\"username\"$" <<< "${last_name}" >/dev/null && utf-16-surrogate-pair-decode "${last_name:13:-12}"\ + || { + grep "\"language_code\"$" <<< "${last_name}" >/dev/null && utf-16-surrogate-pair-decode "${last_name:13:-17}" + } || { + grep "},\"chat\"$" <<< "${last_name}" >/dev/null && utf-16-surrogate-pair-decode "${last_name:13:-9}" + } +} + +getusr_name(){ + local user_name="$(getfirst_name ${1}) $(getlast_name ${1})" + [ "${user_name}" != "" ] && printf "%s" "${user_name}" +} + getusrname(){ local username="$(tail -n 1 "${bot_tmpdir}${1}" | grep -om1\ '"username":"\(\\"\|[^"]*\)*"\(,"language_code"\|},"chat"\)' | head -n1)"