fix get_file, fix EVENT_FILE, reset MESSAGE variables on new message

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-30 19:52:14 +02:00
parent fc36de9fa0
commit 501b308532
8 changed files with 38 additions and 27 deletions

View File

@ -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]}"

View File

@ -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"]}"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
#

View File

@ -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