fix missing ${xxx} warnings

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-04 23:08:09 +01:00
parent a5aa756596
commit 641727dc99
10 changed files with 155 additions and 156 deletions

View File

@ -4,7 +4,7 @@
# this addon counts how many files, e.g. stickers, are sent to # this addon counts how many files, e.g. stickers, are sent to
# a chat and takes actions if threshold is reached # a chat and takes actions if threshold is reached
# #
#### $$VERSION$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-5-ga5aa756
# used events: # used events:
# #
@ -37,7 +37,7 @@ ANTIFL_BAN="5" # 5 minutes
# initialize after installation or update # initialize after installation or update
if [[ "$1" = "init"* ]]; then if [[ "$1" = "init"* ]]; then
jssh_newDB "addons/$ANTIFL_ME" jssh_newDB "addons/${ANTIFL_ME}"
fi fi
@ -46,7 +46,7 @@ fi
if [[ "$1" = "start"* ]]; then if [[ "$1" = "start"* ]]; then
ANTIFL_ADMIN="$(getConfigKey "botadmin")" ANTIFL_ADMIN="$(getConfigKey "botadmin")"
#load existing chat settings on start #load existing chat settings on start
jssh_readDB "ANTIFL_CHATS" "addons/$ANTIFL_ME" jssh_readDB "ANTIFL_CHATS" "addons/${ANTIFL_ME}"
# register to CMD # register to CMD
BASHBOT_EVENT_CMD["${ANTIFL_ME}"]="${ANTIFL_ME}_cmd" BASHBOT_EVENT_CMD["${ANTIFL_ME}"]="${ANTIFL_ME}_cmd"
@ -71,14 +71,14 @@ if [[ "$1" = "start"* ]]; then
"/afdo" | "/afactive") "/afdo" | "/afactive")
[[ "${CMD[1]}" =~ ^[-0-9]+$ ]] && user_is_botadmin "${USER[ID]}" && chat="$3" [[ "${CMD[1]}" =~ ^[-0-9]+$ ]] && user_is_botadmin "${USER[ID]}" && chat="$3"
ANTIFL_CHATS["${chat}","active"]="yes" ANTIFL_CHATS["${chat}","active"]="yes"
jssh_writeDB "ANTIFL_CHATS" "addons/$ANTIFL_ME" & jssh_writeDB "ANTIFL_CHATS" "addons/${ANTIFL_ME}" &
send_normal_message "${USER[ID]}" "Antiflood activated for chat ${chat}" & send_normal_message "${USER[ID]}" "Antiflood activated for chat ${chat}" &
;; ;;
# command /afactive starts counter meausares # command /afactive starts counter meausares
"/afstop") "/afstop")
[[ "${CMD[1]}" =~ ^[-0-9]+$ ]] && user_is_botadmin "${USER[ID]}" && chat="$3" [[ "${CMD[1]}" =~ ^[-0-9]+$ ]] && user_is_botadmin "${USER[ID]}" && chat="$3"
ANTIFL_CHATS["${chat}","active"]="no" ANTIFL_CHATS["${chat}","active"]="no"
jssh_writeDB "ANTIFL_CHATS" "addons/$ANTIFL_ME" & jssh_writeDB "ANTIFL_CHATS" "addons/${ANTIFL_ME}" &
send_normal_message "${USER[ID]}" "Antiflood stopped for chat ${chat}" & send_normal_message "${USER[ID]}" "Antiflood stopped for chat ${chat}" &
;; ;;
esac esac
@ -90,7 +90,7 @@ if [[ "$1" = "start"* ]]; then
# 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}" &
} }
# register to inline and command # register to inline and command

View File

