mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-28 12:50:44 +00:00
fix problems found by tests
This commit is contained in:
parent
2dafbd9d63
commit
ae4610a742
21
bashbot.sh
21
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
|
||||
}
|
||||
|
||||
#########################
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user