From ae4610a742dc554d0eec9bda4cfb4cf72cfd2935 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 27 Jun 2020 18:32:50 +0200 Subject: [PATCH] fix problems found by tests --- bashbot.sh | 21 ++++++++++++++------- dev/all-tests.sh | 8 ++++---- modules/chatMember.sh | 4 ++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index e9d11b2..f96fd61 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.98-pre2-4-g724f36b +#### $$VERSION$$ v0.98-pre2-8-ga656533 # # Exit Codes: # - 0 success (hopefully) @@ -846,7 +846,7 @@ process_message() { NEWMEMBER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","new_chat_member","last_name"]}")" NEWMEMBER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","new_chat_member","username"]}")" NEWMEMBER[ISBOT]="${UPD["result",${num},"message","new_chat_member","is_bot"]}" - MESSAGE[0]="/new_chat_member ${NEWMEMBER[USERNAME]:=${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]}}" + [ -z "${MESSAGE[0]}" ] && MESSAGE[0]="/new_chat_member ${NEWMEMBER[USERNAME]:=${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]}}" fi if grep -qs -e '\["result",'"${num}"',"message","left_chat_member' <<<"${UPDATE}"; then SERVICE[LEFTMEMBER]="${UPD["result",${num},"message","left_chat_member","id"]}" @@ -855,21 +855,28 @@ process_message() { LEFTMEMBER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","left_chat_member","last_name"]}")" LEFTMEBER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","left_chat_member","username"]}")" LEFTMEMBER[ISBOT]="${UPD["result",${num},"message","left_chat_member","is_bot"]}" - MESSAGE[0]="/left_chat_member ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}" + [ -z "${MESSAGE[0]}" ] && MESSAGE[0]="/left_chat_member ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}" fi if grep -qs -e '\["result",'"${num}"',"message","\(new_chat_[tp]\)\|\(pinned_message\)' <<<"${UPDATE}"; then SERVICE[NEWTITLE]="$(JsonDecode "${UPD["result",${num},"message","new_chat_title"]}")" - [ -n "${SERVICE[NEWTITLE]}" ] && MESSAGE[0]="/new_chat_title ${SERVICE[NEWTITLE]}" + [ -z "${MESSAGE[0]}" ] && [ -n "${SERVICE[NEWTITLE]}" ] && MESSAGE[0]="/new_chat_title ${SERVICE[NEWTITLE]}" SERVICE[NEWPHOTO]="$(get_file "${UPD["result",${num},"message","new_chat_photo",0,"file_id"]}")" - [ -n "${SERVICE[NEWPHOTO]}" ] && MESSAGE[0]="/new_chat_photo ${SERVICE[NEWPHOTO]}" + [ -z "${MESSAGE[0]}" ] && [ -n "${SERVICE[NEWPHOTO]}" ] && MESSAGE[0]="/new_chat_photo ${SERVICE[NEWPHOTO]}" SERVICE[PINNED]="$(JsonDecode "${UPD["result",${num},"message","pinned_message"]}")" - [ -n "${SERVICE[PINNED]}" ] && MESSAGE[0]="/new_pinned_message ${SERVICE[PINNED]}" + [ -z "${MESSAGE[0]}" ] && [ -n "${SERVICE[PINNED]}" ] && MESSAGE[0]="/new_pinned_message ${SERVICE[PINNED]}" fi # set SSERVICE to yes if a service message was received [[ "${SERVICE[*]}" =~ ^[[:blank:]]*$ ]] || SERVICE[0]="yes" # split message in command and args - [ "${MESSAGE[0]:0:1}" = "/" ] && read -r CMD <<<"${MESSAGE[0]}" && CMD[0]="${CMD[0]%%@*}" + #[[ "${MESSAGE[0]}" == "/"* ]] && read -r CMD <<<"${MESSAGE[0]}" && CMD[0]="${CMD[0]%%@*}" + if [[ "${MESSAGE[0]}" == "/"* ]]; then + set -f; unset IFS + # shellcheck disable=SC2206 + CMD=( ${MESSAGE[0]} ) + CMD[0]="${CMD[0]%%@*}" + set +f + fi } ######################### diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 288800a..117b394 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.98-pre2-0-ga597303 +#### $$VERSION$$ v0.98-pre2-8-ga656533 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -45,12 +45,12 @@ done if [ "$fail" -eq 0 ]; then /bin/echo -n 'SUCCESS ' exitcode=0 - rm -rf "${TESTENV}" + #rm -rf "${TESTENV}" else /bin/echo -n 'FAILURE ' exitcode=1 - rm -rf "${TESTENV}/test" - find "${TESTENV}/"* ! -name '[a-z]-*' -delete + #rm -rf "${TESTENV}/test" + #find "${TESTENV}/"* ! -name '[a-z]-*' -delete fi echo -e "${passed} / ${tests}\\n" diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 8a086d6..5eccb3a 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.98-pre2-0-ga597303 +#### $$VERSION$$ v0.98-pre2-8-ga656533 # will be automatically sourced from bashbot @@ -54,7 +54,7 @@ user_is_botadmin() { [ "${admin}" = "${1}" ] && return 0 [ "${admin}" = "${2}" ] && return 0 [[ "${admin}" = "@*" ]] && [[ "${admin}" = "${2}" ]] && return 0 - if [ "${admin}" = "?" ]; then setConfigKey "${1:-?}"; return 0; fi + if [ "${admin}" = "?" ]; then setConfigKey "botadmin" "${1:-?}"; return 0; fi return 1 }