From 501b3085324ab4e0baf01ebccce0cd63f94bbc71 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 30 May 2019 19:52:14 +0200 Subject: [PATCH] fix get_file, fix EVENT_FILE, reset MESSAGE variables on new message --- addons/antiFlood.sh | 32 ++++++++++++++++++-------------- bashbot.sh | 21 ++++++++++++++------- modules/aliases.sh | 2 +- modules/answerInline.sh | 2 +- modules/background.sh | 2 +- modules/chatMember.sh | 2 +- modules/jsonDB.sh | 2 +- modules/sendMessage.sh | 2 +- 8 files changed, 38 insertions(+), 27 deletions(-) diff --git a/addons/antiFlood.sh b/addons/antiFlood.sh index d9bc9d0..6a535f5 100644 --- a/addons/antiFlood.sh +++ b/addons/antiFlood.sh @@ -50,27 +50,31 @@ if [[ "$1" = "start"* ]]; then # register to CMD BASHBOT_EVENT_CMD["${ANTIFL_ME}"]="${ANTIFL_ME}_cmd" - antiflood_cmd(){ + antiFlood_cmd(){ case "${CMD[0]}" in - # command /antiflood starts detection, $1 floodlevel - "/antifl"*) + # command /afstart starts detection, $1 floodlevel + "/afstart") ANTIFL_CHATS["${CHAT[ID]}","level"]="${ANTIFL_DEFAULT}" ANTIFL_CHATS["${CHAT[ID]}","ban"]="${ANTIFL_BAN}" [[ "${CMD[1]}" =~ ^[0-9]+$ ]] && ANTIFL_CHATS["${CHAT[ID]}","level"]="${CMD[1]}" - antiflood_timer + antiFlood_timer ;; - # command /floodapply starts counter meausares - "/floodap"*) + # command /afactive starts counter meausares + "/afdo") ANTIFL_CHATS["${CHAT[ID]}","active"]="yes" ;; + # command /afactive starts counter meausares + "/afstop") + ANTIFL_CHATS["${CHAT[ID]}","active"]="no" + ;; esac } # register to timer - BASHBOT_EVENT_TIMER["${ANTIFL_ME}","${ANTIFL_BAN}"]="antiflood_timer" + BASHBOT_EVENT_TIMER["${ANTIFL_ME}","${ANTIFL_BAN}"]="antiFlood_timer" # save settings and reset flood level every BAN Min - antiflood_timer(){ + antiFlood_timer(){ ANTIFL_ACTUALS=( ) jssh_writeDB "ANTIFL_CHATS" "addons/$ANTIFL_ME" & } @@ -79,7 +83,7 @@ if [[ "$1" = "start"* ]]; then BASHBOT_EVENT_TEXT["${ANTIFL_ME}"]="${ANTIFL_ME}_multievent" BASHBOT_EVENT_FILE["${ANTIFL_ME}"]="${ANTIFL_ME}_multievent" - antiflood_multievent(){ + antiFlood_multievent(){ # not started [ "${ANTIFL_CHATS["${CHAT[ID]}","level"]}" = "" ] && return # check user flood text @@ -88,21 +92,21 @@ if [[ "$1" = "start"* ]]; then (( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}"]-- )) # shellcheck disable=SC2154 (( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"]-- )) - else + fi + else # shellcheck disable=SC2154 (( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}"]++ )) - fi fi # check user flood picture # shellcheck disable=SC2154 [ "$1" = "file" ] && (( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"]++ )) - antiflood_action & # do actions in subshell + antiFlood_action & # do actions in subshell } # check and handle actions - antiflood_action() { + antiFlood_action() { # check flood level of user - if [ "${ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"]}" -gt "${ANTIFL_CHATS["${CHAT[ID]}","level"]}" ]; then + if [ "$(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"] +1))" -gt "${ANTIFL_CHATS["${CHAT[ID]}","level"]}" ]; then if [ "${ANTIFL_CHATS["${CHAT[ID]}","active"]}" = "yes" ]; then # remove message delete_message "${CHAT[ID]}" "${MESSAGE[ID]}" diff --git a/bashbot.sh b/bashbot.sh index a0f1732..811f927 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.90-dev2-25-gb240ede +#### $$VERSION$$ v0.90-dev2-27-gfc36de9 # # Exit Codes: # - 0 sucess (hopefully) @@ -216,8 +216,8 @@ delete_message() { get_file() { [ "$1" = "" ] && return - sendJson "" '"file_id": '"${1}""${GETFILE_URL}" - printf '%s\n' "${URL}"/"$(jsonGetString <<< "${res}" '"result","file_path"')" + sendJson "" '"file_id": "'"${1}"'"' "${GETFILE_URL}" + printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')" } # curl is preffered, but may not availible on ebedded systems @@ -342,7 +342,7 @@ process_updates() { } process_client() { local num="$1" debug="$2" - CMD=( ) + CMD=( ); iQUERY=( ) iQUERY[ID]="${UPD["result",${num},"inline_query","id"]}" if [ "${iQUERY[ID]}" = "" ]; then [[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"MESSAGE.log" @@ -407,6 +407,7 @@ event_inline() { done } event_message() { +echo "${MESSAGE[0]}" local event debug="$1" # ${MESSAEG[*]} event_message # shellcheck disable=SC2153 @@ -432,7 +433,6 @@ event_message() { done fi fi - # ${REPLYTO[*]} event_replyto if [ "${REPLYTO[UID]}" != "" ]; then # shellcheck disable=SC2153 @@ -462,7 +462,7 @@ event_message() { # ${VENUE[*]} event_location # ${LOCALTION[*]} event_location - if [ "${LOCATION[*]}" != "" ] || [ "${VENUE[TITLE]}" != "" ]; then + if [ "${LOCATION[LONGITUDE]}" != "" ] || [ "${VENUE[TITLE]}" != "" ]; then # shellcheck disable=SC2153 for event in "${!BASHBOT_EVENT_LOCATION[@]}" do @@ -471,7 +471,8 @@ event_message() { fi # ${URLS[*]} event_file - if [ "${URLS[*]}" = "" ]; then + # NOTE: compare again #URLS -1 blanks! + if [[ "${URLS[*]}" != " " ]]; then # shellcheck disable=SC2153 for event in "${!BASHBOT_EVENT_FILE[@]}" do @@ -512,6 +513,7 @@ process_message() { USER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","from","username"]}")" # in reply to message from + REPLYTO=( ) REPLYTO[UID]="${UPD["result",${num},"message","reply_to_message","from","id"]}" if [ "${REPLYTO[UID]}" != "" ]; then REPLYTO[0]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","text"]}")" @@ -522,6 +524,7 @@ process_message() { fi # forwarded message from + FORWARD=( ) FORWARD[UID]="${UPD["result",${num},"message","forward_from","id"]}" if [ "${FORWARD[UID]}" != "" ]; then FORWARD[ID]="${MESSAGE[ID]}" # same as message ID @@ -531,6 +534,7 @@ process_message() { fi # Audio + URLS=( ) URLS[AUDIO]="$(get_file "${UPD["result",${num},"message","audio","file_id"]}")" # Document URLS[DOCUMENT]="$(get_file "${UPD["result",${num},"message","document","file_id"]}")" @@ -544,6 +548,7 @@ process_message() { URLS[VOICE]="$(get_file "${UPD["result",${num},"message","voice","file_id"]}")" # Contact + CONTACT=( ) CONTACT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","contact","first_name"]}")" if [ "${CONTACT[FIRST_NAME]}" != "" ]; then CONTACT[USER_ID]="$(JsonDecode "${UPD["result",${num},"message","contact","user_id"]}")" @@ -553,6 +558,7 @@ process_message() { fi # vunue + VENUE=( ) VENUE[TITLE]="$(JsonDecode "${UPD["result",${num},"message","venue","title"]}")" if [ "${VENUE[TITLE]}" != "" ]; then VENUE[ADDRESS]="$(JsonDecode "${UPD["result",${num},"message","venue","address"]}")" @@ -565,6 +571,7 @@ process_message() { CAPTION="$(JsonDecode "${UPD["result",${num},"message","caption"]}")" # Location + LOCATION=( ) LOCATION[LONGITUDE]="${UPD["result",${num},"message","location","longitude"]}" LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}" diff --git a/modules/aliases.sh b/modules/aliases.sh index 544bd89..9438f68 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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.90-dev2-0-gec85636 +#### $$VERSION$$ v0.90-dev2-27-gfc36de9 # # source from commands.sh to use the aliases diff --git a/modules/answerInline.sh b/modules/answerInline.sh index 626bae1..e7ab78f 100644 --- a/modules/answerInline.sh +++ b/modules/answerInline.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.90-dev2-13-gcb3f3e3 +#### $$VERSION$$ v0.90-dev2-27-gfc36de9 # source from commands.sh to use the inline functions diff --git a/modules/background.sh b/modules/background.sh index cdd5347..45a53df 100644 --- a/modules/background.sh +++ b/modules/background.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.90-dev2-11-g59aa9fc +#### $$VERSION$$ v0.90-dev2-27-gfc36de9 # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 73a5f12..24b9f0b 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.90-dev2-13-gcb3f3e3 +#### $$VERSION$$ v0.90-dev2-27-gfc36de9 # source from commands.sh to use the member functions diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index bbfa76a..7e1be24 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.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.90-dev2-25-gb240ede +#### $$VERSION$$ v0.90-dev2-27-gfc36de9 # # source from commands.sh to use jsonDB functions # diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index fef5d4b..d6fcb3b 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.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.90-dev2-13-gcb3f3e3 +#### $$VERSION$$ v0.90-dev2-27-gfc36de9 # source from commands.sh to use the sendMessage functions