coding-style: positonal parameters $1 - \9 has precedence over verything

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-05 16:17:34 +01:00
parent 2fe6d4b0cc
commit 4582efd556
46 changed files with 192 additions and 192 deletions

View File

@ -4,7 +4,7 @@
# this addon counts how many files, e.g. stickers, are sent to
# a chat and takes actions if threshold is reached
#
#### $$VERSION$$ v1.25-dev-5-ga5aa756
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
# used events:
#

View File

@ -4,7 +4,7 @@
# Addons can register to bashbot events at startup
# by providing their name and a callback per event
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#
# If an event occurs each registered event function is called.
#

View File

@ -30,7 +30,7 @@
# 8 - curl/wget missing
# 10 - not bash!
#
#### $$VERSION$$ v1.25-dev-5-ga5aa756
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
##################################################################
# emmbeded system may claim bash but it is not
@ -74,22 +74,22 @@ azAZo9="${azAZaz}${o9o9o9}" # a-zA-z0-9 :alnum:
# some important helper functions
# returns true if command exist
_exists() {
[ "$(type -t "${1}")" = "file" ]
[ "$(type -t "$1")" = "file" ]
}
# execute function if exists
_exec_if_function() {
[ "$(type -t "${1}")" != "function" ] && return 1
[ "$(type -t "$1")" != "function" ] && return 1
"$@"
}
# returns true if function exist
_is_function() {
[ "$(type -t "${1}")" = "function" ]
[ "$(type -t "$1")" = "function" ]
}
# round $1 in international notation! , returns float with $2 decimal digits
# if $2 is not given or is not a positive number zero is assumed
_round_float() {
local digit="${2}"; [[ "${2}" =~ ^[${o9o9o9}]+$ ]] || digit="0"
{ LC_ALL=C.utf-8 printf "%.${digit}f" "${1}"; } 2>/dev/null
local digit="$2"; [[ "$2" =~ ^[${o9o9o9}]+$ ]] || digit="0"
{ LC_ALL=C.utf-8 printf "%.${digit}f" "$1"; } 2>/dev/null
}
setConfigKey() {
[[ "$1" =~ ^[-${azAZo9},._]+$ ]] || return 3
@ -103,7 +103,7 @@ getConfigKey() {
# check if $1 seems a valid token
# return true if token seems to be valid
check_token(){
[[ "${1}" =~ ^[${o9o9o9}]{8,10}:[${azAZo9}_-]{35}$ ]] && return 0
[[ "$1" =~ ^[${o9o9o9}]{8,10}:[${azAZo9}_-]{35}$ ]] && return 0
return 1
}
# log $1 with date
@ -121,7 +121,7 @@ export BASHBOTDEBUG
# shellcheck disable=SC2094
debug_checks(){ {
[ -z "${BASHBOTDEBUG}" ] && return
local DATE WHERE MYTOKEN; DATE="$(date)"; WHERE="${1}"; shift
local DATE WHERE MYTOKEN; DATE="$(date)"; WHERE="$1"; shift
printf "%s: debug_checks: %s: bashbot.sh %s\n" "${DATE}" "${WHERE}" "${@##*/}"
# shellcheck disable=SC2094
[ -z "${DEBUGLOG}" ] && printf "%s: %s\n" "${DATE}" "DEBUGLOG not set! =========="
@ -381,20 +381,20 @@ killallproc() {
# shellcheck disable=SC2046
[ -n "${procid}" ] && kill $(proclist -9 "$1")
fi
debug_checks "end killallproc" "${1}"
debug_checks "end killallproc" "$1"
}
# $ chat $2 msg_id $3 nolog
declare -xr DELETE_URL=${URL}'/deleteMessage'
delete_message() {
[ -z "$3" ] && log_update "Delete Message CHAT=${1} MSG_ID=${2}"
sendJson "${1}" '"message_id": '"${2}"'' "${DELETE_URL}"
[ -z "$3" ] && log_update "Delete Message CHAT=$1 MSG_ID=$2"
sendJson "$1" '"message_id": '"$2"'' "${DELETE_URL}"
}
get_file() {
[ -z "$1" ] && return
sendJson "" '"file_id": "'"${1}"'"' "${GETFILE_URL}"
sendJson "" '"file_id": "'"$1"'"' "${GETFILE_URL}"
printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')"
}
@ -441,9 +441,9 @@ TIMEOUT="${BASHBOT_TIMEOUT:-20}"
# usage: sendJson "chat" "JSON" "URL"
sendJson(){
local json chat=""
if [ -n "${1}" ]; then
chat='"chat_id":'"${1}"','
[[ "${1}" == *[!${o9o9o9}-]* ]] && chat='"chat_id":"'"${1}"' NAN",' # chat id not a number!
if [ -n "$1" ]; then
chat='"chat_id":'"$1"','
[[ "$1" == *[!${o9o9o9}-]* ]] && chat='"chat_id":"'"$1"' NAN",' # chat id not a number!
fi
# compose final json
json='{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<"$2")"'}'
@ -459,7 +459,7 @@ sendJson(){
fi
# OK here we go ...
# route to curl/wget specific function
res="$(sendJson_do "${json}" "${3}")"
res="$(sendJson_do "${json}" "$3")"
# check telegram response
sendJsonResult "${res}" "sendJson (${DETECTED_CURL})" "$@"
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@}" &
@ -472,7 +472,7 @@ if detect_curl ; then
# here we have curl ----
[ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl"
getJson(){
[[ -n "${BASHBOTDEBUG}" && -n "${3}" ]] && log_debug "getJson (curl) URL=${1##*/}"
[[ -n "${BASHBOTDEBUG}" && -n "$3" ]] && log_debug "getJson (curl) URL=${1##*/}"
# shellcheck disable=SC2086
"${BASHBOT_CURL}" -sL -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" "$1"
}
@ -481,14 +481,14 @@ if detect_curl ; then
sendJson_do(){
# shellcheck disable=SC2086
"${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
-d "${1}" -X POST "${2}" -H "Content-Type: application/json" | "${JSONSHFILE}" -b -n 2>/dev/null
-d "$1" -X POST "$2" -H "Content-Type: application/json" | "${JSONSHFILE}" -b -n 2>/dev/null
}
#$1 Chat, $2 what, $3 file, $4 URL, $5 caption
sendUpload() {
[ "$#" -lt 4 ] && return
if [ -n "$5" ]; then
[ -n "${BASHBOTDEBUG}" ] &&\
log_update "sendUpload CHAT=${1} WHAT=${2} FILE=${3} CAPT=${5}"
log_update "sendUpload CHAT=$1 WHAT=$2 FILE=$3 CAPT=$5"
# shellcheck disable=SC2086
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
-F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -b -n 2>/dev/null )"
@ -504,7 +504,7 @@ else
# NO curl, try wget
if _exists wget; then
getJson(){
[[ -n "${BASHBOTDEBUG}" && -z "${3}" ]] && log_debug "getJson (wget) URL=${1##*/}"
[[ -n "${BASHBOTDEBUG}" && -z "$3" ]] && log_debug "getJson (wget) URL=${1##*/}"
# shellcheck disable=SC2086
wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - "$1"
}
@ -512,8 +512,8 @@ else
# usage: "JSON" "URL"
sendJson_do(){
# shellcheck disable=SC2086
wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - --post-data="${1}" \
--header='Content-Type:application/json' "${2}" | "${JSONSHFILE}" -b -n 2>/dev/null
wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - --post-data="$1" \
--header='Content-Type:application/json' "$2" | "${JSONSHFILE}" -b -n 2>/dev/null
}
sendUpload() {
log_error "Sorry, wget does not support file upload"
@ -534,9 +534,9 @@ fi
# retry sendJson
# $1 function $2 sleep $3 ... $n arguments
sendJsonRetry(){
local retry="${1}"; shift
[[ "${1}" =~ ^\ *[${o9o9o9}.]+\ *$ ]] && sleep "${1}"; shift
printf "%s: RETRY %s %s %s\n" "$(date)" "${retry}" "${1}" "${2:0:60}"
local retry="$1"; shift
[[ "$1" =~ ^\ *[${o9o9o9}.]+\ *$ ]] && sleep "$1"; shift
printf "%s: RETRY %s %s %s\n" "$(date)" "${retry}" "$1" "${2:0:60}"
case "${retry}" in
'sendJson'*)
sendJson "$@"
@ -552,7 +552,7 @@ sendJsonRetry(){
return
;;
esac
[ "${BOTSENT[OK]}" = "true" ] && log_error "Retry OK:${retry} ${1} ${2:0:60}"
[ "${BOTSENT[OK]}" = "true" ] && log_error "Retry OK:${retry} $1 ${2:0:60}"
} >>"${ERRORLOG}"
# process sendJson result
@ -562,18 +562,18 @@ sendJsonResult(){
local offset=0
BOTSENT=( )
[ -n "${BASHBOTDEBUG}" ] && log_message "New Result ==========\n$1"
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${1}")"
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$1")"
if [ "${BOTSENT[OK]}" = "true" ]; then
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "${1}")"
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$1")"
return
# hot path everything OK!
else
# oops something went wrong!
if [ "${1}" != "" ]; then
BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "${1}")"
BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "${1}")"
grep -qs -F '"parameters","retry_after"' <<< "${1}" &&\
BOTSENT[RETRY]="$(JsonGetValue '"parameters","retry_after"' <<< "${1}")"
if [ "$1" != "" ]; then
BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "$1")"
BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "$1")"
grep -qs -F '"parameters","retry_after"' <<< "$1" &&\
BOTSENT[RETRY]="$(JsonGetValue '"parameters","retry_after"' <<< "$1")"
else
BOTSENT[OK]="false"
BOTSENT[ERROR]="999"
@ -583,7 +583,7 @@ sendJsonResult(){
[[ "${BOTSENT[ERROR]}" = "400" && "${BOTSENT[DESCRIPTION]}" == *"starting at byte offset"* ]] &&\
offset="${BOTSENT[DESCRIPTION]%* }"
printf "%s: RESULT=%s FUNC=%s CHAT[ID]=%s ERROR=%s DESC=%s ACTION=%s\n" "$(date)"\
"${BOTSENT[OK]}" "${2}" "${3}" "${BOTSENT[ERROR]}" "${BOTSENT[DESCRIPTION]}" "${4:${offset}:100}"
"${BOTSENT[OK]}" "$2" "$3" "${BOTSENT[ERROR]}" "${BOTSENT[DESCRIPTION]}" "${4:${offset}:100}"
# warm path, do not retry on error, also if we use wegt
[ -n "${BASHBOT_RETRY}${BASHBOT_WGET}" ] && return
@ -591,8 +591,8 @@ sendJsonResult(){
# throttled, telegram say we send too many messages
if [ -n "${BOTSENT[RETRY]}" ]; then
BASHBOT_RETRY="$(( ++BOTSENT[RETRY] ))"
printf "Retry %s in %s seconds ...\n" "${2}" "${BASHBOT_RETRY}"
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
printf "Retry %s in %s seconds ...\n" "$2" "${BASHBOT_RETRY}"
sendJsonRetry "$2" "${BASHBOT_RETRY}" "${@:3}"
unset BASHBOT_RETRY
return
fi
@ -604,8 +604,8 @@ sendJsonResult(){
# user provided function to recover or notify block
if _exec_if_function bashbotBlockRecover; then
BASHBOT_RETRY="2"
printf "bashbotBlockRecover returned true, retry %s ...\n" "${2}"
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
printf "bashbotBlockRecover returned true, retry %s ...\n" "$2"
sendJsonRetry "$2" "${BASHBOT_RETRY}" "${@:3}"
unset BASHBOT_RETRY
fi
return
@ -613,9 +613,9 @@ sendJsonResult(){
# are not blocked, default curl and args are working
if [ -n "${BASHBOT_CURL_ARGS}" ] || [ "${BASHBOT_CURL}" != "curl" ]; then
printf "Problem with \"%s %s\"? retry %s with default config ...\n"\
"${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "${2}"
"${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "$2"
BASHBOT_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS=""
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
sendJsonRetry "$2" "${BASHBOT_RETRY}" "${@:3}"
unset BASHBOT_RETRY
fi
fi
@ -853,7 +853,7 @@ event_message() {
}
pre_process_message(){
local num="${1}"
local num="$1"
# unset everything to not have old values
CMD=( ); iQUERY=( ); MESSAGE=(); CHAT=(); USER=(); CONTACT=(); LOCATION=(); unset CAPTION
REPLYTO=( ); FORWARD=( ); URLS=(); VENUE=( ); SERVICE=( ); NEWMEMBER=( ); LEFTMEMBER=( ); PINNED=( ); MIGRATE=( )
@ -866,7 +866,7 @@ pre_process_message(){
return 0
}
process_inline() {
local num="${1}"
local num="$1"
iQUERY[0]="$(JsonDecode "${UPD["result",${num},"inline_query","query"]}")"
iQUERY[USER_ID]="${UPD["result",${num},"inline_query","from","id"]}"
iQUERY[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","first_name"]}")"
@ -1025,8 +1025,8 @@ start_bot() {
DEBUGMSG="Start BASHBOT updates in Mode \"${1:-normal}\" =========="
log_update "${DEBUGMSG}"
# redirect to Debug.log
[[ "${1}" == *"debug" ]] && exec &>>"${DEBUGLOG}"
log_debug "${DEBUGMSG}"; DEBUGMSG="${1}"
[[ "$1" == *"debug" ]] && exec &>>"${DEBUGLOG}"
log_debug "${DEBUGMSG}"; DEBUGMSG="$1"
[[ "${DEBUGMSG}" == "xdebug"* ]] && set -x && unset BASHBOT_UPDATELOG
# cleaup old pipes and empty logfiles
find "${DATADIR}" -type p -delete
@ -1175,7 +1175,7 @@ if [ -z "${SOURCE}" ]; then
##############
# internal options only for use from bashbot and developers
# shellcheck disable=SC2221,SC2222
case "${1}" in
case "$1" in
# update botname when starting only
"botname"|"start"*)
ME="$(getBotName)"

View File

@ -13,7 +13,7 @@
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 18.12.2020 12:27
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
############

View File

@ -16,7 +16,7 @@
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 23.12.2020 20:34
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
####

View File

@ -19,7 +19,7 @@
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 03.01.2021 15:37
#
#### $$VERSION$$ v1.25-dev-11-gfc5d50e
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
####

View File

@ -24,7 +24,7 @@
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 16.12.2020 16:14
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
# shellcheck disable=SC2059

View File

@ -22,7 +22,7 @@
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 23.12.2020 16:52
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
####

View File

@ -21,7 +21,7 @@
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 25.12.2020 20:24
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
####

View File

@ -21,7 +21,7 @@
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 16.12.2020 11:34
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
####

View File

@ -15,7 +15,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v1.25-dev-5-ga5aa756
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#
# bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed
@ -51,12 +51,12 @@ Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash)
'
# load modules on startup and always on on debug
if [ -n "${1}" ]; then
if [ -n "$1" ]; then
# load all readable modules
for modules in "${MODULEDIR:-.}"/*.sh ; do
if [[ "${1}" == *"debug"* ]] || ! _is_function "$(basename "${modules}")"; then
if [[ "$1" == *"debug"* ]] || ! _is_function "$(basename "${modules}")"; then
# shellcheck source=./modules/aliases.sh
[ -r "${modules}" ] && source "${modules}" "${1}"
[ -r "${modules}" ] && source "${modules}" "$1"
fi
done
fi
@ -72,10 +72,10 @@ export FILE_REGEX="${BASHBOT_ETC}/.*"
# load mycommands
# shellcheck source=./commands.sh
[ -r "${BASHBOT_ETC:-.}/mycommands.sh" ] && source "${BASHBOT_ETC:-.}/mycommands.sh" "${1}"
[ -r "${BASHBOT_ETC:-.}/mycommands.sh" ] && source "${BASHBOT_ETC:-.}/mycommands.sh" "$1"
if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then
if [ -z "$1" ] || [[ "$1" == *"debug"* ]];then
# detect inline commands....
# no default commands, all processing is done in myinlines()
if [ "${INLINE}" != "0" ] && [ -n "${iQUERY[ID]}" ]; then

View File

@ -5,7 +5,7 @@
#
# Description: run all tests, exit after failed test
#
#### $$VERSION$$ v1.25-dev-6-g641727d
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#############################################################
# magic to ensure that we're always inside the root of our application,

View File

@ -3,7 +3,7 @@
#
# works together with git pre-push.sh and ADD all changed files since last push
#### $$VERSION$$ v1.25-dev-6-g641727d
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v1.25-dev-9-g14fa2c7
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
############
# NOTE: you MUST run install-hooks.sh again when updating this file!

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v1.25-dev-9-g14fa2c7
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
############
# NOTE: you MUST run install-hooks.sh again when updating this file!

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v1.25-dev-9-g14fa2c7
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
############
# NOTE: you MUST run install-hooks.sh again when updating this file!

View File

@ -7,7 +7,7 @@
#
# Usage: source inject-json.sh
#
#### $$VERSION$$ v1.25-dev-6-g641727d
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
##############################################################
# download JSON.sh

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ v1.25-dev-6-g641727d
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -7,7 +7,7 @@
#
# Options: --notest - skip tests
#
#### $$VERSION$$ v1.25-dev-12-gb3c22bc
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
##############################################################
# magic to ensure that we're always inside the root of our application,

View File

@ -7,7 +7,7 @@
#
# Usage: source make-hmtl
#
#### $$VERSION$$ v1.25-dev-6-g641727d
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
##############################################################
# check for correct dir
@ -28,16 +28,16 @@ else
cp README.html html/index.html
# convert *.md files in doc to *.hmtl in html
find doc -iname "*.md" -type f -exec sh -c\
'printf "."; pandoc -s -f commonmark -M "title=Bashobot Documentation - ${0%.md}.html" "${0}" -o "./html/$(basename ${0%.md}.html)"' {} \;
'printf "."; pandoc -s -f commonmark -M "title=Bashobot Documentation - ${0%.md}.html" "$0" -o "./html/$(basename ${0%.md}.html)"' {} \;
# html for examples dir
if [ -d "examples" ]; then
EXAMPLES="examples" # add to final conversion job
find examples -iname "*.md" -type f -exec sh -c\
'printf "."; pandoc -s -f commonmark -M "title=Bashobot Documentation - ${0%.md}.html" "${0}" -o "${0%.md}.html"' {} \;
'printf "."; pandoc -s -f commonmark -M "title=Bashobot Documentation - ${0%.md}.html" "$0" -o "${0%.md}.html"' {} \;
fi
# final: convert links from *.md to *.html
find README.html html "${EXAMPLES}" -iname "*.html" -type f -exec sh -c\
'sed -i -E "s/href=\"(\.\.\/)*doc\//href=\"\1html\//g;s/href=\"(.*).md(#.*)*\"/href=\"\1.html\"/g" ${0}' {} \;
'sed -i -E "s/href=\"(\.\.\/)*doc\//href=\"\1html\//g;s/href=\"(.*).md(#.*)*\"/href=\"\1.html\"/g" $0' {} \;
printf " Done!\n"
fi
fi

View File

@ -9,7 +9,7 @@
# If you your bot is finished you can use make-standalone.sh to create the
# the old all-in-one bashbot: bashbot.sh and commands.sh only!
#
#### $$VERSION$$ v1.25-dev-6-g641727d
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
###################################################################
# magic to ensure that we're always inside the root of our application,

View File

@ -2,7 +2,7 @@
#
# joke hack to obfuscate bashbot.min.sh
#
#### $$VERSION$$ v1.25-dev-6-g641727d
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
# shellcheck disable=SC2028,SC2016,SC1117
infile="bashbot.sh"

View File

@ -1,6 +1,6 @@
#!/bin/bash
#
#### $$VERSION$$ v1.25-dev-6-g641727d
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
# shellcheck disable=SC2016
#
# Easy Versioning in git:

View File

@ -127,5 +127,5 @@ You must update to [Version 1.20](https://github.com/topkecleon/telegram-bot-bas
#### [Next Create Bot](1_firstbot.md)
#### $$VERSION$$ v1.25-dev-13-g1631b02
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b

View File

@ -6,7 +6,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# shellcheck disable=SC1117
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -2,14 +2,14 @@
# file. multibot.sh
# description: run multiple telegram bots from one installation
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
if [ "$2" = "" ] || [ "$2" = "-h" ]; then
echo "Usage: $0 botname command"
exit 1
fi
BOT="${1}"
BOT="$1"
[ "${#BOT}" -lt 5 ] && echo "Botname must have a minimum length of 5 characters" && exit 1
# where should the bots live?

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$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
########################################################################
######

View File

@ -13,7 +13,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v1.25-dev-5-ga5aa756
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
########################################################################
######

View File

@ -10,7 +10,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v1.25-dev-5-ga5aa756
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
########################################################################
######

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$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#
# will be automatically sourced from bashbot
@ -23,36 +23,36 @@ _is_creator() {
user_is_creator "${CHAT[ID]}" "${USER[ID]}"
}
_is_allowed() {
user_is_allowed "${USER[ID]}" "${1}" "${CHAT[ID]}"
user_is_allowed "${USER[ID]}" "$1" "${CHAT[ID]}"
}
_leave() {
leave_chat "${CHAT[ID]}"
}
_kick_user() {
kick_chat_member "${CHAT[ID]}" "${1}"
kick_chat_member "${CHAT[ID]}" "$1"
}
_unban_user() {
unban_chat_member "${CHAT[ID]}" "${1}"
unban_chat_member "${CHAT[ID]}" "$1"
}
# easy sending of messages of messages
_message() {
send_normal_message "${CHAT[ID]}" "${1}"
send_normal_message "${CHAT[ID]}" "$1"
}
_normal_message() {
send_normal_message "${CHAT[ID]}" "${1}"
send_normal_message "${CHAT[ID]}" "$1"
}
_html_message() {
send_html_message "${CHAT[ID]}" "${1}"
send_html_message "${CHAT[ID]}" "$1"
}
_markdown_message() {
send_markdown_message "${CHAT[ID]}" "${1}"
send_markdown_message "${CHAT[ID]}" "$1"
}
# easy handling of keyboards
_inline_button() {
send_inline_button "${CHAT[ID]}" "" "${1}" "${2}"
send_inline_button "${CHAT[ID]}" "" "$1" "$2"
}
_inline_keyboard() {
send_inline_keyboard "${CHAT[ID]}" "" "${1}"
send_inline_keyboard "${CHAT[ID]}" "" "$1"
}
_keyboard_numpad() {
send_keyboard "${CHAT[ID]}" "" '["1","2","3"],["4","5","6"],["7","8","9"],["-","0","."]' "yes"

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$$ v1.25-dev-5-ga5aa756
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
# will be automatically sourced from bashbot
@ -15,10 +15,10 @@ eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
INLINE_QUERY=${URL}'/answerInlineQuery'
answer_inline_query() {
answer_inline_multi "${1}" "$(shift; inline_query_compose "${RANDOM}" "$@")"
answer_inline_multi "$1" "$(shift; inline_query_compose "${RANDOM}" "$@")"
}
answer_inline_multi() {
sendJson "" '"inline_query_id": '"${1}"', "results": ['"${2}"']' "${INLINE_QUERY}"
sendJson "" '"inline_query_id": '"$1"', "results": ['"$2"']' "${INLINE_QUERY}"
}
# $1 unique ID for answer
@ -27,10 +27,10 @@ answer_inline_multi() {
# followed by the optional arguments: https://core.telegram.org/bots/api#inlinequeryresult
inline_query_compose(){
local JSON="{}"
local ID="${1}"
local ID="$1"
local fours last
# title2Json title caption description markup inlinekeyboard
case "${2}" in
case "$2" in
# user provided media
"article"|"message") # article ID title message (markup description)
JSON='{"type":"article","id":"'${ID}'","input_message_content": {"message_text":"'$4'"} '$(title2Json "$3" "" "$5" "$6" "$7")'}'

View File

@ -6,7 +6,7 @@
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
# shellcheck disable=SC1117,SC2059
#### $$VERSION$$ v1.25-dev-5-ga5aa756
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
# will be automatically sourced from bashbot
@ -48,9 +48,9 @@ start_back() {
}
restart_back() {
local fifo; fifo="${DATADIR:-.}/$(procname "$1" "back-$3-")"
printf "%s: Start background job CHAT=%s JOB=%s CMD=%s\n" "$(date)" "${1}" "${fifo##*/}" "${2##*/} ${4} ${5}" >>"${UPDATELOG}"
printf "%s: Start background job CHAT=%s JOB=%s CMD=%s\n" "$(date)" "$1" "${fifo##*/}" "${2##*/} $4 $5" >>"${UPDATELOG}"
check_back "$1" "$3" && kill_proc "$1" "back-$3-"
nohup bash -c "{ $2 \"$4\" \"$5\" \"${fifo}\" | \"${SCRIPT}\" outproc \"${1}\" \"${fifo}\"; }" &>>"${fifo}.log" &
nohup bash -c "{ $2 \"$4\" \"$5\" \"${fifo}\" | \"${SCRIPT}\" outproc \"$1\" \"${fifo}\"; }" &>>"${fifo}.log" &
sleep 0.5 # give bg job some time to init
}
@ -62,10 +62,10 @@ start_proc() {
[ -z "$2" ] && return
[ -x "${2%% *}" ] || return 1
local fifo; fifo="${DATADIR:-.}/$(procname "$1")"
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"
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" &
}
@ -99,7 +99,7 @@ kill_proc() {
fifo="$(procname "$1" "$2")"
prid="$(proclist "${fifo}")"
fifo="${DATADIR:-.}/${fifo}"
printf "%s: Stop interacitve / background CHAT=%s JOB=%s\n" "$(date)" "${1}" "${fifo##*/}" >>"${UPDATELOG}"
printf "%s: Stop interacitve / background CHAT=%s JOB=%s\n" "$(date)" "$1" "${fifo##*/}" >>"${UPDATELOG}"
# shellcheck disable=SC2086
[ -n "${prid}" ] && kill ${prid}
[ -s "${fifo}.log" ] || rm -f "${fifo}.log"
@ -127,7 +127,7 @@ job_control() {
local BOT ADM content proc CHAT job fifo killall=""
BOT="$(getConfigKey "botname")"
ADM="$(getConfigKey "botadmin")"
debug_checks "Enter job_control" "${1}"
debug_checks "Enter job_control" "$1"
for FILE in "${DATADIR:-.}/"*-back.cmd; do
[ "${FILE}" = "${DATADIR:-.}/*-back.cmd" ] && printf "${RED}No background processes.${NN}" && break
content="$(< "${FILE}")"
@ -136,7 +136,7 @@ job_control() {
proc="${job#*:}"
job="${job%:*}"
fifo="$(procname "${CHAT}" "${job}")"
debug_checks "Execute job_control" "${1}" "${FILE##*/}"
debug_checks "Execute job_control" "$1" "${FILE##*/}"
case "$1" in
"resumeb"*|"backgr"*)
printf "Restart Job: %s %s\n" "${proc}" " ${fifo##*/}"
@ -163,7 +163,7 @@ job_control() {
# send message only onnfirst job
ADM=""
done
debug_checks "end job_control" "${1}"
debug_checks "end job_control" "$1"
# kill all requestet. kill ALL background jobs, even not listed in data-bot-bash
[ "${killall}" = "y" ] && killallproc "back-"
}

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$$ v1.25-dev-5-ga5aa756
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
# will be automatically sourced from bashbot
@ -62,8 +62,8 @@ user_is_admin() {
user_is_botadmin() {
[ -z "$1" ] && return 1
local admin; admin="$(getConfigKey "botadmin")"; [ -z "${admin}" ] && return 1
[[ "${admin}" == "${1}" || "${admin}" == "${2}" ]] && return 0
#[[ "${admin}" = "@*" ]] && [[ "${admin}" = "${2}" ]] && return 0
[[ "${admin}" == "$1" || "${admin}" == "$2" ]] && return 0
#[[ "${admin}" = "@*" ]] && [[ "${admin}" = "$2" ]] && return 0
if [ "${admin}" = "?" ]; then setConfigKey "botadmin" "${1:-?}"; return 0; fi
return 1
}

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$$ v1.25-dev-10-g5f50011
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#
# source from commands.sh to use jsonDB functions
#
@ -85,8 +85,8 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
# complex slow, warpper async
jssh_updateDB() {
# for atomic update we can't use read/writeDB
[ -z "${2}" ] && return 1
local DB="${2}.jssh" # check in async
[ -z "$2" ] && return 1
local DB="$2.jssh" # check in async
[ ! -f "${DB}" ] && return 2
{ flock -e -w 10 200; jssh_updateDB_async "$@"; } 200>"${DB}${JSSH_LOCKNAME}"
}
@ -115,9 +115,9 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
# $2 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
# medium complex slow, wrapper async
jssh_deleteKeyDB() {
[ -z "${2}" ] && return 1
[ -z "$2" ] && return 1
[[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3
local DB="${2}.jssh"
local DB="$2.jssh"
# start atomic delete here, exclusive max wait 10s
{ flock -e -w 10 200; jssh_deleteKeyDB_async "$@"; } 200>"${DB}${JSSH_LOCKNAME}"
}
@ -144,9 +144,9 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
# side effect: if $3 is not given, we add to end of file to be as fast as possible
# complex, wrapper to async
jssh_countKeyDB() {
[ -z "${2}" ] && return 1
[ -z "$2" ] && return 1
[[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3
local DB="${2}.jssh"
local DB="$2.jssh"
# start atomic delete here, exclusive max wait 5
{ flock -e -w 5 200; jssh_countKeyDB_async "$@"; } 200>"${DB}${JSSH_LOCKNAME}"
}
@ -158,11 +158,11 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
#no own locking, so async is the same as updatekeyDB
jssh_updateKeyDB() {
[[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3
[ -z "${3}" ] && return 1
[ -z "$3" ] && return 1
declare -A updARR
# shellcheck disable=SC2034
updARR["$1"]="$2"
jssh_updateDB "updARR" "${3}" || return 3
jssh_updateDB "updARR" "$3" || return 3
}
# $1 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
@ -178,11 +178,11 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
# $3 id used to identify caller
# medium complex, wrapper async
jssh_updateArray() {
[ -z "${2}" ] && return 1
local DB="${2}.jssh" # name check in async
[ -z "$2" ] && return 1
local DB="$2.jssh" # name check in async
[ ! -f "${DB}" ] && return 2
declare -n ARRAY="$1"
[[ -z "${ARRAY[*]}" || "${DB}" -nt "${DB}.last${3}" ]] && touch "${DB}.last${3}" && jssh_readDB "${1}" "${2}"
[[ -z "${ARRAY[*]}" || "${DB}" -nt "${DB}.last$3" ]] && touch "${DB}.last$3" && jssh_readDB "$1" "$2"
}
else
@ -228,9 +228,9 @@ jssh_checkDB(){
[ -z "$1" ] && return 1
[[ "$1" = *'../.'* ]] && return 2
if [[ "$1" == "${BASHBOT_VAR:-.}"* ]] || [[ "$1" == "${BASHBOT_DATA:-.}"* ]]; then
DB="${1}.jssh"
DB="$1.jssh"
else
DB="${BASHBOT_VAR:-.}/${1}.jssh"
DB="${BASHBOT_VAR:-.}/$1.jssh"
fi
[ "${DB}" != ".jssh" ] && printf '%s' "${DB}"
}
@ -254,7 +254,7 @@ jssh_writeDB_async() {
}
jssh_updateDB_async() {
[ -z "${2}" ] && return 1
[ -z "$2" ] && return 1
declare -n ARRAY="$1"
[ -z "${ARRAY[*]}" ] && return 1
declare -A oldARR
@ -325,11 +325,11 @@ jssh_countKeyDB_async() {
#no own locking, so async is the same as updatekeyDB
jssh_updateKeyDB_async() {
[[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3
[ -z "${3}" ] && return 1
[ -z "$3" ] && return 1
declare -A updARR
# shellcheck disable=SC2034
updARR["$1"]="$2"
jssh_updateDB_async "updARR" "${3}" || return 3
jssh_updateDB_async "updARR" "$3" || return 3
}
jssh_clearDB_async() {
@ -343,7 +343,7 @@ function jssh_updateArray_async() {
[ -z "${DB}" ] && return 1
[ ! -f "${DB}" ] && return 2
declare -n ARRAY="$1"
[[ -z "${ARRAY[*]}" || "${DB}" -nt "${DB}.last${3}" ]] && touch "${DB}.last${3}" && jssh_readDB_async "${1}" "${2}"
[[ -z "${ARRAY[*]}" || "${DB}" -nt "${DB}.last$3" ]] && touch "${DB}.last$3" && jssh_readDB_async "$1" "$2"
}
##############

View File

@ -6,7 +6,7 @@
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
# shellcheck disable=SC1117
#### $$VERSION$$ v1.25-dev-5-ga5aa756
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
# will be automatically sourced from bashbot
@ -35,17 +35,17 @@ ALBUM_URL=${URL}'/sendMediaGroup'
# $1 CHAT $2 message
send_normal_message() {
local len text; text="$(JsonEscape "${2}")"
local len text; text="$(JsonEscape "$2")"
text="${text//$'\n'/\\n}"
until [ -z "${text}" ]; do
if [ "${#text}" -le 4096 ]; then
sendJson "${1}" '"text":"'"${text}"'"' "${MSG_URL}"
sendJson "$1" '"text":"'"${text}"'"' "${MSG_URL}"
break
else
len=4095
[ "${text:4095:2}" != "\n" ] &&\
len="${text:0:4096}" && len="${len%\\n*}" && len="${#len}"
sendJson "${1}" '"text":"'"${text:0:${len}}"'"' "${MSG_URL}"
sendJson "$1" '"text":"'"${text:0:${len}}"'"' "${MSG_URL}"
text="${text:$((len+2))}"
fi
done
@ -53,48 +53,48 @@ send_normal_message() {
# $1 CHAT $2 message
send_markdown_message() {
_format_message_url "${1}" "${2}" ',"parse_mode":"markdown"' "${MSG_URL}"
_format_message_url "$1" "$2" ',"parse_mode":"markdown"' "${MSG_URL}"
}
# $1 CHAT $2 message
send_markdownv2_message() {
_markdownv2_message_url "${1}" "${2}" ',"parse_mode":"markdownv2"' "${MSG_URL}"
_markdownv2_message_url "$1" "$2" ',"parse_mode":"markdownv2"' "${MSG_URL}"
}
# $1 CHAT $2 message
send_html_message() {
_format_message_url "${1}" "${2}" ',"parse_mode":"html"' "${MSG_URL}"
_format_message_url "$1" "$2" ',"parse_mode":"html"' "${MSG_URL}"
}
# $1 CHAT $2 msg-id $3 message
edit_normal_message() {
_format_message_url "${1}" "${3}" ',"message_id":'"${2}"'' "${EDIT_URL}"
_format_message_url "$1" "$3" ',"message_id":'"$2"'' "${EDIT_URL}"
}
# $1 CHAT $2 msg-id $3 message
edit_markdown_message() {
_format_message_url "${1}" "${3}" ',"message_id":'"${2}"',"parse_mode":"markdown"' "${EDIT_URL}"
_format_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"markdown"' "${EDIT_URL}"
}
# $1 CHAT $2 msg-id $3 message
edit_markdownv2_message() {
_markdownv2_message_url "${1}" "${3}" ',"message_id":'"${2}"',"parse_mode":"markdownv2"' "${EDIT_URL}"
_markdownv2_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"markdownv2"' "${EDIT_URL}"
}
# $1 CHAT $2 msg-id $3 message
edit_html_message() {
_format_message_url "${1}" "${3}" ',"message_id":'"${2}"',"parse_mode":"html"' "${EDIT_URL}"
_format_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"html"' "${EDIT_URL}"
}
# internal function, send/edit formatted message with parse_mode and URL
# $1 CHAT $2 message $3 action $4 URL
_format_message_url(){
local text; text="$(JsonEscape "${2}")"
local text; text="$(JsonEscape "$2")"
text="${text//$'\n'/\\n}"
[ "${#text}" -ge 4096 ] && log_error "Warning: html/markdown message longer than 4096 characters, message is rejected if formatting crosses 4096 border."
until [ -z "${text}" ]; do
sendJson "${1}" '"text":"'"${text:0:4096}"'"'"${3}"'' "${4}"
sendJson "$1" '"text":"'"${text:0:4096}"'"'"$3"'' "$4"
text="${text:4096}"
done
}
@ -102,13 +102,13 @@ _format_message_url(){
# internal function, send/edit markdownv2 message with URL
# $1 CHAT $2 message $3 action $4 URL
_markdownv2_message_url() {
local text; text="$(JsonEscape "${2}")"
local text; text="$(JsonEscape "$2")"
text="${text//$'\n'/\\n}"
[ "${#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!
text="$(sed -E -e 's|([_|~`>+=#{}()!.-])|\\\1|g' <<< "${text}")"
until [ -z "${text}" ]; do
sendJson "${1}" '"text":"'"${text:0:4096}"'"'"${3}"'' "${4}"
sendJson "$1" '"text":"'"${text:0:4096}"'"'"$3"'' "$4"
text="${text:4096}"
done
}
@ -121,37 +121,37 @@ _markdownv2_message_url() {
send_keyboard() {
if [[ "$3" != *'['* ]]; then old_send_keyboard "${@}"; return; fi
local text='"text":"'"Keyboard:"'"'
if [ -n "${2}" ]; then
text="$(JsonEscape "${2}")"
if [ -n "$2" ]; then
text="$(JsonEscape "$2")"
text='"text":"'"${text//$'\n'/\\n}"'"'
fi
local one_time=', "one_time_keyboard":true' && [ -n "$4" ] && one_time=""
sendJson "${1}" "${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"'}' "${MSG_URL}"
# '"text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true}'
sendJson "$1" "${text}"', "reply_markup": {"keyboard": [ '"$3"' ] '"${one_time}"'}' "${MSG_URL}"
# '"text":"$2", "reply_markup": {"keyboard": [ $3 ], "one_time_keyboard": true}'
}
# $1 CHAT $2 message $3 remove
remove_keyboard() {
local text='"text":"'"remove custom keyboard ..."'"'
if [ -n "${2}" ]; then
text="$(JsonEscape "${2}")"
if [ -n "$2" ]; then
text="$(JsonEscape "$2")"
text='"text":"'"${text//$'\n'/\\n}"'"'
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
[[ -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}'
}
# $1 CHAT $2 message $3 keyboard
send_inline_keyboard() {
local text; text='"text":"'$(JsonEscape "${2}")'"'; [ -z "${2}" ] && text='"text":"'"Keyboard:"'"'
sendJson "${1}" "${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]}' "${MSG_URL}"
local text; text='"text":"'$(JsonEscape "$2")'"'; [ -z "$2" ] && text='"text":"'"Keyboard:"'"'
sendJson "$1" "${text}"', "reply_markup": {"inline_keyboard": [ '"$3"' ]}' "${MSG_URL}"
# JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}'
}
# $1 CHAT $2 message $3 button text $4 URL
send_button() {
send_inline_keyboard "${1}" "${2}" '[ {"text":"'"$(JsonEscape "${3}")"'", "url":"'"${4}"'"}]'
send_inline_keyboard "$1" "$2" '[ {"text":"'"$(JsonEscape "$3")"'", "url":"'"$4"'"}]'
}
@ -159,9 +159,9 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
# there are no checks if URL or ID exists
# $1 chat $3 ... $n URL or ID
send_album(){
[ -z "${1}" ] && return 1
[ -z "${3}" ] && return 2 # minimum 2 files
local CHAT JSON IMAGE; CHAT="${1}"; shift
[ -z "$1" ] && return 1
[ -z "$3" ] && return 2 # minimum 2 files
local CHAT JSON IMAGE; CHAT="$1"; shift
for IMAGE in "$@"
do
[ -n "${JSON}" ] && JSON+=","
@ -250,20 +250,20 @@ upload_file(){
STATUS="upload_document"
;;
esac
send_action "${1}" "${STATUS}"
send_action "$1" "${STATUS}"
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
send_action() {
[ -z "$2" ] && return
sendJson "${1}" '"action": "'"${2}"'"' "${ACTION_URL}" &
sendJson "$1" '"action": "'"$2"'"' "${ACTION_URL}" &
}
# $1 CHAT $2 lat $3 long
send_location() {
[ -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
@ -271,7 +271,7 @@ send_venue() {
local add=""
[ -z "$5" ] && return
[ -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}"
}
@ -282,7 +282,7 @@ send_venue() {
# $1 CHAT $2 from chat $3 from msg id
forward_message() {
[ -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_message "$@" || return
@ -292,20 +292,20 @@ forward() { # backward compatibility
send_message() {
[ -z "$2" ] && return
local text keyboard btext burl no_keyboard file lat long title address sent
text="$(sed <<< "${2}" 's/ mykeyboardend.*//;s/ *my[kfltab][a-z]\{2,13\}startshere.*//')$(sed <<< "${2}" -n '/mytextstartshere/ s/.*mytextstartshere//p')"
text="$(sed <<< "$2" 's/ mykeyboardend.*//;s/ *my[kfltab][a-z]\{2,13\}startshere.*//')$(sed <<< "$2" -n '/mytextstartshere/ s/.*mytextstartshere//p')"
#shellcheck disable=SC2001
text="$(sed <<< "${text}" 's/ *mynewlinestartshere */\n/g')"
text="${text//$'\n'/\\n}"
[ "$3" != "safe" ] && {
no_keyboard="$(sed <<< "${2}" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')"
keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere *//;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
btext="$(sed <<< "${2}" '/mybtextstartshere /!d;s/.*mybtextstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
burl="$(sed <<< "${2}" '/myburlstartshere /!d;s/.*myburlstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//g;s/ *mykeyboardendshere.*//g')"
file="$(sed <<< "${2}" '/myfile[^s]*startshere /!d;s/.*myfile[^s]*startshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
lat="$(sed <<< "${2}" '/mylatstartshere /!d;s/.*mylatstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
long="$(sed <<< "${2}" '/mylongstartshere /!d;s/.*mylongstartshere //;s/ *my[nkfltab][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.*//')"
no_keyboard="$(sed <<< "$2" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')"
keyboard="$(sed <<< "$2" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere *//;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
btext="$(sed <<< "$2" '/mybtextstartshere /!d;s/.*mybtextstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
burl="$(sed <<< "$2" '/myburlstartshere /!d;s/.*myburlstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//g;s/ *mykeyboardendshere.*//g')"
file="$(sed <<< "$2" '/myfile[^s]*startshere /!d;s/.*myfile[^s]*startshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
lat="$(sed <<< "$2" '/mylatstartshere /!d;s/.*mylatstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
long="$(sed <<< "$2" '/mylongstartshere /!d;s/.*mylongstartshere //;s/ *my[nkfltab][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.*//')"
}
if [ -n "${no_keyboard}" ]; then
remove_keyboard "$1" "${text}"

View File

@ -9,7 +9,7 @@
# #### mycommands.clean
#
# shellcheck disable=SC1117
#### $$VERSION$$ v1.25-dev-5-ga5aa756
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#
##########
@ -298,7 +298,7 @@ else
# $1 current date, $2 from where the function was called, $3 ... $n optional information
my_debug_checks() {
# example check because my bot created a wrong file
[ -f ".jssh" ] && printf "%s: %s\n" "${1}" "Ups, found file \"${PWD:-.}/.jssh\"! =========="
[ -f ".jssh" ] && printf "%s: %s\n" "$1" "Ups, found file \"${PWD:-.}/.jssh\"! =========="
}
# called when bashbot send_xxx command failed because we can not connect to telegram

View File

@ -10,7 +10,7 @@
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
# magic to ensure that we're always inside the root of our application,

View File

@ -11,7 +11,7 @@
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.25-dev-8-g248a065
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
# common variables
@ -71,11 +71,11 @@ print_array() {
compare_sorted() {
local ret=0
sort -d -o "${1}.sort" "${1}"
sort -d -o "${2}.sort" "${2}"
diff -c "${1}.sort" "${2}.sort" || ret=1
[[ "${1}" != "${TESTDIR}"* ]] && rm -f "${1}.sort"
[[ "${2}" != "${TESTDIR}"* ]] && rm -f "${2}.sort"
sort -d -o "$1.sort" "$1"
sort -d -o "$2.sort" "$2"
diff -c "$1.sort" "$2.sort" || ret=1
[[ "$1" != "${TESTDIR}"* ]] && rm -f "$1.sort"
[[ "$2" != "${TESTDIR}"* ]] && rm -f "$2.sort"
return "${ret}"
}

View File

@ -10,7 +10,7 @@
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
../dev/hooks/pre-commit.sh

View File

@ -10,7 +10,7 @@
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
# include common functions and definitions

View File

@ -10,7 +10,7 @@
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.25-dev-8-g248a065
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
# include common functions and definitions

View File

@ -10,7 +10,7 @@
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
# include common functions and definitions

View File

@ -10,7 +10,7 @@
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
# include common functions and definitions

View File

@ -10,7 +10,7 @@
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.25-dev-8-g248a065
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
# include common functions and definitions
@ -34,15 +34,15 @@ _is_function send_message || printf "Send Message not found!\n"
# over write sendJson to output parameter only
sendEmpty() {
printf 'chat:%s\tJSON:%s\nURL:%s\n\n' "${1}" "${2}" "${3}"
printf 'chat:%s\tJSON:%s\nURL:%s\n\n' "$1" "$2" "$3"
}
sendJson() {
printf 'chat:%s\tJSON:%s\nURL:%s\n\n' "${1}" "${2}" "${3}"
printf 'chat:%s\tJSON:%s\nURL:%s\n\n' "$1" "$2" "$3"
}
sendUpload() {
#JSON:"document":"/tmp/allowed/this_is_my.doc","caption":"Text plus absolute file will appear in chat""
printf 'chat:%s\tJSON:"%s":"%s","caption":"%s"\nURL:%s\n\n' "${1}" "${2}" "${3}" "${5}" "${4}"
printf 'chat:%s\tJSON:"%s":"%s","caption":"%s"\nURL:%s\n\n' "$1" "$2" "$3" "$5" "$4"
}
# send text input to send_message

View File

@ -10,7 +10,7 @@
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.21-0-gc85af77
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
# include common functions and definitions

View File

@ -10,7 +10,7 @@
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.25-dev-8-g248a065
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
#===============================================================================
# include common functions and definitions