@ -30,7 +30,7 @@
# 8 - curl/wget missing # 8 - curl/wget missing
# 10 - not bash! # 10 - not bash!
# #
#### $$VERSION$$ v1.21-7-g0798f1a #### $$VERSION$$ v1.25-dev-5-ga5aa756
################################################################## ##################################################################
# emmbeded system may claim bash but it is not # emmbeded system may claim bash but it is not
@ -42,7 +42,7 @@ fi
# are we running in a terminal? # are we running in a terminal?
NN="\n" NN="\n"
if [ -t 1 ] && [ -n "$TERM" ]; then if [ -t 1 ] && [ -n "${TERM}" ]; then
INTERACTIVE='yes' INTERACTIVE='yes'
RED='\e[31m' RED='\e[31m'
GREEN='\e[32m' GREEN='\e[32m'
@ -150,13 +150,13 @@ MODULEDIR="${SCRIPTDIR}/modules"
# adjust locations based on source and real name # adjust locations based on source and real name
[[ "${SCRIPT}" != "${REALME}" || "$1" == "source" ]] && SOURCE="yes" [[ "${SCRIPT}" != "${REALME}" || "$1" == "source" ]] && SOURCE="yes"
if [ -n "$BASHBOT_HOME" ]; then if [ -n "${BASHBOT_HOME}" ]; then
SCRIPTDIR="$BASHBOT_HOME" SCRIPTDIR="${BASHBOT_HOME}"
else else
BASHBOT_HOME="${SCRIPTDIR}" BASHBOT_HOME="${SCRIPTDIR}"
fi fi
[ -z "${BASHBOT_ETC}" ] && BASHBOT_ETC="$BASHBOT_HOME" [ -z "${BASHBOT_ETC}" ] && BASHBOT_ETC="${BASHBOT_HOME}"
[ -z "${BASHBOT_VAR}" ] && BASHBOT_VAR="$BASHBOT_HOME" [ -z "${BASHBOT_VAR}" ] && BASHBOT_VAR="${BASHBOT_HOME}"
ADDONDIR="${BASHBOT_ETC:-.}/addons" ADDONDIR="${BASHBOT_ETC:-.}/addons"
RUNUSER="${USER}" # USER is overwritten by bashbot array :-(, save original RUNUSER="${USER}" # USER is overwritten by bashbot array :-(, save original
@ -169,16 +169,16 @@ case "$1" in
exit;; exit;;
"help") HELP="${BASHBOT_HOME:-.}/README" "help") HELP="${BASHBOT_HOME:-.}/README"
if [ -n "${INTERACTIVE}" ];then if [ -n "${INTERACTIVE}" ];then
_exists w3m && w3m "$HELP.html" && exit _exists w3m && w3m "${HELP}.html" && exit
_exists lynx && lynx "$HELP.html" && exit _exists lynx && lynx "${HELP}.html" && exit
_exists less && less "$HELP.txt" && exit _exists less && less "${HELP}.txt" && exit
fi fi
cat "$HELP.txt" cat "${HELP}.txt"
exit;; exit;;
esac esac
# OK, ENVIRONMENT is set up, let's do some additional tests # OK, ENVIRONMENT is set up, let's do some additional tests
if [[ -z "${SOURCE}" && -z "$BASHBOT_HOME" ]] && ! cd "${RUNDIR}" ; then if [[ -z "${SOURCE}" && -z "${BASHBOT_HOME}" ]] && ! cd "${RUNDIR}" ; then
printf "${RED}ERROR: Can't change to ${RUNDIR} ...${NN}" printf "${RED}ERROR: Can't change to ${RUNDIR} ...${NN}"
exit 1 exit 1
fi fi
@ -301,10 +301,10 @@ fi
BASHBOT_RETRY="" # retry by default BASHBOT_RETRY="" # retry by default
URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}" URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}"
ME_URL=$URL'/getMe' ME_URL=${URL}'/getMe'
UPD_URL=$URL'/getUpdates?offset=' UPD_URL=${URL}'/getUpdates?offset='
GETFILE_URL=$URL'/getFile' GETFILE_URL=${URL}'/getFile'
################# #################
# BASHBOT COMMON functions # BASHBOT COMMON functions
@ -351,8 +351,8 @@ fi
# outputs final filename # outputs final filename
download() { download() {
local empty="no.file" file="${2:-${empty}}" local empty="no.file" file="${2:-${empty}}"
if [[ "$file" = *"/"* ]] || [[ "$file" = "."* ]]; then file="${empty}"; fi if [[ "${file}" = *"/"* ]] || [[ "${file}" = "."* ]]; then file="${empty}"; fi
while [ -f "${DATADIR:-.}/${file}" ] ; do file="$RAMDOM-${file}"; done while [ -f "${DATADIR:-.}/${file}" ] ; do file="${RANDOM}-${file}"; done
getJson "$1" >"${DATADIR:-.}/${file}" || return getJson "$1" >"${DATADIR:-.}/${file}" || return
printf '%s\n' "${DATADIR:-.}/${file}" printf '%s\n' "${DATADIR:-.}/${file}"
} }
@ -386,7 +386,7 @@ killallproc() {
# $ chat $2 msg_id $3 nolog # $ chat $2 msg_id $3 nolog
declare -xr DELETE_URL=$URL'/deleteMessage' declare -xr DELETE_URL=${URL}'/deleteMessage'
delete_message() { delete_message() {
[ -z "$3" ] && log_update "Delete Message CHAT=${1} MSG_ID=${2}" [ -z "$3" ] && log_update "Delete Message CHAT=${1} MSG_ID=${2}"
sendJson "${1}" '"message_id": '"${2}"'' "${DELETE_URL}" sendJson "${1}" '"message_id": '"${2}"'' "${DELETE_URL}"
@ -435,8 +435,8 @@ if ! _exists iconv; then
function iconv() { cat; } function iconv() { cat; }
fi fi
TIMEOUT="${BASHBOT_TIMEOUT}" TIMEOUT="${BASHBOT_TIMEOUT:-20}"
[[ "$TIMEOUT" =~ ^[${o9o9o9}]+$ ]] || TIMEOUT="20" [[ "${TIMEOUT}" =~ ^[${o9o9o9}]+$ ]] || TIMEOUT="20"
# usage: sendJson "chat" "JSON" "URL" # usage: sendJson "chat" "JSON" "URL"
sendJson(){ sendJson(){
@ -644,7 +644,7 @@ title2Json(){
# get bot name and id from telegram # get bot name and id from telegram
getBotName() { getBotName() {
declare -A BOTARRAY declare -A BOTARRAY
Json2Array 'BOTARRAY' <<<"$(getJson "$ME_URL" | "${JSONSHFILE}" -b -n 2>/dev/null)" Json2Array 'BOTARRAY' <<<"$(getJson "${ME_URL}" | "${JSONSHFILE}" -b -n 2>/dev/null)"
[ -z "${BOTARRAY["result","username"]}" ] && return 1 [ -z "${BOTARRAY["result","username"]}" ] && return 1
# save botname and id # save botname and id
setConfigKey "botname" "${BOTARRAY["result","username"]}" setConfigKey "botname" "${BOTARRAY["result","username"]}"
@ -657,7 +657,7 @@ getBotName() {
JsonDecode() { JsonDecode() {
local out="$1" remain="" U="" local out="$1" remain="" U=""
local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)' local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)'
while [[ "${out}" =~ $regexp ]] ; do while [[ "${out}" =~ ${regexp} ]] ; do
U=$(( ( (0xd${BASH_REMATCH[2]} & 0x3ff) <<10 ) | ( 0xd${BASH_REMATCH[3]} & 0x3ff ) + 0x10000 )) U=$(( ( (0xd${BASH_REMATCH[2]} & 0x3ff) <<10 ) | ( 0xd${BASH_REMATCH[3]} & 0x3ff ) + 0x10000 ))
remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}" remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}"
out="${BASH_REMATCH[1]}" out="${BASH_REMATCH[1]}"
@ -683,7 +683,7 @@ process_updates() {
max="$(grep -F ',"update_id"]' <<< "${UPDATE}" | tail -1 | cut -d , -f 2 )" max="$(grep -F ',"update_id"]' <<< "${UPDATE}" | tail -1 | cut -d , -f 2 )"
Json2Array 'UPD' <<<"${UPDATE}" Json2Array 'UPD' <<<"${UPDATE}"
for ((num=0; num<=max; num++)); do for ((num=0; num<=max; num++)); do
process_client "$num" "${debug}" process_client "${num}" "${debug}"
done done
} }
@ -731,7 +731,7 @@ process_client() {
jssh_countKeyDB_async "${CHAT[ID]}" "${COUNTFILE}" jssh_countKeyDB_async "${CHAT[ID]}" "${COUNTFILE}"
} }
declare -Ax BASHBOT_EVENT_INLINE BASHBOT_EVENT_MESSAGE BASHBOT_EVENT_CMD BASHBOT_EVENT_REPLY BASHBOT_EVENT_FORWARD BASHBOT_EVENT_SEND declare -Ax BASHBOT_EVENT_INLINE BASHBOT_EVENT_MESSAGE BASHBOT_EVENT_CMD BASHBOT_EVENT_REPLYTO BASHBOT_EVENT_FORWARD BASHBOT_EVENT_SEND
declare -Ax BASHBOT_EVENT_CONTACT BASHBOT_EVENT_LOCATION BASHBOT_EVENT_FILE BASHBOT_EVENT_TEXT BASHBOT_EVENT_TIMER BASHBOT_BLOCKED declare -Ax BASHBOT_EVENT_CONTACT BASHBOT_EVENT_LOCATION BASHBOT_EVENT_FILE BASHBOT_EVENT_TEXT BASHBOT_EVENT_TIMER BASHBOT_BLOCKED
start_timer(){ start_timer(){
@ -745,7 +745,7 @@ start_timer(){
EVENT_SEND="0" EVENT_SEND="0"
event_send() { event_send() {
# max recursion level 5 to avoid fork bombs # max recursion level 5 to avoid fork bombs
(( EVENT_SEND++ )); [ "$EVENT_SEND" -gt "5" ] && return (( EVENT_SEND++ )); [ "${EVENT_SEND}" -gt "5" ] && return
# shellcheck disable=SC2153 # shellcheck disable=SC2153
for key in "${!BASHBOT_EVENT_SEND[@]}" for key in "${!BASHBOT_EVENT_SEND[@]}"
do do
@ -761,7 +761,7 @@ event_timer() {
for key in "${!BASHBOT_EVENT_TIMER[@]}" for key in "${!BASHBOT_EVENT_TIMER[@]}"
do do
timer="${key##*,}" timer="${key##*,}"
[[ ! "$timer" =~ ^-*[1-9][0-9]*$ ]] && continue [[ ! "${timer}" =~ ^-*[1-9][0-9]*$ ]] && continue
if [ "$(( EVENT_TIMER % timer ))" = "0" ]; then if [ "$(( EVENT_TIMER % timer ))" = "0" ]; then
_exec_if_function "${BASHBOT_EVENT_TIMER[${key}]}" "timer" "${key}" "${debug}" _exec_if_function "${BASHBOT_EVENT_TIMER[${key}]}" "timer" "${key}" "${debug}"
[ "$(( EVENT_TIMER % timer ))" -lt "0" ] && \ [ "$(( EVENT_TIMER % timer ))" -lt "0" ] && \
@ -1041,7 +1041,7 @@ start_bot() {
# start timer events # start timer events
if [ -n "${BASHBOT_START_TIMER}" ] ; then if [ -n "${BASHBOT_START_TIMER}" ] ; then
# shellcheck disable=SC2064 # shellcheck disable=SC2064
trap "event_timer $DEBUGMSG" ALRM trap "event_timer ${DEBUGMSG}" ALRM
start_timer & start_timer &
# shellcheck disable=SC2064 # shellcheck disable=SC2064
trap "kill -9 $!; exit" EXIT INT HUP TERM QUIT trap "kill -9 $!; exit" EXIT INT HUP TERM QUIT
@ -1075,7 +1075,7 @@ start_bot() {
OFFSET="$(grep <<< "${UPDATE}" '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)" OFFSET="$(grep <<< "${UPDATE}" '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)"
((OFFSET++)) ((OFFSET++))
if [ "$OFFSET" != "1" ]; then if [ "${OFFSET}" != "1" ]; then
nextsleep="100" nextsleep="100"
process_updates "${DEBUGMSG}" process_updates "${DEBUGMSG}"
fi fi
@ -1113,22 +1113,22 @@ bot_init() {
printf "Done.\n" printf "Done.\n"
# setup bashbot # setup bashbot
[[ "${UID}" -eq "0" ]] && RUNUSER="nobody" [[ "${UID}" -eq "0" ]] && RUNUSER="nobody"
printf "Enter User to run bashbot [$RUNUSER]: " printf "Enter User to run bashbot [${RUNUSER}]: "
read -r TOUSER read -r TOUSER
[ -z "$TOUSER" ] && TOUSER="$RUNUSER" [ -z "${TOUSER}" ] && TOUSER="${RUNUSER}"
if ! id "$TOUSER" &>/dev/null; then if ! id "${TOUSER}" &>/dev/null; then
printf "${RED}User \"$TOUSER\" not found!${NN}" printf "${RED}User \"${TOUSER}\" not found!${NN}"
exit 3 exit 3
else else
printf "Adjusting files and permissions for user \"${TOUSER}\" ...\n" printf "Adjusting files and permissions for user \"${TOUSER}\" ...\n"
[ -w "bashbot.rc" ] && sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'$TOUSER'"/' "bashbot.rc" [ -w "bashbot.rc" ] && sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'"${TOUSER}"'"/' "bashbot.rc"
chmod 711 . chmod 711 .
chmod -R o-w ./* chmod -R o-w ./*
chmod -R u+w "${COUNTFILE}"* "${BLOCKEDFILE}"* "${DATADIR}" logs "${LOGDIR}/"*.log 2>/dev/null chmod -R u+w "${COUNTFILE}"* "${BLOCKEDFILE}"* "${DATADIR}" logs "${LOGDIR}/"*.log 2>/dev/null
chmod -R o-r,o-w "${COUNTFILE}"* "${BLOCKEDFILE}"* "${DATADIR}" "${BOTACL}" 2>/dev/null chmod -R o-r,o-w "${COUNTFILE}"* "${BLOCKEDFILE}"* "${DATADIR}" "${BOTACL}" 2>/dev/null
# jsshDB must writeable by owner # jsshDB must writeable by owner
find . -name '*.jssh*' -exec chmod u+w \{\} + find . -name '*.jssh*' -exec chmod u+w \{\} +
chown -R "$TOUSER" . ./* chown -R "${TOUSER}" . ./*
printf "Done.\n" printf "Done.\n"
fi fi
# ask to check bottoken online # ask to check bottoken online
@ -1187,7 +1187,7 @@ if [ -z "${SOURCE}" ]; then
else else
printf "${GREY}Info: Can't get Botname from Telegram, try cached one ...${NN}" printf "${GREY}Info: Can't get Botname from Telegram, try cached one ...${NN}"
ME="$(getConfigKey "botname")" ME="$(getConfigKey "botname")"
if [ -z "$ME" ]; then if [ -z "${ME}" ]; then
printf "${RED}ERROR: No cached botname, can't continue! ...${NN}" printf "${RED}ERROR: No cached botname, can't continue! ...${NN}"
exit 1 exit 1
fi fi
@ -1202,7 +1202,7 @@ if [ -z "${SOURCE}" ]; then
ME="$(getConfigKey "botname")" ME="$(getConfigKey "botname")"
# read until terminated # read until terminated
while read -r line ;do while read -r line ;do
[ -n "$line" ] && send_message "$2" "$line" [ -n "${line}" ] && send_message "$2" "${line}"
done done
# cleanup datadir, keep logfile if not empty # cleanup datadir, keep logfile if not empty
rm -f -r "${DATADIR:-.}/$3" rm -f -r "${DATADIR:-.}/$3"
@ -1256,7 +1256,7 @@ if [ -z "${SOURCE}" ]; then
BOTPID="$(proclist "${SESSION}")" BOTPID="$(proclist "${SESSION}")"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
[ -n "${BOTPID}" ] && kill ${BOTPID} [ -n "${BOTPID}" ] && kill ${BOTPID}
nohup "$SCRIPT" "startbot" "$2" "${SESSION}" &>/dev/null & nohup "${SCRIPT}" "startbot" "$2" "${SESSION}" &>/dev/null &
printf "Session Name: %s\n" "${SESSION}" printf "Session Name: %s\n" "${SESSION}"
sleep 1 sleep 1
if [ -n "$(proclist "${SESSION}")" ]; then if [ -n "$(proclist "${SESSION}")" ]; then

View File

@ -15,7 +15,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$$ v1.25-dev-0-gd310805 #### $$VERSION$$ v1.25-dev-5-ga5aa756
# #
# bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed # bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed
@ -78,7 +78,7 @@ export FILE_REGEX="${BASHBOT_ETC}/.*"
if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then
# detect inline commands.... # detect inline commands....
# no default commands, all processing is done in myinlines() # no default commands, all processing is done in myinlines()
if [ "$INLINE" != "0" ] && [ -n "${iQUERY[ID]}" ]; then if [ "${INLINE}" != "0" ] && [ -n "${iQUERY[ID]}" ]; then
# forward iinline query to optional dispatcher # forward iinline query to optional dispatcher
_exec_if_function myinlines _exec_if_function myinlines

View File

@ -13,7 +13,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$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-5-ga5aa756
######################################################################## ########################################################################
###### ######
@ -47,6 +47,6 @@ printf "Output time every %s seconds ...\n" "${SLEEP}"
while true while true
do do
date "+* It's %k:%M:%S o'clock ..." date "+* It's %k:%M:%S o'clock ..."
sleep $SLEEP sleep "${SLEEP}"
done done

View File

@ -10,7 +10,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$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-5-ga5aa756
######################################################################## ########################################################################
###### ######
@ -39,7 +39,7 @@ else
fi fi
# question with Keyboard, repeating until correct answer given # question with Keyboard, repeating until correct answer given
until [ "$SUCCESS" = "y" ] ;do until [ "${SUCCESS}" = "y" ] ;do
printf 'Do you like Music? mykeyboardstartshere "Yass!" , "No"\n' printf 'Do you like Music? mykeyboardstartshere "Yass!" , "No"\n'
read -r answer <"${INPUT}" read -r answer <"${INPUT}"
case ${answer,,} in case ${answer,,} in

View File

@ -5,17 +5,17 @@
# 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$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-5-ga5aa756
# will be automatically sourced from bashbot # will be automatically sourced from bashbot
# source once magic, function named like file # source once magic, function named like file
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
INLINE_QUERY=$URL'/answerInlineQuery' INLINE_QUERY=${URL}'/answerInlineQuery'
answer_inline_query() { answer_inline_query() {
answer_inline_multi "${1}" "$(shift; inline_query_compose "$RANDOM" "$@")" answer_inline_multi "${1}" "$(shift; inline_query_compose "${RANDOM}" "$@")"
} }
answer_inline_multi() { answer_inline_multi() {
sendJson "" '"inline_query_id": '"${1}"', "results": ['"${2}"']' "${INLINE_QUERY}" sendJson "" '"inline_query_id": '"${1}"', "results": ['"${2}"']' "${INLINE_QUERY}"
@ -33,70 +33,70 @@ inline_query_compose(){
case "${2}" in case "${2}" in
# user provided media # user provided media
"article"|"message") # article ID title message (markup description) "article"|"message") # article ID title message (markup description)
JSON='{"type":"article","id":"'$ID'","input_message_content": {"message_text":"'$4'"} '$(title2Json "$3" "" "$5" "$6" "$7")'}' JSON='{"type":"article","id":"'${ID}'","input_message_content": {"message_text":"'$4'"} '$(title2Json "$3" "" "$5" "$6" "$7")'}'
;; ;;
"photo") # photo ID photoURL (thumbURL title description caption) "photo") # photo ID photoURL (thumbURL title description caption)
[ -z "$4" ] && tumb="$3" [ -z "$4" ] && tumb="$3"
JSON='{"type":"photo","id":"'$ID'","photo_url":"'$3'","thumb_url":"'$4${tumb}'"'$(title2Json "$5" "$7" "$6" "$7" "$8")'}' JSON='{"type":"photo","id":"'${ID}'","photo_url":"'$3'","thumb_url":"'$4${tumb}'"'$(title2Json "$5" "$7" "$6" "$7" "$8")'}'
;; ;;
"gif") # gif ID photoURL (thumbURL title caption) "gif") # gif ID photoURL (thumbURL title caption)
[ -z "$4" ] && tumb="$3" [ -z "$4" ] && tumb="$3"
JSON='{"type":"gif","id":"'$ID'","gif_url":"'$3'", "thumb_url":"'$4${tumb}'"'$(title2Json "$5" "$6" "$7" "$8" "$9")'}' JSON='{"type":"gif","id":"'${ID}'","gif_url":"'$3'", "thumb_url":"'$4${tumb}'"'$(title2Json "$5" "$6" "$7" "$8" "$9")'}'
;; ;;
"mpeg4_gif") # mpeg4_gif ID mpegURL (thumbURL title caption) "mpeg4_gif") # mpeg4_gif ID mpegURL (thumbURL title caption)
[ -n "$4" ] && tumb='","thumb_url":"'$4'"' [ -n "$4" ] && tumb='","thumb_url":"'$4'"'
JSON='{"type":"mpeg4_gif","id":"'$ID'","mpeg4_url":"'$3'"'${tumb}$(title2Json "$5" "$6" "" "$7" "$8")'}' JSON='{"type":"mpeg4_gif","id":"'${ID}'","mpeg4_url":"'$3'"'${tumb}$(title2Json "$5" "$6" "" "$7" "$8")'}'
;; ;;
"video") # video ID videoURL mime thumbURL title (caption) "video") # video ID videoURL mime thumbURL title (caption)
JSON='{"type":"video","id":"'$ID'","video_url":"'$3'","mime_type":"'$4'","thumb_url":"'$5'"'$(title2Json "$6" "$7" "$8" "$9" "${10}")'}' JSON='{"type":"video","id":"'${ID}'","video_url":"'$3'","mime_type":"'$4'","thumb_url":"'$5'"'$(title2Json "$6" "$7" "$8" "$9" "${10}")'}'
;; ;;
"audio") # audio ID audioURL title (caption) "audio") # audio ID audioURL title (caption)
JSON='{"type":"audio","id":"'$ID'","audio_url":"'$3'"'$(title2Json "$4" "$5" "" "" "$6")'}' JSON='{"type":"audio","id":"'${ID}'","audio_url":"'$3'"'$(title2Json "$4" "$5" "" "" "$6")'}'
;; ;;
"voice") # voice ID voiceURL title (caption) "voice") # voice ID voiceURL title (caption)
JSON='{"type":"voice","id":"'$ID'","voice_url":"'$3'"'$(title2Json "$4" "$5" "" "" "$6")'}' JSON='{"type":"voice","id":"'${ID}'","voice_url":"'$3'"'$(title2Json "$4" "$5" "" "" "$6")'}'
;; ;;
"document") # document ID title documentURL mimetype (caption description) "document") # document ID title documentURL mimetype (caption description)
JSON='{"type":"document","id":"'$ID'","document_url":"'$4'","mime_type":"'$5'"'$(title2Json "$3" "$6" "$7" "$8" "$9")'}' JSON='{"type":"document","id":"'${ID}'","document_url":"'$4'","mime_type":"'$5'"'$(title2Json "$3" "$6" "$7" "$8" "$9")'}'
;; ;;
"location") # location ID lat long title "location") # location ID lat long title
JSON='{"type":"location","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'"}' JSON='{"type":"location","id":"'${ID}'","latitude":"'$3'","longitude":"'$4'","title":"'$5'"}'
;; ;;
"venue") # venue ID lat long title (address forsquare) "venue") # venue ID lat long title (address forsquare)
[ -z "$6" ] && addr="$5" [ -z "$6" ] && addr="$5"
[ -n "$7" ] && fours=',"foursquare_id":"'$7'"' [ -n "$7" ] && fours=',"foursquare_id":"'$7'"'
JSON='{"type":"venue","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'","address":"'$6${addr}'"'${fours}'}' JSON='{"type":"venue","id":"'${ID}'","latitude":"'$3'","longitude":"'$4'","title":"'$5'","address":"'$6${addr}'"'${fours}'}'
;; ;;
"contact") # contact ID phone first (last thumb) "contact") # contact ID phone first (last thumb)
[ -n "$5" ] && last=',"last_name":"'$5'"' [ -n "$5" ] && last=',"last_name":"'$5'"'
[ -n "$6" ] && tumb='","thumb_url":"'$6'"' [ -n "$6" ] && tumb='","thumb_url":"'$6'"'
JSON='{"type":"contact","id":"'$ID'","phone_number":"'$3'","first_name":"'$4'"'${last}'"}' JSON='{"type":"contact","id":"'${ID}'","phone_number":"'$3'","first_name":"'$4'"'${last}'"}'
;; ;;
# title2Json title caption description markup inlinekeyboard # title2Json title caption description markup inlinekeyboard
# Cached media stored in Telegram server # Cached media stored in Telegram server
"cached_photo") # photo ID file (title description caption) "cached_photo") # photo ID file (title description caption)
JSON='{"type":"photo","id":"'$ID'","photo_file_id":"'$3'"'$(title2Json "$4" "$6" "$5" "$7" "$8")'}' JSON='{"type":"photo","id":"'${ID}'","photo_file_id":"'$3'"'$(title2Json "$4" "$6" "$5" "$7" "$8")'}'
;; ;;
"cached_gif") # gif ID file (title caption) "cached_gif") # gif ID file (title caption)
JSON='{"type":"gif","id":"'$ID'","gif_file_id":"'$3'"'$(title2Json "$4" "$5" "$6" "$7" "$8" )'}' JSON='{"type":"gif","id":"'${ID}'","gif_file_id":"'$3'"'$(title2Json "$4" "$5" "$6" "$7" "$8" )'}'
;; ;;
"cached_mpeg4_gif") # mpeg ID file (title caption) "cached_mpeg4_gif") # mpeg ID file (title caption)
JSON='{"type":"mpeg4_gif","id":"'$ID'","mpeg4_file_id":"'$3'"'$(title2Json "$4" "$5" "" "$6" "$7")'}' JSON='{"type":"mpeg4_gif","id":"'${ID}'","mpeg4_file_id":"'$3'"'$(title2Json "$4" "$5" "" "$6" "$7")'}'
;; ;;
"cached_sticker") # sticker ID file "cached_sticker") # sticker ID file
JSON='{"type":"sticker","id":"'$ID'","sticker_file_id":"'$3'"}' JSON='{"type":"sticker","id":"'${ID}'","sticker_file_id":"'$3'"}'
;; ;;
"cached_document") # document ID title file (description caption) "cached_document") # document ID title file (description caption)
JSON='{"type":"document","id":"'$ID'","document_file_id":"'$4'"'$(title2Json "$3" "$6" "$5" "$6" "$7")'}' JSON='{"type":"document","id":"'${ID}'","document_file_id":"'$4'"'$(title2Json "$3" "$6" "$5" "$6" "$7")'}'
;; ;;
"cached_video") # video ID file title (description caption) "cached_video") # video ID file title (description caption)
JSON='{"type":"video","id":"'$ID'","video_file_id":"'$3'"'$(title2Json "$4" "$6" "$5" "$7" "$8")'}' JSON='{"type":"video","id":"'${ID}'","video_file_id":"'$3'"'$(title2Json "$4" "$6" "$5" "$7" "$8")'}'
;; ;;
"cached_voice") # voice ID file title (caption) "cached_voice") # voice ID file title (caption)
JSON='{"type":"voice","id":"'$ID'","voice_file_id":"'$3'"'$(title2Json "$4" "$5" "" "" "$6")'}' JSON='{"type":"voice","id":"'${ID}'","voice_file_id":"'$3'"'$(title2Json "$4" "$5" "" "" "$6")'}'
;; ;;
"cached_audio") # audio ID file title (caption) "cached_audio") # audio ID file title (caption)
JSON='{"type":"audio","id":"'$ID'","audio_file_id":"'$3'"'$(title2Json "$4" "$5" "" "" "$6")'}' JSON='{"type":"audio","id":"'${ID}'","audio_file_id":"'$3'"'$(title2Json "$4" "$5" "" "" "$6")'}'
;; ;;
esac esac

View File

@ -6,7 +6,7 @@
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
# shellcheck disable=SC1117,SC2059 # shellcheck disable=SC1117,SC2059
#### $$VERSION$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-5-ga5aa756
# will be automatically sourced from bashbot # will be automatically sourced from bashbot
@ -65,7 +65,7 @@ start_proc() {
printf "%s: Start interacitve script CHAT=%s JOB=%s CMD=%s\n" "$(date)" "${1}" "${fifo##*/}" "${2} ${3} ${4}" >>"${UPDATELOG}" printf "%s: Start interacitve script CHAT=%s JOB=%s CMD=%s\n" "$(date)" "${1}" "${fifo##*/}" "${2} ${3} ${4}" >>"${UPDATELOG}"
check_proc "$1" && kill_proc "$1" check_proc "$1" && kill_proc "$1"
mkfifo "${fifo}" mkfifo "${fifo}"
nohup bash -c "{ $2 \"$4\" \"$5\" \"$fifo\" | \"${SCRIPT}\" outproc \"${1}\" \"${fifo}\" nohup bash -c "{ $2 \"$4\" \"$5\" \"${fifo}\" | \"${SCRIPT}\" outproc \"${1}\" \"${fifo}\"
rm \"${fifo}\"; [ -s \"${fifo}.log\" ] || rm -f \"${fifo}.log\"; }" &>>"${fifo}.log" & rm \"${fifo}\"; [ -s \"${fifo}.log\" ] || rm -f \"${fifo}.log\"; }" &>>"${fifo}.log" &
} }

View File

@ -5,36 +5,36 @@
# 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$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-5-ga5aa756
# will be automatically sourced from bashbot # will be automatically sourced from bashbot
# source once magic, function named like file # source once magic, function named like file
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
LEAVE_URL=$URL'/leaveChat' LEAVE_URL=${URL}'/leaveChat'
KICK_URL=$URL'/kickChatMember' KICK_URL=${URL}'/kickChatMember'
UNBAN_URL=$URL'/unbanChatMember' UNBAN_URL=${URL}'/unbanChatMember'
GETMEMBER_URL=$URL'/getChatMember' GETMEMBER_URL=${URL}'/getChatMember'
# usage: status="$(get_chat_member_status "chat" "user")" # usage: status="$(get_chat_member_status "chat" "user")"
# $1 chat # $2 user # $1 chat # $2 user
get_chat_member_status() { get_chat_member_status() {
sendJson "$1" '"user_id":'"$2"'' "$GETMEMBER_URL" sendJson "$1" '"user_id":'"$2"'' "${GETMEMBER_URL}"
# shellcheck disable=SC2154 # shellcheck disable=SC2154
JsonGetString '"result","status"' <<< "$res" JsonGetString '"result","status"' <<< "${res}"
} }
kick_chat_member() { kick_chat_member() {
sendJson "$1" 'user_id: '"$2"'' "$KICK_URL" sendJson "$1" 'user_id: '"$2"'' "${KICK_URL}"
} }
unban_chat_member() { unban_chat_member() {
sendJson "$1" 'user_id: '"$2"'' "$UNBAN_URL" sendJson "$1" 'user_id: '"$2"'' "${UNBAN_URL}"
} }
leave_chat() { leave_chat() {
sendJson "$1" "" "$LEAVE_URL" sendJson "$1" "" "${LEAVE_URL}"
} }
user_is_creator() { user_is_creator() {

View File

@ -6,7 +6,7 @@
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
# shellcheck disable=SC1117 # shellcheck disable=SC1117
#### $$VERSION$$ v1.21-0-gc85af77 #### $$VERSION$$ v1.25-dev-5-ga5aa756
# will be automatically sourced from bashbot # will be automatically sourced from bashbot
@ -15,19 +15,19 @@ eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
# source from commands.sh to use the sendMessage functions # source from commands.sh to use the sendMessage functions
MSG_URL=$URL'/sendMessage' MSG_URL=${URL}'/sendMessage'
EDIT_URL=$URL'/editMessageText' EDIT_URL=${URL}'/editMessageText'
PHO_URL=$URL'/sendPhoto' PHO_URL=${URL}'/sendPhoto'
AUDIO_URL=$URL'/sendAudio' AUDIO_URL=${URL}'/sendAudio'
DOCUMENT_URL=$URL'/sendDocument' DOCUMENT_URL=${URL}'/sendDocument'
STICKER_URL=$URL'/sendSticker' STICKER_URL=${URL}'/sendSticker'
VIDEO_URL=$URL'/sendVideo' VIDEO_URL=${URL}'/sendVideo'
VOICE_URL=$URL'/sendVoice' VOICE_URL=${URL}'/sendVoice'
LOCATION_URL=$URL'/sendLocation' LOCATION_URL=${URL}'/sendLocation'
VENUE_URL=$URL'/sendVenue' VENUE_URL=${URL}'/sendVenue'
ACTION_URL=$URL'/sendChatAction' ACTION_URL=${URL}'/sendChatAction'
FORWARD_URL=$URL'/forwardMessage' FORWARD_URL=${URL}'/forwardMessage'
ALBUM_URL=$URL'/sendMediaGroup' ALBUM_URL=${URL}'/sendMediaGroup'
# #
# send/edit message variants ------------------ # send/edit message variants ------------------
@ -106,7 +106,7 @@ _markdownv2_message_url() {
text="${text//$'\n'/\\n}" text="${text//$'\n'/\\n}"
[ "${#text}" -ge 4096 ] && log_error "Warning: markdownv2 message longer than 4096 characters, message is rejected if formatting crosses 4096 border." [ "${#text}" -ge 4096 ] && log_error "Warning: markdownv2 message longer than 4096 characters, message is rejected if formatting crosses 4096 border."
# markdown v2 needs additional double escaping! # markdown v2 needs additional double escaping!
text="$(sed -E -e 's|([_|~`>+=#{}()!.-])|\\\1|g' <<< "$text")" text="$(sed -E -e 's|([_|~`>+=#{}()!.-])|\\\1|g' <<< "${text}")"
until [ -z "${text}" ]; do until [ -z "${text}" ]; do
sendJson "${1}" '"text":"'"${text:0:4096}"'"'"${3}"'' "${4}" sendJson "${1}" '"text":"'"${text:0:4096}"'"'"${3}"'' "${4}"
text="${text:4096}" text="${text:4096}"
@ -126,7 +126,7 @@ send_keyboard() {
text='"text":"'"${text//$'\n'/\\n}"'"' text='"text":"'"${text//$'\n'/\\n}"'"'
fi fi
local one_time=', "one_time_keyboard":true' && [ -n "$4" ] && one_time="" local one_time=', "one_time_keyboard":true' && [ -n "$4" ] && one_time=""
sendJson "${1}" "${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"'}' "$MSG_URL" sendJson "${1}" "${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"'}' "${MSG_URL}"
# '"text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true}' # '"text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true}'
} }
@ -137,7 +137,7 @@ remove_keyboard() {
text="$(JsonEscape "${2}")" text="$(JsonEscape "${2}")"
text='"text":"'"${text//$'\n'/\\n}"'"' text='"text":"'"${text//$'\n'/\\n}"'"'
fi fi
sendJson "${1}" "${text}"', "reply_markup": {"remove_keyboard":true}' "$MSG_URL" sendJson "${1}" "${text}"', "reply_markup": {"remove_keyboard":true}' "${MSG_URL}"
# delete message if no message or $3 not empty # delete message if no message or $3 not empty
[[ -z "${2}" || -n "${3}" ]] && delete_message "${1}" "${BOTSENT[ID]}" "nolog" [[ -z "${2}" || -n "${3}" ]] && delete_message "${1}" "${BOTSENT[ID]}" "nolog"
#JSON='"text":"$2", "reply_markup": {"remove_keyboard":true}' #JSON='"text":"$2", "reply_markup": {"remove_keyboard":true}'
@ -146,7 +146,7 @@ remove_keyboard() {
# $1 CHAT $2 message $3 keyboard # $1 CHAT $2 message $3 keyboard
send_inline_keyboard() { send_inline_keyboard() {
local text; text='"text":"'$(JsonEscape "${2}")'"'; [ -z "${2}" ] && text='"text":"'"Keyboard:"'"' local text; text='"text":"'$(JsonEscape "${2}")'"'; [ -z "${2}" ] && text='"text":"'"Keyboard:"'"'
sendJson "${1}" "${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]}' "$MSG_URL" sendJson "${1}" "${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]}' "${MSG_URL}"
# JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}' # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}'
} }
# $1 CHAT $2 message $3 button text $4 URL # $1 CHAT $2 message $3 button text $4 URL
@ -192,7 +192,7 @@ send_file() {
if [ "${err}" != "0" ]; then if [ "${err}" != "0" ]; then
BOTSENT=() BOTSENT=()
BOTSENT[OK]="false" BOTSENT[OK]="false"
case "$err" in case "${err}" in
1) BOTSENT[ERROR]="Path to file $2 contains to much '../' or starts with '.'";; 1) BOTSENT[ERROR]="Path to file $2 contains to much '../' or starts with '.'";;
2) BOTSENT[ERROR]="Path to file $2 does not match regex: ${FILE_REGEX} ";; 2) BOTSENT[ERROR]="Path to file $2 does not match regex: ${FILE_REGEX} ";;
3) if [[ "$2" == "/"* ]];then 3) if [[ "$2" == "/"* ]];then
@ -208,63 +208,62 @@ send_file() {
upload_file(){ upload_file(){
local CUR_URL WHAT STATUS text=$3 file="$2" local CUR_URL WHAT STATUS text=$3 file="$2"
# file access checks ... # file access checks ...
[[ "$file" = *'..'* ]] && return 1 # no directory traversal [[ "${file}" = *'..'* ]] && return 1 # no directory traversal
[[ "$file" = '.'* ]] && return 1 # no hidden or relative files [[ "${file}" = '.'* ]] && return 1 # no hidden or relative files
if [[ "$file" = '/'* ]] ; then if [[ "${file}" = '/'* ]] ; then
[[ ! "$file" =~ ${FILE_REGEX} ]] && return 2 # absolute must match REGEX [[ ! "${file}" =~ ${FILE_REGEX} ]] && return 2 # absolute must match REGEX
else else
file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # othiers must be in UPLOADDIR file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # othiers must be in UPLOADDIR
fi fi
[ ! -r "$file" ] && return 3 # and file must exits of course [ ! -r "${file}" ] && return 3 # and file must exits of course
local ext="${file##*.}" case "${file##*.}" in
case $ext in
mp3|flac) mp3|flac)
CUR_URL="$AUDIO_URL" CUR_URL="${AUDIO_URL}"
WHAT="audio" WHAT="audio"
STATUS="upload_audio" STATUS="upload_audio"
;; ;;
png|jpg|jpeg|gif|pic) png|jpg|jpeg|gif|pic)
CUR_URL="$PHO_URL" CUR_URL="${PHO_URL}"
WHAT="photo" WHAT="photo"
STATUS="upload_photo" STATUS="upload_photo"
;; ;;
webp) webp)
CUR_URL="$STICKER_URL" CUR_URL="${STICKER_URL}"
WHAT="sticker" WHAT="sticker"
STATUS="upload_photo" STATUS="upload_photo"
;; ;;
mp4) mp4)
CUR_URL="$VIDEO_URL" CUR_URL="${VIDEO_URL}"
WHAT="video" WHAT="video"
STATUS="upload_video" STATUS="upload_video"
;; ;;
ogg) ogg)
CUR_URL="$VOICE_URL" CUR_URL="${VOICE_URL}"
WHAT="voice" WHAT="voice"
STATUS="upload_audio" STATUS="upload_audio"
;; ;;
*) *)
CUR_URL="$DOCUMENT_URL" CUR_URL="${DOCUMENT_URL}"
WHAT="document" WHAT="document"
STATUS="upload_document" STATUS="upload_document"
;; ;;
esac esac
send_action "${1}" "$STATUS" send_action "${1}" "${STATUS}"
sendUpload "$1" "${WHAT}" "${file}" "${CUR_URL}" "${text//\\n/$'\n'}" sendUpload "$1" "${WHAT}" "${file}" "${CUR_URL}" "${text//\\n/$'\n'}"
} }
# typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location # typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location
send_action() { send_action() {
[ -z "$2" ] && return [ -z "$2" ] && return
sendJson "${1}" '"action": "'"${2}"'"' "$ACTION_URL" & sendJson "${1}" '"action": "'"${2}"'"' "${ACTION_URL}" &
} }
# $1 CHAT $2 lat $3 long # $1 CHAT $2 lat $3 long
send_location() { send_location() {
[ -z "$3" ] && return [ -z "$3" ] && return
sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"'' "$LOCATION_URL" sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"'' "${LOCATION_URL}"
} }
# $1 CHAT $2 lat $3 long $4 title $5 address $6 foursquard id # $1 CHAT $2 lat $3 long $4 title $5 address $6 foursquard id
@ -272,7 +271,7 @@ send_venue() {
local add="" local add=""
[ -z "$5" ] && return [ -z "$5" ] && return
[ -n "$6" ] && add=', "foursquare_id": '"$6"'' [ -n "$6" ] && add=', "foursquare_id": '"$6"''
sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"', "address": "'"${5}"'", "title": "'"${4}"'"'"${add}" "$VENUE_URL" sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"', "address": "'"${5}"'", "title": "'"${4}"'"'"${add}" "${VENUE_URL}"
} }
@ -283,7 +282,7 @@ send_venue() {
# $1 CHAT $2 from chat $3 from msg id # $1 CHAT $2 from chat $3 from msg id
forward_message() { forward_message() {
[ -z "$3" ] && return [ -z "$3" ] && return
sendJson "${1}" '"from_chat_id": '"${2}"', "message_id": '"${3}"'' "$FORWARD_URL" sendJson "${1}" '"from_chat_id": '"${2}"', "message_id": '"${3}"'' "${FORWARD_URL}"
} }
forward() { # backward compatibility forward() { # backward compatibility
forward_message "$@" || return forward_message "$@" || return
@ -308,35 +307,35 @@ send_message() {
title="$(sed <<< "${2}" '/mytitlestartshere /!d;s/.*mytitlestartshere //;s/ *my[kfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')" title="$(sed <<< "${2}" '/mytitlestartshere /!d;s/.*mytitlestartshere //;s/ *my[kfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
address="$(sed <<< "${2}" '/myaddressstartshere /!d;s/.*myaddressstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')" address="$(sed <<< "${2}" '/myaddressstartshere /!d;s/.*myaddressstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
} }
if [ -n "$no_keyboard" ]; then if [ -n "${no_keyboard}" ]; then
remove_keyboard "$1" "$text" remove_keyboard "$1" "${text}"
sent=y sent=y
fi fi
if [ -n "$keyboard" ]; then if [ -n "${keyboard}" ]; then
if [[ "$keyboard" != *"["* ]]; then # pre 0.60 style if [[ "${keyboard}" != *"["* ]]; then # pre 0.60 style
keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]" keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]"
fi fi
send_keyboard "$1" "$text" "$keyboard" send_keyboard "$1" "${text}" "${keyboard}"
sent=y sent=y
fi fi
if [ -n "$btext" ] && [ -n "$burl" ]; then if [ -n "${btext}" ] && [ -n "${burl}" ]; then
send_button "$1" "$text" "$btext" "$burl" send_button "$1" "${text}" "${btext}" "${burl}"
sent=y sent=y
fi fi
if [ -n "$file" ]; then if [ -n "${file}" ]; then
send_file "$1" "$file" "$text" send_file "$1" "${file}" "${text}"
sent=y sent=y
fi fi
if [ -n "$lat" ] && [ -n "$long" ]; then if [ -n "${lat}" ] && [ -n "${long}" ]; then
if [ -n "$address" ] && [ -n "$title" ]; then if [ -n "${address}" ] && [ -n "${title}" ]; then
send_venue "$1" "$lat" "$long" "$title" "$address" send_venue "$1" "${lat}" "${long}" "${title}" "${address}"
else else
send_location "$1" "$lat" "$long" send_location "$1" "${lat}" "${long}"
fi fi
sent=y sent=y
fi fi
if [ "$sent" != "y" ];then if [ "${sent}" != "y" ];then
send_text_mode "$1" "$text" send_text_mode "$1" "${text}"
fi fi
} }

