mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-21 23:25:08 +00:00
fix get_file, fix EVENT_FILE, reset MESSAGE variables on new message
This commit is contained in:
parent
fc36de9fa0
commit
501b308532
@ -50,27 +50,31 @@ if [[ "$1" = "start"* ]]; then
|
|||||||
# register to CMD
|
# register to CMD
|
||||||
BASHBOT_EVENT_CMD["${ANTIFL_ME}"]="${ANTIFL_ME}_cmd"
|
BASHBOT_EVENT_CMD["${ANTIFL_ME}"]="${ANTIFL_ME}_cmd"
|
||||||
|
|
||||||
antiflood_cmd(){
|
antiFlood_cmd(){
|
||||||
case "${CMD[0]}" in
|
case "${CMD[0]}" in
|
||||||
# command /antiflood starts detection, $1 floodlevel
|
# command /afstart starts detection, $1 floodlevel
|
||||||
"/antifl"*)
|
"/afstart")
|
||||||
ANTIFL_CHATS["${CHAT[ID]}","level"]="${ANTIFL_DEFAULT}"
|
ANTIFL_CHATS["${CHAT[ID]}","level"]="${ANTIFL_DEFAULT}"
|
||||||
ANTIFL_CHATS["${CHAT[ID]}","ban"]="${ANTIFL_BAN}"
|
ANTIFL_CHATS["${CHAT[ID]}","ban"]="${ANTIFL_BAN}"
|
||||||
[[ "${CMD[1]}" =~ ^[0-9]+$ ]] && ANTIFL_CHATS["${CHAT[ID]}","level"]="${CMD[1]}"
|
[[ "${CMD[1]}" =~ ^[0-9]+$ ]] && ANTIFL_CHATS["${CHAT[ID]}","level"]="${CMD[1]}"
|
||||||
antiflood_timer
|
antiFlood_timer
|
||||||
;;
|
;;
|
||||||
# command /floodapply starts counter meausares
|
# command /afactive starts counter meausares
|
||||||
"/floodap"*)
|
"/afdo")
|
||||||
ANTIFL_CHATS["${CHAT[ID]}","active"]="yes"
|
ANTIFL_CHATS["${CHAT[ID]}","active"]="yes"
|
||||||
;;
|
;;
|
||||||
|
# command /afactive starts counter meausares
|
||||||
|
"/afstop")
|
||||||
|
ANTIFL_CHATS["${CHAT[ID]}","active"]="no"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# register to timer
|
# 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
|
# save settings and reset flood level every BAN Min
|
||||||
antiflood_timer(){
|
antiFlood_timer(){
|
||||||
ANTIFL_ACTUALS=( )
|
ANTIFL_ACTUALS=( )
|
||||||
jssh_writeDB "ANTIFL_CHATS" "addons/$ANTIFL_ME" &
|
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_TEXT["${ANTIFL_ME}"]="${ANTIFL_ME}_multievent"
|
||||||
BASHBOT_EVENT_FILE["${ANTIFL_ME}"]="${ANTIFL_ME}_multievent"
|
BASHBOT_EVENT_FILE["${ANTIFL_ME}"]="${ANTIFL_ME}_multievent"
|
||||||
|
|
||||||
antiflood_multievent(){
|
antiFlood_multievent(){
|
||||||
# not started
|
# not started
|
||||||
[ "${ANTIFL_CHATS["${CHAT[ID]}","level"]}" = "" ] && return
|
[ "${ANTIFL_CHATS["${CHAT[ID]}","level"]}" = "" ] && return
|
||||||
# check user flood text
|
# check user flood text
|
||||||
@ -88,21 +92,21 @@ if [[ "$1" = "start"* ]]; then
|
|||||||
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}"]-- ))
|
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}"]-- ))
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"]-- ))
|
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"]-- ))
|
||||||
else
|
fi
|
||||||
|
else
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}"]++ ))
|
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}"]++ ))
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
# check user flood picture
|
# check user flood picture
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
[ "$1" = "file" ] && (( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"]++ ))
|
[ "$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
|
# check and handle actions
|
||||||
antiflood_action() {
|
antiFlood_action() {
|
||||||
# check flood level of user
|
# 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
|
if [ "${ANTIFL_CHATS["${CHAT[ID]}","active"]}" = "yes" ]; then
|
||||||
# remove message
|
# remove message
|
||||||
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
|
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
|
||||||
|
21
bashbot.sh
21
bashbot.sh
@ -11,7 +11,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.90-dev2-25-gb240ede
|
#### $$VERSION$$ v0.90-dev2-27-gfc36de9
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -216,8 +216,8 @@ delete_message() {
|
|||||||
|
|
||||||
get_file() {
|
get_file() {
|
||||||
[ "$1" = "" ] && return
|
[ "$1" = "" ] && return
|
||||||
sendJson "" '"file_id": '"${1}""${GETFILE_URL}"
|
sendJson "" '"file_id": "'"${1}"'"' "${GETFILE_URL}"
|
||||||
printf '%s\n' "${URL}"/"$(jsonGetString <<< "${res}" '"result","file_path"')"
|
printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')"
|
||||||
}
|
}
|
||||||
|
|
||||||
# curl is preffered, but may not availible on ebedded systems
|
# curl is preffered, but may not availible on ebedded systems
|
||||||
@ -342,7 +342,7 @@ process_updates() {
|
|||||||
}
|
}
|
||||||
process_client() {
|
process_client() {
|
||||||
local num="$1" debug="$2"
|
local num="$1" debug="$2"
|
||||||
CMD=( )
|
CMD=( ); iQUERY=( )
|
||||||
iQUERY[ID]="${UPD["result",${num},"inline_query","id"]}"
|
iQUERY[ID]="${UPD["result",${num},"inline_query","id"]}"
|
||||||
if [ "${iQUERY[ID]}" = "" ]; then
|
if [ "${iQUERY[ID]}" = "" ]; then
|
||||||
[[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"MESSAGE.log"
|
[[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"MESSAGE.log"
|
||||||
@ -407,6 +407,7 @@ event_inline() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
event_message() {
|
event_message() {
|
||||||
|
echo "${MESSAGE[0]}"
|
||||||
local event debug="$1"
|
local event debug="$1"
|
||||||
# ${MESSAEG[*]} event_message
|
# ${MESSAEG[*]} event_message
|
||||||
# shellcheck disable=SC2153
|
# shellcheck disable=SC2153
|
||||||
@ -432,7 +433,6 @@ event_message() {
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ${REPLYTO[*]} event_replyto
|
# ${REPLYTO[*]} event_replyto
|
||||||
if [ "${REPLYTO[UID]}" != "" ]; then
|
if [ "${REPLYTO[UID]}" != "" ]; then
|
||||||
# shellcheck disable=SC2153
|
# shellcheck disable=SC2153
|
||||||
@ -462,7 +462,7 @@ event_message() {
|
|||||||
|
|
||||||
# ${VENUE[*]} event_location
|
# ${VENUE[*]} event_location
|
||||||
# ${LOCALTION[*]} event_location
|
# ${LOCALTION[*]} event_location
|
||||||
if [ "${LOCATION[*]}" != "" ] || [ "${VENUE[TITLE]}" != "" ]; then
|
if [ "${LOCATION[LONGITUDE]}" != "" ] || [ "${VENUE[TITLE]}" != "" ]; then
|
||||||
# shellcheck disable=SC2153
|
# shellcheck disable=SC2153
|
||||||
for event in "${!BASHBOT_EVENT_LOCATION[@]}"
|
for event in "${!BASHBOT_EVENT_LOCATION[@]}"
|
||||||
do
|
do
|
||||||
@ -471,7 +471,8 @@ event_message() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# ${URLS[*]} event_file
|
# ${URLS[*]} event_file
|
||||||
if [ "${URLS[*]}" = "" ]; then
|
# NOTE: compare again #URLS -1 blanks!
|
||||||
|
if [[ "${URLS[*]}" != " " ]]; then
|
||||||
# shellcheck disable=SC2153
|
# shellcheck disable=SC2153
|
||||||
for event in "${!BASHBOT_EVENT_FILE[@]}"
|
for event in "${!BASHBOT_EVENT_FILE[@]}"
|
||||||
do
|
do
|
||||||
@ -512,6 +513,7 @@ process_message() {
|
|||||||
USER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","from","username"]}")"
|
USER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","from","username"]}")"
|
||||||
|
|
||||||
# in reply to message from
|
# in reply to message from
|
||||||
|
REPLYTO=( )
|
||||||
REPLYTO[UID]="${UPD["result",${num},"message","reply_to_message","from","id"]}"
|
REPLYTO[UID]="${UPD["result",${num},"message","reply_to_message","from","id"]}"
|
||||||
if [ "${REPLYTO[UID]}" != "" ]; then
|
if [ "${REPLYTO[UID]}" != "" ]; then
|
||||||
REPLYTO[0]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","text"]}")"
|
REPLYTO[0]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","text"]}")"
|
||||||
@ -522,6 +524,7 @@ process_message() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# forwarded message from
|
# forwarded message from
|
||||||
|
FORWARD=( )
|
||||||
FORWARD[UID]="${UPD["result",${num},"message","forward_from","id"]}"
|
FORWARD[UID]="${UPD["result",${num},"message","forward_from","id"]}"
|
||||||
if [ "${FORWARD[UID]}" != "" ]; then
|
if [ "${FORWARD[UID]}" != "" ]; then
|
||||||
FORWARD[ID]="${MESSAGE[ID]}" # same as message ID
|
FORWARD[ID]="${MESSAGE[ID]}" # same as message ID
|
||||||
@ -531,6 +534,7 @@ process_message() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Audio
|
# Audio
|
||||||
|
URLS=( )
|
||||||
URLS[AUDIO]="$(get_file "${UPD["result",${num},"message","audio","file_id"]}")"
|
URLS[AUDIO]="$(get_file "${UPD["result",${num},"message","audio","file_id"]}")"
|
||||||
# Document
|
# Document
|
||||||
URLS[DOCUMENT]="$(get_file "${UPD["result",${num},"message","document","file_id"]}")"
|
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"]}")"
|
URLS[VOICE]="$(get_file "${UPD["result",${num},"message","voice","file_id"]}")"
|
||||||
|
|
||||||
# Contact
|
# Contact
|
||||||
|
CONTACT=( )
|
||||||
CONTACT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","contact","first_name"]}")"
|
CONTACT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","contact","first_name"]}")"
|
||||||
if [ "${CONTACT[FIRST_NAME]}" != "" ]; then
|
if [ "${CONTACT[FIRST_NAME]}" != "" ]; then
|
||||||
CONTACT[USER_ID]="$(JsonDecode "${UPD["result",${num},"message","contact","user_id"]}")"
|
CONTACT[USER_ID]="$(JsonDecode "${UPD["result",${num},"message","contact","user_id"]}")"
|
||||||
@ -553,6 +558,7 @@ process_message() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# vunue
|
# vunue
|
||||||
|
VENUE=( )
|
||||||
VENUE[TITLE]="$(JsonDecode "${UPD["result",${num},"message","venue","title"]}")"
|
VENUE[TITLE]="$(JsonDecode "${UPD["result",${num},"message","venue","title"]}")"
|
||||||
if [ "${VENUE[TITLE]}" != "" ]; then
|
if [ "${VENUE[TITLE]}" != "" ]; then
|
||||||
VENUE[ADDRESS]="$(JsonDecode "${UPD["result",${num},"message","venue","address"]}")"
|
VENUE[ADDRESS]="$(JsonDecode "${UPD["result",${num},"message","venue","address"]}")"
|
||||||
@ -565,6 +571,7 @@ process_message() {
|
|||||||
CAPTION="$(JsonDecode "${UPD["result",${num},"message","caption"]}")"
|
CAPTION="$(JsonDecode "${UPD["result",${num},"message","caption"]}")"
|
||||||
|
|
||||||
# Location
|
# Location
|
||||||
|
LOCATION=( )
|
||||||
LOCATION[LONGITUDE]="${UPD["result",${num},"message","location","longitude"]}"
|
LOCATION[LONGITUDE]="${UPD["result",${num},"message","location","longitude"]}"
|
||||||
LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}"
|
LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}"
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# 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
|
# source from commands.sh to use the aliases
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# 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
|
# source from commands.sh to use the inline functions
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# 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
|
# source from commands.sh if you want ro use interactive or background jobs
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# 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
|
# source from commands.sh to use the member functions
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# 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
|
# source from commands.sh to use jsonDB functions
|
||||||
#
|
#
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# 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
|
# source from commands.sh to use the sendMessage functions
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user