View File

@ -9,7 +9,7 @@
# #### mycommands.clean # #### mycommands.clean
# #
# shellcheck disable=SC1117 # shellcheck disable=SC1117
#### $$VERSION$$ v1.25-dev-0-gd310805 #### $$VERSION$$ v1.25-dev-5-ga5aa756
# #
########## ##########
@ -193,40 +193,40 @@ else
################## ##################
# example commands, replace thm by your own # example commands, replace thm by your own
'/echo'*) # example echo command '/echo'*) # example echo command
send_normal_message "${CHAT[ID]}" "$MESSAGE" send_normal_message "${CHAT[ID]}" "${MESSAGE}"
;; ;;
'/question'*) # start interactive questions '/question'*) # start interactive questions
checkproc checkproc
if [ "$res" -gt 0 ] ; then if [ "${res}" -gt 0 ] ; then
startproc "examples/question.sh" || send_normal_message "${CHAT[ID]}" "Can't start question." startproc "examples/question.sh" || send_normal_message "${CHAT[ID]}" "Can't start question."
else else
send_normal_message "${CHAT[ID]}" "$MESSAGE already running ..." send_normal_message "${CHAT[ID]}" "${MESSAGE} already running ..."
fi fi
;; ;;
'/cancel'*) # cancel interactive command '/cancel'*) # cancel interactive command
checkproc checkproc
if [ "$res" -gt 0 ] ;then if [ "${res}" -gt 0 ] ;then
killproc && send_normal_message "${CHAT[ID]}" "Command canceled." killproc && send_normal_message "${CHAT[ID]}" "Command canceled."
else else
send_normal_message "${CHAT[ID]}" "No command is currently running." send_normal_message "${CHAT[ID]}" "No command is currently running."
fi fi
;; ;;
'/run_notify'*) # start notify background job '/run_notify'*) # start notify background job
myback="notify"; checkback "$myback" myback="notify"; checkback "${myback}"
if [ "$res" -gt 0 ] ; then if [ "${res}" -gt 0 ] ; then
background "examples/notify.sh 60" "$myback" || send_normal_message "${CHAT[ID]}" "Can't start notify." background "examples/notify.sh 60" "${myback}" || send_normal_message "${CHAT[ID]}" "Can't start notify."
else else
send_normal_message "${CHAT[ID]}" "Background command $myback already running ..." send_normal_message "${CHAT[ID]}" "Background command ${myback} already running ..."
fi fi
;; ;;
'/stop_notify'*) # kill notify background job '/stop_notify'*) # kill notify background job
myback="notify"; checkback "$myback" myback="notify"; checkback "${myback}"
if [ "$res" -eq 0 ] ; then if [ "${res}" -eq 0 ] ; then
killback "$myback" killback "${myback}"
send_normal_message "${CHAT[ID]}" "Background command $myback canceled." send_normal_message "${CHAT[ID]}" "Background command ${myback} canceled."
else else
send_normal_message "${CHAT[ID]}" "No background command $myback is currently running.." send_normal_message "${CHAT[ID]}" "No background command ${myback} is currently running.."
fi fi
;; ;;
@ -262,15 +262,15 @@ else
;; ;;
"2"*) # two photos "2"*) # two photos
answer_inline_multi "${iQUERY[ID]}" " answer_inline_multi "${iQUERY[ID]}" "
$(inline_query_compose "$RANDOM" "photo" "https://avatars.githubusercontent.com/u/13046303"), $(inline_query_compose "${RANDOM}" "photo" "https://avatars.githubusercontent.com/u/13046303"),
$(inline_query_compose "$RANDOM" "photo" "https://avatars.githubusercontent.com/u/4593242") $(inline_query_compose "${RANDOM}" "photo" "https://avatars.githubusercontent.com/u/4593242")
" "
;; ;;
"3"*) # three photos "3"*) # three photos
answer_inline_multi "${iQUERY[ID]}" " answer_inline_multi "${iQUERY[ID]}" "
$(inline_query_compose "$RANDOM" "photo" "https://avatars.githubusercontent.com/u/13046303"), $(inline_query_compose "${RANDOM}" "photo" "https://avatars.githubusercontent.com/u/13046303"),
$(inline_query_compose "$RANDOM" "photo" "https://avatars.githubusercontent.com/u/4593242") $(inline_query_compose "${RANDOM}" "photo" "https://avatars.githubusercontent.com/u/4593242")
$(inline_query_compose "$RANDOM" "photo" "https://avatars.githubusercontent.com/u/102707") $(inline_query_compose "${RANDOM}" "photo" "https://avatars.githubusercontent.com/u/102707")
" "
;; ;;
@ -279,7 +279,7 @@ else
local avatar=("https://avatars.githubusercontent.com/u/13046303" "https://avatars.githubusercontent.com/u/4593242" "https://avatars.githubusercontent.com/u/102707" "https://avatars.githubusercontent.com/u/6460407") local avatar=("https://avatars.githubusercontent.com/u/13046303" "https://avatars.githubusercontent.com/u/4593242" "https://avatars.githubusercontent.com/u/102707" "https://avatars.githubusercontent.com/u/6460407")
answer_inline_multi "${iQUERY[ID]}" " answer_inline_multi "${iQUERY[ID]}" "
$(for photo in ${avatar[*]} ; do $(for photo in ${avatar[*]} ; do
printf "%s\n" "${sep}"; inline_query_compose "$RANDOM" "photo" "${photo}" "${photo}"; sep="," printf "%s\n" "${sep}"; inline_query_compose "${RANDOM}" "photo" "${photo}" "${photo}"; sep=","
done) done)
" "
;; ;;
@ -318,10 +318,10 @@ else
local image result sep="" count="1" local image result sep="" count="1"
result="$(wget --user-agent 'Mozilla/5.0' -qO - "https://images.search.yahoo.com/search/images?p=$1" | sed 's/</\n</g' | grep "<img src=")" result="$(wget --user-agent 'Mozilla/5.0' -qO - "https://images.search.yahoo.com/search/images?p=$1" | sed 's/</\n</g' | grep "<img src=")"
while read -r image; do while read -r image; do
[ "$count" -gt "20" ] && break [ "${count}" -gt "20" ] && break
image="${image#* src=\'}"; image="${image%%&pid=*}" image="${image#* src=\'}"; image="${image%%&pid=*}"
[[ "${image}" = *"src="* ]] && continue [[ "${image}" = *"src="* ]] && continue
printf "%s\n" "${sep}"; inline_query_compose "$RANDOM" "photo" "${image}"; sep="," printf "%s\n" "${sep}"; inline_query_compose "${RANDOM}" "photo" "${image}"; sep=","
count=$(( count + 1 )) count=$(( count + 1 ))
done <<<"${result}" done <<<"${result}"
} }