From 83fc57e46c2d01f61c894a7020cffa236b5513b3 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 12:33:36 +0100 Subject: [PATCH 01/98] doc: minor fix --- doc/0_install.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/0_install.md b/doc/0_install.md index 20a1f90..66eb0d0 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -63,9 +63,9 @@ Most systems with awk can use `JSON.awk` as drop in replacement BSD and MacOS users must install `gnu awk` and adjust the shebang, see below -After you have checked that 'JSON.awk.dist' is working correct on your system copy it to `JSON.awk` and (re)start bashbot. +After you have checked that `JSON.awk.dist` is working correct on your system copy it to `JSON.awk` and (re)start bashbot. -Note: If you are not using the zip / tar archive, you must install `JSON.awk` manually into the same directory as 'JSON.sh`: +Note: If you are not using the zip / tar archive, you must install `JSON.awk` manually into the same directory as `JSON.sh`: wget https://cdn.jsdelivr.net/gh/step-/JSON.awk/JSON.awk wget https://cdn.jsdelivr.net/gh/step-/JSON.awk/tool/patch-for-busybox-awk.sh @@ -124,7 +124,7 @@ to get an impression how different they are. #### Support for update from pre-1.0 removed -From Version 1.21 on updating from a pre-1.0 version is no more supported! +From Version 1.21 on updating from a pre-1.0 version (_no \*.jssh config_) is no more supported! You must update to [Version 1.20](https://github.com/topkecleon/telegram-bot-bash/releases/tags/v1.20) first! From 5ad7be59ba22400d5bf7e9cab0ac1a62a2f359e5 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 12:38:20 +0100 Subject: [PATCH 02/98] *IMPORTANT* fix for ranges a-z dependig on locale! --- modules/jsonDB.sh | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index 90f11f9..a51c329 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.21-1-g83fc57e # # source from commands.sh to use jsonDB functions # @@ -27,6 +27,18 @@ eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" # lockfile filename.flock is persistent and will be testet with flock for active lock (file open) export JSSH_LOCKNAME=".flock" +# in UTF-8 äöü etc. are part of [:alnum:] and rages (e.g. a-z), but we want ASCII a-z ranges! +# there are two solutions: set "LC_COLLATE=C" or set bash option "globasciiranges" +# to be independent of the settings mentioned above, we define our own "ranges" +azazaz='abcdefghijklmnopqrstuvwxyz' # a-z :lower: +AZAZAZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ' # A-Z :upper: +R090909='0123456789' # 0-9 :digit: +azAZaz="${azazaz}${AZAZAZ}" # a-zA-Z :alpha: +azAZ09="${azAZaz}${R090909}" # a-zA-z0-9 :alnum: + +# characters allowed for key in key/value pairs +JSSH_KEYOK="[-${azAZ09},._]" + # use flock if command exist if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then @@ -76,7 +88,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then alias jssh_insertDB=jssh_insertKeyDB # backward compatibility # renamed to be more consistent jssh_insertKeyDB() { - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3 local DB; DB="$(jssh_checkDB "$3")" [ -z "${DB}" ] && return 1 [ ! -f "${DB}" ] && return 2 @@ -94,7 +106,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then # medium complex slow, wrapper async jssh_deleteKeyDB() { [ -z "${2}" ] && return 1 - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3 local DB="${2}.jssh" # start atomic delete here, exclusive max wait 10s { flock -e -w 10 200; jssh_deleteKeyDB_async "$@"; } 200>"${DB}${JSSH_LOCKNAME}" @@ -105,7 +117,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then # $2 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..' alias jssh_getDB=jssh_getKeyDB jssh_getKeyDB() { - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3 local DB; DB="$(jssh_checkDB "$2")" [ -z "${DB}" ] && return 1 # start atomic delete here, exclusive max wait 1s @@ -123,7 +135,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then # complex, wrapper to async jssh_countKeyDB() { [ -z "${2}" ] && return 1 - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3 local DB="${2}.jssh" # start atomic delete here, exclusive max wait 5 { flock -e -w 5 200; jssh_countKeyDB_async "$@"; } 200>"${DB}${JSSH_LOCKNAME}" @@ -135,7 +147,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then # $3 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..' #no own locking, so async is the same as updatekeyDB jssh_updateKeyDB() { - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3 [ -z "${3}" ] && return 1 declare -A updARR # shellcheck disable=SC2034 @@ -253,7 +265,7 @@ jssh_updateDB_async() { jssh_insertDB_async() { jssh_insertKeyDB "$@"; } jssh_insertKeyDB_async() { - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3 local DB; DB="$(jssh_checkDB "$3")" [ -z "${DB}" ] && return 1 [ ! -f "${DB}" ] && return 2 @@ -263,7 +275,7 @@ jssh_insertKeyDB_async() { } jssh_deleteKeyDB_async() { - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3 local DB; DB="$(jssh_checkDB "$2")" [ -z "${DB}" ] && return 1 declare -A oldARR @@ -273,14 +285,14 @@ jssh_deleteKeyDB_async() { } jssh_getKeyDB_async() { - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3 local DB; DB="$(jssh_checkDB "$2")" [ -z "${DB}" ] && return 1 [ -r "${DB}" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' <"${DB}" | tail -n 1 } jssh_countKeyDB_async() { - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3 local VAL DB; DB="$(jssh_checkDB "$2")" [ -z "${DB}" ] && return 1 # start atomic delete here, exclusive max wait 5 @@ -302,7 +314,7 @@ jssh_countKeyDB_async() { # $3 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..' #no own locking, so async is the same as updatekeyDB jssh_updateKeyDB_async() { - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3 [ -z "${3}" ] && return 1 declare -A updARR # shellcheck disable=SC2034 @@ -344,9 +356,9 @@ Array2Json() { declare -n ARRAY="$1" for key in "${!ARRAY[@]}" do + #[[ "${key}" =~ ^${JSSH_KEYOK}$ ]] || continue # in case val contains newline convert to \n val="${ARRAY[${key}]//$'\n'/\\n}" printf '["%s"]\t"%s"\n' "${key//,/\",\"}" "${val//\"/\\\"}" done } - From e072afac41361b74ee1aa94e3e67fe2a6b28d82e Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 12:40:14 +0100 Subject: [PATCH 03/98] modules/jsonDB: add Jssh_stripKey --- modules/jsonDB.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index a51c329..f3ea543 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.21-1-g83fc57e +#### $$VERSION$$ v1.21-2-g5ad7be5 # # source from commands.sh to use jsonDB functions # @@ -39,6 +39,17 @@ azAZ09="${azAZaz}${R090909}" # a-zA-z0-9 :alnum: # characters allowed for key in key/value pairs JSSH_KEYOK="[-${azAZ09},._]" +# read string from stdin and and strip invalid characters +# $1 - invalid charcaters are replaced with first character +# or deleted if $1 is empty +jssh_stripKey() { # tr: we must escape first - in [-a-z...] + if [[ "$1" =~ ^${JSSH_KEYOK} ]]; then # tr needs [\-... + tr -c "${JSSH_KEYOK/\[-/[\\-}\r\n" "${1:0:1}" + else + tr -dc "${JSSH_KEYOK/\[-/[\\-}\r\n" + fi +} + # use flock if command exist if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then From 966ee5d5a73c69d888c27cdcbf31265c4da666a2 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 12:49:43 +0100 Subject: [PATCH 04/98] modules/jsonDB: activate stripping of not allowed keys --- modules/jsonDB.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index f3ea543..4dfecb6 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.21-2-g5ad7be5 +#### $$VERSION$$ v1.21-3-ge072afa # # source from commands.sh to use jsonDB functions # @@ -27,7 +27,7 @@ eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" # lockfile filename.flock is persistent and will be testet with flock for active lock (file open) export JSSH_LOCKNAME=".flock" -# in UTF-8 äöü etc. are part of [:alnum:] and rages (e.g. a-z), but we want ASCII a-z ranges! +# in UTF-8 äöü etc. are part of [:alnum:] and ranges (e.g. a-z), but we want ASCII a-z ranges! # there are two solutions: set "LC_COLLATE=C" or set bash option "globasciiranges" # to be independent of the settings mentioned above, we define our own "ranges" azazaz='abcdefghijklmnopqrstuvwxyz' # a-z :lower: @@ -367,7 +367,7 @@ Array2Json() { declare -n ARRAY="$1" for key in "${!ARRAY[@]}" do - #[[ "${key}" =~ ^${JSSH_KEYOK}$ ]] || continue + [[ "${key}" =~ ^${JSSH_KEYOK}$ ]] || continue # in case val contains newline convert to \n val="${ARRAY[${key}]//$'\n'/\\n}" printf '["%s"]\t"%s"\n' "${key//,/\",\"}" "${val//\"/\\\"}" From 8a095bc79f8502c77f60f2397617264aa55d89ff Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 14:49:04 +0100 Subject: [PATCH 05/98] doc: add known locale problems --- doc/4_expert.md | 56 +++++++++++++++++++++++++++++++++++++++++++++-- modules/jsonDB.sh | 2 +- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/doc/4_expert.md b/doc/4_expert.md index 19a4171..ca46ef3 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -35,7 +35,59 @@ export 'LANGUAGE=den_US.UTF-8' ``` 3. make sure your bot scripts use the correct settings, eg. include the lines above at the beginning of your scripts -To display all available locales on your system run `locale -a | more`. [Gentoo Wiki](https://wiki.gentoo.org/wiki/UTF-8) +#### Known UTF-8 pitfalls + +##### Missing locale C + +Even required by POSIX standard some systems (e.g. Manjaro Linux) has no locale `C` and `C.UTF-8` installed. +If bashbot display a warning about missing locale you must install locale `C` and `C.UTF-8`. + +If you don't know what locales are installed on your sytsem use `locale -a | more` to display them. +[Gentoo Wiki](https://wiki.gentoo.org/wiki/UTF-8). + + +##### Character classes + +In ASCII times it was clear `[:lower:]` and `[a-z]` means ONLY the lowercase letters `[abcd...xyz]`. +With introdution of locales character classes and ranges contains every character fitting the class definition. + +This mean `[:lower:]` and `[a-z]` contains ALL lowercase letters e.g. `ä á ø dž ȼ` +also, see [Unicode Latin lowercase letters]https://www.fileformat.info/info/unicode/category/Ll/list.htm) + +If that's ok for your script your'e fine, but many scripts rely on the idea of ASCII ranges and may produce undesired results. + +```bash +# try with different locales ... +lowercase="abcäöü" + +[[ "$string" =~ ^[a-z]$ ] && echo "String is all lower case" + +LANG="en_EN +[[ "$string" =~ ^[a-z]$ ] && echo "String is all lower case" + +LANG="C" +[[ "$string" =~ ^[a-z]$ ] && echo "String is all lower case" +``` + +There are three solutions: + +1. list exactly the characters you want: `[abcd...]` +2. instruct bash to use `C` locale for ranges: `shopt -s "globasciiranges"` +3. use `LC_COLLATE` to change behavior of all programs: `export LC_COLLATE=C` + + +To work independent of language and bash settings bashbot uses solution 1. and uses own "classes" if an exact match is mandatory: + +```bash +azazaz='abcdefghijklmnopqrstuvwxyz' # a-z :lower: +AZAZAZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ' # A-Z :upper: +R090909='0123456789' # 0-9 :digit: +azAZaz="${azazaz}${AZAZAZ}" # a-zA-Z :alpha: +azAZ09="${azAZaz}${R090909}" # a-zA-z0-9 :alnum: + +# e.g. characters allowed for key in key/value pairs +JSSH_KEYOK="[-${azAZ09},._]" +``` #### Bashbot UTF-8 Support Bashbot handles all messages transparently, regardless of the charset in use. The only exception is when converting from JSON data to strings. @@ -378,5 +430,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Advanced Use](3_advanced.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.21-4-g966ee5d diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index 4dfecb6..d27288b 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.21-3-ge072afa +#### $$VERSION$$ v1.21-4-g966ee5d # # source from commands.sh to use jsonDB functions # From 5f6476d691e3b100a4ebc5e54002f1d1564a55a6 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 15:39:01 +0100 Subject: [PATCH 06/98] doc: fix locale range description --- doc/4_expert.md | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/doc/4_expert.md b/doc/4_expert.md index ca46ef3..a4f6f9a 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -9,13 +9,13 @@ two bytes for encoding and covers almost all `Latin` alphabets, also `Greek`, `C `Hebrew`, `Arabic` and more. See [Wikipedia](https://en.wikipedia.org/wiki/UTF-8) for more details. #### Setting up your Environment -In general `bash` and `GNU` utitities are UTF-8 aware if you to setup your environment -and your scripts accordingly: +In general `bash` and `GNU` utitities are UTF-8 aware aware if you to setup your environment +and your scripts accordingly (_locale setting_): 1. Your Terminal and Editor must support UTF-8: Set Terminal and Editor locale to UTF-8, eg. in `Settings/Configuration` select UTF-8 (Unicode) as Charset. -2. Set `Shell` environment to UTF-8 in your `.profile` and your scripts. The usual settings are: +2. Set `Shell` locale environment to UTF-8 in your `.profile` and your scripts. The usual settings are: ```bash export 'LC_ALL=C.UTF-8' @@ -31,18 +31,19 @@ export 'LANGUAGE=de_DE.UTF-8' ```bash export 'LC_ALL=en_US.UTF-8' export 'LANG=de_en_US.UTF-8' -export 'LANGUAGE=den_US.UTF-8' +export 'LANGUAGE=en_US.UTF-8' ``` -3. make sure your bot scripts use the correct settings, eg. include the lines above at the beginning of your scripts +3. make sure your bot scripts use the correct settings, eg. include the lines above at the beginning of your scripts -#### Known UTF-8 pitfalls + +#### Known locale pitfalls ##### Missing locale C Even required by POSIX standard some systems (e.g. Manjaro Linux) has no locale `C` and `C.UTF-8` installed. If bashbot display a warning about missing locale you must install locale `C` and `C.UTF-8`. -If you don't know what locales are installed on your sytsem use `locale -a | more` to display them. +If you don't know what locales are installed on your sytsem use `locale -a` to display them. [Gentoo Wiki](https://wiki.gentoo.org/wiki/UTF-8). @@ -51,22 +52,25 @@ If you don't know what locales are installed on your sytsem use `locale -a | mor In ASCII times it was clear `[:lower:]` and `[a-z]` means ONLY the lowercase letters `[abcd...xyz]`. With introdution of locales character classes and ranges contains every character fitting the class definition. -This mean `[:lower:]` and `[a-z]` contains ALL lowercase letters e.g. `ä á ø dž ȼ` -also, see [Unicode Latin lowercase letters]https://www.fileformat.info/info/unicode/category/Ll/list.htm) +This means for UTF-8 locales `[:lower:]` and `[a-z]` contains ALL lowercase letters, e.g. `á ø ü` also, +see [Unicode Latin lowercase letters](https://www.fileformat.info/info/unicode/category/Ll/list.htm) If that's ok for your script your'e fine, but many scripts rely on the idea of ASCII ranges and may produce undesired results. ```bash # try with different locales ... -lowercase="abcäöü" +# new bash to not change your current locale! +bash +lower="abcö" -[[ "$string" =~ ^[a-z]$ ] && echo "String is all lower case" +echo "$LC_ALL" +[[ "$lower" =~ ^[a-z]+$ ]] && echo "Ups, $lower is all lower case!" || echo "OK, not lower case" -LANG="en_EN -[[ "$string" =~ ^[a-z]$ ] && echo "String is all lower case" +LC_ALL="en_US.UTF-8" +[[ "$lower" =~ ^[a-z]+$ ]] && echo "Ups, $lower is all lower case!" || echo "OK, not lower case" -LANG="C" -[[ "$string" =~ ^[a-z]$ ] && echo "String is all lower case" +LC_ALL="C" +[[ "$lower" =~ ^[a-z]+$ ]] && echo "Ups, $lower is all lower case!" || echo "OK, not lower case" ``` There are three solutions: @@ -430,5 +434,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Advanced Use](3_advanced.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v1.21-4-g966ee5d +#### $$VERSION$$ v1.21-5-g8a095bc From 0798f1ae00118960068dc12e244776851d526add Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 16:03:53 +0100 Subject: [PATCH 07/98] bashbot.sh implement new a-z soluition --- bashbot.sh | 30 +++++++++++++++++++----------- doc/4_expert.md | 4 ++-- modules/jsonDB.sh | 5 ++--- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 8d7906f..3bd3b77 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.21-6-g5f6476d ################################################################## # emmbeded system may claim bash but it is not @@ -63,6 +63,14 @@ if [ "$({ LC_ALL=C.utf-8 printf "%b" "\u1111"; } 2>/dev/null)" = "\u1111" ]; the fi +# in UTF-8 äöü etc. are part of [:alnum:] and ranges (e.g. a-z), but we want ASCII a-z ranges! +# for more information see doc/4_expert.md#Character_classes +azazaz='abcdefghijklmnopqrstuvwxyz' # a-z :lower: +AZAZAZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ' # A-Z :upper: +R090909='0123456789' # 0-9 :digit: +azAZaz="${azazaz}${AZAZAZ}" # a-zA-Z :alpha: +azAZ09="${azAZaz}${R090909}" # a-zA-z0-9 :alnum: + # some important helper functions # returns true if command exist _exists() { @@ -80,22 +88,22 @@ _is_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}" =~ ^[0-9]+$ ]] || digit="0" + local digit="${2}"; [[ "${2}" =~ ^[${R090909}]+$ ]] || digit="0" { LC_ALL=C.utf-8 printf "%.${digit}f" "${1}"; } 2>/dev/null } setConfigKey() { - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^[-${azAZ09},._]+$ ]] || return 3 [ -z "${BOTCONFIG}" ] && return 1 printf '["%s"]\t"%s"\n' "${1//,/\",\"}" "${2//\"/\\\"}" >>"${BOTCONFIG}.jssh" } getConfigKey() { - [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + [[ "$1" =~ ^[-${azAZ09},._]+$ ]] || return 3 [ -r "${BOTCONFIG}.jssh" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' <"${BOTCONFIG}.jssh" | tail -n 1 } # check if $1 seems a valid token # return true if token seems to be valid check_token(){ - [[ "${1}" =~ ^[0-9]{8,10}:[a-zA-Z0-9_-]{35}$ ]] && return 0 + [[ "${1}" =~ ^[${R090909}]{8,10}:[${azAZ09}_-]{35}$ ]] && return 0 return 1 } # log $1 with date @@ -278,11 +286,11 @@ if ! check_token "${BOTTOKEN}"; then "${RED}:${NC}<35_alphanumeric_characters-hash> ${RED}e.g. =>${NC} 123456789${RED}:${NC}Aa-Zz_0Aa-Zz_1Aa-Zz_2Aa-Zz_3Aa-Zz_4\n\n"\ "${GREY}Your bot token: '${NC}${BOTTOKEN//:/${RED}:${NC}}'\n" - if [[ ! "${BOTTOKEN}" =~ ^[0-9]{8,10}: ]]; then + if [[ ! "${BOTTOKEN}" =~ ^[${R090909}]{8,10}: ]]; then printf "${GREY}\tHint: Bot id not a number or wrong len: ${NC}$(($(wc -c <<<"${BOTTOKEN%:*}")-1)) ${GREY}but should be${NC} 8-10\n" [ -n "$(getConfigKey "botid")" ] && printf "\t${GREEN}Did you mean: \"${NC}$(getConfigKey "botid")${GREEN}\" ?${NN}" fi - [[ ! "${BOTTOKEN}" =~ :[a-zA-Z0-9_-]{35}$ ]] &&\ + [[ ! "${BOTTOKEN}" =~ :[${azAZ09}_-]{35}$ ]] &&\ printf "${GREY}\tHint: Hash contains invalid character or has not len${NC} 35 ${GREY}, hash len is ${NC}$(($(wc -c <<<"${BOTTOKEN#*:}")-1))\n" printf "\n" fi @@ -428,14 +436,14 @@ if ! _exists iconv; then fi TIMEOUT="${BASHBOT_TIMEOUT}" -[[ "$TIMEOUT" =~ ^[0-9]+$ ]] || TIMEOUT="20" +[[ "$TIMEOUT" =~ ^[${R090909}]+$ ]] || TIMEOUT="20" # usage: sendJson "chat" "JSON" "URL" sendJson(){ local json chat="" if [ -n "${1}" ]; then chat='"chat_id":'"${1}"',' - [[ "${1}" == *[!0-9-]* ]] && chat='"chat_id":"'"${1}"' NAN",' # chat id not a number! + [[ "${1}" == *[!${R090909}-]* ]] && 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")"'}' @@ -527,7 +535,7 @@ fi # $1 function $2 sleep $3 ... $n arguments sendJsonRetry(){ local retry="${1}"; shift - [[ "${1}" =~ ^\ *[0-9.]+\ *$ ]] && sleep "${1}"; shift + [[ "${1}" =~ ^\ *[${R090909}.]+\ *$ ]] && sleep "${1}"; shift printf "%s: RETRY %s %s %s\n" "$(date)" "${retry}" "${1}" "${2:0:60}" case "${retry}" in 'sendJson'*) @@ -1135,7 +1143,7 @@ bot_init() { # check if botconf seems valid printf "${GREEN}This is your bot config:${NN}" sed 's/^/\t/' "${BOTCONFIG}.jssh" | grep -vF '["bot_config_key"]' - if check_token "$(getConfigKey "bottoken")" && [[ "$(getConfigKey "botadmin")" =~ ^[0-9]+$ ]]; then + if check_token "$(getConfigKey "bottoken")" && [[ "$(getConfigKey "botadmin")" =~ ^[${R090909}]+$ ]]; then printf "Bot config seems to be valid. Should I make a backup copy? (Y/n) Y\b" read -r ANSWER if [[ -z "${ANSWER}" || "${ANSWER}" =~ ^[^Nn] ]]; then diff --git a/doc/4_expert.md b/doc/4_expert.md index a4f6f9a..d197256 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -9,7 +9,7 @@ two bytes for encoding and covers almost all `Latin` alphabets, also `Greek`, `C `Hebrew`, `Arabic` and more. See [Wikipedia](https://en.wikipedia.org/wiki/UTF-8) for more details. #### Setting up your Environment -In general `bash` and `GNU` utitities are UTF-8 aware aware if you to setup your environment +In general `bash` and `GNU` utitities are UTF-8 aware if you to setup your environment and your scripts accordingly (_locale setting_): 1. Your Terminal and Editor must support UTF-8: @@ -434,5 +434,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Advanced Use](3_advanced.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v1.21-5-g8a095bc +#### $$VERSION$$ v1.21-6-g5f6476d diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index d27288b..fed9ea4 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.21-4-g966ee5d +#### $$VERSION$$ v1.21-6-g5f6476d # # source from commands.sh to use jsonDB functions # @@ -28,8 +28,7 @@ eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" export JSSH_LOCKNAME=".flock" # in UTF-8 äöü etc. are part of [:alnum:] and ranges (e.g. a-z), but we want ASCII a-z ranges! -# there are two solutions: set "LC_COLLATE=C" or set bash option "globasciiranges" -# to be independent of the settings mentioned above, we define our own "ranges" +# for more information see doc/4_expert.md#Character_classes azazaz='abcdefghijklmnopqrstuvwxyz' # a-z :lower: AZAZAZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ' # A-Z :upper: R090909='0123456789' # 0-9 :digit: From d310805a98f415b685fc3fdfcc9b7f60da8c5795 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 16:10:43 +0100 Subject: [PATCH 08/98] replace R090909 -> o9o9o9 , better readable --- bashbot.sh | 26 +++++++++++++------------- doc/4_expert.md | 8 ++++---- modules/jsonDB.sh | 8 ++++---- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 3bd3b77..8838091 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.21-6-g5f6476d +#### $$VERSION$$ v1.21-7-g0798f1a ################################################################## # emmbeded system may claim bash but it is not @@ -67,9 +67,9 @@ fi # for more information see doc/4_expert.md#Character_classes azazaz='abcdefghijklmnopqrstuvwxyz' # a-z :lower: AZAZAZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ' # A-Z :upper: -R090909='0123456789' # 0-9 :digit: +o9o9o9='0123456789' # 0-9 :digit: azAZaz="${azazaz}${AZAZAZ}" # a-zA-Z :alpha: -azAZ09="${azAZaz}${R090909}" # a-zA-z0-9 :alnum: +azAZo9="${azAZaz}${o9o9o9}" # a-zA-z0-9 :alnum: # some important helper functions # returns true if command exist @@ -88,22 +88,22 @@ _is_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}" =~ ^[${R090909}]+$ ]] || digit="0" + local digit="${2}"; [[ "${2}" =~ ^[${o9o9o9}]+$ ]] || digit="0" { LC_ALL=C.utf-8 printf "%.${digit}f" "${1}"; } 2>/dev/null } setConfigKey() { - [[ "$1" =~ ^[-${azAZ09},._]+$ ]] || return 3 + [[ "$1" =~ ^[-${azAZo9},._]+$ ]] || return 3 [ -z "${BOTCONFIG}" ] && return 1 printf '["%s"]\t"%s"\n' "${1//,/\",\"}" "${2//\"/\\\"}" >>"${BOTCONFIG}.jssh" } getConfigKey() { - [[ "$1" =~ ^[-${azAZ09},._]+$ ]] || return 3 + [[ "$1" =~ ^[-${azAZo9},._]+$ ]] || return 3 [ -r "${BOTCONFIG}.jssh" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' <"${BOTCONFIG}.jssh" | tail -n 1 } # check if $1 seems a valid token # return true if token seems to be valid check_token(){ - [[ "${1}" =~ ^[${R090909}]{8,10}:[${azAZ09}_-]{35}$ ]] && return 0 + [[ "${1}" =~ ^[${o9o9o9}]{8,10}:[${azAZo9}_-]{35}$ ]] && return 0 return 1 } # log $1 with date @@ -286,11 +286,11 @@ if ! check_token "${BOTTOKEN}"; then "${RED}:${NC}<35_alphanumeric_characters-hash> ${RED}e.g. =>${NC} 123456789${RED}:${NC}Aa-Zz_0Aa-Zz_1Aa-Zz_2Aa-Zz_3Aa-Zz_4\n\n"\ "${GREY}Your bot token: '${NC}${BOTTOKEN//:/${RED}:${NC}}'\n" - if [[ ! "${BOTTOKEN}" =~ ^[${R090909}]{8,10}: ]]; then + if [[ ! "${BOTTOKEN}" =~ ^[${o9o9o9}]{8,10}: ]]; then printf "${GREY}\tHint: Bot id not a number or wrong len: ${NC}$(($(wc -c <<<"${BOTTOKEN%:*}")-1)) ${GREY}but should be${NC} 8-10\n" [ -n "$(getConfigKey "botid")" ] && printf "\t${GREEN}Did you mean: \"${NC}$(getConfigKey "botid")${GREEN}\" ?${NN}" fi - [[ ! "${BOTTOKEN}" =~ :[${azAZ09}_-]{35}$ ]] &&\ + [[ ! "${BOTTOKEN}" =~ :[${azAZo9}_-]{35}$ ]] &&\ printf "${GREY}\tHint: Hash contains invalid character or has not len${NC} 35 ${GREY}, hash len is ${NC}$(($(wc -c <<<"${BOTTOKEN#*:}")-1))\n" printf "\n" fi @@ -436,14 +436,14 @@ if ! _exists iconv; then fi TIMEOUT="${BASHBOT_TIMEOUT}" -[[ "$TIMEOUT" =~ ^[${R090909}]+$ ]] || TIMEOUT="20" +[[ "$TIMEOUT" =~ ^[${o9o9o9}]+$ ]] || TIMEOUT="20" # usage: sendJson "chat" "JSON" "URL" sendJson(){ local json chat="" if [ -n "${1}" ]; then chat='"chat_id":'"${1}"',' - [[ "${1}" == *[!${R090909}-]* ]] && chat='"chat_id":"'"${1}"' NAN",' # chat id not a number! + [[ "${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")"'}' @@ -535,7 +535,7 @@ fi # $1 function $2 sleep $3 ... $n arguments sendJsonRetry(){ local retry="${1}"; shift - [[ "${1}" =~ ^\ *[${R090909}.]+\ *$ ]] && sleep "${1}"; shift + [[ "${1}" =~ ^\ *[${o9o9o9}.]+\ *$ ]] && sleep "${1}"; shift printf "%s: RETRY %s %s %s\n" "$(date)" "${retry}" "${1}" "${2:0:60}" case "${retry}" in 'sendJson'*) @@ -1143,7 +1143,7 @@ bot_init() { # check if botconf seems valid printf "${GREEN}This is your bot config:${NN}" sed 's/^/\t/' "${BOTCONFIG}.jssh" | grep -vF '["bot_config_key"]' - if check_token "$(getConfigKey "bottoken")" && [[ "$(getConfigKey "botadmin")" =~ ^[${R090909}]+$ ]]; then + if check_token "$(getConfigKey "bottoken")" && [[ "$(getConfigKey "botadmin")" =~ ^[${o9o9o9}]+$ ]]; then printf "Bot config seems to be valid. Should I make a backup copy? (Y/n) Y\b" read -r ANSWER if [[ -z "${ANSWER}" || "${ANSWER}" =~ ^[^Nn] ]]; then diff --git a/doc/4_expert.md b/doc/4_expert.md index d197256..880988f 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -85,12 +85,12 @@ To work independent of language and bash settings bashbot uses solution 1. and u ```bash azazaz='abcdefghijklmnopqrstuvwxyz' # a-z :lower: AZAZAZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ' # A-Z :upper: -R090909='0123456789' # 0-9 :digit: +o9o9o9='0123456789' # 0-9 :digit: azAZaz="${azazaz}${AZAZAZ}" # a-zA-Z :alpha: -azAZ09="${azAZaz}${R090909}" # a-zA-z0-9 :alnum: +azAZo9="${azAZaz}${o9o9o9}" # a-zA-z0-9 :alnum: # e.g. characters allowed for key in key/value pairs -JSSH_KEYOK="[-${azAZ09},._]" +JSSH_KEYOK="[-${azAZo9},._]" ``` #### Bashbot UTF-8 Support @@ -434,5 +434,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Advanced Use](3_advanced.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v1.21-6-g5f6476d +#### $$VERSION$$ v1.21-7-g0798f1a diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index fed9ea4..d80b094 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.21-6-g5f6476d +#### $$VERSION$$ v1.21-7-g0798f1a # # source from commands.sh to use jsonDB functions # @@ -31,12 +31,12 @@ export JSSH_LOCKNAME=".flock" # for more information see doc/4_expert.md#Character_classes azazaz='abcdefghijklmnopqrstuvwxyz' # a-z :lower: AZAZAZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ' # A-Z :upper: -R090909='0123456789' # 0-9 :digit: +o9o9o9='0123456789' # 0-9 :digit: azAZaz="${azazaz}${AZAZAZ}" # a-zA-Z :alpha: -azAZ09="${azAZaz}${R090909}" # a-zA-z0-9 :alnum: +azAZo9="${azAZaz}${o9o9o9}" # a-zA-z0-9 :alnum: # characters allowed for key in key/value pairs -JSSH_KEYOK="[-${azAZ09},._]" +JSSH_KEYOK="[-${azAZo9},._]" # read string from stdin and and strip invalid characters # $1 - invalid charcaters are replaced with first character From 8162695451b6b2fc94585082feaf15b99c9407ee Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 16:37:54 +0100 Subject: [PATCH 09/98] mycommands: set custom locale, explain LC_COLLATE --- commands.sh | 5 ++--- mycommands.sh | 19 +++++++++++++++++-- mycommands.sh.clean | 16 +++++++++++++++- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/commands.sh b/commands.sh index 6d76673..cad0010 100644 --- a/commands.sh +++ b/commands.sh @@ -15,11 +15,10 @@ # 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-0-gd310805 # -# adjust your language setting here, e.g. when run from other user or cron. -# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment +# bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed export 'LC_ALL=C.UTF-8' export 'LANG=C.UTF-8' export 'LANGUAGE=C.UTF-8' diff --git a/mycommands.sh b/mycommands.sh index e5acad7..99c8d72 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -9,10 +9,25 @@ # #### mycommands.clean # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-0-gd310805 # -# uncomment the following lines to overwrite info and help messages +########## +# adjust your language setting here, default is C.UTF-8 +# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment +export 'LC_ALL=C.UTF-8' +export 'LANG=C.UTF-8' +export 'LANGUAGE=C.UTF-8' + +########## +# in UTF-8 äöü etc. are part of [:alnum:] and ranges (e.g. a-z) +# for more information see doc/4_expert.md#Character_classes +# uncomment next line if you want classic ASCII ranges for [a-z] etc. +#export LC_COLLATE=C + + +########## +# edit the following lines to fit your bot usage # use ${ME} for current bot name in messages # Note: you must escape '_' in botname with two \ in markdown messages! export bashbot_info='This is @'"${ME//_/\\\\_}"', the Telegram example bot written entirely in bash. diff --git a/mycommands.sh.clean b/mycommands.sh.clean index f8abce8..eae37af 100644 --- a/mycommands.sh.clean +++ b/mycommands.sh.clean @@ -4,9 +4,23 @@ # files: mycommands.sh.clean # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-0-gd310805 # +########## +# adjust your language setting here, default is C.UTF-8 +# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment +export 'LC_ALL=C.UTF-8' +export 'LANG=C.UTF-8' +export 'LANGUAGE=C.UTF-8' + +########## +# in UTF-8 äöü etc. are part of [:alnum:] and ranges (e.g. a-z) +# for more information see doc/4_expert.md#Character_classes +# uncomment next line if you want classic ASCII ranges for [a-z] etc. +#export LC_COLLATE=C + + ########## # edit the following lines to fit your bot usage From 0d678f4234b3fe39065c2ce3f02f66990b976e2d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 17:00:55 +0100 Subject: [PATCH 10/98] doc: unify use of locale, range and utf --- doc/4_expert.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/4_expert.md b/doc/4_expert.md index 880988f..6166183 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -38,10 +38,10 @@ export 'LANGUAGE=en_US.UTF-8' #### Known locale pitfalls -##### Missing locale C +##### Missing C locale -Even required by POSIX standard some systems (e.g. Manjaro Linux) has no locale `C` and `C.UTF-8` installed. -If bashbot display a warning about missing locale you must install locale `C` and `C.UTF-8`. +Even required by POSIX standard some systems (e.g. Manjaro Linux) has `C` and `C.UTF-8` locale not installed. +If bashbot display a warning about missing locale you must install `C` and `C.UTF-8` locale. If you don't know what locales are installed on your sytsem use `locale -a` to display them. [Gentoo Wiki](https://wiki.gentoo.org/wiki/UTF-8). @@ -50,9 +50,9 @@ If you don't know what locales are installed on your sytsem use `locale -a` to d ##### Character classes In ASCII times it was clear `[:lower:]` and `[a-z]` means ONLY the lowercase letters `[abcd...xyz]`. -With introdution of locales character classes and ranges contains every character fitting the class definition. +With introdution of localesi, character classes and ranges contains all charatcers fitting the class definition. -This means for UTF-8 locales `[:lower:]` and `[a-z]` contains ALL lowercase letters, e.g. `á ø ü` also, +This means with a Latin UTF-8 locale `[:lower:]` and `[a-z]` contains also e.g. `á ø ü` etc, see [Unicode Latin lowercase letters](https://www.fileformat.info/info/unicode/category/Ll/list.htm) If that's ok for your script your'e fine, but many scripts rely on the idea of ASCII ranges and may produce undesired results. @@ -63,7 +63,7 @@ If that's ok for your script your'e fine, but many scripts rely on the idea of A bash lower="abcö" -echo "$LC_ALL" +echo "$LC_ALL $LC_COLLATE" [[ "$lower" =~ ^[a-z]+$ ]] && echo "Ups, $lower is all lower case!" || echo "OK, not lower case" LC_ALL="en_US.UTF-8" @@ -80,7 +80,7 @@ There are three solutions: 3. use `LC_COLLATE` to change behavior of all programs: `export LC_COLLATE=C` -To work independent of language and bash settings bashbot uses solution 1. and uses own "classes" if an exact match is mandatory: +To work independent of language and bash settings bashbot uses solution 1.: Own "ranges" if an exact match is mandatory: ```bash azazaz='abcdefghijklmnopqrstuvwxyz' # a-z :lower: @@ -434,5 +434,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Advanced Use](3_advanced.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v1.21-7-g0798f1a +#### $$VERSION$$ v1.25-dev-1-g8162695 From 53c107d4eeeec7fa8b66e7f275185513327c1913 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 20:51:13 +0100 Subject: [PATCH 11/98] doc: adjust installation / update instructions --- doc/0_install.md | 76 +++++++++++++++++++++++------------------------- doc/4_expert.md | 4 +-- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/doc/0_install.md b/doc/0_install.md index 66eb0d0..9fc6ab2 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -2,7 +2,7 @@ ## Check bash installation -There may systems where bash seems to be installed but it is not, e.g. embedded systems, or where bash is to old. +There may systems where bash seems to be installed but it is not (e.g. embedded systems_) or where bash is to old. Bashbot has some builtin checks but it may better to check before installing bashbot. Run the following commands to see if your bash looks ok ... @@ -15,7 +15,7 @@ if which bash; then echo "bash seems available..."; else echo "NO bash"; fi bash -c 'if eval "a[1]=1"; then echo "Shell support arrays..."; else echo "Shell has NO arrays"; fi' # check for bash version by feature -bash -c 'if [ "$(echo -e "\u1111")" != "\u1111" ]; then echo "Bash version ok ..."; else echo "Bash version may to old ..."; fi' +bash -c 'if [ "$(LANG=C.UTF-8 echo -e "\u1111")" != "\u1111" ]; then echo "Bash version ok ..."; else echo "Bash version may to old ..."; fi' # display bash version, must be greater than 4.3 bash --version | grep "bash" @@ -23,58 +23,59 @@ bash --version | grep "bash" ## Install bashbot -1. Go to the directory you want to install bashbot, e.g. - * your $HOME directory (install and run with your user-ID) - * /usr/local if you want to run as service -2. [Download latest release zip / tar archive from github](https://github.com/topkecleon/telegram-bot-bash/releases/latest) and extract all files. +Installing bashbot is very simple: Download and extract the installation archive. + +1. Choose a directory to install bashbot (_e.g.your HOME or /usr/local_) +2. Download [latest release zip / tar archive] (https://github.com/topkecleon/telegram-bot-bash/releases/latest) and extract all files. 3. Change into the directory `telegram-bot-bash` 4. Copy `mycommands.sh.dist` or `mycommands.sh.clean` to `mycommands.sh` -5. Run `./bashbot.sh init` to setup the environment and enter your Bots token given by botfather. +5. Run `./bashbot.sh init`\* to setup the environment and enter your Bots token given by botfather. Edit `mycommands.sh` to fit your needs. Now your Bot is ready to start ... -**If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots)** +*If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots)* +\* _Run with sudo if you want to run bashbot from different user, e.g. from `bashbot.rc`._ ### Update bashbot -**Important: all files including `mycommands.sh` may overwritten, make a backup!** +Update bashbot is almost identical to installing bashbot: Download and extract the installation archive. -1. Go to the directory where you have installed bashbot, e.g. - * your $HOME directory - * /usr/local -2. [Download latest release zip / tar archive from github](https://github.com/topkecleon/telegram-bot-bash/releases/latest) +**Important: All files may overwritten, make a backup!** + +1. Go to the directory where bashbot is installed (_e.g.$HOME/telegram-bot-bash or /usr/local/telegram-bot-bash_) +2. Download [latest release zip / tar archive](https://github.com/topkecleon/telegram-bot-bash/releases/latest) 3. Stop all running instances of bashbot `./bashbot.sh stop` -4. Extract all files to your existing bashbot dir -5. Run `sudo ./bashbot.sh init` to setup your environment after the update +4. Change to parent directory of bashbot installation and extract all files from archive. +5. Run `./bashbot.sh init`\* to setup your environment after the update +6. Restart your bot `./bashbot.sh start` -If you modified `commands.sh` move your changes to `mycommands.sh`, this avoids overwriting your commands on every update. - -Now you can restart your bashbot instances. +`mycommands.sh` will not overwritten, this avoids losing your bot commands on updates. *Note*: If you are updating from a pre-1.0 version, update to [Version 1.20](https://github.com/topkecleon/telegram-bot-bash/releases/tags/v1.20) first! -### Use JSON.awk (beta) +### Use JSON.awk [JSON.awk](https://github.com/step-/JSON.awk) is an awk port of `JSON.sh`, it provides the same functionality but is 5 times faster. -Most systems with awk can use `JSON.awk` as drop in replacement +On most systems you can use `JSON.awk` with system default awk installation. ( [gnu awk, posix awk, mawk, busybox akw](https://github.com/step-/JSON.awk#compatibility-with-awk-implementations) ). +After you have checked that `JSON.awk.dist` is working on your system copy it to `JSON.awk` and (re)start bashbot. + BSD and MacOS users must install `gnu awk` and adjust the shebang, see below -After you have checked that `JSON.awk.dist` is working correct on your system copy it to `JSON.awk` and (re)start bashbot. - -Note: If you are not using the zip / tar archive, you must install `JSON.awk` manually into the same directory as `JSON.sh`: +*Note*: To install or update `JSON.awk` manually execute the following commands in the directory `JSON.sh/`: wget https://cdn.jsdelivr.net/gh/step-/JSON.awk/JSON.awk wget https://cdn.jsdelivr.net/gh/step-/JSON.awk/tool/patch-for-busybox-awk.sh bash patch-for-busybox-awk.sh + chmod +x JSON.awk ### Install bashbot from git repo -Installation and Updates should be done using the zip / tar archives provided on github to avoid +Installation and updates should be done using the zip / tar archives provided on github to avoid problems and not overwriting your bot config and `mycommands.sh`. Nevertheless you can install or update bashbot from a git repo, see next chapter ... @@ -82,7 +83,8 @@ Nevertheless you can install or update bashbot from a git repo, see next chapter ### Create Installation / Update archives -To install or update bashbot from git repo execute `dev/make-distribution.sh`, this creates the archives and set up bashbot to run in `DIST/telegram.bot-bash`. +To install or update bashbot from git repo execute `dev/make-distribution.sh`. +This creates the installation archives in `DIST/` and a ready to run test installation in `DIST/telegram.bot-bash`. *Note:* You should be familiar with `git`. @@ -92,10 +94,12 @@ To install or update bashbot from git repo execute `dev/make-distribution.sh`, t 4. Run ` dev/make-distribution.sh` (_add --notest to skip tests_) 5. Change to dir `DIST/` -Use the archives created in `DIST/` to install or update bashbot as described above. +Use the installation archives to install or update bashbot as described above. To run a test bot, e.g. while development or testing latest changes, you can use the bashbot installation provided in `DIST/telegram-bot-bash`. -To update the test installation, e.g. after git pull, local changes or switch master/develop, run `dev/make-distrubition.sh` again. +To update\* the test installation (_after git pull, local changes or switch master/develop_) run `dev/make-distrubition.sh` again. + +\* _`mycommands.sh` and `bashbot.rc` will be overwritten._ ### Note for BSD and MacOS @@ -104,18 +108,14 @@ To update the test installation, e.g. after git pull, local changes or switch ma see e.g. [Install Bash on Mac](http://macappstore.org/bash/) **On BSD and MacOS** I recommend to install gnu coreutils and include them in your PATH -environment variable before running bashbot, e.g. the gnu versions of sed, grep, find ... +environment variable before running bashbot, e.g. the gnu versions of sed, grep, find, awk ... -On BSD and MacOS you must adjust the shebang line of the scripts ```bashbot.sh``` and ```json.sh``` to point to to the correct bash -or use the script: ```examples/bash2env *.sh */*.sh``` to convert them for you. +On BSD and MacOS you must adjust the shebang line of the scripts `bashbot.sh` and `json.sh` to point to to the correct bash +or use the script: `examples/bash2env *.sh */*.sh` to convert them for you. -Bashbot will stay with /bin/bash shebang, as using a fixed path is more secure than the portable /usr/bin/env variant, see -[Security Considerations](../README.md#Security-Considerations) +Bashbot will stay with `#!/bin/bash` shebang, as using a fixed path is IMHO more secure than the portable '!/usr/bin/env bash` variant. -I considered to make bashbot BSD sed compatible, but much of the bashbot "magic" relies on -(gnu) sed features, e.g. alternation ```|```, non printables ```\n\t\<``` or repeat ```?+``` pattern, not supported by BSD sed. - -BSD/MacOS sed compatibility will result in a rewrite of all grep/sed commands with an uncertain outcome, +Compatibility with BSD/MacOS will result in a rewrite of all grep/sed commands with an uncertain outcome, see [BSD/MacOS vs. GNU sed](https://riptutorial.com/sed/topic/9436/bsd-macos-sed-vs--gnu-sed-vs--the-posix-sed-specification) to get an impression how different they are. @@ -127,9 +127,7 @@ to get an impression how different they are. From Version 1.21 on updating from a pre-1.0 version (_no \*.jssh config_) is no more supported! You must update to [Version 1.20](https://github.com/topkecleon/telegram-bot-bash/releases/tags/v1.20) first! - - #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-2-g0d678f4 diff --git a/doc/4_expert.md b/doc/4_expert.md index 6166183..1404470 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -50,7 +50,7 @@ If you don't know what locales are installed on your sytsem use `locale -a` to d ##### Character classes In ASCII times it was clear `[:lower:]` and `[a-z]` means ONLY the lowercase letters `[abcd...xyz]`. -With introdution of localesi, character classes and ranges contains all charatcers fitting the class definition. +With introdution of locales, character classes and ranges contains all characters fitting the class definition. This means with a Latin UTF-8 locale `[:lower:]` and `[a-z]` contains also e.g. `á ø ü` etc, see [Unicode Latin lowercase letters](https://www.fileformat.info/info/unicode/category/Ll/list.htm) @@ -434,5 +434,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Advanced Use](3_advanced.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v1.25-dev-1-g8162695 +#### $$VERSION$$ v1.25-dev-2-g0d678f4 From 63379de77b974a8a46a500d30a1f66354c5e8e7d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 20:55:20 +0100 Subject: [PATCH 12/98] doc: fix missing _ --- doc/0_install.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/0_install.md b/doc/0_install.md index 9fc6ab2..203ec27 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -2,7 +2,7 @@ ## Check bash installation -There may systems where bash seems to be installed but it is not (e.g. embedded systems_) or where bash is to old. +There may systems where bash seems to be installed but it is not (_e.g. embedded systems_) or where bash is to old. Bashbot has some builtin checks but it may better to check before installing bashbot. Run the following commands to see if your bash looks ok ... From a5aa7565961973349ce9a57752548b014982d70c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 21:00:41 +0100 Subject: [PATCH 13/98] doc: fix missing _ --- doc/0_install.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/0_install.md b/doc/0_install.md index 203ec27..6e26d92 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -26,7 +26,7 @@ bash --version | grep "bash" Installing bashbot is very simple: Download and extract the installation archive. 1. Choose a directory to install bashbot (_e.g.your HOME or /usr/local_) -2. Download [latest release zip / tar archive] (https://github.com/topkecleon/telegram-bot-bash/releases/latest) and extract all files. +2. Download [latest release zip / tar archive](https://github.com/topkecleon/telegram-bot-bash/releases/latest) and extract all files. 3. Change into the directory `telegram-bot-bash` 4. Copy `mycommands.sh.dist` or `mycommands.sh.clean` to `mycommands.sh` 5. Run `./bashbot.sh init`\* to setup the environment and enter your Bots token given by botfather. @@ -129,5 +129,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-2-g0d678f4 +#### $$VERSION$$ v1.25-dev-3-g53c107d From 641727dc99b19104059935d416b5ccf5a3471452 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 4 Jan 2021 23:08:09 +0100 Subject: [PATCH 14/98] fix missing ${xxx} warnings --- addons/antiFlood.sh | 12 ++--- bashbot.sh | 72 ++++++++++++++-------------- commands.sh | 4 +- examples/notify.sh | 4 +- examples/question.sh | 4 +- modules/answerInline.sh | 44 ++++++++--------- modules/background.sh | 4 +- modules/chatMember.sh | 20 ++++---- modules/sendMessage.sh | 103 ++++++++++++++++++++-------------------- mycommands.sh | 44 ++++++++--------- 10 files changed, 155 insertions(+), 156 deletions(-) diff --git a/addons/antiFlood.sh b/addons/antiFlood.sh index b014341..616d938 100644 --- a/addons/antiFlood.sh +++ b/addons/antiFlood.sh @@ -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.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-5-ga5aa756 # used events: # @@ -37,7 +37,7 @@ ANTIFL_BAN="5" # 5 minutes # initialize after installation or update if [[ "$1" = "init"* ]]; then - jssh_newDB "addons/$ANTIFL_ME" + jssh_newDB "addons/${ANTIFL_ME}" fi @@ -46,7 +46,7 @@ fi if [[ "$1" = "start"* ]]; then ANTIFL_ADMIN="$(getConfigKey "botadmin")" #load existing chat settings on start - jssh_readDB "ANTIFL_CHATS" "addons/$ANTIFL_ME" + jssh_readDB "ANTIFL_CHATS" "addons/${ANTIFL_ME}" # register to CMD BASHBOT_EVENT_CMD["${ANTIFL_ME}"]="${ANTIFL_ME}_cmd" @@ -71,14 +71,14 @@ if [[ "$1" = "start"* ]]; then "/afdo" | "/afactive") [[ "${CMD[1]}" =~ ^[-0-9]+$ ]] && user_is_botadmin "${USER[ID]}" && chat="$3" 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}" & ;; # command /afactive starts counter meausares "/afstop") [[ "${CMD[1]}" =~ ^[-0-9]+$ ]] && user_is_botadmin "${USER[ID]}" && chat="$3" 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}" & ;; esac @@ -90,7 +90,7 @@ if [[ "$1" = "start"* ]]; then # save settings and reset flood level every BAN Min antiFlood_timer(){ ANTIFL_ACTUALS=( ) - jssh_writeDB "ANTIFL_CHATS" "addons/$ANTIFL_ME" & + jssh_writeDB "ANTIFL_CHATS" "addons/${ANTIFL_ME}" & } # register to inline and command diff --git a/bashbot.sh b/bashbot.sh index 8838091..5c8ab7e 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.21-7-g0798f1a +#### $$VERSION$$ v1.25-dev-5-ga5aa756 ################################################################## # emmbeded system may claim bash but it is not @@ -42,7 +42,7 @@ fi # are we running in a terminal? NN="\n" -if [ -t 1 ] && [ -n "$TERM" ]; then +if [ -t 1 ] && [ -n "${TERM}" ]; then INTERACTIVE='yes' RED='\e[31m' GREEN='\e[32m' @@ -150,13 +150,13 @@ MODULEDIR="${SCRIPTDIR}/modules" # adjust locations based on source and real name [[ "${SCRIPT}" != "${REALME}" || "$1" == "source" ]] && SOURCE="yes" -if [ -n "$BASHBOT_HOME" ]; then - SCRIPTDIR="$BASHBOT_HOME" +if [ -n "${BASHBOT_HOME}" ]; then + SCRIPTDIR="${BASHBOT_HOME}" else BASHBOT_HOME="${SCRIPTDIR}" fi -[ -z "${BASHBOT_ETC}" ] && BASHBOT_ETC="$BASHBOT_HOME" -[ -z "${BASHBOT_VAR}" ] && BASHBOT_VAR="$BASHBOT_HOME" +[ -z "${BASHBOT_ETC}" ] && BASHBOT_ETC="${BASHBOT_HOME}" +[ -z "${BASHBOT_VAR}" ] && BASHBOT_VAR="${BASHBOT_HOME}" ADDONDIR="${BASHBOT_ETC:-.}/addons" RUNUSER="${USER}" # USER is overwritten by bashbot array :-(, save original @@ -169,16 +169,16 @@ case "$1" in exit;; "help") HELP="${BASHBOT_HOME:-.}/README" if [ -n "${INTERACTIVE}" ];then - _exists w3m && w3m "$HELP.html" && exit - _exists lynx && lynx "$HELP.html" && exit - _exists less && less "$HELP.txt" && exit + _exists w3m && w3m "${HELP}.html" && exit + _exists lynx && lynx "${HELP}.html" && exit + _exists less && less "${HELP}.txt" && exit fi - cat "$HELP.txt" + cat "${HELP}.txt" exit;; esac # 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}" exit 1 fi @@ -301,10 +301,10 @@ fi BASHBOT_RETRY="" # retry by default URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}" -ME_URL=$URL'/getMe' +ME_URL=${URL}'/getMe' -UPD_URL=$URL'/getUpdates?offset=' -GETFILE_URL=$URL'/getFile' +UPD_URL=${URL}'/getUpdates?offset=' +GETFILE_URL=${URL}'/getFile' ################# # BASHBOT COMMON functions @@ -351,8 +351,8 @@ fi # outputs final filename download() { local empty="no.file" file="${2:-${empty}}" - if [[ "$file" = *"/"* ]] || [[ "$file" = "."* ]]; then file="${empty}"; fi - while [ -f "${DATADIR:-.}/${file}" ] ; do file="$RAMDOM-${file}"; done + if [[ "${file}" = *"/"* ]] || [[ "${file}" = "."* ]]; then file="${empty}"; fi + while [ -f "${DATADIR:-.}/${file}" ] ; do file="${RANDOM}-${file}"; done getJson "$1" >"${DATADIR:-.}/${file}" || return printf '%s\n' "${DATADIR:-.}/${file}" } @@ -386,7 +386,7 @@ killallproc() { # $ chat $2 msg_id $3 nolog -declare -xr DELETE_URL=$URL'/deleteMessage' +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}" @@ -435,8 +435,8 @@ if ! _exists iconv; then function iconv() { cat; } fi -TIMEOUT="${BASHBOT_TIMEOUT}" -[[ "$TIMEOUT" =~ ^[${o9o9o9}]+$ ]] || TIMEOUT="20" +TIMEOUT="${BASHBOT_TIMEOUT:-20}" +[[ "${TIMEOUT}" =~ ^[${o9o9o9}]+$ ]] || TIMEOUT="20" # usage: sendJson "chat" "JSON" "URL" sendJson(){ @@ -644,7 +644,7 @@ title2Json(){ # get bot name and id from telegram getBotName() { 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 # save botname and id setConfigKey "botname" "${BOTARRAY["result","username"]}" @@ -657,7 +657,7 @@ getBotName() { JsonDecode() { local out="$1" remain="" U="" 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 )) remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}" out="${BASH_REMATCH[1]}" @@ -683,7 +683,7 @@ process_updates() { max="$(grep -F ',"update_id"]' <<< "${UPDATE}" | tail -1 | cut -d , -f 2 )" Json2Array 'UPD' <<<"${UPDATE}" for ((num=0; num<=max; num++)); do - process_client "$num" "${debug}" + process_client "${num}" "${debug}" done } @@ -731,7 +731,7 @@ process_client() { 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 start_timer(){ @@ -745,7 +745,7 @@ start_timer(){ EVENT_SEND="0" event_send() { # 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 for key in "${!BASHBOT_EVENT_SEND[@]}" do @@ -761,7 +761,7 @@ event_timer() { for key in "${!BASHBOT_EVENT_TIMER[@]}" do timer="${key##*,}" - [[ ! "$timer" =~ ^-*[1-9][0-9]*$ ]] && continue + [[ ! "${timer}" =~ ^-*[1-9][0-9]*$ ]] && continue if [ "$(( EVENT_TIMER % timer ))" = "0" ]; then _exec_if_function "${BASHBOT_EVENT_TIMER[${key}]}" "timer" "${key}" "${debug}" [ "$(( EVENT_TIMER % timer ))" -lt "0" ] && \ @@ -1041,7 +1041,7 @@ start_bot() { # start timer events if [ -n "${BASHBOT_START_TIMER}" ] ; then # shellcheck disable=SC2064 - trap "event_timer $DEBUGMSG" ALRM + trap "event_timer ${DEBUGMSG}" ALRM start_timer & # shellcheck disable=SC2064 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++)) - if [ "$OFFSET" != "1" ]; then + if [ "${OFFSET}" != "1" ]; then nextsleep="100" process_updates "${DEBUGMSG}" fi @@ -1113,22 +1113,22 @@ bot_init() { printf "Done.\n" # setup bashbot [[ "${UID}" -eq "0" ]] && RUNUSER="nobody" - printf "Enter User to run bashbot [$RUNUSER]: " + printf "Enter User to run bashbot [${RUNUSER}]: " read -r TOUSER - [ -z "$TOUSER" ] && TOUSER="$RUNUSER" - if ! id "$TOUSER" &>/dev/null; then - printf "${RED}User \"$TOUSER\" not found!${NN}" + [ -z "${TOUSER}" ] && TOUSER="${RUNUSER}" + if ! id "${TOUSER}" &>/dev/null; then + printf "${RED}User \"${TOUSER}\" not found!${NN}" exit 3 else 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 -R o-w ./* 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 # jsshDB must writeable by owner find . -name '*.jssh*' -exec chmod u+w \{\} + - chown -R "$TOUSER" . ./* + chown -R "${TOUSER}" . ./* printf "Done.\n" fi # ask to check bottoken online @@ -1187,7 +1187,7 @@ if [ -z "${SOURCE}" ]; then else printf "${GREY}Info: Can't get Botname from Telegram, try cached one ...${NN}" ME="$(getConfigKey "botname")" - if [ -z "$ME" ]; then + if [ -z "${ME}" ]; then printf "${RED}ERROR: No cached botname, can't continue! ...${NN}" exit 1 fi @@ -1202,7 +1202,7 @@ if [ -z "${SOURCE}" ]; then ME="$(getConfigKey "botname")" # read until terminated while read -r line ;do - [ -n "$line" ] && send_message "$2" "$line" + [ -n "${line}" ] && send_message "$2" "${line}" done # cleanup datadir, keep logfile if not empty rm -f -r "${DATADIR:-.}/$3" @@ -1256,7 +1256,7 @@ if [ -z "${SOURCE}" ]; then BOTPID="$(proclist "${SESSION}")" # shellcheck disable=SC2086 [ -n "${BOTPID}" ] && kill ${BOTPID} - nohup "$SCRIPT" "startbot" "$2" "${SESSION}" &>/dev/null & + nohup "${SCRIPT}" "startbot" "$2" "${SESSION}" &>/dev/null & printf "Session Name: %s\n" "${SESSION}" sleep 1 if [ -n "$(proclist "${SESSION}")" ]; then diff --git a/commands.sh b/commands.sh index cad0010..dbb5ce8 100644 --- a/commands.sh +++ b/commands.sh @@ -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-0-gd310805 +#### $$VERSION$$ v1.25-dev-5-ga5aa756 # # 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 # detect inline commands.... # 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 _exec_if_function myinlines diff --git a/examples/notify.sh b/examples/notify.sh index 2cc2678..a1e1864 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -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.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-5-ga5aa756 ######################################################################## ###### @@ -47,6 +47,6 @@ printf "Output time every %s seconds ...\n" "${SLEEP}" while true do date "+* It's %k:%M:%S o'clock ..." - sleep $SLEEP + sleep "${SLEEP}" done diff --git a/examples/question.sh b/examples/question.sh index 17479b0..5981f2a 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -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.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-5-ga5aa756 ######################################################################## ###### @@ -39,7 +39,7 @@ else fi # 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' read -r answer <"${INPUT}" case ${answer,,} in diff --git a/modules/answerInline.sh b/modules/answerInline.sh index 83534da..636fb4d 100644 --- a/modules/answerInline.sh +++ b/modules/answerInline.sh @@ -5,17 +5,17 @@ # 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-5-ga5aa756 # will be automatically sourced from bashbot # source once magic, function named like file eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" -INLINE_QUERY=$URL'/answerInlineQuery' +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}" @@ -33,70 +33,70 @@ inline_query_compose(){ 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")'}' + JSON='{"type":"article","id":"'${ID}'","input_message_content": {"message_text":"'$4'"} '$(title2Json "$3" "" "$5" "$6" "$7")'}' ;; "photo") # photo ID photoURL (thumbURL title description caption) [ -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) [ -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) [ -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) - 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) - 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) - 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) - 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 - 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) [ -z "$6" ] && addr="$5" [ -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) [ -n "$5" ] && last=',"last_name":"'$5'"' [ -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 # Cached media stored in Telegram server "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) - 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) - 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 - 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) - 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) - 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) - 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) - 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 diff --git a/modules/background.sh b/modules/background.sh index 5e0513b..7b83af4 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117,SC2059 -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-5-ga5aa756 # 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}" 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" & } diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 4f23645..796da8b 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,36 +5,36 @@ # 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-5-ga5aa756 # will be automatically sourced from bashbot # source once magic, function named like file eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" -LEAVE_URL=$URL'/leaveChat' -KICK_URL=$URL'/kickChatMember' -UNBAN_URL=$URL'/unbanChatMember' -GETMEMBER_URL=$URL'/getChatMember' +LEAVE_URL=${URL}'/leaveChat' +KICK_URL=${URL}'/kickChatMember' +UNBAN_URL=${URL}'/unbanChatMember' +GETMEMBER_URL=${URL}'/getChatMember' # usage: status="$(get_chat_member_status "chat" "user")" # $1 chat # $2 user get_chat_member_status() { - sendJson "$1" '"user_id":'"$2"'' "$GETMEMBER_URL" + sendJson "$1" '"user_id":'"$2"'' "${GETMEMBER_URL}" # shellcheck disable=SC2154 - JsonGetString '"result","status"' <<< "$res" + JsonGetString '"result","status"' <<< "${res}" } kick_chat_member() { - sendJson "$1" 'user_id: '"$2"'' "$KICK_URL" + sendJson "$1" 'user_id: '"$2"'' "${KICK_URL}" } unban_chat_member() { - sendJson "$1" 'user_id: '"$2"'' "$UNBAN_URL" + sendJson "$1" 'user_id: '"$2"'' "${UNBAN_URL}" } leave_chat() { - sendJson "$1" "" "$LEAVE_URL" + sendJson "$1" "" "${LEAVE_URL}" } user_is_creator() { diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index e5ef612..2f56287 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-5-ga5aa756 # will be automatically sourced from bashbot @@ -15,19 +15,19 @@ eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" # source from commands.sh to use the sendMessage functions -MSG_URL=$URL'/sendMessage' -EDIT_URL=$URL'/editMessageText' -PHO_URL=$URL'/sendPhoto' -AUDIO_URL=$URL'/sendAudio' -DOCUMENT_URL=$URL'/sendDocument' -STICKER_URL=$URL'/sendSticker' -VIDEO_URL=$URL'/sendVideo' -VOICE_URL=$URL'/sendVoice' -LOCATION_URL=$URL'/sendLocation' -VENUE_URL=$URL'/sendVenue' -ACTION_URL=$URL'/sendChatAction' -FORWARD_URL=$URL'/forwardMessage' -ALBUM_URL=$URL'/sendMediaGroup' +MSG_URL=${URL}'/sendMessage' +EDIT_URL=${URL}'/editMessageText' +PHO_URL=${URL}'/sendPhoto' +AUDIO_URL=${URL}'/sendAudio' +DOCUMENT_URL=${URL}'/sendDocument' +STICKER_URL=${URL}'/sendSticker' +VIDEO_URL=${URL}'/sendVideo' +VOICE_URL=${URL}'/sendVoice' +LOCATION_URL=${URL}'/sendLocation' +VENUE_URL=${URL}'/sendVenue' +ACTION_URL=${URL}'/sendChatAction' +FORWARD_URL=${URL}'/forwardMessage' +ALBUM_URL=${URL}'/sendMediaGroup' # # send/edit message variants ------------------ @@ -106,7 +106,7 @@ _markdownv2_message_url() { 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")" + text="$(sed -E -e 's|([_|~`>+=#{}()!.-])|\\\1|g' <<< "${text}")" until [ -z "${text}" ]; do sendJson "${1}" '"text":"'"${text:0:4096}"'"'"${3}"'' "${4}" text="${text:4096}" @@ -126,7 +126,7 @@ send_keyboard() { 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" + sendJson "${1}" "${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"'}' "${MSG_URL}" # '"text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true}' } @@ -137,7 +137,7 @@ remove_keyboard() { 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" #JSON='"text":"$2", "reply_markup": {"remove_keyboard":true}' @@ -146,7 +146,7 @@ remove_keyboard() { # $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" + 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 @@ -192,7 +192,7 @@ send_file() { if [ "${err}" != "0" ]; then BOTSENT=() BOTSENT[OK]="false" - case "$err" in + case "${err}" in 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} ";; 3) if [[ "$2" == "/"* ]];then @@ -208,63 +208,62 @@ send_file() { upload_file(){ local CUR_URL WHAT STATUS text=$3 file="$2" # file access checks ... - [[ "$file" = *'..'* ]] && return 1 # no directory traversal - [[ "$file" = '.'* ]] && return 1 # no hidden or relative files - if [[ "$file" = '/'* ]] ; then - [[ ! "$file" =~ ${FILE_REGEX} ]] && return 2 # absolute must match REGEX + [[ "${file}" = *'..'* ]] && return 1 # no directory traversal + [[ "${file}" = '.'* ]] && return 1 # no hidden or relative files + if [[ "${file}" = '/'* ]] ; then + [[ ! "${file}" =~ ${FILE_REGEX} ]] && return 2 # absolute must match REGEX else file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # othiers must be in UPLOADDIR 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 $ext in + case "${file##*.}" in mp3|flac) - CUR_URL="$AUDIO_URL" + CUR_URL="${AUDIO_URL}" WHAT="audio" STATUS="upload_audio" ;; png|jpg|jpeg|gif|pic) - CUR_URL="$PHO_URL" + CUR_URL="${PHO_URL}" WHAT="photo" STATUS="upload_photo" ;; webp) - CUR_URL="$STICKER_URL" + CUR_URL="${STICKER_URL}" WHAT="sticker" STATUS="upload_photo" ;; mp4) - CUR_URL="$VIDEO_URL" + CUR_URL="${VIDEO_URL}" WHAT="video" STATUS="upload_video" ;; ogg) - CUR_URL="$VOICE_URL" + CUR_URL="${VOICE_URL}" WHAT="voice" STATUS="upload_audio" ;; *) - CUR_URL="$DOCUMENT_URL" + CUR_URL="${DOCUMENT_URL}" WHAT="document" 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 @@ -272,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}" } @@ -283,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 @@ -308,35 +307,35 @@ send_message() { 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" + if [ -n "${no_keyboard}" ]; then + remove_keyboard "$1" "${text}" sent=y fi - if [ -n "$keyboard" ]; then - if [[ "$keyboard" != *"["* ]]; then # pre 0.60 style + if [ -n "${keyboard}" ]; then + if [[ "${keyboard}" != *"["* ]]; then # pre 0.60 style keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]" fi - send_keyboard "$1" "$text" "$keyboard" + send_keyboard "$1" "${text}" "${keyboard}" sent=y fi - if [ -n "$btext" ] && [ -n "$burl" ]; then - send_button "$1" "$text" "$btext" "$burl" + if [ -n "${btext}" ] && [ -n "${burl}" ]; then + send_button "$1" "${text}" "${btext}" "${burl}" sent=y fi - if [ -n "$file" ]; then - send_file "$1" "$file" "$text" + if [ -n "${file}" ]; then + send_file "$1" "${file}" "${text}" sent=y fi - if [ -n "$lat" ] && [ -n "$long" ]; then - if [ -n "$address" ] && [ -n "$title" ]; then - send_venue "$1" "$lat" "$long" "$title" "$address" + if [ -n "${lat}" ] && [ -n "${long}" ]; then + if [ -n "${address}" ] && [ -n "${title}" ]; then + send_venue "$1" "${lat}" "${long}" "${title}" "${address}" else - send_location "$1" "$lat" "$long" + send_location "$1" "${lat}" "${long}" fi sent=y fi - if [ "$sent" != "y" ];then - send_text_mode "$1" "$text" + if [ "${sent}" != "y" ];then + send_text_mode "$1" "${text}" fi } diff --git a/mycommands.sh b/mycommands.sh index 99c8d72..f1eb481 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -9,7 +9,7 @@ # #### mycommands.clean # # 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 '/echo'*) # example echo command - send_normal_message "${CHAT[ID]}" "$MESSAGE" + send_normal_message "${CHAT[ID]}" "${MESSAGE}" ;; '/question'*) # start interactive questions checkproc - if [ "$res" -gt 0 ] ; then + if [ "${res}" -gt 0 ] ; then startproc "examples/question.sh" || send_normal_message "${CHAT[ID]}" "Can't start question." else - send_normal_message "${CHAT[ID]}" "$MESSAGE already running ..." + send_normal_message "${CHAT[ID]}" "${MESSAGE} already running ..." fi ;; '/cancel'*) # cancel interactive command checkproc - if [ "$res" -gt 0 ] ;then + if [ "${res}" -gt 0 ] ;then killproc && send_normal_message "${CHAT[ID]}" "Command canceled." else send_normal_message "${CHAT[ID]}" "No command is currently running." fi ;; '/run_notify'*) # start notify background job - myback="notify"; checkback "$myback" - if [ "$res" -gt 0 ] ; then - background "examples/notify.sh 60" "$myback" || send_normal_message "${CHAT[ID]}" "Can't start notify." + myback="notify"; checkback "${myback}" + if [ "${res}" -gt 0 ] ; then + background "examples/notify.sh 60" "${myback}" || send_normal_message "${CHAT[ID]}" "Can't start notify." else - send_normal_message "${CHAT[ID]}" "Background command $myback already running ..." + send_normal_message "${CHAT[ID]}" "Background command ${myback} already running ..." fi ;; '/stop_notify'*) # kill notify background job - myback="notify"; checkback "$myback" - if [ "$res" -eq 0 ] ; then - killback "$myback" - send_normal_message "${CHAT[ID]}" "Background command $myback canceled." + myback="notify"; checkback "${myback}" + if [ "${res}" -eq 0 ] ; then + killback "${myback}" + send_normal_message "${CHAT[ID]}" "Background command ${myback} canceled." 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 ;; @@ -262,15 +262,15 @@ else ;; "2"*) # two photos 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/4593242") + $(inline_query_compose "${RANDOM}" "photo" "https://avatars.githubusercontent.com/u/13046303"), + $(inline_query_compose "${RANDOM}" "photo" "https://avatars.githubusercontent.com/u/4593242") " ;; "3"*) # three photos 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/4593242") - $(inline_query_compose "$RANDOM" "photo" "https://avatars.githubusercontent.com/u/102707") + $(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/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") answer_inline_multi "${iQUERY[ID]}" " $(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) " ;; @@ -318,10 +318,10 @@ else 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/ Date: Tue, 5 Jan 2021 11:40:28 +0100 Subject: [PATCH 15/98] dev/: fix missing ${xxx} --- dev/all-tests.sh | 12 ++++++------ dev/git-add.sh | 8 ++++---- dev/inject-json.sh | 2 +- dev/install-hooks.sh | 8 ++++---- dev/make-distribution.sh | 19 ++++++++++--------- dev/make-html.sh | 4 ++-- dev/make-standalone.sh | 14 +++++++------- dev/obfuscate.sh | 2 +- dev/version.sh | 8 ++++---- 9 files changed, 39 insertions(+), 38 deletions(-) diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 4923962..e766105 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -5,14 +5,14 @@ # # Description: run all tests, exit after failed test # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-6-g641727d ############################################################# # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "$GIT_DIR" != "" ] ; then - cd "$GIT_DIR/.." || exit 1 +if [ "${GIT_DIR}" != "" ] ; then + cd "${GIT_DIR}/.." || exit 1 else printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 fi @@ -52,7 +52,7 @@ do "${test}" "${TESTENV}" ret=$? set +e - if [ "$ret" -eq 0 ] ; then + if [ "${ret}" -eq 0 ] ; then printf "OK: ---- %s\n" "${test}" passed=$((passed+1)) else @@ -64,7 +64,7 @@ done ########################### # cleanup depending on test state -if [ "$fail" -eq 0 ]; then +if [ "${fail}" -eq 0 ]; then printf 'SUCCESS ' exitcode=0 rm -rf "${TESTENV}" @@ -82,4 +82,4 @@ printf "%s\n\n" "${passed} / ${tests}" ls -ld /tmp/bashbot.test* 2>/dev/null && printf "Do not forget to delete bashbot test files in /tmp!!\n" -exit ${exitcode} +exit "${exitcode}" diff --git a/dev/git-add.sh b/dev/git-add.sh index 1a6f337..b7e2ab7 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,13 +3,13 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-6-g641727d # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "$GIT_DIR" != "" ] ; then - cd "$GIT_DIR/.." || exit 1 +if [ "${GIT_DIR}" != "" ] ; then + cd "${GIT_DIR}/.." || exit 1 else printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 fi @@ -31,7 +31,7 @@ for file in ${FILES} do [ -d "${file}" ] && continue printf "%s" "${file} " - git add "$file" + git add "${file}" done printf " - Done.\n" diff --git a/dev/inject-json.sh b/dev/inject-json.sh index f470500..805ae9e 100644 --- a/dev/inject-json.sh +++ b/dev/inject-json.sh @@ -7,7 +7,7 @@ # # Usage: source inject-json.sh # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-6-g641727d ############################################################## # download JSON.sh diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index d004ec8..e0bd873 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-6-g641727d # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "$GIT_DIR" != "" ] ; then - cd "$GIT_DIR/.." || exit 1 +if [ "${GIT_DIR}" != "" ] ; then + cd "${GIT_DIR}/.." || exit 1 else printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 fi @@ -19,7 +19,7 @@ for hook in pre-commit post-commit pre-push do rm -f "${GIT_DIR}/hooks/${hook}" if [ -f "${HOOKDIR}/${hook}.sh" ]; then - printf "%s"" $hook" + printf "%s"" ${hook}" ln -s "../../${HOOKDIR}/${hook}.sh" "${GIT_DIR}/hooks/${hook}" fi done diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index f67a85b..9ca43d0 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -7,15 +7,15 @@ # # Options: --notest - skip tests # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-6-g641727d ############################################################## # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "$GIT_DIR" != "" ] ; then - [[ "$GIT_DIR" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}" - cd "$GIT_DIR/.." || exit 1 +if [ "${GIT_DIR}" != "" ] ; then + [[ "${GIT_DIR}" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}" + cd "${GIT_DIR}/.." || exit 1 else printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 fi @@ -47,6 +47,7 @@ cp -r ${DISTFILES} "${DISTDIR}" cd "${DISTDIR}" || exit 1 printf "Create directories\n" +# shellcheck disable=SC2250 for dir in $DISTMKDIR do [ ! -d "${dir}" ] && mkdir "${dir}" @@ -62,7 +63,7 @@ done # inject JSON.sh into distribution # shellcheck disable=SC1090 -source "$GIT_DIR/../dev/inject-json.sh" +source "${GIT_DIR}/../dev/inject-json.sh" # make html doc printf "Create html doc\n" @@ -73,13 +74,13 @@ source "../../dev/make-html.sh" cd .. || exit 1 printf "Create dist archives\n" # shellcheck disable=SC2046 -zip -rq - "${DISTNAME}" --exclude $(cat "$GIT_DIR/../dev/${0##*/}.exclude") >"${DISTNAME}-${VERSION}.zip" -tar --exclude-ignore="$GIT_DIR/../dev/${0##*/}.exclude" -czf "${DISTNAME}-${VERSION}.tar.gz" "${DISTNAME}" +zip -rq - "${DISTNAME}" --exclude $(cat "${GIT_DIR}/../dev/${0##*/}.exclude") >"${DISTNAME}-${VERSION}.zip" +tar --exclude-ignore="${GIT_DIR}/../dev/${0##*/}.exclude" -czf "${DISTNAME}-${VERSION}.tar.gz" "${DISTNAME}" printf "%s Done!\n" "$0" # shellcheck disable=SC2086 -ls -ld ${DISTNAME}-${VERSION}.* +ls -ld "${DISTNAME}-${VERSION}".* # an empty DEBUG.log is created ... :-( -rm -f "$GIT_DIR/../test/"*.log +rm -f "${GIT_DIR}/../test/"*.log diff --git a/dev/make-html.sh b/dev/make-html.sh index c8be7e8..70327c5 100644 --- a/dev/make-html.sh +++ b/dev/make-html.sh @@ -7,7 +7,7 @@ # # Usage: source make-hmtl # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-6-g641727d ############################################################## # check for correct dir @@ -36,7 +36,7 @@ else '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\ + 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}' {} \; printf " Done!\n" fi diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index edcf64b..b061f97 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -9,21 +9,21 @@ # 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.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-6-g641727d ################################################################### # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "$GIT_DIR" != "" ] ; then - [[ "$GIT_DIR" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}" - cd "$GIT_DIR/.." || exit 1 +if [ "${GIT_DIR}" != "" ] ; then + [[ "${GIT_DIR}" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}" + cd "${GIT_DIR}/.." || exit 1 else [ ! -f "bashbot.sh" ] && printf "bashbot.sh not found in %s\n" " $(pwd)" && exit 1 fi #DISTNAME="telegram-bot-bash" -DISTDIR="./STANDALONE/${DISTNAME}" +DISTDIR="./STANDALONE" DISTFILES="bashbot.sh bashbot.rc commands.sh mycommands.sh dev/obfuscate.sh modules scripts logs LICENSE README.* doc botacl botconfig.jssh" # run pre_commit on files @@ -37,7 +37,7 @@ cd "${DISTDIR}" || exit 1 # inject JSON.sh into distribution # shellcheck disable=SC1090 -source "$GIT_DIR/../dev/inject-json.sh" +source "${GIT_DIR}/../dev/inject-json.sh" ####################### # here the magic starts @@ -95,7 +95,7 @@ chmod +x bashbot.sh.min # make html doc printf "Create html doc\n" #shellcheck disable=SC1090 -source "$GIT_DIR/../dev/make-html.sh" +source "${GIT_DIR}/../dev/make-html.sh" printf "%s Done!\n" "$0" diff --git a/dev/obfuscate.sh b/dev/obfuscate.sh index 2db4016..aa2470a 100755 --- a/dev/obfuscate.sh +++ b/dev/obfuscate.sh @@ -2,7 +2,7 @@ # # joke hack to obfuscate bashbot.min.sh # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-6-g641727d # shellcheck disable=SC2028,SC2016,SC1117 infile="bashbot.sh" diff --git a/dev/version.sh b/dev/version.sh index eb759d4..580adbb 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-6-g641727d # shellcheck disable=SC2016 # # Easy Versioning in git: @@ -37,8 +37,8 @@ # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "$GIT_DIR" != "" ] ; then - cd "$GIT_DIR/.." || exit 1 +if [ "${GIT_DIR}" != "" ] ; then + cd "${GIT_DIR}/.." || exit 1 else printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 fi @@ -52,7 +52,7 @@ printf "Update to version %s ...\n" "${VERSION}" FILES="$(find ./*)" [ "$1" != "" ] && FILES="$*" -for file in $FILES +for file in ${FILES} do [ ! -f "${file}" ] && continue #[ "${file}" == "version" ] && continue From 248a065be4dd9e40f191485cb011a6141a3e1fbe Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 5 Jan 2021 11:58:30 +0100 Subject: [PATCH 16/98] example/: fix missing ${xxx} --- examples/background-scripts/mycommands.sh | 12 ++++++------ examples/background-scripts/run_diskusage.sh | 10 +++++----- examples/background-scripts/run_filecontent.sh | 4 ++-- examples/background-scripts/run_filename.sh | 4 ++-- examples/background-scripts/run_notify.sh | 8 ++++---- examples/jsonDB-keyboard/mycommands.sh | 6 +++--- examples/send-system-status/mycommands.sh | 12 ++++++------ 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/examples/background-scripts/mycommands.sh b/examples/background-scripts/mycommands.sh index 9a813e4..79bf773 100644 --- a/examples/background-scripts/mycommands.sh +++ b/examples/background-scripts/mycommands.sh @@ -6,12 +6,12 @@ export res # your additional bashbot commands ... mycommands() { - case "$MESSAGE" in + case "${MESSAGE}" in '/run_'*) myback="run_${MESSAGE#*_}" if [ -x "./${myback}.sh" ]; then checkback "${myback}" - if [ "$res" -gt 0 ] ; then + if [ "${res}" -gt 0 ] ; then send_normal_message "${CHAT[ID]}" "Start ${myback}, use /kill${myback} to stop it." background "./${myback}.sh" "${myback}" else @@ -23,7 +23,7 @@ mycommands() { myback="run_${MESSAGE#*_}" if [ -x "./${myback}.sh" ]; then checkback "${myback}" - if [ "$res" -eq 0 ] ; then + if [ "${res}" -eq 0 ] ; then killback "${myback}" send_normal_message "${CHAT[ID]}" "Stopping ${myback}, use /run_${myback} to start again." else @@ -56,7 +56,7 @@ watch_dir_loop() { echo "$(date): new file: ${newfile}" >>"$0.log" # note: loop callback must a function in the calling script! if _is_function loop_callback ; then - loop_callback "$1/$newfile" + loop_callback "$1/${newfile}" else echo "ERROR: loop_callback not found!" >&2 exit 1 @@ -94,8 +94,8 @@ output_file() { sed <<< "${1}" ' s/ *mynewlinestartshere */\n/ s/ my[a-z]\{3,15}\(start\|ends\)here.*//g - ' >"$publish$$" - cat "$publish" >>"$publish$$" + ' >"${publish}$$" + cat "${publish}" >>"${publish}$$" mv "${publish}$$" "${publish}" } # >>"$0.log" 2>&1 diff --git a/examples/background-scripts/run_diskusage.sh b/examples/background-scripts/run_diskusage.sh index eadbfbe..e0d3660 100755 --- a/examples/background-scripts/run_diskusage.sh +++ b/examples/background-scripts/run_diskusage.sh @@ -4,7 +4,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-7-g9ef8778 ###### # parameters @@ -28,8 +28,8 @@ cat >/dev/null & source "./mycommands.sh" # check if $1 is a number -re='^[0-9]+$' -if [[ $1 =~ $re ]] ; then +regex='^[0-9]+$' +if [[ $1 =~ ${regex} ]] ; then SLEEP="$1" else SLEEP=100 # time between time notifications @@ -39,11 +39,11 @@ NEWLINE=$'\n' # output disk usage every $1 seconds WAIT=0 -while sleep $WAIT +while sleep "${WAIT}" do output_telegram "Current Disk usage ${NEWLINE} $(df -h / /tmp /usr /var /home)" # only for testing, delete echo line for production ... echo "Current Disk usage ${NEWLINE} $(df -h / /tmp /usr /var /home)" - WAIT="$SLEEP" + WAIT="${SLEEP}" done diff --git a/examples/background-scripts/run_filecontent.sh b/examples/background-scripts/run_filecontent.sh index 04cbfdd..8194ff9 100755 --- a/examples/background-scripts/run_filecontent.sh +++ b/examples/background-scripts/run_filecontent.sh @@ -2,7 +2,7 @@ # file: run_filename # background job to display content of all new files in WATCHDIR # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-7-g9ef8778 ###### # parameters @@ -40,4 +40,4 @@ loop_callback() { output_telegram "Contents of ${1}: ${NEWLINE} $(cat "${1}")" } -watch_dir_loop "$WATCHDIR" +watch_dir_loop "${WATCHDIR}" diff --git a/examples/background-scripts/run_filename.sh b/examples/background-scripts/run_filename.sh index 1b562e6..fb1a85e 100755 --- a/examples/background-scripts/run_filename.sh +++ b/examples/background-scripts/run_filename.sh @@ -2,7 +2,7 @@ # file: run_filename # background job to display all new files in WATCHDIR # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-7-g9ef8778 ###### # parameters @@ -38,5 +38,5 @@ loop_callback() { echo "New file ${1} created in ${WATCHDIR}!" } -watch_dir_loop "$WATCHDIR" +watch_dir_loop "${WATCHDIR}" diff --git a/examples/background-scripts/run_notify.sh b/examples/background-scripts/run_notify.sh index 67cf313..3140de8 100755 --- a/examples/background-scripts/run_notify.sh +++ b/examples/background-scripts/run_notify.sh @@ -4,7 +4,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-7-g9ef8778 ###### # parameters @@ -25,15 +25,15 @@ unset IFS cat >/dev/null & # check if $1 is a number -re='^[0-9]+$' -if [[ $1 =~ $re ]] ; then +regex='^[0-9]+$' +if [[ "$1" =~ ${regex} ]] ; then SLEEP="$1" else SLEEP=10 # time between time notifications fi # output current time every $1 seconds -while sleep $SLEEP +while sleep "${SLEEP}" do date "+* It's %k:%M:%S o' clock ..." done diff --git a/examples/jsonDB-keyboard/mycommands.sh b/examples/jsonDB-keyboard/mycommands.sh index 2352974..7505c42 100644 --- a/examples/jsonDB-keyboard/mycommands.sh +++ b/examples/jsonDB-keyboard/mycommands.sh @@ -10,7 +10,7 @@ # AUTHOR: KayM (), kay@rrr.de # DATE: 19.12.2020 19:03 # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-7-g9ef8778 #=============================================================================== # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -326,8 +326,8 @@ fi MYKEYF="$2" MINLEN="4" # check len of keys - for MYKEY in ${MYFIND}; do [ "${#MYKEY}" -lt ${MINLEN} ] && break; done - if [ "${#MYKEY}" -lt ${MINLEN} ]; then + for MYKEY in ${MYFIND}; do [ "${#MYKEY}" -lt "${MINLEN}" ] && break; done + if [ "${#MYKEY}" -lt "${MINLEN}" ]; then send_markdownv2_message "${CHAT[ID]}" "*Ein Suchbegriff ist kürzer als ${MINLEN} Zeichen!*" else MYFIND="$(create_pattern "${MYFIND}")" diff --git a/examples/send-system-status/mycommands.sh b/examples/send-system-status/mycommands.sh index 2704143..148437f 100644 --- a/examples/send-system-status/mycommands.sh +++ b/examples/send-system-status/mycommands.sh @@ -5,7 +5,7 @@ # to show how you can customize bashbot by only editing mycommands.sh # NOTE: this is not tested, simply copied from original source and reworked! # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-7-g9ef8778 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -38,7 +38,7 @@ mycommands() { local msg="" if user_is_botadmin "${USER[ID]}" || user_is_allowed "${USER[ID]}" "systemstatus"; then - case "$CMD" in + case "${CMD}" in '/md'*) msg="$(cat /proc/mdstat)";; '/smb'*) msg="$(smbstatus)" ;; '/se'*) msg="$(sensors | sed -r 's/\s|\)+//g' | sed -r 's/\(high=|\(min=/\//' | sed -r 's/\,crit=|\,max=/\//')";; @@ -51,14 +51,14 @@ mycommands() { '/smart'*) [ "${CMD[1]}" == "" ] && msg="example \`/smart sda\`" && return drive="$(echo "${CMD[1]}" | cut -c 1-3)" - echo "smartctl -a /dev/$drive" - msg="$(smartctl -a "/dev/$drive")" + echo "smartctl -a /dev/${drive}" + msg="$(smartctl -a "/dev/${drive}")" ;; '/df') msg="$(df -h | sed -r 's/^/\n/' | sed -r 's/\s+/\n/g')";; esac - if [ "$msg" != "" ]; then - send_normal_message "${CHAT[ID]}" "$msg" + if [ "${msg}" != "" ]; then + send_normal_message "${CHAT[ID]}" "${msg}" fi else send_normal_message "${USER[ID]}" "Sorry, you are not allowed to use this bot!" From 14fa2c763500d4e9701165de351c07523ee11f13 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 5 Jan 2021 12:06:22 +0100 Subject: [PATCH 17/98] test/: fix missing ${xxx} --- test/ALL-tests.inc.sh | 8 ++++---- test/c-init-test.sh | 6 +++--- test/d-send_message-test.sh | 14 +++++++------- test/e-env-test.sh | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 2431581..f199ce0 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -11,7 +11,7 @@ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-8-g248a065 #=============================================================================== # common variables @@ -61,9 +61,9 @@ print_array() { local idx t local arrays=( "${@}" ) for idx in "${arrays[@]}"; do - declare -n temp="$idx" + declare -n temp="${idx}" for t in "${!temp[@]}"; do - printf '%s:\t%s\t%s\n' "$idx" "$t" "${temp[$t]}" + printf '%s:\t%s\t%s\n' "${idx}" "${t}" "${temp[${t}]}" done | sort done | grep -v '^USER: 0' } @@ -76,7 +76,7 @@ compare_sorted() { diff -c "${1}.sort" "${2}.sort" || ret=1 [[ "${1}" != "${TESTDIR}"* ]] && rm -f "${1}.sort" [[ "${2}" != "${TESTDIR}"* ]] && rm -f "${2}.sort" - return "$ret" + return "${ret}" } ###### diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 8dd7057..1d6964d 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -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-8-g248a065 #=============================================================================== # include common functions and definitions @@ -24,7 +24,7 @@ TESTFILES="${TOKENFILE} ${ACLFILE} ${COUNTFILE} ${BLOCKEDFILE} ${ADMINFILE}" # run bashbot first time with init printf "Run bashbot init ...\n" "${TESTDIR}/bashbot.sh" init >"${LOGFILE}" <>"${OUTPUTFILE}" + send_message "123456" "${line}" >>"${OUTPUTFILE}" set +x; set -e printf "." done < "${INPUTFILE}" 2>>"${LOGFILE}" -[ -d "$ALLOW" ] && rm -rf "$ALLOW" +[ -d "${ALLOW}" ] && rm -rf "${ALLOW}" printf " done.\n" diff --git a/test/e-env-test.sh b/test/e-env-test.sh index 17fc8df..01617aa 100755 --- a/test/e-env-test.sh +++ b/test/e-env-test.sh @@ -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-8-g248a065 #=============================================================================== # include common functions and definitions @@ -53,7 +53,7 @@ mkdir "${BASHBOT_VAR}/${DATADIR}" # run bashbot first time with init "${BASHBOT_BIN}/bashbot.sh" init >"${LOGFILE}" < Date: Tue, 5 Jan 2021 12:25:49 +0100 Subject: [PATCH 18/98] hooks: enbable more shellcheck tests and fix resulting ${xxx} warnings --- bashbot.rc | 21 ++++++++++++--------- dev/hooks/post-commit.sh | 4 ++-- dev/hooks/pre-commit.sh | 8 ++++---- dev/hooks/pre-push.sh | 4 ++-- mycommands.sh.clean | 8 ++++---- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index bf895c7..7044f46 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-9-g14fa2c7 # shellcheck disable=SC2009 # shellcheck disable=SC2181 @@ -30,8 +30,8 @@ runcmd="echo Dry run:" # not activated until you edit lines below runas="nobody" # uncomment one of the example lines to fit your system -# runcmd="su $runas -s /bin/bash -c " # runasuser with *su* -# runcmd="runuser $runas -s /bin/bash -c " # runasuser with *runuser* +# runcmd="su ${runas} -s /bin/bash -c " # runasuser with *su* +# runcmd="runuser ${runas} -s /bin/bash -c " # runasuser with *runuser* # edit the values of the following lines to fit your config: start="cd /usr/local/telegram-bot-bash; /usr/local/telegram-bot-bash/bashbot.sh" # location of your bashbot.sh script @@ -40,24 +40,26 @@ name='' # your bot name as given to botfather, e.g. mysomething_bot # END Configuration ####################### -[ "$name" = "" ] && name="$runas" +[ "${name}" = "" ] && name="${runas}" case "$1" in 'start') + # shellcheck disable=SC2250 $runcmd "$start start" # >/dev/null 2>&1 /dev/null 2>&1 + kill -9 $(ps -u "${runas}" | grep inotifywait | sed 's/ .*//') >/dev/null 2>&1 fi ;; *) @@ -83,4 +86,4 @@ case "$1" in RETVAL=1 ;; esac -exit $RETVAL +exit "${RETVAL}" diff --git a/dev/hooks/post-commit.sh b/dev/hooks/post-commit.sh index e8ad88c..038ee15 100755 --- a/dev/hooks/post-commit.sh +++ b/dev/hooks/post-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-9-g14fa2c7 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! @@ -7,7 +7,7 @@ # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script GIT_DIR=$(git rev-parse --git-dir) -cd "$GIT_DIR/.." || exit 1 +cd "${GIT_DIR}/.." || exit 1 export HOOKDIR="dev/hooks" LASTPUSH='.git/.lastcommit' diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 8880d05..0e3082c 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-9-g14fa2c7 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! @@ -7,7 +7,7 @@ # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script GIT_DIR=$(git rev-parse --git-dir) -cd "$GIT_DIR/.." || exit 1 +cd "${GIT_DIR}/.." || exit 1 export HOOKDIR="dev/hooks" LASTPUSH='.git/.lastpush' @@ -32,9 +32,9 @@ set +f FILES="$(find ./* -name '*.sh' | grep -v -e 'DIST\/' -e 'STANDALONE\/' -e 'JSON.sh')" set -f FILES="${FILES} $(sed '/^#/d' <"dev/shellcheck.files")" -if [ "$FILES" != "" ]; then +if [ "${FILES}" != "" ]; then # shellcheck disable=SC2086 - shellcheck -x ${FILES} || exit 1 + shellcheck -o all -e SC2249,SC2154 -x ${FILES} || exit 1 printf " OK\n............................\n" else # something went wrong diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index 26f4658..a0f6912 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-9-g14fa2c7 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! @@ -7,7 +7,7 @@ # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script GIT_DIR=$(git rev-parse --git-dir) -cd "$GIT_DIR/.." || exit 1 +cd "${GIT_DIR}/.." || exit 1 export HOOKDIR="dev/hooks" LASTPUSH='.git/.lastpush' diff --git a/mycommands.sh.clean b/mycommands.sh.clean index eae37af..d744161 100644 --- a/mycommands.sh.clean +++ b/mycommands.sh.clean @@ -4,7 +4,7 @@ # files: mycommands.sh.clean # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v1.25-dev-0-gd310805 +#### $$VERSION$$ v1.25-dev-9-g14fa2c7 # ########## @@ -108,7 +108,7 @@ else ################## # example command, replace them by your own '/echo'*) # example echo command - send_normal_message "${CHAT[ID]}" "$MESSAGE" + send_normal_message "${CHAT[ID]}" "${MESSAGE}" ;; ########## @@ -152,10 +152,10 @@ else 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/ Date: Tue, 5 Jan 2021 12:57:07 +0100 Subject: [PATCH 19/98] modules: Array2Json fix missing + in regex --- modules/jsonDB.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index d80b094..62dd876 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.21-7-g0798f1a +#### $$VERSION$$ v1.25-dev-10-g5f50011 # # source from commands.sh to use jsonDB functions # @@ -366,7 +366,7 @@ Array2Json() { declare -n ARRAY="$1" for key in "${!ARRAY[@]}" do - [[ "${key}" =~ ^${JSSH_KEYOK}$ ]] || continue + [[ "${key}" =~ ^${JSSH_KEYOK}+$ ]] || continue # in case val contains newline convert to \n val="${ARRAY[${key}]//$'\n'/\\n}" printf '["%s"]\t"%s"\n' "${key//,/\",\"}" "${val//\"/\\\"}" From b3c22bcf749398c24e5ea21f33bc751b6425457c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 5 Jan 2021 13:06:14 +0100 Subject: [PATCH 20/98] bin: delete_message.sh --- bin/delete_message.sh | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 bin/delete_message.sh diff --git a/bin/delete_message.sh b/bin/delete_message.sh new file mode 100755 index 0000000..dc02461 --- /dev/null +++ b/bin/delete_message.sh @@ -0,0 +1,63 @@ +#!/bin/bash +#=============================================================================== +# +# FILE: bin/delete_message.sh +# +# USAGE: delete_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" [debug] +# +# DESCRIPTION: delete a message in the given user/group +# +# OPTIONS: CHAT[ID] - ID number of CHAT or BOTADMIN +# MESSAGE[ID] - message to delete +# +# -h - display short help +# --help - this help +# +# Set BASHBOT_HOME to your installation directory +# +# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ +# AUTHOR: KayM (gnadelwartz), kay@rrr.de +# CREATED: 03.01.2021 15:37 +# +#### $$VERSION$$ v1.25-dev-11-gfc5d50e +#=============================================================================== + +#### +# parse args +DELETE="delete_message" +case "$1" in + '') + printf "missing arguments\n" + ;& + "-h"*) + printf 'usage: send_edit_message [-h|--help] [format] "CHAT[ID]" "MESSAGE[ID]" "message ..." [debug]\n' + exit 1 + ;; + '--h'*) + sed -n '3,/###/p' <"$0" + exit 1 + ;; +esac + + +# set bashbot environment +# shellcheck disable=SC1090 +source "${0%/*}/bashbot_env.inc.sh" "$3" # $3 debug + +#### +#### +# ready, do stuff here ----- +if [ "$1" == "BOTADMIN" ]; then + CHAT="${BOT_ADMIN}" +else + CHAT="$1" +fi + +# delete message +"${DELETE}" "${CHAT}" "$2" + +[ "${BOTSENT[OK]}" = "true" ] && BOTSENT[ID]="$2" + +# output send message result +jssh_printDB "BOTSENT" | sort -r + From 1631b0263b15c4dc54ef0b6719e462560d261656 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 5 Jan 2021 13:27:20 +0100 Subject: [PATCH 21/98] dev: make-dist do not overwrite mycommands and addons/*.sh in DIST/telegram-bot-bash --- dev/make-distribution.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index 9ca43d0..414daa2 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -7,7 +7,7 @@ # # Options: --notest - skip tests # -#### $$VERSION$$ v1.25-dev-6-g641727d +#### $$VERSION$$ v1.25-dev-12-gb3c22bc ############################################################## # magic to ensure that we're always inside the root of our application, @@ -24,8 +24,10 @@ VERSION="$(git describe --tags | sed -e 's/-[0-9].*//' -e 's/v//')" DISTNAME="telegram-bot-bash" DISTDIR="./DIST/${DISTNAME}" -DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh mycommands.sh.clean bin doc examples scripts modules addons LICENSE README.md README.txt README.html" -DISTMKDIR="data-bot-bash logs bin bin/logs" +DISTMKDIR="data-bot-bash logs bin bin/logs addons" + +DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh.clean bin doc examples scripts modules LICENSE README.md README.txt README.html" +DISTFILESDIST="mycommands.sh bashbot.rc $(echo "addons/"*.sh)" # run tests first! for test in $1 dev/all-test*.sh @@ -55,10 +57,10 @@ done # do not overwrite on update printf "Create .dist files\n" -for file in mycommands.sh bashbot.rc addons/*.sh +for file in ${DISTFILESDIST} do [ "${file}" = "addons/*.sh" ] && continue - mv "${file}" "${file}.dist" + cp "${GIT_DIR}/../${file}" "${file}.dist" done # inject JSON.sh into distribution From 2fe6d4b0ccc4c70ee53c0058ea88ab21ade88a7e Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 5 Jan 2021 13:30:44 +0100 Subject: [PATCH 22/98] doc: fix overwrite in DIST/ test installation --- doc/0_install.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/0_install.md b/doc/0_install.md index 6e26d92..c841f76 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -97,9 +97,7 @@ This creates the installation archives in `DIST/` and a ready to run test instal Use the installation archives to install or update bashbot as described above. To run a test bot, e.g. while development or testing latest changes, you can use the bashbot installation provided in `DIST/telegram-bot-bash`. -To update\* the test installation (_after git pull, local changes or switch master/develop_) run `dev/make-distrubition.sh` again. - -\* _`mycommands.sh` and `bashbot.rc` will be overwritten._ +To update the test installation (_after git pull, local changes or switch master/develop_) run `dev/make-distrubition.sh` again. ### Note for BSD and MacOS @@ -129,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-3-g53c107d +#### $$VERSION$$ v1.25-dev-13-g1631b02 From 4582efd556d8f51c9e9c322713f03244e89ca668 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 5 Jan 2021 16:17:34 +0100 Subject: [PATCH 23/98] coding-style: positonal parameters $1 - \9 has precedence over verything --- addons/antiFlood.sh | 2 +- addons/example.sh | 2 +- bashbot.sh | 90 +++++++++++++++++----------------- bin/bashbot_env.inc.sh | 2 +- bin/bashbot_stats.sh | 2 +- bin/delete_message.sh | 2 +- bin/send_broadcast.sh | 2 +- bin/send_edit_message.sh | 2 +- bin/send_file.sh | 2 +- bin/send_message.sh | 2 +- commands.sh | 12 ++--- dev/all-tests.sh | 2 +- dev/git-add.sh | 2 +- dev/hooks/post-commit.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/inject-json.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-distribution.sh | 2 +- dev/make-html.sh | 8 +-- dev/make-standalone.sh | 2 +- dev/obfuscate.sh | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- examples/bash2env.sh | 2 +- examples/bashbot-multi.sh | 6 +-- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 20 ++++---- modules/answerInline.sh | 10 ++-- modules/background.sh | 18 +++---- modules/chatMember.sh | 6 +-- modules/jsonDB.sh | 36 +++++++------- modules/sendMessage.sh | 88 ++++++++++++++++----------------- mycommands.sh | 4 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 12 ++--- test/a-commit-test.sh | 2 +- test/b-example-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-process_inline-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 8 +-- test/d-user_is-test.sh | 2 +- test/e-env-test.sh | 2 +- 46 files changed, 192 insertions(+), 192 deletions(-) diff --git a/addons/antiFlood.sh b/addons/antiFlood.sh index 616d938..3a4b5fd 100644 --- a/addons/antiFlood.sh +++ b/addons/antiFlood.sh @@ -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: # diff --git a/addons/example.sh b/addons/example.sh index 1cbf168..362392b 100644 --- a/addons/example.sh +++ b/addons/example.sh @@ -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. # diff --git a/bashbot.sh b/bashbot.sh index 5c8ab7e..95978b3 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -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)" diff --git a/bin/bashbot_env.inc.sh b/bin/bashbot_env.inc.sh index f1da22b..2cc4bc4 100644 --- a/bin/bashbot_env.inc.sh +++ b/bin/bashbot_env.inc.sh @@ -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 #=============================================================================== ############ diff --git a/bin/bashbot_stats.sh b/bin/bashbot_stats.sh index ddf34d6..164c6af 100755 --- a/bin/bashbot_stats.sh +++ b/bin/bashbot_stats.sh @@ -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 #=============================================================================== #### diff --git a/bin/delete_message.sh b/bin/delete_message.sh index dc02461..905687f 100755 --- a/bin/delete_message.sh +++ b/bin/delete_message.sh @@ -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 #=============================================================================== #### diff --git a/bin/send_broadcast.sh b/bin/send_broadcast.sh index 2d38083..d66402c 100755 --- a/bin/send_broadcast.sh +++ b/bin/send_broadcast.sh @@ -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 diff --git a/bin/send_edit_message.sh b/bin/send_edit_message.sh index ef99801..5e0cf1e 100755 --- a/bin/send_edit_message.sh +++ b/bin/send_edit_message.sh @@ -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 #=============================================================================== #### diff --git a/bin/send_file.sh b/bin/send_file.sh index 04d6261..958dd31 100755 --- a/bin/send_file.sh +++ b/bin/send_file.sh @@ -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 #=============================================================================== #### diff --git a/bin/send_message.sh b/bin/send_message.sh index 47fac76..1af3522 100755 --- a/bin/send_message.sh +++ b/bin/send_message.sh @@ -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 #=============================================================================== #### diff --git a/commands.sh b/commands.sh index dbb5ce8..585b7b2 100644 --- a/commands.sh +++ b/commands.sh @@ -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 diff --git a/dev/all-tests.sh b/dev/all-tests.sh index e766105..f644247 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -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, diff --git a/dev/git-add.sh b/dev/git-add.sh index b7e2ab7..36916d4 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -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 diff --git a/dev/hooks/post-commit.sh b/dev/hooks/post-commit.sh index 038ee15..934b57b 100755 --- a/dev/hooks/post-commit.sh +++ b/dev/hooks/post-commit.sh @@ -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! diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 0e3082c..3db551e 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -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! diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index a0f6912..a34d01c 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -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! diff --git a/dev/inject-json.sh b/dev/inject-json.sh index 805ae9e..8ad32d4 100644 --- a/dev/inject-json.sh +++ b/dev/inject-json.sh @@ -7,7 +7,7 @@ # # Usage: source inject-json.sh # -#### $$VERSION$$ v1.25-dev-6-g641727d +#### $$VERSION$$ v1.25-dev-14-g2fe6d4b ############################################################## # download JSON.sh diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index e0bd873..54f5adc 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -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 diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index 414daa2..d656709 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -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, diff --git a/dev/make-html.sh b/dev/make-html.sh index 70327c5..c978c22 100644 --- a/dev/make-html.sh +++ b/dev/make-html.sh @@ -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 diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index b061f97..bfb0ea6 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -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, diff --git a/dev/obfuscate.sh b/dev/obfuscate.sh index aa2470a..3d64dd6 100755 --- a/dev/obfuscate.sh +++ b/dev/obfuscate.sh @@ -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" diff --git a/dev/version.sh b/dev/version.sh index 580adbb..36e1ed7 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -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: diff --git a/doc/0_install.md b/doc/0_install.md index c841f76..db08bdd 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -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 diff --git a/examples/bash2env.sh b/examples/bash2env.sh index 2870fcc..98ff048 100755 --- a/examples/bash2env.sh +++ b/examples/bash2env.sh @@ -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 diff --git a/examples/bashbot-multi.sh b/examples/bashbot-multi.sh index a0b3951..3d1d9e8 100755 --- a/examples/bashbot-multi.sh +++ b/examples/bashbot-multi.sh @@ -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? diff --git a/examples/calc.sh b/examples/calc.sh index 72f94f6..d8316f5 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -11,7 +11,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-14-g2fe6d4b ######################################################################## ###### diff --git a/examples/notify.sh b/examples/notify.sh index a1e1864..8b57e76 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -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 ######################################################################## ###### diff --git a/examples/question.sh b/examples/question.sh index 5981f2a..614ac79 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -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 ######################################################################## ###### diff --git a/modules/aliases.sh b/modules/aliases.sh index a160db0..214ffd6 100644 --- a/modules/aliases.sh +++ b/modules/aliases.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ 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" diff --git a/modules/answerInline.sh b/modules/answerInline.sh index 636fb4d..8b6a8b8 100644 --- a/modules/answerInline.sh +++ b/modules/answerInline.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ 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")'}' diff --git a/modules/background.sh b/modules/background.sh index 7b83af4..8cb55cd 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -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-" } diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 796da8b..ba32967 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ 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 } diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index 62dd876..5aeca19 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ 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" } ############## diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 2f56287..a140c38 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -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}" diff --git a/mycommands.sh b/mycommands.sh index f1eb481..28bc1d3 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -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 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index f51e935..7300d1f 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -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, diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index f199ce0..02621a7 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -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}" } diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 1e97b94..d5b2887 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -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 diff --git a/test/b-example-test.sh b/test/b-example-test.sh index 1e54f0c..c694c15 100644 --- a/test/b-example-test.sh +++ b/test/b-example-test.sh @@ -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 diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 1d6964d..a766074 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -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 diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh index e5f0635..6019a5d 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -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 diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 14e4a48..9faa0a3 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -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 diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index 33bd3de..085054b 100755 --- a/test/d-send_message-test.sh +++ b/test/d-send_message-test.sh @@ -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 diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 5cee920..65be377 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -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 diff --git a/test/e-env-test.sh b/test/e-env-test.sh index 01617aa..0a14607 100755 --- a/test/e-env-test.sh +++ b/test/e-env-test.sh @@ -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 From 7cf624ff2e4547dc407312cb2df86c30b6582cf0 Mon Sep 17 00:00:00 2001 From: David Coomber <47242934+dcoomber@users.noreply.github.com> Date: Tue, 5 Jan 2021 20:26:00 +0200 Subject: [PATCH 24/98] Updates to 7_develop, including specific similarities in other documentation files --- doc/0_install.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 20 ++++++++++---------- doc/7_develop.md | 47 +++++++++++++++++++++++------------------------ 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/doc/0_install.md b/doc/0_install.md index db08bdd..79982fa 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -97,7 +97,7 @@ This creates the installation archives in `DIST/` and a ready to run test instal Use the installation archives to install or update bashbot as described above. To run a test bot, e.g. while development or testing latest changes, you can use the bashbot installation provided in `DIST/telegram-bot-bash`. -To update the test installation (_after git pull, local changes or switch master/develop_) run `dev/make-distrubition.sh` again. +To update the test installation (_after git pull, local changes or switch master/develop_) run `dev/make-distribution.sh` again. ### Note for BSD and MacOS diff --git a/doc/3_advanced.md b/doc/3_advanced.md index efa507f..e29f0c5 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -171,7 +171,7 @@ All output of the script will be sent to the user, to stop a background job use: ```bash kill_back "${CHAT[ID]}" "jobname" ``` -You can also suspend and resume currently running background jobs from outside bashbot, e.g. in your startup schripts: +You can also suspend and resume currently running background jobs from outside bashbot, e.g. in your startup scripts: ```bash ./bashbot.sh suspendback ./bashbot.sh resumeback diff --git a/doc/4_expert.md b/doc/4_expert.md index 1404470..1616cd6 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -50,12 +50,12 @@ If you don't know what locales are installed on your sytsem use `locale -a` to d ##### Character classes In ASCII times it was clear `[:lower:]` and `[a-z]` means ONLY the lowercase letters `[abcd...xyz]`. -With introdution of locales, character classes and ranges contains all characters fitting the class definition. +With the introduction of locales, character classes and ranges now contain all characters fitting the class definition. This means with a Latin UTF-8 locale `[:lower:]` and `[a-z]` contains also e.g. `á ø ü` etc, see [Unicode Latin lowercase letters](https://www.fileformat.info/info/unicode/category/Ll/list.htm) -If that's ok for your script your'e fine, but many scripts rely on the idea of ASCII ranges and may produce undesired results. +If that's ok for your script you're fine, but many scripts rely on the idea of ASCII ranges and may produce undesired results. ```bash # try with different locales ... @@ -101,11 +101,11 @@ The Emoticons ` 😁 😘 ❤️ 😊 👍 ` are encoded as: ` \uD83D\uDE01 \uD8 **This "mixed" JSON encoding needs special handling and can not decoded from** `echo -e` or `printf '%s\\n'` -Bbashbot uses an internal, pure bash implementation which is well tested now, even there may some corner cases*. +Bashbot uses an internal, pure bash implementation which is well tested now, even there may some corner cases*. ### Run as other user or system service -Bashbot is desingned to run manually by the user who installed it. Nevertheless it's possible to run it by an other user-ID, as a system service or scheduled from cron. This is recommended if you want to bashbot run as a service. +Bashbot is designed to run manually by the user who installed it. Nevertheless it's possible to run it by an other user-ID, as a system service or scheduled from cron. This is recommended if you want to bashbot run as a service. Setup the environment for the user you want to run bashbot and enter desired username, e.g. nobody : ```bash @@ -154,7 +154,7 @@ To use bashbot as a system service include a working `bashbot.rc` in your init s An example crontab is provided in `examples/bashbot.cron`. - If you are running bashbot with your user-ID, copy the examples lines to your crontab and remove username `nobody`. -- if you run bashbot as an other user or a system service edit `examples/bashbot.cron` to fit your needs and replace username `nobody` with the username you want to run bashbot. copy the modified file to `/etc/cron.d/bashbot` +- if you run bashbot as an other user or a system service edit `examples/bashbot.cron` to fit your needs and replace username `nobody` with the username you want to run bashbot. Copy the modified file to `/etc/cron.d/bashbot` ### Use bashbot from CLI and scripts @@ -231,10 +231,10 @@ User or Chat you are in. See [Send Messages](2_usage.md#sending-messages). *Examples:* You can test this by sending messages to yourself: ```bash -# fist Hello World +# first Hello World send_normal_message "$(getConfigKey "botadmin")" "Hello World! This is my first message" -# now with some markdown and HTML +# now with some markdown and HTML send_markdown_message "$(getConfigKey "botadmin")" '*Hello World!* _This is my first markdown message_' send_html_message "$(getConfigKey "botadmin")" 'Hello World! This is my first HTML message' send_keyboard "$(getConfigKey "botadmin")" 'Do you like it?' '[ "Yep" , "No" ]' @@ -258,10 +258,10 @@ This section describe how you can customize bashbot to your needs by setting env #### Change file locations -In standard setup bashbot is self containing, this means you can place 'telegram-bot-bash' any location +In standard setup bashbot is self containing, this means you can place 'telegram-bot-bash' any location and run it from there. All files - program, config, data etc - will reside in 'telegram-bot-bash'. -If you want to have other locations for config, data etc, define and export the following environment variables. +If you want to have other locations for config, data etc, define and export the following environment variables. **Note: all specified directories and files must exist or running 'bashbot.sh' will fail.** ##### BASHBOT_ETC @@ -379,7 +379,7 @@ BASHBOT_TIMEOUT to a numeric value between 1 and 999. Any non numeric or negativ ##### BASHBOT_SLEEP Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling. -If messages are received bashbot polls with no dealy. If no messages are available bashbot add 100ms delay +If messages are received bashbot polls with no delay. If no messages are available bashbot add 100ms delay for every poll until the maximum of BASHBOT_SLEEP ms. ```bash unset BASHBOT_SLEEP # 5000ms (default) diff --git a/doc/7_develop.md b/doc/7_develop.md index eb12beb..c9c9071 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -1,7 +1,7 @@ #### [Home](../README.md) ## Notes for bashbot developers -This section is about help and best practices for new bashbot developers. The main focus on is creating new versions of bashbot, modules and addons, not on develop your individual bot. Nevertheless the information provided here should help your bot development also. +This section is about help and best practices for new bashbot developers. The main focus on is creating new versions of bashbot, modules and addons, not on developing your individual bot. Nevertheless the information provided here should also help you with your bot development. If you want to provide fixes or new features [fork bashbot on github](https://help.github.com/en/articles/fork-a-repo) and provide changes as [pull request on github](https://help.github.com/en/articles/creating-a-pull-request). @@ -21,11 +21,11 @@ you can the change the level of verbosity of the debug argument: sometimes its useful to watch the bot live in the terminal: "debugx" debug output and errors are sent to terminal - "xdebugx" same as debugx plus set bash option '-x' to show any executed command + "xdebugx" same as debugx plus set bash option '-x' to show any executed command ``` -Logging of telegram update poll is disabled by default, also in `debug` mode. To enable it without using verbose `xdebug` mode +Logging of Telegram update poll is disabled by default, also in `debug` mode. To enable it without using verbose `xdebug` mode set `BASHBOT_UPDATELOG` to an empty value (not unset) `export BASHBOT_UPDATELOG=""` ### Modules and Addons @@ -36,7 +36,7 @@ disable modules, e.g. by rename the respective module file to 'module.sh.off'. Modules must use only functions provided by 'bashbot.sh' or the module itself and should not depend on other modules or addons. The only mandatory module is 'module/sendMessage.sh'. -If a not mandatory module is used in 'bashbot.sh' or 'commands.sh', the use of `_is_function` or +If an optional module is used in 'bashbot.sh' or 'commands.sh', the use of `_is_function` or `_execute_if_function` is mandatory to catch absence of the module. **Addons** resides in `addons/*.sh.dist` and are not enabled by default. To activate an addon rename it to end with '.sh', e.g. by @@ -63,18 +63,17 @@ Note: For the same reason event function MUST return immediately! Time consuming ##### SEND RECEIVE events -An RECEIVE event is executed when a Message is received, same iQuery / Message variables are available as in commands.sh +A RECEIVE event is executed when a Message is received, same iQuery / Message variables are available as in commands.sh -* `BASHBOT_EVENT_INLINE` an inline query is received - -* BASHBOT_EVENT_MESSAGE` any of the following message types is received - * `BASHBOT_EVENT_TEXT` a message containing text is received - * `BASHBOT_EVENT_CMD` a message containing a command is received (starts with /) - * `BASHBOT_EVENT_REPLYTO` a reply to a message is received - * `BASHBOT_EVENT_FORWARD` a forwarded message is received - * `BASHBOT_EVENT_CONTACT` a contact is received - * `BASHBOT_EVENT_LOCATION` a location or a venue is received - * `BASHBOT_EVENT_FILE` a file is received +* `BASHBOT_EVENT_INLINE` an inline query is received +* `BASHBOT_EVENT_MESSAGE` any of the following message types is received +* `BASHBOT_EVENT_TEXT` a message containing text is received +* `BASHBOT_EVENT_CMD` a message containing a command is received (starts with /) +* `BASHBOT_EVENT_REPLYTO` a reply to a message is received +* `BASHBOT_EVENT_FORWARD` a forwarded message is received +* `BASHBOT_EVENT_CONTACT` a contact is received +* `BASHBOT_EVENT_LOCATION` a location or a venue is received +* `BASHBOT_EVENT_FILE` a file is received *usage*: BASHBOT_EVENT_xxx[ "unique-name" ]="callback" @@ -182,8 +181,8 @@ You don't need all these files after you're finished with your cool new bot. Let's create a stripped down version: - delete all modules you do not need from `modules`, e.g. `modules/inline.sh` if you don't use inline queries -- delete not needed standard commands and messages from `commands.sh` -- delete not needed commands and functions from `mycommands.sh` +- delete unused standard commands and messages from `commands.sh` +- delete unused commands and functions from `mycommands.sh` - run `dev/make-standalone.sh` to create a a stripped down version of your bot Now have a look at the directory `standalone`, here you find the files `bashbot.sh` and `commands.sh` containing everything to run your bot. @@ -198,8 +197,8 @@ Now have a look at the directory `standalone`, here you find the files `bashbot. 5. give your (dev) fork a new version tag: `git tag v1.xx` 6. setup github hooks by running `dev/install-hooks.sh` -Run `dev/make-distrubition.sh` to create installation archives and a test installation in `DIST/`. -To update the test installation, e.g. after git pull, local changes or switch master/develop, run `dev/make-distrubition.sh` again. +Run `dev/make-distribution.sh` to create installation archives and a test installation in `DIST/`. +To update the test installation, e.g. after git pull, local changes or switch master/develop, run `dev/make-distribution.sh` again. Note for Debian: Debian Buster ships older versions of many utilities, pls try to install from [buster-backports](https://backports.debian.org/Instructions/) ```bash @@ -210,7 +209,7 @@ sudo apt-get -t buster-backports install git shellcheck pandoc codespell curl A typical bashbot develop loop looks as follow: 1. start developing - *change, copy, edit bashbot files ...* -2. after changing a bash sript: `shellcheck -x script.sh` +2. after changing a bash script: `shellcheck -x script.sh` 3. `dev/all-tests.sh` - *in case if errors back to 2.* 4. `dev/git-add.sh` - *check for changed files, update version string, run git add* 5. `git commit -m "COMMIT MESSAGE"; git push` @@ -291,15 +290,15 @@ To update version in all files run 'dev/version.sh' without parameter. For a shell script running as a service it's important to be paranoid about quoting, globbing and other common problems. So it's a must to run shellchek on all shell scripts before you commit a change. this is automated by a git hook activated in Setup step 6. -To run shellcheck for a single script run `shellcheck -x script.sh`, to check all schripts run `dev/hooks/pre-commit.sh`. +To run shellcheck for a single script run `shellcheck -x script.sh`, to check all scripts run `dev/hooks/pre-commit.sh`. ### bashbot test suite -Starting with version 0.70 bashbot has a test suite. To start testsuite run `dev/all-tests.sh`. all-tests.sh will return 'SUCCESS' only if all tests pass. +Starting with version 0.70 bashbot has a test suite. To start the test suite run `dev/all-tests.sh`. all-tests.sh will return 'SUCCESS' if ALL tests pass. #### enabling / disabling tests -All tests are placed in the directory `test`. To disable a test remove the execute flag from the '*-test.sh' script, to (re)enable a test make the script executable again. +All tests are placed in the directory `test`. To disable a test remove the execute flag from the '*-test.sh' script, to (re)enable a test make the script executable again. #### creating new tests @@ -328,7 +327,7 @@ The file `ALL-tests.inc.sh` must be included from all tests and provide the test ADMINFILE="botadmin" DATADIR="data-bot-bash" -# SUCCESS NOSUCCES -> echo "${SUCCESS}" or echo "${NOSUCCESS}" +# SUCCESS NOSUCCESS -> echo "${SUCCESS}" or echo "${NOSUCCESS}" SUCCESS=" OK" NOSUCCESS=" FAILED!" From 6408befddd19a6094700d0b716f0811f2736d072 Mon Sep 17 00:00:00 2001 From: David Coomber <47242934+dcoomber@users.noreply.github.com> Date: Tue, 5 Jan 2021 20:40:21 +0200 Subject: [PATCH 25/98] Display update to 7_develop --- README.txt | 5 +++-- doc/7_develop.md | 13 ++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.txt b/README.txt index f05309f..5ee1713 100644 --- a/README.txt +++ b/README.txt @@ -158,9 +158,10 @@ start debug` │   ├── BASHBOT.log # log what your bot is doing ... │   ├── ERROR.log # connection errors from / to Telegram API │   │ -│   ├── DEBUG.log # stdout/stderr of you bot (debug mode enabled) -│   └── MESSAGE.log # full text of all message send/received (debug mode +│   ├── DEBUG.log # stdout/stderr of you bot (debug mode enabled) +│   └── MESSAGE.log # full text of all message send/received +(debug mode enabled) ``` ---- diff --git a/doc/7_develop.md b/doc/7_develop.md index c9c9071..e80674f 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -13,16 +13,15 @@ you can the change the level of verbosity of the debug argument: ``` "debug" all output is redirected to "DEBUG.log", in addition every incoming message is logged in "MESSAGE.log" and "INLINE.log" "xdebug" same as debug plus set bash option '-x' to log any executed command in "DEBUG.log" - - use the command tail to watch your bot live, e.g. "tail -f DEBUG.log", to obtain more information place set -x; set +x in your code. ``` -``` - sometimes its useful to watch the bot live in the terminal: +Use the command `tail` to watch your bot live, e.g. "tail -f DEBUG.log". To obtain more information place set -x; set +x in your code. +Sometimes it's useful to watch the bot live in the terminal: + +``` "debugx" debug output and errors are sent to terminal - "xdebugx" same as debugx plus set bash option '-x' to show any executed command - + "xdebugx" same as debugx plus set bash option '-x' to show any executed command ``` Logging of Telegram update poll is disabled by default, also in `debug` mode. To enable it without using verbose `xdebug` mode @@ -357,5 +356,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.21-24-g7cf624f From 0d3a53a7d2bbc549915a3ce68f6d0b217254d7a2 Mon Sep 17 00:00:00 2001 From: David Coomber <47242934+dcoomber@users.noreply.github.com> Date: Tue, 5 Jan 2021 20:42:36 +0200 Subject: [PATCH 26/98] Display update to 7_develop --- doc/7_develop.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/7_develop.md b/doc/7_develop.md index e80674f..8febf48 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -21,7 +21,7 @@ Sometimes it's useful to watch the bot live in the terminal: ``` "debugx" debug output and errors are sent to terminal - "xdebugx" same as debugx plus set bash option '-x' to show any executed command + "xdebugx" same as debugx plus set bash option '-x' to show any executed command ``` Logging of Telegram update poll is disabled by default, also in `debug` mode. To enable it without using verbose `xdebug` mode From dd19f0f34e145397472b48427506e120bbc9c145 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 5 Jan 2021 22:01:32 +0100 Subject: [PATCH 27/98] modules: send_file support for URL --- bashbot.sh | 10 +++++----- bin/send_file.sh | 5 +++-- modules/sendMessage.sh | 42 +++++++++++++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 95978b3..25d6b61 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-15-g4582efd ################################################################## # emmbeded system may claim bash but it is not @@ -487,13 +487,13 @@ if detect_curl ; then sendUpload() { [ "$#" -lt 4 ] && return if [ -n "$5" ]; then - [ -n "${BASHBOTDEBUG}" ] &&\ - log_update "sendUpload CHAT=$1 WHAT=$2 FILE=$3 CAPT=$5" - # shellcheck disable=SC2086 + [ -n "${BASHBOTDEBUG}" ] &&\ + 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 )" else - # shellcheck disable=SC2086 + # shellcheck disable=SC2086 res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\ -F "$2=@$3;${3##*/}" | "${JSONSHFILE}" -b -n 2>/dev/null )" fi diff --git a/bin/send_file.sh b/bin/send_file.sh index 958dd31..585ddf4 100755 --- a/bin/send_file.sh +++ b/bin/send_file.sh @@ -21,7 +21,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 25.12.2020 20:24 # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-15-g4582efd #=============================================================================== #### @@ -54,7 +54,8 @@ else fi FILE="$2" -[[ "$2" != "/"* ]] && FILE="${PWD}/$2" +# convert to absolute path if not start with / or http:// +[[ ! ( "$2" == "/"* || "$2" =~ ^https*:// ) ]] && FILE="${PWD}/$2" # send message in selected format "${SEND}" "${CHAT}" "${FILE}" "$3" diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index a140c38..b120023 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-15-g4582efd # will be automatically sourced from bashbot @@ -205,19 +205,28 @@ send_file() { fi } +# supports http and local file +# $1 chat, $2 file, $3 caption, $4 extension (optional) upload_file(){ - local CUR_URL WHAT STATUS text=$3 file="$2" - # file access checks ... - [[ "${file}" = *'..'* ]] && return 1 # no directory traversal - [[ "${file}" = '.'* ]] && return 1 # no hidden or relative files - if [[ "${file}" = '/'* ]] ; then - [[ ! "${file}" =~ ${FILE_REGEX} ]] && return 2 # absolute must match REGEX + local CUR_URL WHAT STATUS media text file="$2" ext="$4" + text="$(JsonEscape "$3")" + if [[ "${file}" =~ ^https*:// ]]; then + media="URL" else - file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # othiers must be in UPLOADDIR + # we have a file, check file location ... + media="FILE" + [[ "${file}" = *'..'* ]] && return 1 # no directory traversal + [[ "${file}" = '.'* ]] && return 1 # no hidden or relative files + if [[ "${file}" = '/'* ]] ; then + [[ ! "${file}" =~ ${FILE_REGEX} ]] && return 2 # absolute must match REGEX + else + file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # othiers must be in UPLOADDIR + fi + [ ! -r "${file}" ] && return 3 # and file must exits of course fi - [ ! -r "${file}" ] && return 3 # and file must exits of course - case "${file##*.}" in + [ -z "${ext}" ] && ext="${file##*.}" + case "${ext}" in mp3|flac) CUR_URL="${AUDIO_URL}" WHAT="audio" @@ -250,8 +259,19 @@ upload_file(){ STATUS="upload_document" ;; esac + + # prepare to send FILE / URL send_action "$1" "${STATUS}" - sendUpload "$1" "${WHAT}" "${file}" "${CUR_URL}" "${text//\\n/$'\n'}" + # select method to use + case "${media}" in + FILE) # send local file ... + sendUpload "$1" "${WHAT}" "${file}" "${CUR_URL}" "${text//\\n/$'\n'}";; + + URL) # send URL, should also work for file_id ... + # e.g. '"photo":"https://dealz.rrr.de/assets/images/rbofd-1.gif","caption":"some text"' + sendJson "$1" '"'"${WHAT}"'":"'"${file}"'","caption":"'"${text//\\n/$'\n'}"'"' "${CUR_URL}" + esac + return 0 } # 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 From 126f61f00c4286408bb8e9f4afc98ed545575472 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 5 Jan 2021 22:33:44 +0100 Subject: [PATCH 28/98] modules: send_file add file type classes --- modules/sendMessage.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index b120023..f5ad2d1 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -227,28 +227,28 @@ upload_file(){ [ -z "${ext}" ] && ext="${file##*.}" case "${ext}" in - mp3|flac) + audio|mp3|flac) CUR_URL="${AUDIO_URL}" WHAT="audio" STATUS="upload_audio" ;; - png|jpg|jpeg|gif|pic) + photo|png|jpg|jpeg|gif|pic) CUR_URL="${PHO_URL}" WHAT="photo" STATUS="upload_photo" ;; - webp) + sticker|webp) CUR_URL="${STICKER_URL}" WHAT="sticker" STATUS="upload_photo" ;; - mp4) + video|mp4) CUR_URL="${VIDEO_URL}" WHAT="video" STATUS="upload_video" ;; - ogg) + voice|ogg) CUR_URL="${VOICE_URL}" WHAT="voice" STATUS="upload_audio" From 3d9f7848cf99a02c77d861a65ff5e6e210aaf8c6 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 5 Jan 2021 22:35:34 +0100 Subject: [PATCH 29/98] doc: add send_file URL and file type --- doc/6_reference.md | 20 +++++++++++++------- modules/sendMessage.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/doc/6_reference.md b/doc/6_reference.md index cca5abd..0c67f00 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -117,21 +117,27 @@ The main use case for send_message is to process the output of interactive chats ##### send_file -send_file can send different type's of files, e.g. photos, stickers, audio, media, etc. -[see Telegram API documentation](https://core.telegram.org/bots/api#sending-files). +send_file can send different file types using a local file or a http URL (_e.g. https://) -It's recommended to use __absolute path names__ (_starting with `/`_), as relative path names are threated as __relative to UPLOADDIR__ `data-bot-bash/upload`! +*usage:* send_file "${CHAT[ID]}" "file/URL" "caption" ["type"] -For security reasons the following restrictions apply: +Argument "type" is optional, if not given `send_file` detects file type by the file extension. +Supported file types are: photo (_png jpg jpeg gif pic_) audio (_mp3 flac_) sticker (_webp_) video (_mp4_) voice (_ogg_) or document. + +It's recommended to use __absolute path names__ for local files (_starting with `/`_), as relative path names are threated as __relative to UPLOADDIR__ `data-bot-bash/upload`! + +For security reasons the following restrictions apply to local files: - absolute path name must match the __shell regex__ `FILE_REGEX` (_not file glob_) - path must not start with `./` and not contain `../` -*usage:* send_file "${CHAT[ID]}" "file" "caption" *example:* ```bash -# recommended: absolute path +# send picture from web +send_file "${CHAT[ID]}" "https://dealz.rrr.de/assets/images/rbofd-1.gif" "My Bot" + +# local file recommended: absolute path send_file "${CHAT[ID]}" "/home/user/dog.jpg" "My Dog" # relative to UPLOADDIR: data-bot-bash/upload/dog.jpg @@ -1187,5 +1193,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-16-gdd19f0f diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index f5ad2d1..c7e1cb8 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.25-dev-15-g4582efd +#### $$VERSION$$ v1.25-dev-16-gdd19f0f # will be automatically sourced from bashbot diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 8d2b988..21adca1 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-14-g2fe6d4b # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From ac02f5a3d3bc8c72a02a53563583a06c4ba7f506 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 5 Jan 2021 22:47:18 +0100 Subject: [PATCH 30/98] bin: send_file add URL and file type --- bin/send_file.sh | 15 +++++++++------ doc/2_usage.md | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/send_file.sh b/bin/send_file.sh index 585ddf4..d419b92 100755 --- a/bin/send_file.sh +++ b/bin/send_file.sh @@ -3,14 +3,17 @@ # # FILE: bin/send_file.sh # -# USAGE: send_file.sh [-h|--help] "CHAT[ID]" "file" "caption ...." [debug] +# USAGE: send_file.sh [-h|--help] "CHAT[ID]" "file|URL" "caption ...." [type] [debug] # # DESCRIPTION: send a file to the given user/group # # OPTIONS: CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself -# file - file to send, must be an absolute path or relative to pwd +# file - local file to send, must be an absolute path or relative to pwd # Note: must not contain .. or . and located below BASHBOT_ETC +# URL - send an URL instead local file +# # caption - message to send with file +# type - photo, video, sticker, voice, document (optional) # # -h - display short help # --help - this help @@ -21,7 +24,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 25.12.2020 20:24 # -#### $$VERSION$$ v1.25-dev-15-g4582efd +#### $$VERSION$$ v1.25-dev-18-g3d9f784 #=============================================================================== #### @@ -32,7 +35,7 @@ case "$1" in printf "missing arguments\n" ;& "-h"*) - printf 'usage: send_file [-h|--help] "CHAT[ID]" "file" "caption ...." [debug]\n' + printf 'usage: send_file [-h|--help] "CHAT[ID]" "file" "caption ...." [type] [debug]\n' exit 1 ;; '--h'*) @@ -43,7 +46,7 @@ esac # set bashbot environment # shellcheck disable=SC1090 -source "${0%/*}/bashbot_env.inc.sh" "$4" # $4 debug +source "${0%/*}/bashbot_env.inc.sh" "$5" # $5 debug #### # ready, do stuff here ----- @@ -58,7 +61,7 @@ FILE="$2" [[ ! ( "$2" == "/"* || "$2" =~ ^https*:// ) ]] && FILE="${PWD}/$2" # send message in selected format -"${SEND}" "${CHAT}" "${FILE}" "$3" +"${SEND}" "${CHAT}" "${FILE}" "$3" "$4" # output send message result jssh_printDB "BOTSENT" | sort -r diff --git a/doc/2_usage.md b/doc/2_usage.md index e8a39e3..848c1b1 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -33,6 +33,7 @@ Have FUN! ├── bin # ready to use scripts, use `scriptname --help` for help │   ├── send_message.sh # send message to given chat │   ├── edit_message.sh # replace given message id in given chat +│   ├── delete_message.sh # delete given message id in given chat │   ├── send_broadcast.sh # send message to all known chats │   ├── send_file.sh # send file to given chat │   ├── bashbot_stats.sh # does what it says ... @@ -341,5 +342,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-18-g3d9f784 From bbc679463acf2c5c59fddd1b9fc2acb539ba6a29 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 6 Jan 2021 08:48:25 +0100 Subject: [PATCH 31/98] internal: printf date is 100 times faster --- README.txt | 5 ++--- bashbot.sh | 44 ++++++++++++++++++++++++-------------------- doc/0_install.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/7_develop.md | 16 +++++++++------- 6 files changed, 38 insertions(+), 33 deletions(-) diff --git a/README.txt b/README.txt index 5ee1713..f05309f 100644 --- a/README.txt +++ b/README.txt @@ -158,10 +158,9 @@ start debug` │   ├── BASHBOT.log # log what your bot is doing ... │   ├── ERROR.log # connection errors from / to Telegram API │   │ -│   ├── DEBUG.log # stdout/stderr of you bot (debug mode +│   ├── DEBUG.log # stdout/stderr of you bot (debug mode enabled) +│   └── MESSAGE.log # full text of all message send/received (debug mode enabled) -│   └── MESSAGE.log # full text of all message send/received -(debug mode enabled) ``` ---- diff --git a/bashbot.sh b/bashbot.sh index 25d6b61..2a1a972 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.25-dev-15-g4582efd +#### $$VERSION$$ v1.25-dev-23-g8be95a3 ################################################################## # emmbeded system may claim bash but it is not @@ -91,6 +91,10 @@ _round_float() { local digit="$2"; [[ "$2" =~ ^[${o9o9o9}]+$ ]] || digit="0" { LC_ALL=C.utf-8 printf "%.${digit}f" "$1"; } 2>/dev/null } +# date is external, printf is much faster +_date(){ + printf "%(%c)T\n" -1 +} setConfigKey() { [[ "$1" =~ ^[-${azAZo9},._]+$ ]] || return 3 [ -z "${BOTCONFIG}" ] && return 1 @@ -107,11 +111,11 @@ check_token(){ return 1 } # log $1 with date -log_error(){ printf "%s: %s\n" "$(date)" "$*" >>"${ERRORLOG}"; } -log_debug(){ printf "%s: %s\n" "$(date)" "$*" >>"${DEBUGLOG}"; } -log_update(){ printf "%s: %s\n" "$(date)" "$*" >>"${UPDATELOG}"; } +log_error(){ printf "%(%c)T: %s\n" "-1" "$*" >>"${ERRORLOG}"; } +log_debug(){ printf "%(%c)T: %s\n" "-1" "$*" >>"${DEBUGLOG}"; } +log_update(){ printf "%(%c)T: %s\n" "-1" "$*" >>"${UPDATELOG}"; } # log $1 with date, special first \n -log_message(){ printf "\n%s: %s\n" "$(date)" "${1/\\n/$'\n'}" >>"${MESSAGELOG}"; } +log_message(){ printf "\n%(%c)T: %s\n" "-1" "${1/\\n/$'\n'}" >>"${MESSAGELOG}"; } # additional tests if we run in debug mode export BASHBOTDEBUG @@ -121,16 +125,16 @@ export BASHBOTDEBUG # shellcheck disable=SC2094 debug_checks(){ { [ -z "${BASHBOTDEBUG}" ] && return - local DATE WHERE MYTOKEN; DATE="$(date)"; WHERE="$1"; shift - printf "%s: debug_checks: %s: bashbot.sh %s\n" "${DATE}" "${WHERE}" "${@##*/}" + local where token; where="$1"; shift + printf "%(%c)T: debug_checks: %s: bashbot.sh %s\n" "-1" "${where}" "${1##*/}" # shellcheck disable=SC2094 - [ -z "${DEBUGLOG}" ] && printf "%s: %s\n" "${DATE}" "DEBUGLOG not set! ==========" - MYTOKEN="$(getConfigKey "bottoken")" - [ -z "${MYTOKEN}" ] && printf "%s: %s\n" "${DATE}" "Bot token is missing! ==========" - check_token "${MYTOKEN}" || printf "%s: %s\n" "${DATE}" "Invalid bot token! ==========" - [ -z "$(getConfigKey "botadmin")" ] && printf "%s: %s\n" "${DATE}" "Bot admin is missing! ==========" + [ -z "${DEBUGLOG}" ] && printf "%(%c)T: %s\n" "-1" "DEBUGLOG not set! ==========" + token="$(getConfigKey "bottoken")" + [ -z "${token}" ] && printf "%(%c)T: %s\n" "-1" "Bot token is missing! ==========" + check_token "${token}" || printf "%(%c)T: %s\n%s\n" "-1" "Invalid bot token! ==========" "${token}" + [ -z "$(getConfigKey "botadmin")" ] && printf "%(%c)T: %s\n" "-1" "Bot admin is missing! ==========" # call user defined debug_checks if exists - _exec_if_function my_debug_checks "${DATE}" "${WHERE}" "$*" + _exec_if_function my_debug_checks "$(_date)" "${where}" "$*" } >>"${DEBUGLOG}" } @@ -261,7 +265,6 @@ ERRORLOG="${LOGDIR}/ERROR.log" UPDATELOG="${LOGDIR}/BASHBOT.log" MESSAGELOG="${LOGDIR}/MESSAGE.log" -debug_checks "start SOURCE=${SOURCE:-no}" "$@" # read BOTTOKEN from bot database if not set if [ -z "${BOTTOKEN}" ]; then BOTTOKEN="$(getConfigKey "bottoken")" @@ -327,6 +330,7 @@ if [ -r "${COMMANDS}" ]; then else [ -z "${SOURCE}" ] && printf "${RED}Warning: ${COMMANDS} does not exist or is not readable!.${NN}" fi +debug_checks "start SOURCE=${SOURCE:-no}" "$@" ############### # load modules @@ -536,7 +540,7 @@ fi sendJsonRetry(){ local retry="$1"; shift [[ "$1" =~ ^\ *[${o9o9o9}.]+\ *$ ]] && sleep "$1"; shift - printf "%s: RETRY %s %s %s\n" "$(date)" "${retry}" "$1" "${2:0:60}" + printf "%(%c)T: RETRY %s %s %s\n" "-1" "${retry}" "$1" "${2:0:60}" case "${retry}" in 'sendJson'*) sendJson "$@" @@ -582,7 +586,7 @@ sendJsonResult(){ # log error [[ "${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)"\ + printf "%(%c)T: RESULT=%s FUNC=%s CHAT[ID]=%s ERROR=%s DESC=%s ACTION=%s\n" "-1"\ "${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 @@ -600,7 +604,7 @@ sendJsonResult(){ if [ "${BOTSENT[ERROR]}" == "999" ];then # check if default curl and args are OK if ! curl -sL -k -m 2 "${URL}" >/dev/null 2>&1 ; then - printf "%s: BASHBOT IP Address seems blocked!\n" "$(date)" + printf "%(%c)T: BASHBOT IP Address seems blocked!\n" "-1" # user provided function to recover or notify block if _exec_if_function bashbotBlockRecover; then BASHBOT_RETRY="2" @@ -706,12 +710,12 @@ process_client() { MESSAGE[0]="/_edited_message " fi process_message "${num}" "${debug}" - printf "%s: update received FROM=%s CHAT=%s CMD=%s\n" "$(date)" "${USER[USERNAME]:0:20} (${USER[ID]})"\ + printf "%(%c)T: update received FROM=%s CHAT=%s CMD=%s\n" "-1" "${USER[USERNAME]:0:20} (${USER[ID]})"\ "${CHAT[USERNAME]:0:20}${CHAT[TITLE]:0:30} (${CHAT[ID]})"\ "${MESSAGE:0:30}${CAPTION:0:30}${URLS[*]:0:30}" >>"${UPDATELOG}" else process_inline "${num}" "${debug}" - printf "%s: iQuery received FROM=%s iQUERY=%s\n" "$(date)"\ + printf "%(%c)T: iQuery received FROM=%s iQUERY=%s\n" "-1"\ "${iQUERY[USERNAME]:0:20} (${iQUERY[USER_ID]})" "${iQUERY[0]}" >>"${UPDATELOG}" fi ##### @@ -1050,7 +1054,7 @@ start_bot() { jssh_deleteKeyDB "CLEAN_COUNTER_DATABASE_ON_STARTUP" "${COUNTFILE}" [ -f "${COUNTFILE}.jssh.flock" ] && rm -f "${COUNTFILE}.jssh.flock" # store start time and cleanup botconfig on startup - jssh_updateKeyDB "startup" "$(date)" "${BOTCONFIG}" + jssh_updateKeyDB "startup" "$(_date)" "${BOTCONFIG}" [ -f "${BOTCONFIG}.jssh.flock" ] && rm -f "${BOTCONFIG}.jssh.flock" # read blocked users jssh_readDB_async "BASHBOTBLOCKED" "${BLOCKEDFILE}" diff --git a/doc/0_install.md b/doc/0_install.md index 79982fa..8032701 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -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-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-23-g8be95a3 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index e29f0c5..e16359f 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -301,5 +301,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-23-g8be95a3 diff --git a/doc/4_expert.md b/doc/4_expert.md index 1616cd6..b5a6f8c 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -434,5 +434,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Advanced Use](3_advanced.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v1.25-dev-2-g0d678f4 +#### $$VERSION$$ v1.25-dev-23-g8be95a3 diff --git a/doc/7_develop.md b/doc/7_develop.md index 8febf48..b6ced9a 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -11,11 +11,11 @@ If you want to get error messages (and more) start bashbot `./bashbot.sh startb you can the change the level of verbosity of the debug argument: ``` - "debug" all output is redirected to "DEBUG.log", in addition every incoming message is logged in "MESSAGE.log" and "INLINE.log" - "xdebug" same as debug plus set bash option '-x' to log any executed command in "DEBUG.log" + "debug" all output is redirected to `DEBUG.log`, in addition every incoming message is logged in `MESSAGE.log` and `INLINE.log` + "xdebug" same as debug plus set bash option '-x' to log any executed command in `DEBUG.log` ``` -Use the command `tail` to watch your bot live, e.g. "tail -f DEBUG.log". To obtain more information place set -x; set +x in your code. +Use the command `tail` to watch your bot live, e.g. `tail -f DEBUG.log`. To obtain more information place `set -x; ... set +x` around suspected code. Sometimes it's useful to watch the bot live in the terminal: @@ -147,7 +147,7 @@ This means if you register an every 5 minutes callback first execution may < 5 M * x execute every x minutes * -x execute once WITHIN the next x Minutes (next 10 Minutes since start "event") -Note: If you want exact "in x minutes" use "EVENT_TIMER plus x" as time: `-(EVENT_TIMER + x)` +Note: If you want exact "in x minutes" use "EVENT_TIMER" as reference: `(EVENT_TIMER +x)` *Example:* ```bash @@ -166,8 +166,8 @@ BASHBOT_EVENT_TIMER["example_every5","5"]="example_every5min" # execute once on the next 10 minutes since start "event" BASHBOT_EVENT_TIMER["example_10min","-10"]="example_in10min" -# once in exact 10 minutes -BASHBOT_EVENT_TIMER["example_10min","$(( (EVENT_TIMER+10) * -1 ))"]="example_in10min" +# once in exact 10 minutes, note the - +BASHBOT_EVENT_TIMER["example_10min","-$(( EVENT_TIMER+10 ))"]="example_in10min" ``` @@ -252,6 +252,8 @@ data="$(cat file)" -> data="$(<"file")" DIR="$(dirname $0) -> DIR="${0%/*}" +date -> printf"%(%c)T\n" -1 # 100 times faster! + PROG="($basename $0)" -> PROG="${0##*/}* ADDME="$ADDME something to add" -> ADDME+=" something to add"" @@ -356,5 +358,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.21-24-g7cf624f +#### $$VERSION$$ v1.25-dev-23-g8be95a3 From cb81f7c8e0835f904b2e5be2699fdcc191eced7a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 6 Jan 2021 15:33:07 +0100 Subject: [PATCH 32/98] internal: some cleanup --- bashbot.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 2a1a972..c3e37bb 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.25-dev-23-g8be95a3 +#### $$VERSION$$ v1.25-dev-24-gbbc6794 ################################################################## # emmbeded system may claim bash but it is not @@ -111,11 +111,11 @@ check_token(){ return 1 } # log $1 with date -log_error(){ printf "%(%c)T: %s\n" "-1" "$*" >>"${ERRORLOG}"; } -log_debug(){ printf "%(%c)T: %s\n" "-1" "$*" >>"${DEBUGLOG}"; } -log_update(){ printf "%(%c)T: %s\n" "-1" "$*" >>"${UPDATELOG}"; } +log_error(){ printf "%(%c)T: %s\n" -1 "$*" >>"${ERRORLOG}"; } +log_debug(){ printf "%(%c)T: %s\n" -1 "$*" >>"${DEBUGLOG}"; } +log_update(){ printf "%(%c)T: %s\n" -1 "$*" >>"${UPDATELOG}"; } # log $1 with date, special first \n -log_message(){ printf "\n%(%c)T: %s\n" "-1" "${1/\\n/$'\n'}" >>"${MESSAGELOG}"; } +log_message(){ printf "\n%(%c)T: %s\n" -1 "${1/\\n/$'\n'}" >>"${MESSAGELOG}"; } # additional tests if we run in debug mode export BASHBOTDEBUG @@ -126,13 +126,13 @@ export BASHBOTDEBUG debug_checks(){ { [ -z "${BASHBOTDEBUG}" ] && return local where token; where="$1"; shift - printf "%(%c)T: debug_checks: %s: bashbot.sh %s\n" "-1" "${where}" "${1##*/}" + printf "%(%c)T: debug_checks: %s: bashbot.sh %s\n" -1 "${where}" "${1##*/}" # shellcheck disable=SC2094 - [ -z "${DEBUGLOG}" ] && printf "%(%c)T: %s\n" "-1" "DEBUGLOG not set! ==========" + [ -z "${DEBUGLOG}" ] && printf "%(%c)T: %s\n" -1 "DEBUGLOG not set! ==========" token="$(getConfigKey "bottoken")" - [ -z "${token}" ] && printf "%(%c)T: %s\n" "-1" "Bot token is missing! ==========" - check_token "${token}" || printf "%(%c)T: %s\n%s\n" "-1" "Invalid bot token! ==========" "${token}" - [ -z "$(getConfigKey "botadmin")" ] && printf "%(%c)T: %s\n" "-1" "Bot admin is missing! ==========" + [ -z "${token}" ] && printf "%(%c)T: %s\n" -1 "Bot token is missing! ==========" + check_token "${token}" || printf "%(%c)T: %s\n%s\n" -1 "Invalid bot token! ==========" "${token}" + [ -z "$(getConfigKey "botadmin")" ] && printf "%(%c)T: %s\n" -1 "Bot admin is missing! ==========" # call user defined debug_checks if exists _exec_if_function my_debug_checks "$(_date)" "${where}" "$*" } >>"${DEBUGLOG}" @@ -540,7 +540,7 @@ fi sendJsonRetry(){ local retry="$1"; shift [[ "$1" =~ ^\ *[${o9o9o9}.]+\ *$ ]] && sleep "$1"; shift - printf "%(%c)T: RETRY %s %s %s\n" "-1" "${retry}" "$1" "${2:0:60}" + printf "%(%c)T: RETRY %s %s %s\n" -1 "${retry}" "$1" "${2:0:60}" case "${retry}" in 'sendJson'*) sendJson "$@" @@ -573,7 +573,7 @@ sendJsonResult(){ # hot path everything OK! else # oops something went wrong! - if [ "$1" != "" ]; then + if [ -n "$1" ]; then BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "$1")" BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "$1")" grep -qs -F '"parameters","retry_after"' <<< "$1" &&\ @@ -586,7 +586,7 @@ sendJsonResult(){ # log error [[ "${BOTSENT[ERROR]}" = "400" && "${BOTSENT[DESCRIPTION]}" == *"starting at byte offset"* ]] &&\ offset="${BOTSENT[DESCRIPTION]%* }" - printf "%(%c)T: RESULT=%s FUNC=%s CHAT[ID]=%s ERROR=%s DESC=%s ACTION=%s\n" "-1"\ + printf "%(%c)T: RESULT=%s FUNC=%s CHAT[ID]=%s ERROR=%s DESC=%s ACTION=%s\n" -1\ "${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 @@ -604,7 +604,7 @@ sendJsonResult(){ if [ "${BOTSENT[ERROR]}" == "999" ];then # check if default curl and args are OK if ! curl -sL -k -m 2 "${URL}" >/dev/null 2>&1 ; then - printf "%(%c)T: BASHBOT IP Address seems blocked!\n" "-1" + printf "%(%c)T: BASHBOT IP Address seems blocked!\n" -1 # user provided function to recover or notify block if _exec_if_function bashbotBlockRecover; then BASHBOT_RETRY="2" @@ -710,12 +710,12 @@ process_client() { MESSAGE[0]="/_edited_message " fi process_message "${num}" "${debug}" - printf "%(%c)T: update received FROM=%s CHAT=%s CMD=%s\n" "-1" "${USER[USERNAME]:0:20} (${USER[ID]})"\ + printf "%(%c)T: update received FROM=%s CHAT=%s CMD=%s\n" -1 "${USER[USERNAME]:0:20} (${USER[ID]})"\ "${CHAT[USERNAME]:0:20}${CHAT[TITLE]:0:30} (${CHAT[ID]})"\ "${MESSAGE:0:30}${CAPTION:0:30}${URLS[*]:0:30}" >>"${UPDATELOG}" else process_inline "${num}" "${debug}" - printf "%(%c)T: iQuery received FROM=%s iQUERY=%s\n" "-1"\ + printf "%(%c)T: iQuery received FROM=%s iQUERY=%s\n" -1\ "${iQUERY[USERNAME]:0:20} (${iQUERY[USER_ID]})" "${iQUERY[0]}" >>"${UPDATELOG}" fi ##### From c205ae528c007dbbc893d1f79c879471816ee4de Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 6 Jan 2021 16:43:18 +0100 Subject: [PATCH 33/98] modules: send_file send and save file_id --- bin/send_file.sh | 4 ++-- modules/sendMessage.sh | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/bin/send_file.sh b/bin/send_file.sh index d419b92..f18cd3c 100755 --- a/bin/send_file.sh +++ b/bin/send_file.sh @@ -24,7 +24,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 25.12.2020 20:24 # -#### $$VERSION$$ v1.25-dev-18-g3d9f784 +#### $$VERSION$$ v1.25-dev-25-gcb81f7c #=============================================================================== #### @@ -58,7 +58,7 @@ fi FILE="$2" # convert to absolute path if not start with / or http:// -[[ ! ( "$2" == "/"* || "$2" =~ ^https*:// ) ]] && FILE="${PWD}/$2" +[[ ! ( "$2" == "/"* || "$2" =~ ^https*:// || "$2" == "file_id://"*) ]] && FILE="${PWD}/$2" # send message in selected format "${SEND}" "${CHAT}" "${FILE}" "$3" "$4" diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index c7e1cb8..d0184cf 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.25-dev-16-gdd19f0f +#### $$VERSION$$ v1.25-dev-25-gcb81f7c # will be automatically sourced from bashbot @@ -212,6 +212,9 @@ upload_file(){ text="$(JsonEscape "$3")" if [[ "${file}" =~ ^https*:// ]]; then media="URL" + elif [[ "${file}" == file_id://* ]]; then + media="ID" + file="${file#file_id://}" else # we have a file, check file location ... media="FILE" @@ -224,8 +227,11 @@ upload_file(){ fi [ ! -r "${file}" ] && return 3 # and file must exits of course fi - - [ -z "${ext}" ] && ext="${file##*.}" + # no type given, use file ext, if no ext type photo + if [ -z "${ext}" ]; then + ext="${file##*.}" + [ "${ext}" = "${file}" ] && ext="photo" + fi case "${ext}" in audio|mp3|flac) CUR_URL="${AUDIO_URL}" @@ -267,10 +273,13 @@ upload_file(){ FILE) # send local file ... sendUpload "$1" "${WHAT}" "${file}" "${CUR_URL}" "${text//\\n/$'\n'}";; - URL) # send URL, should also work for file_id ... - # e.g. '"photo":"https://dealz.rrr.de/assets/images/rbofd-1.gif","caption":"some text"' + URL|ID) # send URL, should also work for file_id ... sendJson "$1" '"'"${WHAT}"'":"'"${file}"'","caption":"'"${text//\\n/$'\n'}"'"' "${CUR_URL}" esac + if [ "${BOTSENT[OK]}" = "true" ]; then + BOTSENT[FILE_ID]="$(JsonGetString '.*,"file_id"' <<< "${res}")" + BOTSENT[FILE_TYPE]="${WHAT}" + fi return 0 } From f08df73ddd65c71525863b5ab7a2926f02b94369 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 6 Jan 2021 17:22:25 +0100 Subject: [PATCH 34/98] doc: send_file URL and file_id --- doc/2_usage.md | 10 ++++++---- doc/6_reference.md | 14 +++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/doc/2_usage.md b/doc/2_usage.md index 848c1b1..5e4f4e7 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -261,7 +261,8 @@ BOTSENT is set on every send_xxx action and only valid until next send action. F * `$BOTSENT`: This array contains the parsed results from the last transmission to telegram. * `${BOTSENT[OK]}`: contains the string `true`: after a successful transmission * `${BOTSENT[ID]}`: Message ID of sent message, image, file etc., if OK is true - + * `${BOTSENT[FILE_ID]}`: unique identifier returned for an uploaded file or URL + * `${BOTSENT[FILE_TYPE]}`: file type: photo, audio, video, sticker, voice, document ## Usage of bashbot functions @@ -315,9 +316,10 @@ send_message "${CHAT[ID]}" "lol" "safe" #### Send files, locations, keyboards. -To send images, videos, voice files, photos etc. use the `send_photo`function (remember to change the safety Regex @ line 14 of command.sh to allow sending files only from certain directories): +To send local files or URL's (photo, video, voice, sticker, documents) use the `send_file` function. ```bash -send_file "${CHAT[ID]}" "/home/user/doge.jpg" "Lool" +send_file "${CHAT[ID]}" "/home/user/dog.jpg" "Lool" "photo" +send_file "${CHAT[ID]}" "https://images-na.ssl-images-amazon.com/images/I/81DQ0FpoSNL._AC_SL1500_.jpg" ``` To send custom keyboards use the `send_keyboard`function: ```bash @@ -342,5 +344,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.25-dev-18-g3d9f784 +#### $$VERSION$$ v1.25-dev-26-gc205ae5 diff --git a/doc/6_reference.md b/doc/6_reference.md index 0c67f00..478034d 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -117,25 +117,29 @@ The main use case for send_message is to process the output of interactive chats ##### send_file -send_file can send different file types using a local file or a http URL (_e.g. https://) +send_file can send local files, URL's or file_id's as different filex types (_e.g. photo video sticker_) -*usage:* send_file "${CHAT[ID]}" "file/URL" "caption" ["type"] +*usage:* send_file "${CHAT[ID]}" "file/URL/file_id" "caption" ["type"] Argument "type" is optional, if not given `send_file` detects file type by the file extension. +if file/URL has no extension `photo` is assumed. Unknown types and extensions are send as type `document` + Supported file types are: photo (_png jpg jpeg gif pic_) audio (_mp3 flac_) sticker (_webp_) video (_mp4_) voice (_ogg_) or document. It's recommended to use __absolute path names__ for local files (_starting with `/`_), as relative path names are threated as __relative to UPLOADDIR__ `data-bot-bash/upload`! For security reasons the following restrictions apply to local files: -- absolute path name must match the __shell regex__ `FILE_REGEX` (_not file glob_) +- absolute path name must match the __shell regex__ `FILE_REGEX` +- relative path name is threated as relative to `UPLOADDIR` (_default: data-bot-bash/upload_) - path must not start with `./` and not contain `../` *example:* ```bash # send picture from web -send_file "${CHAT[ID]}" "https://dealz.rrr.de/assets/images/rbofd-1.gif" "My Bot" +send_file "${CHAT[ID]}" "https://dealz.rrr.de/assets/images/rbofd-1.gif" "My Bot" "photo" +send_file "${CHAT[ID]}" "https://images-na.ssl-images-amazon.com/images/I/81DQ0FpoSNL._AC_SL1500_.jpg" # local file recommended: absolute path send_file "${CHAT[ID]}" "/home/user/dog.jpg" "My Dog" @@ -1193,5 +1197,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.25-dev-16-gdd19f0f +#### $$VERSION$$ v1.25-dev-26-gc205ae5 From 1525ac8231f9940ef4b251da00cdab9c857c9809 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 6 Jan 2021 17:45:13 +0100 Subject: [PATCH 35/98] modules: unify send_file send_upload --- modules/sendMessage.sh | 94 +++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 56 deletions(-) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index d0184cf..afe6a55 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.25-dev-25-gcb81f7c +#### $$VERSION$$ v1.25-dev-27-gf08df73 # will be automatically sourced from bashbot @@ -183,32 +183,10 @@ fi UPLOADDIR="${BASHBOT_UPLOAD:-${DATADIR}/upload}" -# for now this can only send local files with curl! -# extend to allow send files by URL or telegram ID -send_file() { - local err - upload_file "${@}"; err="$?" - # fake Telegram response to provide error - if [ "${err}" != "0" ]; then - BOTSENT=() - BOTSENT[OK]="false" - case "${err}" in - 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} ";; - 3) if [[ "$2" == "/"* ]];then - BOTSENT[ERROR]="File not found: $2" - else - BOTSENT[ERROR]="File not found: ${UPLOADDIR}/$2" - fi;; - esac - [ -n "${BASHBOTDEBUG}" ] && log_message "Error in upload_file: ${BOTSENT[ERROR]}" - fi -} - -# supports http and local file -# $1 chat, $2 file, $3 caption, $4 extension (optional) -upload_file(){ - local CUR_URL WHAT STATUS media text file="$2" ext="$4" +# supports local file, URL and file_id +# $1 chat, $2 file https::// file_id:// , $3 caption, $4 extension (optional) +send_file(){ + local CUR_URL WHAT STATUS err media text file="$2" ext="$4" text="$(JsonEscape "$3")" if [[ "${file}" =~ ^https*:// ]]; then media="URL" @@ -218,64 +196,68 @@ upload_file(){ else # we have a file, check file location ... media="FILE" - [[ "${file}" = *'..'* ]] && return 1 # no directory traversal - [[ "${file}" = '.'* ]] && return 1 # no hidden or relative files + [[ "${file}" = *'..'* || "${file}" = '.'* ]] && err=1 # no directory traversal if [[ "${file}" = '/'* ]] ; then - [[ ! "${file}" =~ ${FILE_REGEX} ]] && return 2 # absolute must match REGEX + [[ ! "${file}" =~ ${FILE_REGEX} ]] && err=2 # absolute must match REGEX else - file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # othiers must be in UPLOADDIR + file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # others must be in UPLOADDIR fi - [ ! -r "${file}" ] && return 3 # and file must exits of course + [ ! -r "${file}" ] && err=3 # and file must exits of course + # file path error, generate error response + if [ -n "${err}" ]; then + BOTSENT=(); BOTSENT[OK]="false" + case "${err}" in + 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} ";; + 3) if [[ "$2" == "/"* ]];then + BOTSENT[ERROR]="File not found: $2" + else + BOTSENT[ERROR]="File not found: ${UPLOADDIR}/$2" + fi;; + esac + [ -n "${BASHBOTDEBUG}" ] && log_message "Error in upload_file: ${BOTSENT[ERROR]}" + return + fi + # file OK, let's continue fi + # no type given, use file ext, if no ext type photo if [ -z "${ext}" ]; then ext="${file##*.}" [ "${ext}" = "${file}" ] && ext="photo" fi + # select upload URL case "${ext}" in audio|mp3|flac) - CUR_URL="${AUDIO_URL}" - WHAT="audio" - STATUS="upload_audio" + CUR_URL="${AUDIO_URL}"; WHAT="audio"; STATUS="upload_audio" ;; photo|png|jpg|jpeg|gif|pic) - CUR_URL="${PHO_URL}" - WHAT="photo" - STATUS="upload_photo" + CUR_URL="${PHO_URL}"; WHAT="photo"; STATUS="upload_photo" ;; sticker|webp) - CUR_URL="${STICKER_URL}" - WHAT="sticker" - STATUS="upload_photo" + CUR_URL="${STICKER_URL}"; WHAT="sticker"; STATUS="upload_photo" ;; video|mp4) - CUR_URL="${VIDEO_URL}" - WHAT="video" - STATUS="upload_video" + CUR_URL="${VIDEO_URL}"; WHAT="video"; STATUS="upload_video" ;; - voice|ogg) - CUR_URL="${VOICE_URL}" - WHAT="voice" - STATUS="upload_audio" + CUR_URL="${VOICE_URL}"; WHAT="voice"; STATUS="record_audio" ;; - *) - CUR_URL="${DOCUMENT_URL}" - WHAT="document" - STATUS="upload_document" + *) CUR_URL="${DOCUMENT_URL}"; WHAT="document"; STATUS="upload_document" ;; esac - # prepare to send FILE / URL + # show file upload to user send_action "$1" "${STATUS}" - # select method to use + # select method to send case "${media}" in FILE) # send local file ... sendUpload "$1" "${WHAT}" "${file}" "${CUR_URL}" "${text//\\n/$'\n'}";; - URL|ID) # send URL, should also work for file_id ... + URL|ID) # send URL, file_id ... sendJson "$1" '"'"${WHAT}"'":"'"${file}"'","caption":"'"${text//\\n/$'\n'}"'"' "${CUR_URL}" esac + # get file_id and file_type if [ "${BOTSENT[OK]}" = "true" ]; then BOTSENT[FILE_ID]="$(JsonGetString '.*,"file_id"' <<< "${res}")" BOTSENT[FILE_TYPE]="${WHAT}" @@ -283,7 +265,7 @@ upload_file(){ return 0 } -# 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 +# $1 typing upload_photo record_video upload_video record_audio upload_audio upload_document find_location send_action() { [ -z "$2" ] && return sendJson "$1" '"action": "'"$2"'"' "${ACTION_URL}" & From ac2e1a96f73527a147a567adc3a0924891dca55a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 6 Jan 2021 18:10:58 +0100 Subject: [PATCH 36/98] doc: add return of file_id file_type --- doc/6_reference.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/6_reference.md b/doc/6_reference.md index 478034d..3051867 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -121,6 +121,10 @@ send_file can send local files, URL's or file_id's as different filex types (_e. *usage:* send_file "${CHAT[ID]}" "file/URL/file_id" "caption" ["type"] +URL's must start with `http://` or `https://` and remote server must send an appropriate media type. +A file_id must start with `file_id://`, all other file names are threated as local files. +If Telegram accepts the file `BOTSENT[FILE_ID]` and `BOTSENT[FILE_TYPE]` are set. + Argument "type" is optional, if not given `send_file` detects file type by the file extension. if file/URL has no extension `photo` is assumed. Unknown types and extensions are send as type `document` @@ -1197,5 +1201,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.25-dev-26-gc205ae5 +#### $$VERSION$$ v1.25-dev-28-g1525ac8 From efca2e013b57ec8938949bf67c8371fedd14bc1f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 6 Jan 2021 18:32:53 +0100 Subject: [PATCH 37/98] modules: send_file locals lowercase --- modules/sendMessage.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index afe6a55..38ea92a 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.25-dev-27-gf08df73 +#### $$VERSION$$ v1.25-dev-29-gac2e1a9 # will be automatically sourced from bashbot @@ -186,8 +186,8 @@ UPLOADDIR="${BASHBOT_UPLOAD:-${DATADIR}/upload}" # supports local file, URL and file_id # $1 chat, $2 file https::// file_id:// , $3 caption, $4 extension (optional) send_file(){ - local CUR_URL WHAT STATUS err media text file="$2" ext="$4" - text="$(JsonEscape "$3")" + local url what stat err media capt file="$2" ext="$4" + capt="$(JsonEscape "$3")" if [[ "${file}" =~ ^https*:// ]]; then media="URL" elif [[ "${file}" == file_id://* ]]; then @@ -229,38 +229,38 @@ send_file(){ # select upload URL case "${ext}" in audio|mp3|flac) - CUR_URL="${AUDIO_URL}"; WHAT="audio"; STATUS="upload_audio" + url="${AUDIO_URL}"; what="audio"; stat="upload_audio" ;; photo|png|jpg|jpeg|gif|pic) - CUR_URL="${PHO_URL}"; WHAT="photo"; STATUS="upload_photo" + url="${PHO_URL}"; what="photo"; stat="upload_photo" ;; sticker|webp) - CUR_URL="${STICKER_URL}"; WHAT="sticker"; STATUS="upload_photo" + url="${STICKER_URL}"; what="sticker"; stat="upload_photo" ;; video|mp4) - CUR_URL="${VIDEO_URL}"; WHAT="video"; STATUS="upload_video" + url="${VIDEO_URL}"; what="video"; stat="upload_video" ;; voice|ogg) - CUR_URL="${VOICE_URL}"; WHAT="voice"; STATUS="record_audio" + url="${VOICE_URL}"; what="voice"; stat="record_audio" ;; - *) CUR_URL="${DOCUMENT_URL}"; WHAT="document"; STATUS="upload_document" + *) url="${DOCUMENT_URL}"; what="document"; stat="upload_document" ;; esac # show file upload to user - send_action "$1" "${STATUS}" + send_action "$1" "${stat}" # select method to send case "${media}" in FILE) # send local file ... - sendUpload "$1" "${WHAT}" "${file}" "${CUR_URL}" "${text//\\n/$'\n'}";; + sendUpload "$1" "${what}" "${file}" "${url}" "${capt//\\n/$'\n'}";; URL|ID) # send URL, file_id ... - sendJson "$1" '"'"${WHAT}"'":"'"${file}"'","caption":"'"${text//\\n/$'\n'}"'"' "${CUR_URL}" + sendJson "$1" '"'"${what}"'":"'"${file}"'","caption":"'"${capt//\\n/$'\n'}"'"' "${url}" esac # get file_id and file_type if [ "${BOTSENT[OK]}" = "true" ]; then BOTSENT[FILE_ID]="$(JsonGetString '.*,"file_id"' <<< "${res}")" - BOTSENT[FILE_TYPE]="${WHAT}" + BOTSENT[FILE_TYPE]="${what}" fi return 0 } From 6f8515d7014c55deb7af70dc64b55a0c51b70a3a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 6 Jan 2021 19:22:24 +0100 Subject: [PATCH 38/98] doc: modules: multiple manipulation without tmp var --- doc/7_develop.md | 16 +++++++++++++++- modules/jsonDB.sh | 10 +++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/doc/7_develop.md b/doc/7_develop.md index b6ced9a..40dd0c5 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -262,6 +262,20 @@ VAR="$(( 1 + 2 ))" -> (( var=1+2 )) INDEX="$(( ${INDEX} + 1 ))" -> (( INDEX++ )) +# manipulate the same variable multiple times without storing intermediate +START="1a23_b__x###" + +BAR="${START//[0-9]}" # a_b__x### +BAR="${BAR%%#*}" # a_b__x +BAR="${BAR/__x/_c}" # a_b_c + +: "${START//[0-9]}" # a_b__x### +: "${_%%#*}" # a_b__x +BAR="${_/__x/_c}" # a_b_c + +# works also for output of commands +: "$(date "+%A")" # Weekday +UPPERDAY="${_^^}" # WEEKDAY ``` For more examples see [Pure bash bible](https://github.com/dylanaraps/pure-bash-bible) @@ -358,5 +372,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.25-dev-23-g8be95a3 +#### $$VERSION$$ v1.25-dev-30-gefca2e0 diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index 5aeca19..108438c 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-30-gefca2e0 # # source from commands.sh to use jsonDB functions # @@ -362,13 +362,13 @@ Json2Array() { # $1 ARRAY name, must be declared with "declare -A ARRAY" before calling Array2Json() { [ -z "$1" ] && return 1 - local key val + local key declare -n ARRAY="$1" for key in "${!ARRAY[@]}" do [[ "${key}" =~ ^${JSSH_KEYOK}+$ ]] || continue - # in case val contains newline convert to \n - val="${ARRAY[${key}]//$'\n'/\\n}" - printf '["%s"]\t"%s"\n' "${key//,/\",\"}" "${val//\"/\\\"}" + # in case value contains newline convert to \n + : "${ARRAY[${key}]//$'\n'/\\n}" + printf '["%s"]\t"%s"\n' "${key//,/\",\"}" "${_//\"/\\\"}" done } From d3253fdf76893819974d33b380b4dcd231c01a3d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 7 Jan 2021 08:58:34 +0100 Subject: [PATCH 39/98] doc: $_ pitfalls --- doc/7_develop.md | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/doc/7_develop.md b/doc/7_develop.md index 40dd0c5..d3f3cb2 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -261,21 +261,32 @@ ADDME="$ADDME something to add" -> ADDME+=" something to add"" VAR="$(( 1 + 2 ))" -> (( var=1+2 )) INDEX="$(( ${INDEX} + 1 ))" -> (( INDEX++ )) +``` -# manipulate the same variable multiple times without storing intermediate -START="1a23_b__x###" +The special variable stores the expanded __last__ argument of the previous command. +This allows some useful optimisations, especially in combination with the no-op command `:`. -BAR="${START//[0-9]}" # a_b__x### -BAR="${BAR%%#*}" # a_b__x -BAR="${BAR/__x/_c}" # a_b_c +```bash +# mkdir plus cd to it +mkdir "tmpdir$$" && cd "$_" # rmpdir1234 (process id) -: "${START//[0-9]}" # a_b__x### +# manipulate a variable multiple times without storing intermediate results +start="1a23_b__x###" +... +: "${start//[0-9]}" # a_b__x### : "${_%%#*}" # a_b__x -BAR="${_/__x/_c}" # a_b_c +bar="${_/__x/_c}" # a_b_c -# works also for output of commands -: "$(date "+%A")" # Weekday -UPPERDAY="${_^^}" # WEEKDAY + +# BE AWARE OF ... +# pitfall/magic missing quotes: $_ is LAST arg +: ${SOMEVAR} # String in var $_ -> "var" +: $(<"file") # Content of\n file $_ -> "file" + +# pitfall/magic command substitution: globbing and IFS is applied! +: "$(echo "a* is born")"# $_ -> a* is globbed even quoted! +: "$(echo "a b c")" # $_ -> "a b c" +: "$(<"file")" # "Content of\n file" $_ -> "Content of file" ``` For more examples see [Pure bash bible](https://github.com/dylanaraps/pure-bash-bible) @@ -372,5 +383,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.25-dev-30-gefca2e0 +#### $$VERSION$$ v1.25-dev-31-g6f8515d From 04e3c18cc41b96040a11c2576e63a92fa83fd118 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 7 Jan 2021 09:00:48 +0100 Subject: [PATCH 40/98] doc: missing $_ mention --- doc/7_develop.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/7_develop.md b/doc/7_develop.md index d3f3cb2..f0e8fed 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -263,8 +263,9 @@ VAR="$(( 1 + 2 ))" -> (( var=1+2 )) INDEX="$(( ${INDEX} + 1 ))" -> (( INDEX++ )) ``` -The special variable stores the expanded __last__ argument of the previous command. -This allows some useful optimisations, especially in combination with the no-op command `:`. +The special variable `$_` stores the expanded __last__ argument of the previous command. +This allows some nice optimisations, especially in combination with the no-op command `:`, +but be aware of the pitfalls. ```bash # mkdir plus cd to it From da214ab81904e85608b1dc00f90bfb20e9214de7 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 7 Jan 2021 09:40:57 +0100 Subject: [PATCH 41/98] dev: generate README.txt from README.html --- README.html | 22 +-- README.md | 22 +-- README.txt | 506 +++++++++++++++++++++++-------------------------- dev/version.sh | 19 +- 4 files changed, 269 insertions(+), 300 deletions(-) diff --git a/README.html b/README.html index eafdc6a..4dfa5ed 100644 --- a/README.html +++ b/README.html @@ -316,10 +316,10 @@ Written by Drew (@topkecleon) and Kay M (@gnadelwartz).
/start
 
 You are Botadmin
-*Available commands*:
-*• /start*: _Start bot and get this message_.
-*• /help*: _Get this message_.
-*• /info*: _Get shorter info message about this bot_....
+Available commands:
+  /start: _Start bot and get this message_.
+  /help: _Get this message_.
+  /info: _Get shorter info message about this bot_....
 
 /info
 
@@ -329,12 +329,12 @@ It features background tasks and interactive chats, and can serve as an interfac
 

Log files

Bashbot actions are logged to BASHBOT.log. Telegram send/receive errors are logged to ERROR.log. Start bashbot in debug mode to see all messages sent to / received from Telegram, as well as bash command error messages.

To enable debug mode, start bashbot with debug as third argument: bashbot start debug

-
├── logs 
-│   ├── BASHBOT.log      # log what your bot is doing ...
-│   ├── ERROR.log        # connection errors from / to Telegram API
-│   │
-│   ├── DEBUG.log        # stdout/stderr of you bot (debug mode enabled)
-│   └── MESSAGE.log      # full text of all message send/received (debug mode enabled)
+
|__ logs
+|     |__ BASHBOT.log  # log what your bot is doing ...
+|     |__ ERROR.log    # connection errors from / to Telegram API
+|     |
+|     |__ DEBUG.log    # stdout/stderr of you bot (debug mode enabled)
+|     |__ MESSAGE.log  # full text of all message send/received (debug mode enabled)

Security Considerations

Running a Telegram Bot means it is connected to the public and you never know what's send to your Bot.

@@ -390,6 +390,6 @@ It features background tasks and interactive chats, and can serve as an interfac

@Gnadelwartz

That's it all guys!

If you feel that there's something missing or if you found a bug, feel free to submit a pull request!

-

$$VERSION$$ v1.21-0-gc85af77

+

$$VERSION$$ v1.25-dev-33-g04e3c18

diff --git a/README.md b/README.md index 0b28c5d..42bedb8 100644 --- a/README.md +++ b/README.md @@ -104,10 +104,10 @@ Now open the Telegram App on your mobile phone and start a chat with your bot (_ /start You are Botadmin -*Available commands*: -*• /start*: _Start bot and get this message_. -*• /help*: _Get this message_. -*• /info*: _Get shorter info message about this bot_.... +Available commands: + /start: _Start bot and get this message_. + /help: _Get this message_. + /info: _Get shorter info message about this bot_.... /info @@ -124,12 +124,12 @@ Start bashbot in debug mode to see all messages sent to / received from Telegram To enable debug mode, start bashbot with debug as third argument: `bashbot start debug` ``` -├── logs -│   ├── BASHBOT.log # log what your bot is doing ... -│   ├── ERROR.log # connection errors from / to Telegram API -│   │ -│   ├── DEBUG.log # stdout/stderr of you bot (debug mode enabled) -│   └── MESSAGE.log # full text of all message send/received (debug mode enabled) +|__ logs +| |__ BASHBOT.log # log what your bot is doing ... +| |__ ERROR.log # connection errors from / to Telegram API +| | +| |__ DEBUG.log # stdout/stderr of you bot (debug mode enabled) +| |__ MESSAGE.log # full text of all message send/received (debug mode enabled) ``` ---- @@ -238,4 +238,4 @@ See `mycommnds.sh.dist` for an example. If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.25-dev-33-g04e3c18 diff --git a/README.txt b/README.txt index f05309f..2a91806 100644 --- a/README.txt +++ b/README.txt @@ -1,324 +1,284 @@ -

-Bashbot - A Telegram bot written in bash. -

+ + + + + +Bashbot README + + + Bashbot - A Telegram bot written in bash. + Written by Drew (@topkecleon) and Kay M (@gnadelwartz). +Contributions by Daniil Gentili (@danog), JuanPotato, BigNerd95, TiagoDanin, iicc1 and +dcoomber. +Released to the public domain wherever applicable. Elsewhere, consider it released under +the WTFPLv2. +Linted by #ShellCheck -Contributions by Daniil Gentili (@danog), JuanPotato, BigNerd95, TiagoDanin, -iicc1 and dcoomber. +Prerequisites -Released to the public domain wherever applicable. -Elsewhere, consider it released under the -[WTFPLv2](http://www.wtfpl.net/txt/copying/). +Uses JSON.sh and the magic of sed. +Bashbot is written in bash. It depends on commands typically available in a Linux/Unix +Environment. For more concrete information on the common commands provided by recent +versions of coreutils, busybox or toybox, see Developer_Notes. +Note for MacOS and BSD Users: Bashbot will not run without installing additional software +as it uses modern bash and (gnu) grep/sed features. See Install_Bashbot. +Note for embedded systems: You need to install a "real" bash as the vanilla installation +of busybox or toybox is not sufficient. See Install_Bashbot. +Bashbot Documentation and Downloads are available on www.github.com. -Linted by [#ShellCheck](https://github.com/koalaman/shellcheck) +Documentation -## Prerequisites -Uses [JSON.sh](http://github.com/dominictarr/JSON.sh) and the magic of sed. -Bashbot is written in bash. It depends on commands typically available in a -Linux/Unix Environment. -For more concrete information on the common commands provided by recent -versions of -[coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), -[busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or -[toybox](https://landley.net/toybox/help.html), see [Developer -Notes](doc/7_develop.md#common-commands). +* Introduction_to_Telegram_Bots +* Install_Bashbot -**Note for MacOS and BSD Users:** Bashbot will not run without installing -additional software as it uses modern bash and (gnu) grep/sed features. See -[Install Bashbot](doc/0_install.md). + o Install release + o Install from github + o Update Bashbot + o Notes on Updates -**Note for embedded systems:** You need to install a "real" bash as the vanilla -installation of busybox or toybox is not sufficient. See [Install -Bashbot](doc/0_install.md). +* Get_Bottoken_from_Botfather +* Getting_Started -Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and -[Downloads](https://github.com/topkecleon/telegram-bot-bash/releases) are -available on [www.github.com](https://www.github.com). + o Managing your Bot + o Receive data + o Send messages + o Send files, locations, keyboards -## Documentation -* [Introduction to Telegram Bots](https://core.telegram.org/bots) -* [Install Bashbot](doc/0_install.md) - * Install release - * Install from github - * Update Bashbot - * Notes on Updates -* [Get Bottoken from Botfather](doc/1_firstbot.md) -* [Getting Started](doc/2_usage.md) - * Managing your Bot - * Receive data - * Send messages - * Send files, locations, keyboards -* [Advanced Features](doc/3_advanced.md) - * Access Control - * Interactive Chats - * Background Jobs - * Inline queries - * Send message errors -* [Expert Use](doc/4_expert.md) - * Handling UTF-8 character sets - * Run as other user or system service - * Schedule bashbot from Cron - * Use from CLI and Scripts - * Customize Bashbot Environment -* [Best Practices](doc/5_practice.md) - * Customize mycommands.sh - * Overwrite/disable commands - * Separate logic from commands - * Test your Bot with shellcheck -* [Function Reference](doc/6_reference.md) - * Sending Messages, Files, Keyboards - * User Access Control - * Inline Queries - * jsshDB Bashbot key-value storage - * Background and Interactive Jobs -* [Developer Notes](doc/7_develop.md) - * Debug bashbot - * Modules, addons, events - * Setup your environment - * Bashbot test suite -* [Examples Directory](examples/README.md) +* Advanced_Features -### Your very first bashbot in a nutshell + o Access Control + o Interactive Chats + o Background Jobs + o Inline queries + o Send message errors -To install and run bashbot you need access to a Linux/Unix command line with -bash, a [Telegram client](https://telegram.org) and a mobile phone [with a -Telegram account](https://telegramguide.com/create-a-telegram-account/). +* Expert_Use -First you need to [create a new Telegram Bot token](doc/1_firstbot.md) for your -bot and write it down. + o Handling UTF-8 character sets + o Run as other user or system service + o Schedule bashbot from Cron + o Use from CLI and Scripts + o Customize Bashbot Environment -Now open a Linux/Unix terminal with bash, create a new directory, change to it -and install telegram-bot-bash: +* Best_Practices -```bash -# create bot dir -mkdir mybot -cd mybot + o Customize mycommands.sh + o Overwrite/disable commands + o Separate logic from commands + o Test your Bot with shellcheck -# download latest release with wget or from -https://github.com/topkecleon/telegram-bot-bash/releases/latest -wget "https://github.com/$(wget -q -"https://github.com/topkecleon/telegram-bot-bash/releases/latest" -O - | egrep -'/.*/download/.*/.*tar.gz' -o)" +* Function_Reference -# Extract the tar archive and go into bot dir -tar -xzf *.tar.gz -cd telegram-bot-bash + o Sending Messages, Files, Keyboards + o User Access Control + o Inline Queries + o jsshDB Bashbot key-value storage + o Background and Interactive Jobs -# initialize your bot -# Enter your bot token when asked, all other questions can be answered by -hitting the \ key. -./bashbot.sh init +* Developer_Notes -# Now start your bot -./bashbot.sh start + o Debug bashbot + o Modules, addons, events + o Setup your environment + o Bashbot test suite -Bottoken is valid ... -Bot Name: yourbotname_bot -Session Name: yourbotname_bot-startbot -Bot started successfully. -``` +* Examples_Directory -Now open the Telegram App on your mobile phone and start a chat with your bot -(_your bot's username is shown after 'Bot Name:'_): -``` -/start +Your very first bashbot in a nutshell -You are Botadmin -*Available commands*: -*• /start*: _Start bot and get this message_. -*• /help*: _Get this message_. -*• /info*: _Get shorter info message about this bot_.... +To install and run bashbot you need access to a Linux/Unix command line with bash, a +Telegram_client and a mobile phone with_a_Telegram_account. +First you need to create_a_new_Telegram_Bot_token for your bot and write it down. +Now open a Linux/Unix terminal with bash, create a new directory, change to it and install +telegram-bot-bash: -/info + # create bot dir + mkdir mybot + cd mybot -This is bashbot, the Telegram bot written entirely in bash. -It features background tasks and interactive chats, and can serve as an -interface for CLI programs. -``` -For more Information on how to install, customize and use your new bot, read -the [Documentation](#Documentation). + # download latest release with wget or from https://github.com/topkecleon/telegram-bot- + bash/releases/latest + wget "https://github.com/$(wget -q "https://github.com/topkecleon/telegram- + bot-bash/releases/latest" -O - | egrep '/.*/download/.*/.*tar.gz' -o)" -### Log files + # Extract the tar archive and go into bot dir + tar -xzf *.tar.gz + cd telegram-bot-bash -Bashbot actions are logged to `BASHBOT.log`. Telegram send/receive errors are -logged to `ERROR.log`. -Start bashbot in debug mode to see all messages sent to / received from + # initialize your bot + # Enter your bot token when asked, all other questions can be answered by hitting the + \ key. + ./bashbot.sh init + + # Now start your bot + ./bashbot.sh start + + Bottoken is valid ... + Bot Name: yourbotname_bot + Session Name: yourbotname_bot-startbot + Bot started successfully. + +Now open the Telegram App on your mobile phone and start a chat with your bot (your bot's +username is shown after 'Bot Name:'): + + /start + + You are Botadmin + Available commands: + /start: _Start bot and get this message_. + /help: _Get this message_. + /info: _Get shorter info message about this bot_.... + + /info + + This is bashbot, the Telegram bot written entirely in bash. + It features background tasks and interactive chats, and can serve as an interface for + CLI programs. + +For more Information on how to install, customize and use your new bot, read the +Documentation. + +Log files + +Bashbot actions are logged to BASHBOT.log. Telegram send/receive errors are logged to +ERROR.log. Start bashbot in debug mode to see all messages sent to / received from Telegram, as well as bash command error messages. +To enable debug mode, start bashbot with debug as third argument: bashbot start debug -To enable debug mode, start bashbot with debug as third argument: `bashbot -start debug` + |__ logs + | |__ BASHBOT.log # log what your bot is doing ... + | |__ ERROR.log # connection errors from / to Telegram API + | | + | |__ DEBUG.log # stdout/stderr of you bot (debug mode enabled) + | |__ MESSAGE.log # full text of all message send/received (debug mode enabled) -``` -├── logs -│   ├── BASHBOT.log # log what your bot is doing ... -│   ├── ERROR.log # connection errors from / to Telegram API -│   │ -│   ├── DEBUG.log # stdout/stderr of you bot (debug mode enabled) -│   └── MESSAGE.log # full text of all message send/received (debug mode -enabled) -``` +------------------------------------------------------------------------------------------ ----- +Security Considerations -## Security Considerations -Running a Telegram Bot means it is connected to the public and you never know -what's send to your Bot. +Running a Telegram Bot means it is connected to the public and you never know what's send +to your Bot. +Bash scripts in general are not designed to be bulletproof, so consider this Bot as a +proof of concept. Bash programmers often struggle with 'quoting hell' and globbing, see +Implications_of_wrong_quoting. +Whenever you are processing input from untrusted sources (messages, files, network) you +must be as careful as possible (e.g. set IFS appropriately, disable globbing with set - +f and quote everything). In addition remove unused scripts and examples from your Bot +(e.g. everything in example/) and disable/remove all unused bot commands. +It's important to escape or remove $ in input from user, files or network (as bashbot +does). One of the powerful features of Unix shells is variable and command substitution +using ${} and$() can lead to remote code execution (RCE) or remote information disclosure +(RID) bugs if unescaped $ is included in untrusted input (e.g. $$ or $(rm -rf /*)). +A powerful tool to improve your scripts is shellcheck. You can use_it_online or install +shellcheck_locally. Shellcheck is used extensively in bashbot development to ensure a high +code quality (e.g. it's not allowed to push changes without passing all shellcheck tests). +In addition bashbot has a test_suite to check if important functionality is working as +expected. -Bash scripts in general are not designed to be bulletproof, so consider this -Bot as a proof of concept. -Bash programmers often struggle with 'quoting hell' and globbing, -see [Implications of wrong -quoting](https://unix.stackexchange.com/questions/171346/security-implications-o -f-forgetting-to-quote-a-variable-in-bash-posix-shells). +Use printf whenever possible -Whenever you are processing input from untrusted sources (messages, files, -network) you must be as careful as possible -(e.g. set IFS appropriately, disable globbing with `set -f` and quote -everything). In addition remove unused scripts and examples -from your Bot (e.g. everything in `example/`) and disable/remove all unused bot -commands. +If you're writing a script that accepts external input (e.g. from the user as arguments or +the file system), you shouldn't use echo to display it. Use_printf_whenever_possible. -It's important to escape or remove `$` in input from user, files or network -(_as bashbot does_). -One of the powerful features of Unix shells is variable and command -substitution using `${}` and`$()` can lead to remote code execution (RCE) or -remote information disclosure (RID) bugs if unescaped `$` is included in -untrusted input (e.g. `$$` or `$(rm -rf /*)`). +Run your Bot as a restricted user -A powerful tool to improve your scripts is `shellcheck`. You can [use it -online](https://www.shellcheck.net/) or -[install shellcheck -locally](https://github.com/koalaman/shellcheck#installing). Shellcheck is used -extensively in bashbot development -to ensure a high code quality (e.g. it's not allowed to push changes without -passing all shellcheck tests). -In addition bashbot has a [test suite](doc/7_develop.md) to check if important -functionality is working as expected. +I recommend running your bot as a user with almost no access rights. All files your Bot +has write access to are in danger of being overwritten/deleted if your bot is hacked. For +the same reason every file your Bot can read is in danger of being disclosed. Restrict +your Bots access rights to the absolute minimum. +Never run your Bot as root, this is the most dangerous you can do! Usually the user +'nobody' has almost no rights on Linux/Unix systems. See Expert_use on how to run your Bot +as an other user. -### Use printf whenever possible +Secure your Bot installation -If you're writing a script that accepts external input (e.g. from the user as -arguments or the file system), -you shouldn't use echo to display it. [Use printf whenever -possible](https://unix.stackexchange.com/a/6581). +Your Bot configuration must not be readable by other users. Everyone who can read your +Bots token is able to act as your Bot and has access to all chats the Bot is in! +Everyone with read access to your Bot files can extract your Bots data. Especially your +Bot config inconfig.jssh must be protected against other users. No one except you should +have write access to the Bot files. The Bot should be restricted to have write access +tocount.jssh and data-bot-bash only, all other files must be write protected. +To set access rights for your bashbot installation to a reasonable default runsudo ./ +bashbot.sh init after every update or change to your installation directory. -### Run your Bot as a restricted user -**I recommend running your bot as a user with almost no access rights.** -All files your Bot has write access to are in danger of being -overwritten/deleted if your bot is hacked. -For the same reason every file your Bot can read is in danger of being -disclosed. Restrict your Bots access rights to the absolute minimum. - -**Never run your Bot as root, this is the most dangerous you can do!** Usually -the user 'nobody' has almost no rights on Linux/Unix systems. See [Expert -use](doc/4_expert.md) on how to run your Bot as an other user. - -### Secure your Bot installation -**Your Bot configuration must not be readable by other users.** Everyone who -can read your Bots token is able to act as your Bot and has access to all chats -the Bot is in! - -Everyone with read access to your Bot files can extract your Bots data. -Especially your Bot config in`config.jssh` must be protected against other -users. No one except you should have write access to the Bot files. The Bot -should be restricted to have write access to`count.jssh` and `data-bot-bash` -only, all other files must be write protected. - -To set access rights for your bashbot installation to a reasonable default -run`sudo ./bashbot.sh init` after every update or change to your installation -directory. - -## FAQ - -### Is this Bot insecure? -Bashbot is not more (in)secure than a Bot written in another language. We have -done our best to make it as secure as possible. But YOU are responsible for the -bot commands you wrote and you should know about the risks ... - -**Note:** Up to version 0.941 (mai/22/2020) telegram-bot-bash had a remote code -execution bug, please update if you use an older version! - -### Why Bash and not the much better xyz? -Well, that's a damn good question... maybe because I'm a Unix admin from the -stone age. Nevertheless there are more reasons from my side: - -- bashbot will run wherever bash and (gnu) sed is available, from embedded -Linux to mainframe -- easy to integrate with other shell scripts, e.g. for sending system message / -health status -- no need to install or learn a new programming language, library or framework -- no database, not event driven, not object oriented ... - -### Can I have the single bashbot.sh file back? -At the beginning bashbot was simply the file`bashbot.sh` that you could copy -everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh', -'modules/*.sh' and much more. - -Hey no problem, if you are finished with your cool bot, -run`dev/make-standalone.sh` to create a stripped down version of your bot -containing only -'bashbot.sh' and 'commands.sh'! For more information see [Create a stripped -down version of your Bot](doc/7_develop.md). - -### Can I send messages from CLI and scripts? -Of course you can send messages from command line and scripts! Simply install -bashbot as [described here](#Your-really-first-bashbot-in-a-nutshell), -send the message '/start' to set yourself as botadmin and then stop the bot -with `./bashbot.sh stop`. - -Bashbot provides some ready to use scripts for sending messages from command -line in `bin/` dir, e.g. `send_message.sh`. - -```bash -bin/send_message.sh BOTADMIN "This is my first message send from CLI" - -bin/send_message.sh --help -``` - -You can also source bashbot for use in your scripts, for more information see -[Expert Use](doc/4_expert.md). +FAQ -### Blocked by telegram? -This may happen if too many or wrong requests are sent to api.telegram.org, -e.g. using a invalid token or invalid API calls. -If the block stay for longer time you can ask telegram service to unblock your -IP-Address. +Is this Bot insecure? +Bashbot is not more (in)secure than a Bot written in another language. We have done our +best to make it as secure as possible. But YOU are responsible for the bot commands you +wrote and you should know about the risks ... +Note: Up to version 0.941 (mai/22/2020) telegram-bot-bash had a remote code execution bug, +please update if you use an older version! + +Why Bash and not the much better xyz? + +Well, that's a damn good question... maybe because I'm a Unix admin from the stone age. +Nevertheless there are more reasons from my side: + +* bashbot will run wherever bash and (gnu) sed is available, from embedded Linux to + mainframe +* easy to integrate with other shell scripts, e.g. for sending system message / health + status +* no need to install or learn a new programming language, library or framework +* no database, not event driven, not object oriented ... + + +Can I have the single bashbot.sh file back? + +At the beginning bashbot was simply the filebashbot.sh that you could copy everywhere and +run the bot. Now we have 'commands.sh', 'mycommands.sh', 'modules/*.sh' and much more. +Hey no problem, if you are finished with your cool bot, rundev/make-standalone.sh to +create a stripped down version of your bot containing only 'bashbot.sh' and 'commands.sh'! +For more information see Create_a_stripped_down_version_of_your_Bot. + +Can I send messages from CLI and scripts? + +Of course you can send messages from command line and scripts! Simply install bashbot as +described_here, send the message '/start' to set yourself as botadmin and then stop the +bot with ./bashbot.sh stop. +Bashbot provides some ready to use scripts for sending messages from command line in bin/ +dir, e.g. send_message.sh. + + bin/send_message.sh BOTADMIN "This is my first message send from CLI" + + bin/send_message.sh --help + +You can also source bashbot for use in your scripts, for more information see Expert_Use. + +Blocked by telegram? + +This may happen if too many or wrong requests are sent to api.telegram.org, e.g. using a +invalid token or invalid API calls. If the block stay for longer time you can ask telegram +service to unblock your IP-Address. You can check with curl or wget if you are blocked by Telegram: -```bash -curl -m 10 https://api.telegram.org/bot -#curl: (28) Connection timed out after 10001 milliseconds -wget -t 1 -T 10 https://api.telegram.org/bot -#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... -failed: Connection timed out. + curl -m 10 https://api.telegram.org/bot + #curl: (28) Connection timed out after 10001 milliseconds -nc -w 2 api.telegram.org 443 || echo "your IP seems blocked by telegram" -#your IP seems blocked by telegram -``` + wget -t 1 -T 10 https://api.telegram.org/bot + #Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... failed: + Connection timed out. -Bashbot offers the option to recover from broken connections (blocked). -Therefore you can provide a function -named `bashbotBlockRecover()` in `mycommands.sh`, the function is called every -time when a broken connection is detected. - -Possible actions are: Check if network is working, change IP-Address or simply -wait some time. -See `mycommnds.sh.dist` for an example. - ---- + nc -w 2 api.telegram.org 443 || echo "your IP seems blocked by telegram" + #your IP seems blocked by telegram +Bashbot offers the option to recover from broken connections (blocked). Therefore you can +provide a function named bashbotBlockRecover() in mycommands.sh, the function is called +every time when a broken connection is detected. +Possible actions are: Check if network is working, change IP-Address or simply wait some +time. See mycommnds.sh.dist for an example. +------------------------------------------------------------------------------------------ @Gnadelwartz -## That's it all guys! +That's it all guys! -If you feel that there's something missing or if you found a bug, feel free to -submit a pull request! +If you feel that there's something missing or if you found a bug, feel free to submit a +pull request! + +$$VERSION$$ v1.25-dev-33-g04e3c18 -#### $$VERSION$$ v1.21-0-gc85af77 diff --git a/dev/version.sh b/dev/version.sh index 36e1ed7..21e5c6b 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-33-g04e3c18 # shellcheck disable=SC2016 # # Easy Versioning in git: @@ -52,6 +52,18 @@ printf "Update to version %s ...\n" "${VERSION}" FILES="$(find ./*)" [ "$1" != "" ] && FILES="$*" +# autogenerate REMADME.html REMADE.txt +if [[ "${FILES}" == *"README.md"* ]]; then + FILES+=" README.html README.txt" + type -f pandoc >/dev/null && pandoc -s -f commonmark -M "title=Bashbot README" README.md >README.html + if type -f html2text >/dev/null; then + html2text -style pretty -width 90 README.html >README.txt + else + type -f fold >/dev/null && fold -s -w 90 README.md >README.txt + fi +fi + +# change version string in given files for file in ${FILES} do [ ! -f "${file}" ] && continue @@ -59,9 +71,6 @@ do printf "%s" " ${file}" >&2 sed -i 's/^#### $$VERSION$$.*/#### \$\$VERSION\$\$ '"${VERSION}"'/' "${file}" done -# try to compile README.txt -printf " README.txt" >&2 -type -f pandoc >/dev/null && pandoc -s -f commonmark -M "title=Bashbot README" README.md >README.html -fold -s README.md >README.txt + printf " done.\n" From fa8e8a267c41fd1b3289b6d4afe5caf186a61e9b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 7 Jan 2021 13:15:18 +0100 Subject: [PATCH 42/98] bin: fix some script bugs --- bin/bashbot_env.inc.sh | 2 +- bin/bashbot_stats.sh | 2 +- bin/delete_message.sh | 2 +- bin/send_broadcast.sh | 4 ++-- bin/send_edit_message.sh | 5 ++--- bin/send_file.sh | 4 ++-- bin/send_message.sh | 4 ++-- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/bin/bashbot_env.inc.sh b/bin/bashbot_env.inc.sh index 2cc4bc4..eb9000c 100644 --- a/bin/bashbot_env.inc.sh +++ b/bin/bashbot_env.inc.sh @@ -13,7 +13,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 18.12.2020 12:27 # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-34-gda214ab #=============================================================================== ############ diff --git a/bin/bashbot_stats.sh b/bin/bashbot_stats.sh index 164c6af..66358a9 100755 --- a/bin/bashbot_stats.sh +++ b/bin/bashbot_stats.sh @@ -16,7 +16,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 20:34 # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-34-gda214ab #=============================================================================== #### diff --git a/bin/delete_message.sh b/bin/delete_message.sh index 905687f..e0c08ce 100755 --- a/bin/delete_message.sh +++ b/bin/delete_message.sh @@ -19,7 +19,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 03.01.2021 15:37 # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-34-gda214ab #=============================================================================== #### diff --git a/bin/send_broadcast.sh b/bin/send_broadcast.sh index d66402c..89442a4 100755 --- a/bin/send_broadcast.sh +++ b/bin/send_broadcast.sh @@ -24,7 +24,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 16:14 # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-34-gda214ab #=============================================================================== # shellcheck disable=SC2059 @@ -55,7 +55,7 @@ fi # parse args ----------------- SEND="send_message" case "$1" in - "nor*"|"tex*") + "nor"*|"tex"*) SEND="send_normal_message" shift ;; diff --git a/bin/send_edit_message.sh b/bin/send_edit_message.sh index 5e0cf1e..6dbb640 100755 --- a/bin/send_edit_message.sh +++ b/bin/send_edit_message.sh @@ -22,14 +22,14 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 16:52 # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-34-gda214ab #=============================================================================== #### # parse args SEND="edit_normal_message" case "$1" in - "nor*"|"tex*") + "nor"*|"tex"*) SEND="edit_normal_message" shift ;; @@ -54,7 +54,6 @@ case "$1" in ;; esac - # set bashbot environment # shellcheck disable=SC1090 source "${0%/*}/bashbot_env.inc.sh" "$4" # $4 debug diff --git a/bin/send_file.sh b/bin/send_file.sh index f18cd3c..64c3579 100755 --- a/bin/send_file.sh +++ b/bin/send_file.sh @@ -24,12 +24,12 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 25.12.2020 20:24 # -#### $$VERSION$$ v1.25-dev-25-gcb81f7c +#### $$VERSION$$ v1.25-dev-34-gda214ab #=============================================================================== #### # parse args -SEND="upload_file" +SEND="send_file" case "$1" in '') printf "missing arguments\n" diff --git a/bin/send_message.sh b/bin/send_message.sh index 1af3522..1ec494e 100755 --- a/bin/send_message.sh +++ b/bin/send_message.sh @@ -21,14 +21,14 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 11:34 # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-34-gda214ab #=============================================================================== #### # parse args SEND="send_message" case "$1" in - "nor*"|"tex*") + "nor"*|"tex"*) SEND="send_normal_message" shift ;; From 58e789a07937d88e6e817e8b50fd153e596ea35c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 8 Jan 2021 15:18:58 +0100 Subject: [PATCH 43/98] dev: make-dist do not overwrite bashbot.rc --- dev/make-distribution.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index d656709..a5d2f04 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -7,7 +7,7 @@ # # Options: --notest - skip tests # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-35-gfa8e8a2 ############################################################## # magic to ensure that we're always inside the root of our application, @@ -26,7 +26,7 @@ DISTNAME="telegram-bot-bash" DISTDIR="./DIST/${DISTNAME}" DISTMKDIR="data-bot-bash logs bin bin/logs addons" -DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh.clean bin doc examples scripts modules LICENSE README.md README.txt README.html" +DISTFILES="bashbot.sh commands.sh mycommands.sh.clean bin doc examples scripts modules LICENSE README.md README.txt README.html" DISTFILESDIST="mycommands.sh bashbot.rc $(echo "addons/"*.sh)" # run tests first! From f0a2843f2afdb3b7f73acb8a36d1be5b6a77021f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 8 Jan 2021 15:29:36 +0100 Subject: [PATCH 44/98] doc: more careful $_ advise --- doc/7_develop.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/doc/7_develop.md b/doc/7_develop.md index f0e8fed..e5a14aa 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -262,34 +262,36 @@ VAR="$(( 1 + 2 ))" -> (( var=1+2 )) INDEX="$(( ${INDEX} + 1 ))" -> (( INDEX++ )) ``` +For more examples see [Pure bash bible](https://github.com/dylanaraps/pure-bash-bible) The special variable `$_` stores the expanded __last__ argument of the previous command. -This allows some nice optimisations, especially in combination with the no-op command `:`, -but be aware of the pitfalls. +This allows a nice optimisation in combination with the no-op command `:`, but be aware of `$_` pitfalls. ```bash -# mkdir plus cd to it -mkdir "tmpdir$$" && cd "$_" # rmpdir1234 (process id) +# $_ example: mkdir plus cd to it +mkdir "somedir-$$" && cd "$_" # somedir-1234 (process id) # manipulate a variable multiple times without storing intermediate results -start="1a23_b__x###" +foo="1a23_b__x###" ... -: "${start//[0-9]}" # a_b__x### +: "${foo//[0-9]}" # a_b__x### : "${_%%#*}" # a_b__x bar="${_/__x/_c}" # a_b_c # BE AWARE OF ... -# pitfall/magic missing quotes: $_ is LAST arg -: ${SOMEVAR} # String in var $_ -> "var" -: $(<"file") # Content of\n file $_ -> "file" +# pitfall missing quotes: $_ is LAST arg +: ${SOMEVAR} # "String in var" $_ -> "var" +: $(<"file") # "Content of\n file" $_ -> "file" -# pitfall/magic command substitution: globbing and IFS is applied! +# pitfall test command +[ -n "$MYVAR" ] && echo "$_" # outputs "]" + +# pitfall command substitution: globbing and IFS is applied! : "$(echo "a* is born")"# $_ -> a* is globbed even quoted! -: "$(echo "a b c")" # $_ -> "a b c" +: "$(echo "a b c")"# $_ -> "a b c" : "$(<"file")" # "Content of\n file" $_ -> "Content of file" ``` -For more examples see [Pure bash bible](https://github.com/dylanaraps/pure-bash-bible) #### Prepare a new version After some development it may time to create a new version for the users. a new version can be in sub version upgrade, e.g. for fixes and smaller additions or @@ -384,5 +386,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.25-dev-31-g6f8515d +#### $$VERSION$$ v1.25-dev-36-g58e789a From 1eafc914526fbba4537354a1252be80a9b4ba609 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 8 Jan 2021 15:52:07 +0100 Subject: [PATCH 45/98] dev: preservere links for README.txt --- README.html | 2 +- README.md | 2 +- README.txt | 73 +++++++++++++++++++++++++++----------------------- dev/version.sh | 6 +++-- 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/README.html b/README.html index 4dfa5ed..3502ec8 100644 --- a/README.html +++ b/README.html @@ -390,6 +390,6 @@ It features background tasks and interactive chats, and can serve as an interfac

@Gnadelwartz

That's it all guys!

If you feel that there's something missing or if you found a bug, feel free to submit a pull request!

-

$$VERSION$$ v1.25-dev-33-g04e3c18

+

$$VERSION$$ v1.25-dev-37-gf0a2843

diff --git a/README.md b/README.md index 42bedb8..7ee6443 100644 --- a/README.md +++ b/README.md @@ -238,4 +238,4 @@ See `mycommnds.sh.dist` for an example. If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.25-dev-33-g04e3c18 +#### $$VERSION$$ v1.25-dev-37-gf0a2843 diff --git a/README.txt b/README.txt index 2a91806..c9fb4fa 100644 --- a/README.txt +++ b/README.txt @@ -12,41 +12,44 @@ Written by Drew (@topkecleon) and Kay M (@gnadelwartz). Contributions by Daniil Gentili (@danog), JuanPotato, BigNerd95, TiagoDanin, iicc1 and dcoomber. Released to the public domain wherever applicable. Elsewhere, consider it released under -the WTFPLv2. +the WTFPLv2 [http://www.wtfpl.net/txt/copying/]. Linted by #ShellCheck Prerequisites -Uses JSON.sh and the magic of sed. +Uses JSON.sh [http://github.com/dominictarr/JSON.sh] and the magic of sed. Bashbot is written in bash. It depends on commands typically available in a Linux/Unix Environment. For more concrete information on the common commands provided by recent -versions of coreutils, busybox or toybox, see Developer_Notes. +versions of coreutils [https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands], +busybox or toybox, see Developer_Notes. Note for MacOS and BSD Users: Bashbot will not run without installing additional software -as it uses modern bash and (gnu) grep/sed features. See Install_Bashbot. +as it uses modern bash and (gnu) grep/sed features. See Install Bashbot [doc/ +0_install.md]. Note for embedded systems: You need to install a "real" bash as the vanilla installation -of busybox or toybox is not sufficient. See Install_Bashbot. -Bashbot Documentation and Downloads are available on www.github.com. +of busybox or toybox is not sufficient. See Install Bashbot [doc/0_install.md]. +Bashbot Documentation [https://github.com/topkecleon/telegram-bot-bash] and Downloads are +available on www.github.com. Documentation -* Introduction_to_Telegram_Bots -* Install_Bashbot +* Introduction to Telegram Bots [https://core.telegram.org/bots] +* Install Bashbot [doc/0_install.md] o Install release o Install from github o Update Bashbot o Notes on Updates -* Get_Bottoken_from_Botfather -* Getting_Started +* Get Bottoken from Botfather [doc/1_firstbot.md] +* Getting Started [doc/2_usage.md] o Managing your Bot o Receive data o Send messages o Send files, locations, keyboards -* Advanced_Features +* Advanced Features [doc/3_advanced.md] o Access Control o Interactive Chats @@ -54,7 +57,7 @@ Documentation o Inline queries o Send message errors -* Expert_Use +* Expert Use [doc/4_expert.md] o Handling UTF-8 character sets o Run as other user or system service @@ -62,14 +65,14 @@ Documentation o Use from CLI and Scripts o Customize Bashbot Environment -* Best_Practices +* Best Practices [doc/5_practice.md] o Customize mycommands.sh o Overwrite/disable commands o Separate logic from commands o Test your Bot with shellcheck -* Function_Reference +* Function Reference [doc/6_reference.md] o Sending Messages, Files, Keyboards o User Access Control @@ -77,21 +80,22 @@ Documentation o jsshDB Bashbot key-value storage o Background and Interactive Jobs -* Developer_Notes +* Developer Notes [doc/7_develop.md] o Debug bashbot o Modules, addons, events o Setup your environment o Bashbot test suite -* Examples_Directory +* Examples Directory [examples/README.md] Your very first bashbot in a nutshell To install and run bashbot you need access to a Linux/Unix command line with bash, a -Telegram_client and a mobile phone with_a_Telegram_account. -First you need to create_a_new_Telegram_Bot_token for your bot and write it down. +Telegram client [https://telegram.org] and a mobile phone with_a_Telegram_account. +First you need to create a new Telegram Bot token [doc/1_firstbot.md] for your bot and +write it down. Now open a Linux/Unix terminal with bash, create a new directory, change to it and install telegram-bot-bash: @@ -139,7 +143,7 @@ username is shown after 'Bot Name:'): CLI programs. For more Information on how to install, customize and use your new bot, read the -Documentation. +Documentation [#Documentation]. Log files @@ -163,7 +167,8 @@ Running a Telegram Bot means it is connected to the public and you never know wh to your Bot. Bash scripts in general are not designed to be bulletproof, so consider this Bot as a proof of concept. Bash programmers often struggle with 'quoting hell' and globbing, see -Implications_of_wrong_quoting. +Implications of wrong quoting [https://unix.stackexchange.com/questions/171346/security- +implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells]. Whenever you are processing input from untrusted sources (messages, files, network) you must be as careful as possible (e.g. set IFS appropriately, disable globbing with set - f and quote everything). In addition remove unused scripts and examples from your Bot @@ -172,16 +177,17 @@ It's important to escape or remove $ in input from user, files or network (as ba does). One of the powerful features of Unix shells is variable and command substitution using ${} and$() can lead to remote code execution (RCE) or remote information disclosure (RID) bugs if unescaped $ is included in untrusted input (e.g. $$ or $(rm -rf /*)). -A powerful tool to improve your scripts is shellcheck. You can use_it_online or install -shellcheck_locally. Shellcheck is used extensively in bashbot development to ensure a high -code quality (e.g. it's not allowed to push changes without passing all shellcheck tests). -In addition bashbot has a test_suite to check if important functionality is working as -expected. +A powerful tool to improve your scripts is shellcheck. You can use it online [https:// +www.shellcheck.net/] or install_shellcheck_locally. Shellcheck is used extensively in +bashbot development to ensure a high code quality (e.g. it's not allowed to push changes +without passing all shellcheck tests). In addition bashbot has a test_suite to check if +important functionality is working as expected. Use printf whenever possible If you're writing a script that accepts external input (e.g. from the user as arguments or -the file system), you shouldn't use echo to display it. Use_printf_whenever_possible. +the file system), you shouldn't use echo to display it. Use printf whenever possible +[https://unix.stackexchange.com/a/6581]. Run your Bot as a restricted user @@ -190,8 +196,8 @@ has write access to are in danger of being overwritten/deleted if your bot is ha the same reason every file your Bot can read is in danger of being disclosed. Restrict your Bots access rights to the absolute minimum. Never run your Bot as root, this is the most dangerous you can do! Usually the user -'nobody' has almost no rights on Linux/Unix systems. See Expert_use on how to run your Bot -as an other user. +'nobody' has almost no rights on Linux/Unix systems. See Expert use [doc/4_expert.md] on +how to run your Bot as an other user. Secure your Bot installation @@ -234,13 +240,13 @@ At the beginning bashbot was simply the filebashbot.sh that you could copy every run the bot. Now we have 'commands.sh', 'mycommands.sh', 'modules/*.sh' and much more. Hey no problem, if you are finished with your cool bot, rundev/make-standalone.sh to create a stripped down version of your bot containing only 'bashbot.sh' and 'commands.sh'! -For more information see Create_a_stripped_down_version_of_your_Bot. +For more information see Create a stripped down version of your Bot [doc/7_develop.md]. Can I send messages from CLI and scripts? Of course you can send messages from command line and scripts! Simply install bashbot as -described_here, send the message '/start' to set yourself as botadmin and then stop the -bot with ./bashbot.sh stop. +described here [#Your-really-first-bashbot-in-a-nutshell], send the message '/start' to +set yourself as botadmin and then stop the bot with ./bashbot.sh stop. Bashbot provides some ready to use scripts for sending messages from command line in bin/ dir, e.g. send_message.sh. @@ -248,7 +254,8 @@ dir, e.g. send_message.sh. bin/send_message.sh --help -You can also source bashbot for use in your scripts, for more information see Expert_Use. +You can also source bashbot for use in your scripts, for more information see Expert Use +[doc/4_expert.md]. Blocked by telegram? @@ -280,5 +287,5 @@ That's it all guys! If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -$$VERSION$$ v1.25-dev-33-g04e3c18 +$$VERSION$$ v1.25-dev-37-gf0a2843 diff --git a/dev/version.sh b/dev/version.sh index 21e5c6b..65ed0dd 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v1.25-dev-33-g04e3c18 +#### $$VERSION$$ v1.25-dev-37-gf0a2843 # shellcheck disable=SC2016 # # Easy Versioning in git: @@ -57,7 +57,9 @@ if [[ "${FILES}" == *"README.md"* ]]; then FILES+=" README.html README.txt" type -f pandoc >/dev/null && pandoc -s -f commonmark -M "title=Bashbot README" README.md >README.html if type -f html2text >/dev/null; then - html2text -style pretty -width 90 README.html >README.txt + # convert html links to text [link] + sed -E 's/([^<#]+)<\/a>/\2 [\1]/' README.txt else type -f fold >/dev/null && fold -s -w 90 README.md >README.txt fi From bd2d2e1e5806f79376b872991dd9d84f64fb8dfb Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 8 Jan 2021 20:42:38 +0100 Subject: [PATCH 46/98] modules: backgound use log_message --- modules/background.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/background.sh b/modules/background.sh index 8cb55cd..69a7203 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117,SC2059 -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-38-g1eafc91 # will be automatically sourced from bashbot @@ -48,7 +48,7 @@ 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}" + log_message "Start background job CHAT=$1 JOB=${fifo##*/} CMD=${2##*/} $4 $5" check_back "$1" "$3" && kill_proc "$1" "back-$3-" nohup bash -c "{ $2 \"$4\" \"$5\" \"${fifo}\" | \"${SCRIPT}\" outproc \"$1\" \"${fifo}\"; }" &>>"${fifo}.log" & sleep 0.5 # give bg job some time to init @@ -62,7 +62,7 @@ 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}" + log_message "Start interactive script CHAT=$1 JOB=${fifo##*/} CMD=$2 $3 $4" check_proc "$1" && kill_proc "$1" mkfifo "${fifo}" nohup bash -c "{ $2 \"$4\" \"$5\" \"${fifo}\" | \"${SCRIPT}\" outproc \"$1\" \"${fifo}\" @@ -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}" + log_message "Stop interactive / background CHAT=$1 JOB=${fifo##*/}" # shellcheck disable=SC2086 [ -n "${prid}" ] && kill ${prid} [ -s "${fifo}.log" ] || rm -f "${fifo}.log" From 4a9d1f0a29c2731d9c06aa4db7b0eed0d266a413 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 8 Jan 2021 22:12:03 +0100 Subject: [PATCH 47/98] README: bashbot ascii art --- README.html | 2 +- README.md | 2 +- README.txt | 24 +++++++++++++++++++++++- bashbot.sh | 2 +- dev/bashbot.ascii | 22 ++++++++++++++++++++++ dev/version.sh | 9 +++++---- 6 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 dev/bashbot.ascii diff --git a/README.html b/README.html index 3502ec8..bc896ba 100644 --- a/README.html +++ b/README.html @@ -390,6 +390,6 @@ It features background tasks and interactive chats, and can serve as an interfac

@Gnadelwartz

That's it all guys!

If you feel that there's something missing or if you found a bug, feel free to submit a pull request!

-

$$VERSION$$ v1.25-dev-37-gf0a2843

+

$$VERSION$$ v1.25-dev-39-gbd2d2e1

diff --git a/README.md b/README.md index 7ee6443..d52e813 100644 --- a/README.md +++ b/README.md @@ -238,4 +238,4 @@ See `mycommnds.sh.dist` for an example. If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.25-dev-37-gf0a2843 +#### $$VERSION$$ v1.25-dev-39-gbd2d2e1 diff --git a/README.txt b/README.txt index c9fb4fa..e43e4b3 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,26 @@ + .. + **** + ****oooooo***** + *****ooooooooooooo***** + *****oooooooooooooooooooooo**** + ****oooooooooooooooooooooooooooooooo** + *.*oooooooooooooooooooooooooooooooooooo** + *.ooooooooooooooooooooooooooooooooo**.... + *.oooooooooooooooooooooooooooo**......... + *.oooooooooooooooooooooooo**............. + *.ooooooooooooooooooo**.................. ____ _ _ _ + *.oooooooooooooooooo.......,............. | _ \ | | | | | | + *.ooooooooooooooooo*.....,***,........... | |_) | __ _ ___ | |__ | |__ ___ | |_ + *.ooooooooooooooooo*....o*............... | _ < / _` |/ __|| '_ \ | '_ \ / _ \ | __| + *.ooooooooooooooooo*....*o***,........... | |_) || (_| |\__ \| | | || |_) || (_) || |_ + *.*oooooooooooooooo*........o*.....oo.... |____/ \__,_||___/|_| |_||_.__/ \___/ \__| + ****ooooooooooooo*....`***....oo...... + *****oooooooo*......*..oo.....** + ******ooo*.............* + ***oo........** + **...** + @@ -287,5 +309,5 @@ That's it all guys! If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -$$VERSION$$ v1.25-dev-37-gf0a2843 +$$VERSION$$ v1.25-dev-39-gbd2d2e1 diff --git a/bashbot.sh b/bashbot.sh index c3e37bb..337d393 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.25-dev-24-gbbc6794 +#### $$VERSION$$ v1.25-dev-39-gbd2d2e1 ################################################################## # emmbeded system may claim bash but it is not diff --git a/dev/bashbot.ascii b/dev/bashbot.ascii new file mode 100644 index 0000000..00bc91a --- /dev/null +++ b/dev/bashbot.ascii @@ -0,0 +1,22 @@ + + .. + **** + ****oooooo***** + *****ooooooooooooo***** + *****oooooooooooooooooooooo**** + ****oooooooooooooooooooooooooooooooo** + *.*oooooooooooooooooooooooooooooooooooo** + *.ooooooooooooooooooooooooooooooooo**.... + *.oooooooooooooooooooooooooooo**......... + *.oooooooooooooooooooooooo**............. + *.ooooooooooooooooooo**.................. ____ _ _ _ + *.oooooooooooooooooo.......,............. | _ \ | | | | | | + *.ooooooooooooooooo*.....,***,........... | |_) | __ _ ___ | |__ | |__ ___ | |_ + *.ooooooooooooooooo*....o*............... | _ < / _` |/ __|| '_ \ | '_ \ / _ \ | __| + *.ooooooooooooooooo*....*o***,........... | |_) || (_| |\__ \| | | || |_) || (_) || |_ + *.*oooooooooooooooo*........o*.....oo.... |____/ \__,_||___/|_| |_||_.__/ \___/ \__| + ****ooooooooooooo*....`***....oo...... + *****oooooooo*......*..oo.....** + ******ooo*.............* + ***oo........** + **...** diff --git a/dev/version.sh b/dev/version.sh index 65ed0dd..685d8eb 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v1.25-dev-37-gf0a2843 +#### $$VERSION$$ v1.25-dev-39-gbd2d2e1 # shellcheck disable=SC2016 # # Easy Versioning in git: @@ -56,12 +56,13 @@ FILES="$(find ./*)" if [[ "${FILES}" == *"README.md"* ]]; then FILES+=" README.html README.txt" type -f pandoc >/dev/null && pandoc -s -f commonmark -M "title=Bashbot README" README.md >README.html - if type -f html2text >/dev/null; then + cat "dev/bashbot.ascii" >"README.txt" + if [ -f "README.html" ] && type -f html2text >/dev/null; then # convert html links to text [link] sed -E 's/
([^<#]+)<\/a>/\2 [\1]/' README.txt + html2text -style pretty -width 90 - >>README.txt else - type -f fold >/dev/null && fold -s -w 90 README.md >README.txt + type -f fold >/dev/null && fold -s -w 90 README.md >>README.txt fi fi From 37e4539ef894f6da5483faf2ebb5c82abc76e02b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 8 Jan 2021 22:32:05 +0100 Subject: [PATCH 48/98] dev: move ascii art to bin/ --- bashbot.sh | 10 ++++++---- dev/version.sh | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 337d393..b7e5df8 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -16,7 +16,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # Usage: bashbot.sh [-h|--help|BOTCOMMANDS] - BOTCOMMANDS="start, stop, status, help, init, suspendback, resumeback, killback" +BOTCOMMANDS="--help help init start stop status suspendback resumeback killback" # # Exit Codes: # 0 - success (hopefully) @@ -30,7 +30,7 @@ # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.25-dev-39-gbd2d2e1 +#### $$VERSION$$ v1.25-dev-40-g4a9d1f0 ################################################################## # emmbeded system may claim bash but it is not @@ -167,9 +167,11 @@ RUNUSER="${USER}" # USER is overwritten by bashbot array :-(, save original # provide help case "$1" in - ""|"-h"*) [ -z "${SOURCE}" ] && printf "${ORANGE}Available commands: ${GREY}${BOTCOMMANDS}${NN}" && exit + "") [ -z "${SOURCE}" ] && printf "${ORANGE}Available commands: ${GREY}${BOTCOMMANDS}${NN}" && exit ;; - "--h"*) sed -nE -e '/(NOT EDIT)|(shellcheck)/d' -e '3,/###/p' <"$0" + "--h"*) LOGO="${BASHBOT_HOME:-.}/bin/bashbot.ascii" + [ -r "${LOGO}" ] && cat "${LOGO}" + sed -nE -e '/(NOT EDIT)|(shellcheck)/d' -e '3,/###/p' <"$0" exit;; "help") HELP="${BASHBOT_HOME:-.}/README" if [ -n "${INTERACTIVE}" ];then diff --git a/dev/version.sh b/dev/version.sh index 685d8eb..f1d1492 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v1.25-dev-39-gbd2d2e1 +#### $$VERSION$$ v1.25-dev-40-g4a9d1f0 # shellcheck disable=SC2016 # # Easy Versioning in git: @@ -56,8 +56,8 @@ FILES="$(find ./*)" if [[ "${FILES}" == *"README.md"* ]]; then FILES+=" README.html README.txt" type -f pandoc >/dev/null && pandoc -s -f commonmark -M "title=Bashbot README" README.md >README.html - cat "dev/bashbot.ascii" >"README.txt" - if [ -f "README.html" ] && type -f html2text >/dev/null; then + cat "bin/bashbot.ascii" >"README.txt" + if [ -r "README.html" ] && type -f html2text >/dev/null; then # convert html links to text [link] sed -E 's/([^<#]+)<\/a>/\2 [\1]/' >README.txt From de24dede53c0307d6efe27ec24c1eff55ffe7df5 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 9 Jan 2021 07:46:46 +0100 Subject: [PATCH 49/98] mycommands: factor out config and messages --- bashbot.sh | 6 +-- bin/bashbot_env.inc.sh | 2 +- commands.sh | 2 +- mycommands.conf | 97 +++++++++++++++++++++++++++++++++++++++++ mycommands.sh | 98 +++++++----------------------------------- mycommands.sh.clean | 89 +++++++++----------------------------- 6 files changed, 137 insertions(+), 157 deletions(-) create mode 100644 mycommands.conf diff --git a/bashbot.sh b/bashbot.sh index b7e5df8..a14ac3a 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -16,7 +16,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # Usage: bashbot.sh [-h|--help|BOTCOMMANDS] -BOTCOMMANDS="--help help init start stop status suspendback resumeback killback" +BOTCOMMANDS="-h help init start stop status suspendback resumeback killback" # # Exit Codes: # 0 - success (hopefully) @@ -30,7 +30,7 @@ BOTCOMMANDS="--help help init start stop status suspendback resumeback killbac # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.25-dev-40-g4a9d1f0 +#### $$VERSION$$ v1.25-dev-41-g37e4539 ################################################################## # emmbeded system may claim bash but it is not @@ -169,7 +169,7 @@ RUNUSER="${USER}" # USER is overwritten by bashbot array :-(, save original case "$1" in "") [ -z "${SOURCE}" ] && printf "${ORANGE}Available commands: ${GREY}${BOTCOMMANDS}${NN}" && exit ;; - "--h"*) LOGO="${BASHBOT_HOME:-.}/bin/bashbot.ascii" + "-h"*) LOGO="${BASHBOT_HOME:-.}/bin/bashbot.ascii" [ -r "${LOGO}" ] && cat "${LOGO}" sed -nE -e '/(NOT EDIT)|(shellcheck)/d' -e '3,/###/p' <"$0" exit;; diff --git a/bin/bashbot_env.inc.sh b/bin/bashbot_env.inc.sh index eb9000c..9c68c91 100644 --- a/bin/bashbot_env.inc.sh +++ b/bin/bashbot_env.inc.sh @@ -13,7 +13,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 18.12.2020 12:27 # -#### $$VERSION$$ v1.25-dev-34-gda214ab +#### $$VERSION$$ v1.25-dev-41-g37e4539 #=============================================================================== ############ diff --git a/commands.sh b/commands.sh index 585b7b2..d817662 100644 --- a/commands.sh +++ b/commands.sh @@ -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-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-41-g37e4539 # # bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed diff --git a/mycommands.conf b/mycommands.conf new file mode 100644 index 0000000..c3c992b --- /dev/null +++ b/mycommands.conf @@ -0,0 +1,97 @@ +#!/bin/bash +####################################################### +# +# File: mycommands.conf +# +# Description: place your config and messages here +# +# Usage: will be sourced from mycommands.sh +# +# License: WTFPLv2 http://www.wtfpl.net/txt/copying/ +# Author: KayM (gnadelwartz), kay@rrr.de +# Created: 09.01.2021 07:27 +# +#### $$VERSION$$ v1.25-dev-41-g37e4539 +####################################################### + +########## +# adjust your language setting here, default is C.UTF-8 +# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment +export 'LC_ALL=C.UTF-8' +export 'LANG=C.UTF-8' +export 'LANGUAGE=C.UTF-8' + +########## +# in UTF-8 äöü etc. are part of [:alnum:] and ranges (e.g. a-z) +# for more information see doc/4_expert.md#Character_classes +# uncomment next line if you want classic ASCII ranges for [a-z] etc. +#export LC_COLLATE=C + + +########## +# edit the following lines to fit your bot usage +# use ${ME} for current bot name in messages +# Note: you must escape '_' in botname with two \ in markdown messages! +export bashbot_info='This is @'"${ME//_/\\\\_}"', the Telegram example bot written entirely in bash. +Edit commands and messages in mycommands.sh! +' +# export bashbot_help='*Available commands*: +#' +export res="" + +# Set INLINE to 1 in order to receive inline queries. +# To enable this option in your bot, send the /setinline command to @BotFather. +export INLINE="0" + +# if your bot is group admin it get commands sent to other bots +# Set MEONLY to 1 to ignore commands sent to other bots +export MEONLY="0" + +# Set to .* to allow sending files from all locations +# NOTE: this is a regex, not shell globbing! you must use a valid egex, +# '.' matches any character and '.*' matches all remaining charatcers! +# additionally you must escape special characters with '\', e.g. '\. \? \[ \*" to match them literally +export FILE_REGEX="${BASHBOT_ETC}/.*" + +# set BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling +# problems with send_xxx message etc are looged to logs/ERROR.log +unset BASHBOT_RETRY +#export BASHBOT_RETRY="yes" + +# set value for adaptive sleeping while waiting for uodates in millisconds +# max slepp between polling updates 10s (default 5s) +export BASHBOT_SLEEP="10000" +# add 0.2s if no update available, up to BASHBOT_SLEEP (default 0.1s) +export BASHBOT_SLEEP_STEP="200" + +# if you want to use timer functions, set BASHBOT_START_TIMER to a not empty value +# default is to not start timer +unset BASHBOT_START_TIMER +#export BASHBOT_START_TIMER="yes" + +# set to "yes" and give your bot admin privilegs to remove service messages from groups +export SILENCER="no" + +# uncomment to remove keyboards sent from your bot +# export REMOVEKEYBOARD="yes" +# export REMOVEKEYBOARD_PRIVATE="yes" + +# uncomment to say welcome to new chat members +# export WELCOME_NEWMEMBER="yes" +WELCOME_MSG="Welcome" + +# uncomment to be informed about new/left chat members +# export REPORT_NEWMEMBER="yes" +# export REPORT_LEFTMEMBER="yes" + +# messages for admin only commands +NOTADMIN="Sorry, this command is allowed for admin or owner only" +NOTBOTADMIN="Sorry, this command is allowed for bot owner only" + +######## +# special network setup may require additional ARGS to curl +# +# example: run bashbot over TOR or SOCKS proxy +# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050" # TOR +# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1" # regular SOCKS + diff --git a/mycommands.sh b/mycommands.sh index 28bc1d3..a3ac750 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -1,98 +1,30 @@ #!/bin/bash -######### +####################################################### # -# files: mycommands.sh.dist +# File: mycommands.sh.dist # # this is an out of the box test and example file to show what's possible in mycommands.sh # # #### if you start to develop your own bot, use the clean version of this file: # #### mycommands.clean # +# Usage: will be executed when a bot command is received +# +# License: WTFPLv2 http://www.wtfpl.net/txt/copying/ +# Author: KayM (gnadelwartz), kay@rrr.de +# +#### $$VERSION$$ v1.25-dev-41-g37e4539 +####################################################### # shellcheck disable=SC1117 -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b -# -########## -# adjust your language setting here, default is C.UTF-8 -# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment -export 'LC_ALL=C.UTF-8' -export 'LANG=C.UTF-8' -export 'LANGUAGE=C.UTF-8' - -########## -# in UTF-8 äöü etc. are part of [:alnum:] and ranges (e.g. a-z) -# for more information see doc/4_expert.md#Character_classes -# uncomment next line if you want classic ASCII ranges for [a-z] etc. -#export LC_COLLATE=C +#################### +# Config has moved to bashbot.conf +# shellcheck source=./commands.sh +[ -r "${BASHBOT_ETC:-.}/mycommands.conf" ] && source "${BASHBOT_ETC:-.}/mycommands.conf" "$1" -########## -# edit the following lines to fit your bot usage -# use ${ME} for current bot name in messages -# Note: you must escape '_' in botname with two \ in markdown messages! -export bashbot_info='This is @'"${ME//_/\\\\_}"', the Telegram example bot written entirely in bash. -Edit commands and messages in mycommands.sh! -' -# export bashbot_help='*Available commands*: -#' -export res="" - -# Set INLINE to 1 in order to receive inline queries. -# To enable this option in your bot, send the /setinline command to @BotFather. -export INLINE="0" - -# if your bot is group admin it get commands sent to other bots -# Set MEONLY to 1 to ignore commands sent to other bots -export MEONLY="0" - -# Set to .* to allow sending files from all locations -# NOTE: this is a regex, not shell globbing! you must use a valid egex, -# '.' matches any character and '.*' matches all remaining charatcers! -# additionally you must escape special characters with '\', e.g. '\. \? \[ \*" to match them literally -export FILE_REGEX="${BASHBOT_ETC}/.*" - -# set BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling -# problems with send_xxx message etc are looged to logs/ERROR.log -unset BASHBOT_RETRY -#export BASHBOT_RETRY="yes" - -# set value for adaptive sleeping while waiting for uodates in millisconds -# max slepp between polling updates 10s (default 5s) -export BASHBOT_SLEEP="10000" -# add 0.2s if no update available, up to BASHBOT_SLEEP (default 0.1s) -export BASHBOT_SLEEP_STEP="200" - -# if you want to use timer functions, set BASHBOT_START_TIMER to a not empty value -# default is to not start timer -unset BASHBOT_START_TIMER -#export BASHBOT_START_TIMER="yes" - -# set to "yes" and give your bot admin privilegs to remove service messages from groups -export SILENCER="no" - -# uncomment to remove keyboards sent from your bot -# export REMOVEKEYBOARD="yes" -# export REMOVEKEYBOARD_PRIVATE="yes" - -# uncomment to say welcome to new chat members -# export WELCOME_NEWMEMBER="yes" -WELCOME_MSG="Welcome" - -# uncomment to be informed about new/left chat members -# export REPORT_NEWMEMBER="yes" -# export REPORT_LEFTMEMBER="yes" - -# messages for admin only commands -NOTADMIN="Sorry, this command is allowed for admin or owner only" -NOTBOTADMIN="Sorry, this command is allowed for bot owner only" - -######## -# special network setup may require additional ARGS to curl -# -# example: run bashbot over TOR or SOCKS proxy -# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050" # TOR -# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1" # regular SOCKS - +################## +# let's go ... if [ "$1" = "startbot" ];then ################### # this section is processed on startup diff --git a/mycommands.sh.clean b/mycommands.sh.clean index d744161..0be2849 100644 --- a/mycommands.sh.clean +++ b/mycommands.sh.clean @@ -1,80 +1,31 @@ #!/bin/bash -######## +####################################################### +# +# File: mycommands.sh.clean # -# files: mycommands.sh.clean # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v1.25-dev-9-g14fa2c7 +# Usage: will be executed when a bot command is received # - -########## -# adjust your language setting here, default is C.UTF-8 -# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment -export 'LC_ALL=C.UTF-8' -export 'LANG=C.UTF-8' -export 'LANGUAGE=C.UTF-8' - -########## -# in UTF-8 äöü etc. are part of [:alnum:] and ranges (e.g. a-z) -# for more information see doc/4_expert.md#Character_classes -# uncomment next line if you want classic ASCII ranges for [a-z] etc. -#export LC_COLLATE=C - - -########## -# edit the following lines to fit your bot usage - -export bashbot_info='This is bashbot, the Telegram bot written entirely in bash. -' - -export bashbot_help='*Available commands*: -' -export res="" - -# Set INLINE to 1 in order to receive inline queries. -# To enable this option in your bot must also send the /setinline command to @BotFather. -export INLINE="0" - -# if your bot is group admin it get commands sent to other bots -# Set MEONLY to 1 to ignore commands sent to other bots -export MEONLY="0" - -# NOTE: this is a regex, not shell globbing! you must use a valid egex, -# '.' matches any character and '.*' matches all remaining charatcers! -# additionally you must escape special characters with '\', e.g. '\. \? \[ \*" to match them literally -# do NOT set to .* as this allow sending files from all locations! -export FILE_REGEX="${BASHBOT_ETC}/.*" - -# set BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling -# problems with send_,´message etc are looged to logs/ERROR.log -unset BASHBOT_RETRY -#export BASHBOT_RETRY="yes" - -# set value for adaptive sleeping while waitingnfor uodates in millisconds -# max slepp between polling updates 10s (default 5s) -export BASHBOT_SLEEP="10000" -# add 0.2s if no update available, up to BASHBOT_SLEEP (default 0.1s) -export BASHBOT_SLEEP_STEP="200" - -# if you want to use timer functions, set BASHBOT_START_TIMER to a not empty value -# default is to nit start timer -unset BASHBOT_START_TIMER -#export BASHBOT_START_TIMER="yes" -# set to "yes" and give your bot admin privilegs to remove service messaes from groups -export SILENCER="no" - -# uncomment to remove keyboards sent by your bot -# export REMOVEKEYBOARD="yes" -# export REMOVEKEYBOARD_PRIVATE="yes" - -######## -# special network setup may require additional ARGS to curl +# License: WTFPLv2 http://www.wtfpl.net/txt/copying/ +# Author: KayM (gnadelwartz), kay@rrr.de # -# example: run bashbot over TOR or SOCKS proxy -# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050" # TOR -# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1" # regular SOCKS +#### $$VERSION$$ v1.25-dev-41-g37e4539 +####################################################### +# shellcheck disable=SC1117 +#################### +# Config has moved to bashbot.conf +# shellcheck source=./commands.sh +[ -r "${BASHBOT_ETC:-.}/mycommands.conf" ] && source "${BASHBOT_ETC:-.}/mycommands.conf" "$1" + + +################## +# lets's go if [ "$1" = "startbot" ];then + ################### + # this section is processed on startup + # run once after startup when the first message is received my_startup(){ : From eac21375e8ee96b9d23ebf1fe3f801bba6d1afd1 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 9 Jan 2021 08:10:52 +0100 Subject: [PATCH 50/98] doc: config moved --- dev/make-distribution.sh | 4 ++-- doc/0_install.md | 11 ++++++++--- doc/2_usage.md | 6 ++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index a5d2f04..b2d673e 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -7,7 +7,7 @@ # # Options: --notest - skip tests # -#### $$VERSION$$ v1.25-dev-35-gfa8e8a2 +#### $$VERSION$$ v1.25-dev-42-gde24ded ############################################################## # magic to ensure that we're always inside the root of our application, @@ -27,7 +27,7 @@ DISTDIR="./DIST/${DISTNAME}" DISTMKDIR="data-bot-bash logs bin bin/logs addons" DISTFILES="bashbot.sh commands.sh mycommands.sh.clean bin doc examples scripts modules LICENSE README.md README.txt README.html" -DISTFILESDIST="mycommands.sh bashbot.rc $(echo "addons/"*.sh)" +DISTFILESDIST="mycommands.sh mycommands.conf bashbot.rc $(echo "addons/"*.sh)" # run tests first! for test in $1 dev/all-test*.sh diff --git a/doc/0_install.md b/doc/0_install.md index 8032701..5972732 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -28,10 +28,11 @@ Installing bashbot is very simple: Download and extract the installation archive 1. Choose a directory to install bashbot (_e.g.your HOME or /usr/local_) 2. Download [latest release zip / tar archive](https://github.com/topkecleon/telegram-bot-bash/releases/latest) and extract all files. 3. Change into the directory `telegram-bot-bash` +4. Copy `mycommands.conf.dist` `mycommands.conf` 4. Copy `mycommands.sh.dist` or `mycommands.sh.clean` to `mycommands.sh` 5. Run `./bashbot.sh init`\* to setup the environment and enter your Bots token given by botfather. -Edit `mycommands.sh` to fit your needs. +Edit config in `mycommands.conf` and commands in `mycommands.sh` to fit your need. Now your Bot is ready to start ... *If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots)* @@ -51,7 +52,7 @@ Update bashbot is almost identical to installing bashbot: Download and extract t 5. Run `./bashbot.sh init`\* to setup your environment after the update 6. Restart your bot `./bashbot.sh start` -`mycommands.sh` will not overwritten, this avoids losing your bot commands on updates. +`mycommands.conf` and `mycommands.sh` will not overwritten, this avoids losing your bot config and commands on updates. *Note*: If you are updating from a pre-1.0 version, update to [Version 1.20](https://github.com/topkecleon/telegram-bot-bash/releases/tags/v1.20) first! @@ -120,6 +121,10 @@ to get an impression how different they are. ### Notes on Changes +#### Config moved to mycommands.conf + +From Version 1.30 on config for new bots is moved to `mycommands.conf`. + #### Support for update from pre-1.0 removed From Version 1.21 on updating from a pre-1.0 version (_no \*.jssh config_) is no more supported! @@ -127,5 +132,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-23-g8be95a3 +#### $$VERSION$$ v1.25-dev-42-gde24ded diff --git a/doc/2_usage.md b/doc/2_usage.md index 5e4f4e7..fae09b1 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -19,8 +19,10 @@ Have FUN! ``` . ├── mycommands.sh # THIS is your bot, place logic and commands here! +├── mycommands.conf # place your bot config and bot messages here! │ -├── mycommands.sh.clean # copy to "mycommands.sh" if you start developing your bot +├── mycommands.conf.dist # copy to "mycommands.conf" if not exist +├── mycommands.sh.clean # copy to "mycommands.sh" to start developing a new bot ├── mycommands.sh.dist # example bot, also used for testing bashbot internally │ ├── count.jssh # count bashbot usage in jssh key-value store @@ -344,5 +346,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.25-dev-26-gc205ae5 +#### $$VERSION$$ v1.25-dev-42-gde24ded From 168584d693bde5944704e5f93e724a2a608ef09a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 9 Jan 2021 21:51:28 +0100 Subject: [PATCH 51/98] some minor additions --- bin/bashbot.ascii | 22 ++++++++++++++++++++++ mycommands.conf | 9 ++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 bin/bashbot.ascii diff --git a/bin/bashbot.ascii b/bin/bashbot.ascii new file mode 100644 index 0000000..b413e56 --- /dev/null +++ b/bin/bashbot.ascii @@ -0,0 +1,22 @@ + + .. + **** + ****oooooo***** + *****ooooooooooooo***** + *****oooooooooooooooooooooo**** + ****oooooooooooooooooooooooooooooooo** + *.*oooooooooooooooooooooooooooooooooooo** + *.ooooooooooooooooooooooooooooooooo**.... + *.oooooooooooooooooooooooooooo**......... + *.oooooooooooooooooooooooo**............. + *.ooooooooooooooooooo**.................. ____ _ _ _ + *.ooooooooooooooooo*.......,............. | _ \ | | | | | | + *.ooooooooooooooooo*.....,***,........... | |_) | __ _ ___ | |__ | |__ ___ | |_ + *.ooooooooooooooooo*....o*............... | _ < / _` |/ __|| '_ \ | '_ \ / _ \ | __| + *.ooooooooooooooooo*....*o***,........... | |_) || (_| |\__ \| | | || |_) || (_) || |_ + *.*oooooooooooooooo*........o*.....oo.... |____/ \__,_||___/|_| |_||_.__/ \___/ \__| + ****ooooooooooooo*....`***....oo.....* + *****oooooooo*......*..oo.....** + ******ooo*.............* + ***o*........** + **...** diff --git a/mycommands.conf b/mycommands.conf index c3c992b..58062a2 100644 --- a/mycommands.conf +++ b/mycommands.conf @@ -11,7 +11,7 @@ # Author: KayM (gnadelwartz), kay@rrr.de # Created: 09.01.2021 07:27 # -#### $$VERSION$$ v1.25-dev-41-g37e4539 +#### $$VERSION$$ v1.25-dev-43-geac2137 ####################################################### ########## @@ -32,12 +32,15 @@ export 'LANGUAGE=C.UTF-8' # edit the following lines to fit your bot usage # use ${ME} for current bot name in messages # Note: you must escape '_' in botname with two \ in markdown messages! + +# output of /info command export bashbot_info='This is @'"${ME//_/\\\\_}"', the Telegram example bot written entirely in bash. Edit commands and messages in mycommands.sh! ' + +# output of /help command (uncomment the next 2 lines # export bashbot_help='*Available commands*: -#' -export res="" +# ' # Set INLINE to 1 in order to receive inline queries. # To enable this option in your bot, send the /setinline command to @BotFather. From 2a3ab2a145f9300f7804c7c1ea0b40bad231381f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 9 Jan 2021 22:04:14 +0100 Subject: [PATCH 52/98] bin: extend broadcast to use any jsonDB user db --- bin/send_broadcast.sh | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/bin/send_broadcast.sh b/bin/send_broadcast.sh index 89442a4..9db8156 100755 --- a/bin/send_broadcast.sh +++ b/bin/send_broadcast.sh @@ -1,15 +1,18 @@ #!/bin/bash #=============================================================================== +# shellcheck disable=SC2059 # # FILE: bin/broadcast_message.sh # -# USAGE: broadcast_message.sh [-h|--help] [--doit] [--groups|--both] [format] "message ...." [debug] +USAGE='broadcast_message.sh [-h|--help] [--doit] [--groups|--both|--db=file] [format] "message ...." [debug]' # -# DESCRIPTION: send a message to all users the bot have seen (listet in count.jssh) +# DESCRIPTION: send a message to all users listed in a jsonDB (default count db) # # OPTIONS: --doit - broadcast is dangerous, simulate run without --doit # --groups - send to groups instead of users # --both - send to users and groups +# --db name - send to all user/groups in jsonDB database (e.g. blocked) +# db file: name.jssh, db keys are user/chat id, values are ignored # # format - normal, markdown, html (optional) # message - message to send in specified format @@ -24,13 +27,13 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 16:14 # -#### $$VERSION$$ v1.25-dev-34-gda214ab +#### $$VERSION$$ v1.25-dev-44-g168584d #=============================================================================== -# shellcheck disable=SC2059 #### # minimum messages seen in a chat before send a broadcast to it MINCOUNT=2 +USERDB="" #### # broadcast is dangerous, without --doit we do a dry run ... @@ -49,6 +52,11 @@ elif [ "$1" = "--groups" ]; then SENDTO="groups" GROUPSALSO=" only" shift +elif [ "$1" = "--db" ]; then + USERDB="${2%.jssh}" + MINCOUNT="" + GROUPSALSO=" and groups" + shift 2 fi #### @@ -71,11 +79,11 @@ case "$1" in printf "missing missing arguments\n" ;& "-h"*) - printf 'usage: send_message [-h|--help] [--groups|--both] [format] "message ...." [debug]\n' + printf 'usage: %s\n' "${USAGE}" exit 1 ;; '--h'*) - sed -n '3,/###/p' <"$0" + sed -n -e '/# shellcheck /d' -e '3,/###/p' <"$0" exit 1 ;; esac @@ -85,15 +93,16 @@ esac source "${0%/*}/bashbot_env.inc.sh" "$2" # $3 debug -# read in users +# read in users from given DB or count.jssh +database="${USERDB:-${COUNTFILE}}" declare -A SENDALL -jssh_readDB_async "SENDALL" "${COUNTFILE}" +jssh_readDB_async "SENDALL" "${database}" if [ -z "${SENDALL[*]}" ]; then - printf "${ORANGE}Countfile not found or empty,${NC}\n" + printf "${ORANGE}User database not found or empty: ${NC}${database}\n" fi # loop over users - printf "${GREEN}Sending broadcast message to all users of ${BOT_NAME}${NC}${GREY}" + printf "${GREEN}Sending broadcast message to user of ${BOT_NAME} using database:${NC}${GREY} ${database##*/}" { # dry run [ -z "${DOIT}" ] && printf "${NC}\n${ORANGE}DRY RUN! use --doit as first argument to execute broadcast...${NC}\n" @@ -106,7 +115,7 @@ fi # ignore everything not a user or group [[ ! "${USER}" =~ ^[0-9-]*$ ]] && continue # ignore chats with no count or lower MINCOUNT - [[ ! "${SENDALL[${USER}]}" =~ ^[0-9]*$ || "${SENDALL[${USER}]}" -lt "${MINCOUNT}" ]] && continue + [[ -n "${MINCOUNT}" && ( ! "${SENDALL[${USER}]}" =~ ^[0-9]*$ || "${SENDALL[${USER}]}" -lt "${MINCOUNT}" ) ]] && continue (( COUNT++ )) if [ -z "${DOIT}" ]; then printf "${SEND} ${USER} $1 $2\n" From 8253a53994f229a599db740f3bf6518bfe8fb499 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 9 Jan 2021 22:14:44 +0100 Subject: [PATCH 53/98] bin: usage message --- bin/bashbot_stats.sh | 6 +++--- bin/delete_message.sh | 6 +++--- bin/send_edit_message.sh | 6 +++--- bin/send_file.sh | 8 ++++---- bin/send_message.sh | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bin/bashbot_stats.sh b/bin/bashbot_stats.sh index 66358a9..ea5a911 100755 --- a/bin/bashbot_stats.sh +++ b/bin/bashbot_stats.sh @@ -3,7 +3,7 @@ # # FILE: bin/bashbot_stats.sh # -# USAGE: bashbot_stats.sh [-h|--help] [debug] +USAGE='bashbot_stats.sh [-h|--help] [debug]' # # DESCRIPTION: output bashbot user stats # @@ -16,14 +16,14 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 20:34 # -#### $$VERSION$$ v1.25-dev-34-gda214ab +#### $$VERSION$$ v1.25-dev-45-g2a3ab2a #=============================================================================== #### # parse args case "$1" in "-h"*) - echo "usage: send_message [-h|--help] [debug]" + printf "usage: %s\n" "${USAGE}" exit 1 ;; '--h'*) diff --git a/bin/delete_message.sh b/bin/delete_message.sh index e0c08ce..927af12 100755 --- a/bin/delete_message.sh +++ b/bin/delete_message.sh @@ -3,7 +3,7 @@ # # FILE: bin/delete_message.sh # -# USAGE: delete_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" [debug] +USAGE='delete_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" [debug]' # # DESCRIPTION: delete a message in the given user/group # @@ -19,7 +19,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 03.01.2021 15:37 # -#### $$VERSION$$ v1.25-dev-34-gda214ab +#### $$VERSION$$ v1.25-dev-45-g2a3ab2a #=============================================================================== #### @@ -30,7 +30,7 @@ case "$1" in printf "missing arguments\n" ;& "-h"*) - printf 'usage: send_edit_message [-h|--help] [format] "CHAT[ID]" "MESSAGE[ID]" "message ..." [debug]\n' + printf 'usage: %s\n' "${USAGE}" exit 1 ;; '--h'*) diff --git a/bin/send_edit_message.sh b/bin/send_edit_message.sh index 6dbb640..7e6f968 100755 --- a/bin/send_edit_message.sh +++ b/bin/send_edit_message.sh @@ -3,7 +3,7 @@ # # FILE: bin/send_message.sh # -# USAGE: send_edit_message.sh [-h|--help] [format] "CHAT[ID]" "MESSAGE[ID]" "message ...." [debug] +USAGE='send_edit_message.sh [-h|--help] [format] "CHAT[ID]" "MESSAGE[ID]" "message ...." [debug]' # # DESCRIPTION: replace a message in the given user/group # @@ -22,7 +22,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 16:52 # -#### $$VERSION$$ v1.25-dev-34-gda214ab +#### $$VERSION$$ v1.25-dev-45-g2a3ab2a #=============================================================================== #### @@ -45,7 +45,7 @@ case "$1" in printf "missing arguments\n" ;& "-h"*) - printf 'usage: send_edit_message [-h|--help] [format] "CHAT[ID]" "MESSAGE[ID]" "message ..." [debug]\n' + printf 'usage: %s\n' "${USAGE}" exit 1 ;; '--h'*) diff --git a/bin/send_file.sh b/bin/send_file.sh index 64c3579..f38ca69 100755 --- a/bin/send_file.sh +++ b/bin/send_file.sh @@ -2,8 +2,8 @@ #=============================================================================== # # FILE: bin/send_file.sh -# -# USAGE: send_file.sh [-h|--help] "CHAT[ID]" "file|URL" "caption ...." [type] [debug] +# +USAGE='send_file.sh [-h|--help] "CHAT[ID]" "file|URL" "caption ...." [type] [debug]' # # DESCRIPTION: send a file to the given user/group # @@ -24,7 +24,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 25.12.2020 20:24 # -#### $$VERSION$$ v1.25-dev-34-gda214ab +#### $$VERSION$$ v1.25-dev-45-g2a3ab2a #=============================================================================== #### @@ -35,7 +35,7 @@ case "$1" in printf "missing arguments\n" ;& "-h"*) - printf 'usage: send_file [-h|--help] "CHAT[ID]" "file" "caption ...." [type] [debug]\n' + printf 'usage: %s\n' "${USAGE}" exit 1 ;; '--h'*) diff --git a/bin/send_message.sh b/bin/send_message.sh index 1ec494e..13b1334 100755 --- a/bin/send_message.sh +++ b/bin/send_message.sh @@ -3,7 +3,7 @@ # # FILE: bin/send_message.sh # -# USAGE: send_message.sh [-h|--help] [format] "CHAT[ID]" "message ...." [debug] +USAGE='send_message.sh [-h|--help] [format] "CHAT[ID]" "message ...." [debug]' # # DESCRIPTION: send a message to the given user/group # @@ -21,7 +21,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 11:34 # -#### $$VERSION$$ v1.25-dev-34-gda214ab +#### $$VERSION$$ v1.25-dev-45-g2a3ab2a #=============================================================================== #### @@ -44,7 +44,7 @@ case "$1" in printf "missing arguments\n" ;& "-h"*) - printf 'usage: send_message [-h|--help] [format] "CHAT[ID]" "message ...." [debug]\n' + printf 'usage: %s\n' "${USAGE}" exit 1 ;; '--h'*) From 88a24cb2a367741243fdec3091ccc09eb2327fcf Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 9 Jan 2021 22:25:15 +0100 Subject: [PATCH 54/98] doc: move bashbot.ascii --- bashbot.sh | 4 ++-- dev/version.sh | 4 ++-- {bin => doc}/bashbot.ascii | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename {bin => doc}/bashbot.ascii (100%) diff --git a/bashbot.sh b/bashbot.sh index a14ac3a..99a58d3 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.25-dev-41-g37e4539 +#### $$VERSION$$ v1.25-dev-46-g8253a53 ################################################################## # emmbeded system may claim bash but it is not @@ -169,7 +169,7 @@ RUNUSER="${USER}" # USER is overwritten by bashbot array :-(, save original case "$1" in "") [ -z "${SOURCE}" ] && printf "${ORANGE}Available commands: ${GREY}${BOTCOMMANDS}${NN}" && exit ;; - "-h"*) LOGO="${BASHBOT_HOME:-.}/bin/bashbot.ascii" + "-h"*) LOGO="${BASHBOT_HOME:-.}/doc/bashbot.ascii" [ -r "${LOGO}" ] && cat "${LOGO}" sed -nE -e '/(NOT EDIT)|(shellcheck)/d' -e '3,/###/p' <"$0" exit;; diff --git a/dev/version.sh b/dev/version.sh index f1d1492..66f71a9 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v1.25-dev-40-g4a9d1f0 +#### $$VERSION$$ v1.25-dev-46-g8253a53 # shellcheck disable=SC2016 # # Easy Versioning in git: @@ -56,7 +56,7 @@ FILES="$(find ./*)" if [[ "${FILES}" == *"README.md"* ]]; then FILES+=" README.html README.txt" type -f pandoc >/dev/null && pandoc -s -f commonmark -M "title=Bashbot README" README.md >README.html - cat "bin/bashbot.ascii" >"README.txt" + cat "doc/bashbot.ascii" >"README.txt" if [ -r "README.html" ] && type -f html2text >/dev/null; then # convert html links to text [link] sed -E 's/([^<#]+)<\/a>/\2 [\1]/' Date: Sat, 9 Jan 2021 22:37:28 +0100 Subject: [PATCH 55/98] sync possible untracked files --- README.txt | 6 +++--- dev/bashbot.ascii | 22 ---------------------- mycommands.conf | 2 +- 3 files changed, 4 insertions(+), 26 deletions(-) delete mode 100644 dev/bashbot.ascii diff --git a/README.txt b/README.txt index e43e4b3..2ca2f52 100644 --- a/README.txt +++ b/README.txt @@ -10,15 +10,15 @@ *.oooooooooooooooooooooooooooo**......... *.oooooooooooooooooooooooo**............. *.ooooooooooooooooooo**.................. ____ _ _ _ - *.oooooooooooooooooo.......,............. | _ \ | | | | | | + *.ooooooooooooooooo*.......,............. | _ \ | | | | | | *.ooooooooooooooooo*.....,***,........... | |_) | __ _ ___ | |__ | |__ ___ | |_ *.ooooooooooooooooo*....o*............... | _ < / _` |/ __|| '_ \ | '_ \ / _ \ | __| *.ooooooooooooooooo*....*o***,........... | |_) || (_| |\__ \| | | || |_) || (_) || |_ *.*oooooooooooooooo*........o*.....oo.... |____/ \__,_||___/|_| |_||_.__/ \___/ \__| - ****ooooooooooooo*....`***....oo...... + ****ooooooooooooo*....`***....oo.....* *****oooooooo*......*..oo.....** ******ooo*.............* - ***oo........** + ***o*........** **...** diff --git a/dev/bashbot.ascii b/dev/bashbot.ascii deleted file mode 100644 index 00bc91a..0000000 --- a/dev/bashbot.ascii +++ /dev/null @@ -1,22 +0,0 @@ - - .. - **** - ****oooooo***** - *****ooooooooooooo***** - *****oooooooooooooooooooooo**** - ****oooooooooooooooooooooooooooooooo** - *.*oooooooooooooooooooooooooooooooooooo** - *.ooooooooooooooooooooooooooooooooo**.... - *.oooooooooooooooooooooooooooo**......... - *.oooooooooooooooooooooooo**............. - *.ooooooooooooooooooo**.................. ____ _ _ _ - *.oooooooooooooooooo.......,............. | _ \ | | | | | | - *.ooooooooooooooooo*.....,***,........... | |_) | __ _ ___ | |__ | |__ ___ | |_ - *.ooooooooooooooooo*....o*............... | _ < / _` |/ __|| '_ \ | '_ \ / _ \ | __| - *.ooooooooooooooooo*....*o***,........... | |_) || (_| |\__ \| | | || |_) || (_) || |_ - *.*oooooooooooooooo*........o*.....oo.... |____/ \__,_||___/|_| |_||_.__/ \___/ \__| - ****ooooooooooooo*....`***....oo...... - *****oooooooo*......*..oo.....** - ******ooo*.............* - ***oo........** - **...** diff --git a/mycommands.conf b/mycommands.conf index 58062a2..4cf3c61 100644 --- a/mycommands.conf +++ b/mycommands.conf @@ -11,7 +11,7 @@ # Author: KayM (gnadelwartz), kay@rrr.de # Created: 09.01.2021 07:27 # -#### $$VERSION$$ v1.25-dev-43-geac2137 +#### $$VERSION$$ v1.25-dev-44-g168584d ####################################################### ########## From 41ce9cc486dc28f596fccd2971a465fee021f729 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 9 Jan 2021 22:52:13 +0100 Subject: [PATCH 56/98] bin: fix broadcast messages --- bin/send_broadcast.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/send_broadcast.sh b/bin/send_broadcast.sh index 9db8156..2a8a77f 100755 --- a/bin/send_broadcast.sh +++ b/bin/send_broadcast.sh @@ -10,7 +10,7 @@ USAGE='broadcast_message.sh [-h|--help] [--doit] [--groups|--both|--db=file] [fo # # OPTIONS: --doit - broadcast is dangerous, simulate run without --doit # --groups - send to groups instead of users -# --both - send to users and groups +# --both - send to users and groups (default with --db) # --db name - send to all user/groups in jsonDB database (e.g. blocked) # db file: name.jssh, db keys are user/chat id, values are ignored # @@ -27,7 +27,7 @@ USAGE='broadcast_message.sh [-h|--help] [--doit] [--groups|--both|--db=file] [fo # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 16:14 # -#### $$VERSION$$ v1.25-dev-44-g168584d +#### $$VERSION$$ v1.25-dev-48-g171b196 #=============================================================================== #### @@ -102,7 +102,7 @@ if [ -z "${SENDALL[*]}" ]; then fi # loop over users - printf "${GREEN}Sending broadcast message to user of ${BOT_NAME} using database:${NC}${GREY} ${database##*/}" + printf "${GREEN}Sending broadcast message to ${SENDTO}${GROUPSALSO} of ${BOT_NAME} using database:${NC}${GREY} ${database##*/}" { # dry run [ -z "${DOIT}" ] && printf "${NC}\n${ORANGE}DRY RUN! use --doit as first argument to execute broadcast...${NC}\n" From 427e4df6cae16fc2f12a7f41a235cc18821e3861 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 10 Jan 2021 15:51:16 +0100 Subject: [PATCH 57/98] bin: set debug for send/delete messsge as default --- bin/bashbot_env.inc.sh | 2 +- bin/bashbot_stats.sh | 2 +- bin/delete_message.sh | 4 ++-- bin/send_broadcast.sh | 6 +++--- bin/send_edit_message.sh | 4 ++-- bin/send_file.sh | 4 ++-- bin/send_message.sh | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bin/bashbot_env.inc.sh b/bin/bashbot_env.inc.sh index 9c68c91..79961a5 100644 --- a/bin/bashbot_env.inc.sh +++ b/bin/bashbot_env.inc.sh @@ -13,7 +13,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 18.12.2020 12:27 # -#### $$VERSION$$ v1.25-dev-41-g37e4539 +#### $$VERSION$$ v1.25-dev-49-g41ce9cc #=============================================================================== ############ diff --git a/bin/bashbot_stats.sh b/bin/bashbot_stats.sh index ea5a911..8c5db20 100755 --- a/bin/bashbot_stats.sh +++ b/bin/bashbot_stats.sh @@ -16,7 +16,7 @@ USAGE='bashbot_stats.sh [-h|--help] [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 20:34 # -#### $$VERSION$$ v1.25-dev-45-g2a3ab2a +#### $$VERSION$$ v1.25-dev-49-g41ce9cc #=============================================================================== #### diff --git a/bin/delete_message.sh b/bin/delete_message.sh index 927af12..41bc097 100755 --- a/bin/delete_message.sh +++ b/bin/delete_message.sh @@ -19,7 +19,7 @@ USAGE='delete_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 03.01.2021 15:37 # -#### $$VERSION$$ v1.25-dev-45-g2a3ab2a +#### $$VERSION$$ v1.25-dev-49-g41ce9cc #=============================================================================== #### @@ -42,7 +42,7 @@ esac # set bashbot environment # shellcheck disable=SC1090 -source "${0%/*}/bashbot_env.inc.sh" "$3" # $3 debug +source "${0%/*}/bashbot_env.inc.sh" "${3:-debug}" # $3 debug #### #### diff --git a/bin/send_broadcast.sh b/bin/send_broadcast.sh index 2a8a77f..d701100 100755 --- a/bin/send_broadcast.sh +++ b/bin/send_broadcast.sh @@ -10,7 +10,7 @@ USAGE='broadcast_message.sh [-h|--help] [--doit] [--groups|--both|--db=file] [fo # # OPTIONS: --doit - broadcast is dangerous, simulate run without --doit # --groups - send to groups instead of users -# --both - send to users and groups (default with --db) +# --both - send to users and groups # --db name - send to all user/groups in jsonDB database (e.g. blocked) # db file: name.jssh, db keys are user/chat id, values are ignored # @@ -27,7 +27,7 @@ USAGE='broadcast_message.sh [-h|--help] [--doit] [--groups|--both|--db=file] [fo # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 16:14 # -#### $$VERSION$$ v1.25-dev-48-g171b196 +#### $$VERSION$$ v1.25-dev-49-g41ce9cc #=============================================================================== #### @@ -102,7 +102,7 @@ if [ -z "${SENDALL[*]}" ]; then fi # loop over users - printf "${GREEN}Sending broadcast message to ${SENDTO}${GROUPSALSO} of ${BOT_NAME} using database:${NC}${GREY} ${database##*/}" + printf "${GREEN}Sending broadcast message to user of ${BOT_NAME} using database:${NC}${GREY} ${database##*/}" { # dry run [ -z "${DOIT}" ] && printf "${NC}\n${ORANGE}DRY RUN! use --doit as first argument to execute broadcast...${NC}\n" diff --git a/bin/send_edit_message.sh b/bin/send_edit_message.sh index 7e6f968..7892d07 100755 --- a/bin/send_edit_message.sh +++ b/bin/send_edit_message.sh @@ -22,7 +22,7 @@ USAGE='send_edit_message.sh [-h|--help] [format] "CHAT[ID]" "MESSAGE[ID]" "messa # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 16:52 # -#### $$VERSION$$ v1.25-dev-45-g2a3ab2a +#### $$VERSION$$ v1.25-dev-49-g41ce9cc #=============================================================================== #### @@ -56,7 +56,7 @@ esac # set bashbot environment # shellcheck disable=SC1090 -source "${0%/*}/bashbot_env.inc.sh" "$4" # $4 debug +source "${0%/*}/bashbot_env.inc.sh" "${4:-debug}" # $4 debug #### #### diff --git a/bin/send_file.sh b/bin/send_file.sh index f38ca69..37dd064 100755 --- a/bin/send_file.sh +++ b/bin/send_file.sh @@ -24,7 +24,7 @@ USAGE='send_file.sh [-h|--help] "CHAT[ID]" "file|URL" "caption ...." [type] [deb # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 25.12.2020 20:24 # -#### $$VERSION$$ v1.25-dev-45-g2a3ab2a +#### $$VERSION$$ v1.25-dev-49-g41ce9cc #=============================================================================== #### @@ -46,7 +46,7 @@ esac # set bashbot environment # shellcheck disable=SC1090 -source "${0%/*}/bashbot_env.inc.sh" "$5" # $5 debug +source "${0%/*}/bashbot_env.inc.sh" "${5:-debug}" # $5 debug #### # ready, do stuff here ----- diff --git a/bin/send_message.sh b/bin/send_message.sh index 13b1334..4da7646 100755 --- a/bin/send_message.sh +++ b/bin/send_message.sh @@ -21,7 +21,7 @@ USAGE='send_message.sh [-h|--help] [format] "CHAT[ID]" "message ...." [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 11:34 # -#### $$VERSION$$ v1.25-dev-45-g2a3ab2a +#### $$VERSION$$ v1.25-dev-49-g41ce9cc #=============================================================================== #### @@ -55,7 +55,7 @@ esac # set bashbot environment # shellcheck disable=SC1090 -source "${0%/*}/bashbot_env.inc.sh" "$3" # $3 debug +source "${0%/*}/bashbot_env.inc.sh" "${3:-debug}" # $3 debug #### # ready, do stuff here ----- From b2eecc56e25dcbe87a4159ebec14bc575ff4af41 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 10 Jan 2021 15:57:04 +0100 Subject: [PATCH 58/98] dev: git.add: fix moved or removed files --- dev/git-add.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dev/git-add.sh b/dev/git-add.sh index 36916d4..c8da9f8 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.25-dev-50-g427e4df # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -31,7 +31,9 @@ for file in ${FILES} do [ -d "${file}" ] && continue printf "%s" "${file} " - git add "${file}" done printf " - Done.\n" +# stay with "." for (re)moved files! +git add . + From b9c323573c581837c5450cb903e44bf88de51ea9 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 10 Jan 2021 16:01:52 +0100 Subject: [PATCH 59/98] update bashbot.rc --- bashbot.rc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 7044f46..95648ff 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.25-dev-9-g14fa2c7 +#### $$VERSION$$ v1.25-dev-51-gb2eecc5 # shellcheck disable=SC2009 # shellcheck disable=SC2181 @@ -34,8 +34,12 @@ runas="nobody" # runcmd="runuser ${runas} -s /bin/bash -c " # runasuser with *runuser* # edit the values of the following lines to fit your config: -start="cd /usr/local/telegram-bot-bash; /usr/local/telegram-bot-bash/bashbot.sh" # location of your bashbot.sh script -name='' # your bot name as given to botfather, e.g. mysomething_bot +# your bot installation dir +bashbot="cd /usr/local/telegram-bot-bash; /usr/local/telegram-bot-bash/bashbot.sh" +# your bot name as given to botfather, e.g. mysomething_bot +name="" +# set additionl parameter, e.g. debug +mode="" # END Configuration ####################### @@ -45,12 +49,12 @@ name='' # your bot name as given to botfather, e.g. mysomething_bot case "$1" in 'start') # shellcheck disable=SC2250 - $runcmd "$start start" # >/dev/null 2>&1 /dev/null 2>&1 Date: Sun, 10 Jan 2021 17:16:14 +0100 Subject: [PATCH 60/98] bin: revert acidental revert of broadcast changes --- bin/send_broadcast.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/send_broadcast.sh b/bin/send_broadcast.sh index d701100..05ba7e6 100755 --- a/bin/send_broadcast.sh +++ b/bin/send_broadcast.sh @@ -10,7 +10,7 @@ USAGE='broadcast_message.sh [-h|--help] [--doit] [--groups|--both|--db=file] [fo # # OPTIONS: --doit - broadcast is dangerous, simulate run without --doit # --groups - send to groups instead of users -# --both - send to users and groups +# --both - send to users and groups (default with --db) # --db name - send to all user/groups in jsonDB database (e.g. blocked) # db file: name.jssh, db keys are user/chat id, values are ignored # @@ -27,7 +27,7 @@ USAGE='broadcast_message.sh [-h|--help] [--doit] [--groups|--both|--db=file] [fo # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 16:14 # -#### $$VERSION$$ v1.25-dev-49-g41ce9cc +#### $$VERSION$$ v1.25-dev-52-gb9c3235 #=============================================================================== #### @@ -102,7 +102,7 @@ if [ -z "${SENDALL[*]}" ]; then fi # loop over users - printf "${GREEN}Sending broadcast message to user of ${BOT_NAME} using database:${NC}${GREY} ${database##*/}" + printf "${GREEN}Sending broadcast message to ${SENDTO}${GROUPSALSO} of ${BOT_NAME} using database:${NC}${GREY} ${database##*/}" { # dry run [ -z "${DOIT}" ] && printf "${NC}\n${ORANGE}DRY RUN! use --doit as first argument to execute broadcast...${NC}\n" From bd664dacfe86458afb59338187a4e6cb6782fdc3 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 10 Jan 2021 18:23:37 +0100 Subject: [PATCH 61/98] init: rework adjust user --- bashbot.sh | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 99a58d3..ac36b75 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.25-dev-46-g8253a53 +#### $$VERSION$$ v1.25-dev-53-gfb8b022 ################################################################## # emmbeded system may claim bash but it is not @@ -1105,7 +1105,7 @@ start_bot() { # initialize bot environment, user and permissions bot_init() { [ -n "${BASHBOT_HOME}" ] && cd "${BASHBOT_HOME}" || exit 1 - local DEBUG="$1" + local runuser touser DEBUG="$1" # upgrade from old version # currently no action printf "Check for Update actions ...\n" @@ -1117,26 +1117,31 @@ bot_init() { [ -r "${addons}" ] && source "${addons}" "init" "${DEBUG}" done printf "Done.\n" - # setup bashbot - [[ "${UID}" -eq "0" ]] && RUNUSER="nobody" - printf "Enter User to run bashbot [${RUNUSER}]: " - read -r TOUSER - [ -z "${TOUSER}" ] && TOUSER="${RUNUSER}" - if ! id "${TOUSER}" &>/dev/null; then - printf "${RED}User \"${TOUSER}\" not found!${NN}" + # ask for bashbot user + runuser="${RUNUSER}"; [ "${UID}" = "0" ] && runuser="nobody" + printf "Enter User to run bashbot [${runuser}]: " + read -r touser + [ -z "${touser}" ] && touser="${runuser}" + # check user ... + if ! id "${touser}" &>/dev/null; then + printf "${RED}User \"${touser}\" does not exist!${NN}" exit 3 - else - printf "Adjusting files and permissions for user \"${TOUSER}\" ...\n" - [ -w "bashbot.rc" ] && sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'"${TOUSER}"'"/' "bashbot.rc" - chmod 711 . - chmod -R o-w ./* - 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 - # jsshDB must writeable by owner - find . -name '*.jssh*' -exec chmod u+w \{\} + - chown -R "${TOUSER}" . ./* - printf "Done.\n" + elif [[ "${UID}" != "0" && "${touser}" != "${runuser}" ]]; then + # different user but not root ... + printf "${ORANGE}You are not root change to \"${touser}\" may fail, try \"sudo ./bashbot.sh init\"${NN}" 1>&2 fi + # adjust permissions + printf "Adjusting files and permissions for user \"${touser}\" ...\n" + chmod 711 . + chmod -R o-w ./* + 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 + # jsshDB must writeable by owner + find . -name '*.jssh*' -exec chmod u+w \{\} + + chown -R "${touser}" . ./* + printf "Done.\n" + # adjust values in bashbot.rc + [ -w "bashbot.rc" ] && sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'"${touser}"'"/' "bashbot.rc" # ask to check bottoken online if [ -z "$(getConfigKey "botid")" ]; then printf "Seems to be your first init. Should I verify your bot token online? (y/N) N\b" From c6c30a4b9dc4ddec6c201c5a9f5a26e5a952cad2 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 10 Jan 2021 18:39:43 +0100 Subject: [PATCH 62/98] init: finalize adjust user --- bashbot.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index ac36b75..3040a39 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.25-dev-53-gfb8b022 +#### $$VERSION$$ v1.25-dev-54-gbd664da ################################################################## # emmbeded system may claim bash but it is not @@ -1128,7 +1128,8 @@ bot_init() { exit 3 elif [[ "${UID}" != "0" && "${touser}" != "${runuser}" ]]; then # different user but not root ... - printf "${ORANGE}You are not root change to \"${touser}\" may fail, try \"sudo ./bashbot.sh init\"${NN}" 1>&2 + printf "${ORANGE}You are not root, adjusting permissions may fail. Try \"sudo ./bashbot.sh init\"${NN}Press to stop or to continue..." 1>&2 + [ -n "${INTERACTIVE}" ] && read -r runuser fi # adjust permissions printf "Adjusting files and permissions for user \"${touser}\" ...\n" From d521d358156aa9590c411e67774ffa1567338ecb Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 10 Jan 2021 19:21:18 +0100 Subject: [PATCH 63/98] init: bashbot.rc: adjust botname --- bashbot.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 3040a39..8b0f279 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.25-dev-54-gbd664da +#### $$VERSION$$ v1.25-dev-55-gc6c30a4 ################################################################## # emmbeded system may claim bash but it is not @@ -1105,7 +1105,7 @@ start_bot() { # initialize bot environment, user and permissions bot_init() { [ -n "${BASHBOT_HOME}" ] && cd "${BASHBOT_HOME}" || exit 1 - local runuser touser DEBUG="$1" + local runuser chown touser botname DEBUG="$1" # upgrade from old version # currently no action printf "Check for Update actions ...\n" @@ -1120,8 +1120,8 @@ bot_init() { # ask for bashbot user runuser="${RUNUSER}"; [ "${UID}" = "0" ] && runuser="nobody" printf "Enter User to run bashbot [${runuser}]: " - read -r touser - [ -z "${touser}" ] && touser="${runuser}" + read -r chown + [ -z "${chown}" ] && chown="${runuser}"; touser="${chown%:*}" # check user ... if ! id "${touser}" &>/dev/null; then printf "${RED}User \"${touser}\" does not exist!${NN}" @@ -1139,10 +1139,16 @@ bot_init() { chmod -R o-r,o-w "${COUNTFILE}"* "${BLOCKEDFILE}"* "${DATADIR}" "${BOTACL}" 2>/dev/null # jsshDB must writeable by owner find . -name '*.jssh*' -exec chmod u+w \{\} + - chown -R "${touser}" . ./* + chown -Rf "${chown}" . ./* printf "Done.\n" # adjust values in bashbot.rc - [ -w "bashbot.rc" ] && sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'"${touser}"'"/' "bashbot.rc" + if [ -w "bashbot.rc" ]; then + printf "Adjust user and botname in bashbot.rc ...\n" + sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'"${touser}"'"/' "bashbot.rc" + botname="$(getConfigKey "botname")" + [ -n "${botname}" ] && sed -i '/^[# ]*name=/ s/name=.*$/name="'"${botname}"'"/' "bashbot.rc" + printf "Done.\n" + fi # ask to check bottoken online if [ -z "$(getConfigKey "botid")" ]; then printf "Seems to be your first init. Should I verify your bot token online? (y/N) N\b" From e1f209783fa6238d8d79bb4ab87b6aa2a011e2cf Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 10 Jan 2021 20:30:56 +0100 Subject: [PATCH 64/98] modules: new functions set_chat_title set_chat_description --- modules/chatMember.sh | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/modules/chatMember.sh b/modules/chatMember.sh index ba32967..c7fc95b 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,26 +5,31 @@ # 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-14-g2fe6d4b +#### $$VERSION$$ v1.30-dev-0-gd521d35 # will be automatically sourced from bashbot # source once magic, function named like file eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" -LEAVE_URL=${URL}'/leaveChat' -KICK_URL=${URL}'/kickChatMember' -UNBAN_URL=${URL}'/unbanChatMember' +LEAVE_URL="${URL}"'/leaveChat' +KICK_URL="${URL}"'/kickChatMember' +UNBAN_URL="${URL}"'/unbanChatMember' GETMEMBER_URL=${URL}'/getChatMember' -# usage: status="$(get_chat_member_status "chat" "user")" -# $1 chat # $2 user -get_chat_member_status() { - sendJson "$1" '"user_id":'"$2"'' "${GETMEMBER_URL}" - # shellcheck disable=SC2154 - JsonGetString '"result","status"' <<< "${res}" +# manage chat functions ------- +# $1 chat, $2 title +set_chat_title() { + sendJson "$1" '"title": "'"$2"'"' "${URL}/setChatTitle" } +# $1 chat, $2 title +set_chat_description() { + sendJson "$1" '"description": "'"$2"'"' "${URL}/setChatDescription" +} + + +# manage chat member functions ------- kick_chat_member() { sendJson "$1" 'user_id: '"$2"'' "${KICK_URL}" } @@ -37,6 +42,17 @@ leave_chat() { sendJson "$1" "" "${LEAVE_URL}" } + +# bashbot specific functions --------- + +# usage: status="$(get_chat_member_status "chat" "user")" +# $1 chat # $2 user +get_chat_member_status() { + sendJson "$1" '"user_id":'"$2"'' "${GETMEMBER_URL}" + # shellcheck disable=SC2154 + JsonGetString '"result","status"' <<< "${res}" +} + user_is_creator() { # empty is false ... [[ "${1:--}" == "${2:-+}" || "$(get_chat_member_status "$1" "$2")" == "creator" ]] && return 0 From cc299a581974eb575be43fb3426f3861835c381c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 10 Jan 2021 20:46:56 +0100 Subject: [PATCH 65/98] doc: new functions set_chat_title set_chat_description --- doc/6_reference.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/6_reference.md b/doc/6_reference.md index 3051867..129fcf3 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -115,7 +115,6 @@ The main use case for send_message is to process the output of interactive chats ### File, Album, Location, Venue, Keyboard - ##### send_file send_file can send local files, URL's or file_id's as different filex types (_e.g. photo video sticker_) @@ -254,6 +253,7 @@ send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"b 1", url"":"u 1"}, {"text":"b Edit a message means replace the content of the message in place. The message stay on the same position in the chat and keep the same message id. +If new message is the same than current message Telegram return error 400 with description "Bad Request: chat message is not modified" There is no need to use the same format when replace a message, e.g. a message sent with `send_normal_message` can be replaced with `edit_markdown_message` or `edit_html_message` and vice versa. @@ -314,6 +314,24 @@ edit_html_message "${CHAT[ID]}" "${saved-id}" "this is html text" ``` +--- + +### Manage Chat +To use the following functions the bot must have administrator status in the chat / group + +#### set_chat_title +`set_chat_title` sets a new chat title. If new title is the same than current title Telegram return error 400 +with description "Bad Request: chat title is not modified" + +*usage:* set_chat_title "${CHAT[ID]}" "new chat title" + +#### set_chat_description +`set_chat_description` sets a new description title. If new description is the same than current description Telegram return error 400 +with description "Bad Request: chat description is not modified" + +*usage:* set_chat_description "${CHAT[ID]}" "new chat description" + + ---- ### User Access Control @@ -1201,5 +1219,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.25-dev-28-g1525ac8 +#### $$VERSION$$ v1.30-dev-1-ge1f2097 From f8d8edef0bb5648fc31f73adfa557fb98e247cef Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 10 Jan 2021 23:17:35 +0100 Subject: [PATCH 66/98] modules: reduce URLs used only once --- modules/answerInline.sh | 5 ++--- modules/chatMember.sh | 14 +++++--------- modules/sendMessage.sh | 39 ++++++++++++++------------------------- 3 files changed, 21 insertions(+), 37 deletions(-) diff --git a/modules/answerInline.sh b/modules/answerInline.sh index 8b6a8b8..97d4563 100644 --- a/modules/answerInline.sh +++ b/modules/answerInline.sh @@ -5,20 +5,19 @@ # 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-14-g2fe6d4b +#### $$VERSION$$ v1.30-dev-2-gcc299a5 # will be automatically sourced from bashbot # source once magic, function named like file eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" -INLINE_QUERY=${URL}'/answerInlineQuery' answer_inline_query() { 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"']' "${URL}/answerInlineQuery" } # $1 unique ID for answer diff --git a/modules/chatMember.sh b/modules/chatMember.sh index c7fc95b..f555862 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,17 +5,13 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.30-dev-0-gd521d35 +#### $$VERSION$$ v1.30-dev-2-gcc299a5 # will be automatically sourced from bashbot # source once magic, function named like file eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" -LEAVE_URL="${URL}"'/leaveChat' -KICK_URL="${URL}"'/kickChatMember' -UNBAN_URL="${URL}"'/unbanChatMember' -GETMEMBER_URL=${URL}'/getChatMember' # manage chat functions ------- # $1 chat, $2 title @@ -31,15 +27,15 @@ set_chat_description() { # manage chat member functions ------- kick_chat_member() { - sendJson "$1" 'user_id: '"$2"'' "${KICK_URL}" + sendJson "$1" 'user_id: '"$2"'' "${URL}/kickChatMember" } unban_chat_member() { - sendJson "$1" 'user_id: '"$2"'' "${UNBAN_URL}" + sendJson "$1" 'user_id: '"$2"'' "${URL}/unbanChatMember" } leave_chat() { - sendJson "$1" "" "${LEAVE_URL}" + sendJson "$1" "" "${URL}/leaveChat" } @@ -48,7 +44,7 @@ leave_chat() { # usage: status="$(get_chat_member_status "chat" "user")" # $1 chat # $2 user get_chat_member_status() { - sendJson "$1" '"user_id":'"$2"'' "${GETMEMBER_URL}" + sendJson "$1" '"user_id":'"$2"'' "${URL}/kickChatMember" # shellcheck disable=SC2154 JsonGetString '"result","status"' <<< "${res}" } diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 38ea92a..e4c8808 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.25-dev-29-gac2e1a9 +#### $$VERSION$$ v1.30-dev-2-gcc299a5 # will be automatically sourced from bashbot @@ -17,17 +17,6 @@ eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" MSG_URL=${URL}'/sendMessage' EDIT_URL=${URL}'/editMessageText' -PHO_URL=${URL}'/sendPhoto' -AUDIO_URL=${URL}'/sendAudio' -DOCUMENT_URL=${URL}'/sendDocument' -STICKER_URL=${URL}'/sendSticker' -VIDEO_URL=${URL}'/sendVideo' -VOICE_URL=${URL}'/sendVoice' -LOCATION_URL=${URL}'/sendLocation' -VENUE_URL=${URL}'/sendVenue' -ACTION_URL=${URL}'/sendChatAction' -FORWARD_URL=${URL}'/forwardMessage' -ALBUM_URL=${URL}'/sendMediaGroup' # # send/edit message variants ------------------ @@ -168,7 +157,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then JSON+='{"type":"photo","media":"'${IMAGE}'"}' done # shellcheck disable=SC2086 - res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "${ALBUM_URL}" -F "chat_id=${CHAT}"\ + res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "${URL}/sendMediaGroup" -F "chat_id=${CHAT}"\ -F "media=[${JSON}]" | "${JSONSHFILE}" -s -b -n 2>/dev/null )" sendJsonResult "${res}" "send_album (curl)" "${CHAT}" "$@" [[ -z "${SOURCE}" && -n "${BASHBOT_EVENT_SEND[*]}" ]] && event_send "album" "$@" & @@ -228,22 +217,22 @@ send_file(){ fi # select upload URL case "${ext}" in - audio|mp3|flac) - url="${AUDIO_URL}"; what="audio"; stat="upload_audio" - ;; photo|png|jpg|jpeg|gif|pic) - url="${PHO_URL}"; what="photo"; stat="upload_photo" + url="${URL}/sendPhoto"; what="photo"; stat="upload_photo" + ;; + audio|mp3|flac) + url="${URL}/sendAudio"; what="audio"; stat="upload_audio" ;; sticker|webp) - url="${STICKER_URL}"; what="sticker"; stat="upload_photo" + url="${URL}/sendSticker"; what="sticker"; stat="upload_photo" ;; video|mp4) - url="${VIDEO_URL}"; what="video"; stat="upload_video" + url="${URL}/sendVideo"; what="video"; stat="upload_video" ;; voice|ogg) - url="${VOICE_URL}"; what="voice"; stat="record_audio" + url="${URL}/sendVoice"; what="voice"; stat="record_audio" ;; - *) url="${DOCUMENT_URL}"; what="document"; stat="upload_document" + *) url="${URL}/sendDocument"; what="document"; stat="upload_document" ;; esac @@ -268,13 +257,13 @@ send_file(){ # $1 typing upload_photo record_video upload_video record_audio upload_audio upload_document find_location send_action() { [ -z "$2" ] && return - sendJson "$1" '"action": "'"$2"'"' "${ACTION_URL}" & + sendJson "$1" '"action": "'"$2"'"' "${URL}/sendChatAction" & } # $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"'' "${URL}/sendLocation" } # $1 CHAT $2 lat $3 long $4 title $5 address $6 foursquard id @@ -282,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}" "${URL}/sendVenue" } @@ -293,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"'' "${URL}/forwardMessage" } forward() { # backward compatibility forward_message "$@" || return From f573d63c5555c38ec8d63d14e88e75936073dfaa Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 17:47:06 +0100 Subject: [PATCH 67/98] remove URLs used once --- bashbot.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 8b0f279..21f6736 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.25-dev-55-gc6c30a4 +#### $$VERSION$$ v1.30-dev-3-gf8d8ede ################################################################## # emmbeded system may claim bash but it is not @@ -308,14 +308,11 @@ BASHBOT_RETRY="" # retry by default URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}" ME_URL=${URL}'/getMe' -UPD_URL=${URL}'/getUpdates?offset=' -GETFILE_URL=${URL}'/getFile' - ################# # BASHBOT COMMON functions declare -rx SCRIPT SCRIPTDIR MODULEDIR RUNDIR ADDONDIR BOTACL DATADIR COUNTFILE -declare -rx BOTTOKEN URL ME_URL UPD_URL GETFILE_URL +declare -rx BOTTOKEN URL ME_URL declare -ax CMD declare -Ax UPD BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY @@ -400,7 +397,7 @@ delete_message() { get_file() { [ -z "$1" ] && return - sendJson "" '"file_id": "'"$1"'"' "${GETFILE_URL}" + sendJson "" '"file_id": "'"$1"'"' "${URL}/getFIle" printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')" } @@ -477,8 +474,9 @@ sendJson(){ if detect_curl ; then # here we have curl ---- [ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl" + # $1 URL, $2 hack: log getJson if not "" getJson(){ - [[ -n "${BASHBOTDEBUG}" && -n "$3" ]] && log_debug "getJson (curl) URL=${1##*/}" + [[ -n "${BASHBOTDEBUG}" && -n "$2" ]] && log_debug "getJson (curl) URL=${1##*/}" # shellcheck disable=SC2086 "${BASHBOT_CURL}" -sL -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" "$1" } @@ -510,7 +508,7 @@ else # NO curl, try wget if _exists wget; then getJson(){ - [[ -n "${BASHBOTDEBUG}" && -z "$3" ]] && log_debug "getJson (wget) URL=${1##*/}" + [[ -n "${BASHBOTDEBUG}" && -z "$2" ]] && log_debug "getJson (wget) URL=${1##*/}" # shellcheck disable=SC2086 wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - "$1" } @@ -1068,7 +1066,7 @@ start_bot() { # adaptive sleep in ms rounded to next 0.1 s sleep "$(_round_float "${nextsleep}e-3" "1")" # get next update - UPDATE="$(getJson "${UPD_URL}${OFFSET}" "${BASHBOT_UPDATELOG}" 2>/dev/null | "${JSONSHFILE}" -b -n 2>/dev/null | iconv -f utf-8 -t utf-8 -c)" + UPDATE="$(getJson "${URL}/getUpdates?offset=${OFFSET}" "${BASHBOT_UPDATELOG}" 2>/dev/null | "${JSONSHFILE}" -b -n 2>/dev/null | iconv -f utf-8 -t utf-8 -c)" # did we get an response? if [ -n "${UPDATE}" ]; then # we got something, do processing From daeffb30e8af5256ac7d947fd58af29aaae7620f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 18:06:24 +0100 Subject: [PATCH 68/98] modules: chatMember: new invite, pin unpin unpinAll, delete_chat_photo --- bashbot.sh | 2 +- modules/chatMember.sh | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 21f6736..e8e841f 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-3-gf8d8ede +#### $$VERSION$$ v1.30-dev-4-gf573d63 ################################################################## # emmbeded system may claim bash but it is not diff --git a/modules/chatMember.sh b/modules/chatMember.sh index f555862..e175c80 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.30-dev-2-gcc299a5 +#### $$VERSION$$ v1.30-dev-4-gf573d63 # will be automatically sourced from bashbot @@ -14,6 +14,11 @@ eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" # manage chat functions ------- +# $1 chat +new_chat_invite() { + sendJson "$1" "" "${URL}/exportChatInviteLink" +} + # $1 chat, $2 title set_chat_title() { sendJson "$1" '"title": "'"$2"'"' "${URL}/setChatTitle" @@ -24,6 +29,30 @@ set_chat_description() { sendJson "$1" '"description": "'"$2"'"' "${URL}/setChatDescription" } +# $1 chat +delete_chat_photo() { + sendJson "$1" "" "${URL}/deleteChatPhoto" +} + +# $1 chat, $2 message_id +pin_chat_message() { + sendJson "$1" '"message_id": "'"$2"'"' "${URL}/pinChatMessage" +} + +# $1 chat, $2 message_id +unpin_chat_message() { + sendJson "$1" '"message_id": "'"$2"'"' "${URL}/unpinChatMessage" +} + +# $1 chat +unpinAll_chat_message() { + sendJson "$1" "" "${URL}/unpinAllChatMessage" +} + +# $1 chat +delete_chat_stickers() { + sendJson "$1" "" "${URL}/deleteChatStickerSet" +} # manage chat member functions ------- kick_chat_member() { From 87f618fadbcbc9ed6db7ca3903c68ce01c84b003 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 18:25:53 +0100 Subject: [PATCH 69/98] modules: sendMessage: send_sticker --- modules/sendMessage.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index e4c8808..feb5e55 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.30-dev-2-gcc299a5 +#### $$VERSION$$ v1.30-dev-5-gdaeffb3 # will be automatically sourced from bashbot @@ -143,6 +143,11 @@ send_button() { send_inline_keyboard "$1" "$2" '[ {"text":"'"$(JsonEscape "$3")"'", "url":"'"$4"'"}]' } +# $1 chat, $2 file_id on telegram server +send_sticker() { + sendJson "$1" '"sticker": "'"$2"'"' "${URL}/setChatDescription" +} + if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then # there are no checks if URL or ID exists From 71daed3487ddff953a319f30c72a7cff73ef9950 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 18:31:39 +0100 Subject: [PATCH 70/98] modules: sendMessage: fix curl detection --- bashbot.sh | 2 +- modules/sendMessage.sh | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index e8e841f..32da63f 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-4-gf573d63 +#### $$VERSION$$ v1.30-dev-6-g87f618f ################################################################## # emmbeded system may claim bash but it is not diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index feb5e55..ec02694 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.30-dev-5-gdaeffb3 +#### $$VERSION$$ v1.30-dev-6-g87f618f # will be automatically sourced from bashbot @@ -149,9 +149,10 @@ send_sticker() { } -if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then -# there are no checks if URL or ID exists -# $1 chat $3 ... $n URL or ID +# only curl can send files ... +if detect_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 @@ -169,7 +170,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then } else send_album(){ - log_error "Sorry, wget Album upload not yet implemented" + log_error "Sorry, wget Album upload not implemented" BOTSENT[OK]="false" [[ -z "${SOURCE}" && -n "${BASHBOT_EVENT_SEND[*]}" ]] && event_send "album" "$@" & } From afade2e2f0c2ef62df795f71a2ff2a43521b8167 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 18:50:45 +0100 Subject: [PATCH 71/98] modules: sendMessage: edit_message_caption --- modules/sendMessage.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index ec02694..4683ad7 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.30-dev-6-g87f618f +#### $$VERSION$$ v1.30-dev-7-g71daed3 # will be automatically sourced from bashbot @@ -75,6 +75,11 @@ edit_html_message() { _format_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"html"' "${EDIT_URL}" } +# $1 chat $2 mesage_id, $3 caption +edit_message_caption() { + sendJson "$1" ',"message_id":'"$2"',"caption":"'"$3"'"' "${URL}/editMessageCaption" +} + # internal function, send/edit formatted message with parse_mode and URL # $1 CHAT $2 message $3 action $4 URL From 5f602a9a14fec2e38ad029e7022352e3be13edd0 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 19:49:01 +0100 Subject: [PATCH 72/98] fix typos in changes --- bashbot.sh | 4 ++-- modules/sendMessage.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 32da63f..365fef3 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-6-g87f618f +#### $$VERSION$$ v1.30-dev-8-gafade2e ################################################################## # emmbeded system may claim bash but it is not @@ -397,7 +397,7 @@ delete_message() { get_file() { [ -z "$1" ] && return - sendJson "" '"file_id": "'"$1"'"' "${URL}/getFIle" + sendJson "" '"file_id": "'"$1"'"' "${URL}/getFile" printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')" } diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 4683ad7..6b3d214 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.30-dev-7-g71daed3 +#### $$VERSION$$ v1.30-dev-8-gafade2e # will be automatically sourced from bashbot @@ -150,7 +150,7 @@ send_button() { # $1 chat, $2 file_id on telegram server send_sticker() { - sendJson "$1" '"sticker": "'"$2"'"' "${URL}/setChatDescription" + sendJson "$1" '"sticker": "'"$2"'"' "${URL}/sendSticker" } From e13b9eb9407c85ea4bfe971f1da1ee62d0599b80 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 20:23:18 +0100 Subject: [PATCH 73/98] new example command /unpin, fix user_is_allowed --- doc/3_advanced.md | 3 ++- doc/6_reference.md | 7 ++++--- modules/chatMember.sh | 3 ++- mycommands.sh | 6 +++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/doc/3_advanced.md b/doc/3_advanced.md index e16359f..6189159 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -62,6 +62,7 @@ You must use the function `user_is_allowed` to check if a user has the capabilit # GLOBAL commands start here, only edit messages '/start'*) user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*." + # true if: user is botadmin, user is group admin, user is allowed if user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then bot_help "${CHAT[ID]}" else @@ -301,5 +302,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v1.25-dev-23-g8be95a3 +#### $$VERSION$$ v1.30-dev-9-g5f602a9 diff --git a/doc/6_reference.md b/doc/6_reference.md index 129fcf3..46876c7 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -422,9 +422,10 @@ fi *See also [Chat Member](https://core.telegram.org/bots/api/#chatmember)* ##### user_is_allowed -Bashbot supports User Access Control, see [Advanced Usage](3_advanced.md) +`uers_is_allowed` checks if: user id botadmin, user is group admin or user is allowed to execute action.. +Allowed actions are configured as User Access Control rules, see [Advanced Usage](3_advanced.md) -*usage:* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}" +*usage:* user_is_allowed "${USER[ID]}" "action" "${CHAT[ID]}" *example:* ```bash @@ -1219,5 +1220,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.30-dev-1-ge1f2097 +#### $$VERSION$$ v1.30-dev-9-g5f602a9 diff --git a/modules/chatMember.sh b/modules/chatMember.sh index e175c80..879bc85 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.30-dev-4-gf573d63 +#### $$VERSION$$ v1.30-dev-9-g5f602a9 # will be automatically sourced from bashbot @@ -112,6 +112,7 @@ user_is_botadmin() { # $1 user # $2 key # $3 chat user_is_allowed() { [ -z "$1" ] && return 1 + user_is_admin "$1" && return 0 # user can do everything grep -F -xq "$1:*:*" <"${BOTACL}" && return 0 [ -z "$2" ] && return 1 diff --git a/mycommands.sh b/mycommands.sh index a3ac750..b1bf008 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -13,7 +13,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-41-g37e4539 +#### $$VERSION$$ v1.30-dev-9-g5f602a9 ####################################################### # shellcheck disable=SC1117 @@ -124,6 +124,10 @@ else case "${MESSAGE}" in ################## # example commands, replace thm by your own + '/unpin'*) # unpin all messages if (bot)admin or allowed for user + user_is_allowed "${USER[ID]}" "unpin" "${CHAT[ID]}" &&\ + unpinall_chat_messages "${CHAT[ID]}" + ;; '/echo'*) # example echo command send_normal_message "${CHAT[ID]}" "${MESSAGE}" ;; From ab71f3765b01cfbcbdf22301d50a0ffea64dbfb5 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 20:57:23 +0100 Subject: [PATCH 74/98] doc: add new functions --- doc/6_reference.md | 59 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/doc/6_reference.md b/doc/6_reference.md index 46876c7..84a6933 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -214,7 +214,7 @@ _keyboard_numpad ---- ##### send_button -*usage:* send_button "chat-id" "message" "text" "URL" +*usage:* send_button "$CHAT[ID]" "message" "text" "URL" *alias:* _button "text" "URL" @@ -223,6 +223,12 @@ _keyboard_numpad send_button "${CHAT[ID]}" "MAKE MONEY FAST!!!" "Visit my Shop" "https://dealz.rrr.de" ``` +##### send_sticker +`send_sticker` sends a sticker using a `file_id` to send a sticker that exists on the Telegram servers. + +*usage:* send_sticker "$CHAT[ID]" "file_id" + + ##### send_inline_keyboard Even its called keyboard, this function is different from send_keyboard. The main difference is that it's only possible to specify URL buttons, no Text Buttons and the Buttons must be an Array of Buttons as specified for @@ -313,25 +319,68 @@ saved-id="${BOTSENT[ID]}" edit_html_message "${CHAT[ID]}" "${saved-id}" "this is html text" ``` +##### edit_message_caption +`edit_message_caption` changes the caption of a message (photo, audio, video, document) in the given chat. + +*usage:* edit_message_caption "${CHAT[ID]}" "MESSAGE-ID" "caption" + --- -### Manage Chat +### Manage Group To use the following functions the bot must have administrator status in the chat / group -#### set_chat_title +##### set_chat_title `set_chat_title` sets a new chat title. If new title is the same than current title Telegram return error 400 with description "Bad Request: chat title is not modified" *usage:* set_chat_title "${CHAT[ID]}" "new chat title" -#### set_chat_description + +##### set_chat_description `set_chat_description` sets a new description title. If new description is the same than current description Telegram return error 400 with description "Bad Request: chat description is not modified" *usage:* set_chat_description "${CHAT[ID]}" "new chat description" +##### new_chat_invite +`new_chat_invite` generate a new invite link for a chat; any previously generated link is revoked. +Returns the new invite link as String on success. + +*usage:* new_chat_invite "${CHAT[ID]}" + + +##### delete_chat_photo + +*usage:* delete_chat_photo "${CHAT[ID]}" + + +##### pin_chat_message +# $1 chat, $2 message_id +`pin_chat_message` add a message to the list of pinned messages in a chat. + +*usage:* pin_chat_message "${CHAT[ID]}" "message_id" + + +##### unpin_chat_message +`unpin_chat_message` remove a message from the list of pinned messages in a chat. + +*usage:* unpin_chat_message "${CHAT[ID]}" "message_id" + + +##### unpinall_chat_message +`unpinall_chat_message` clear the list of pinned messages in a chat. + +*usage:* unpinall_chat_message "${CHAT[ID]}" + + +##### delete_chat_stickers +`delete_chat_stickers` deletes a group sticker set from a supergroup. + +*usage:* delete_chat_stickers "${CHAT[ID]}" + + ---- ### User Access Control @@ -1220,5 +1269,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.30-dev-9-g5f602a9 +#### $$VERSION$$ v1.30-dev-10-ge13b9eb From 0739a51130ac1d43c05035a22e49f0fb549be51c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 21:02:35 +0100 Subject: [PATCH 75/98] modules: chatMember: unpinAll -> unpinall --- modules/chatMember.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 879bc85..3c37035 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.30-dev-9-g5f602a9 +#### $$VERSION$$ v1.30-dev-11-gab71f37 # will be automatically sourced from bashbot @@ -45,7 +45,7 @@ unpin_chat_message() { } # $1 chat -unpinAll_chat_message() { +unpinall_chat_message() { sendJson "$1" "" "${URL}/unpinAllChatMessage" } From 29fa5cfcca247fa7aaedaaa26bfc470f4f682809 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 22:15:32 +0100 Subject: [PATCH 76/98] move detect_curl to common functions --- bashbot.sh | 54 ++++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 365fef3..cd1bfed 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-8-gafade2e +#### $$VERSION$$ v1.30-dev-12-g0739a51 ################################################################## # emmbeded system may claim bash but it is not @@ -116,6 +116,27 @@ log_debug(){ printf "%(%c)T: %s\n" -1 "$*" >>"${DEBUGLOG}"; } log_update(){ printf "%(%c)T: %s\n" -1 "$*" >>"${UPDATELOG}"; } # log $1 with date, special first \n log_message(){ printf "\n%(%c)T: %s\n" -1 "${1/\\n/$'\n'}" >>"${MESSAGELOG}"; } +# curl is preferred, try detect curl even not in PATH +# sets BASHBOT_CURL to point to curl +DETECTED_CURL="curl" +detect_curl() { + local file warn="Warning: Curl not detected, try fallback to wget! pls install curl or adjust BASHBOT_CURL/BASHBOT_WGET environment variables." + # custom curl command + [ -n "${BASHBOT_CURL}" ] && return 0 + # use wget + [ -n "${BASHBOT_WGET}" ] && DETECTED_CURL="wget" && return 1 + # default use curl in PATH + BASHBOT_CURL="curl" + _exists curl && return 0 + # search in usual locations + for file in /usr/bin /bin /usr/local/bin; do + [ -x "${file}/curl" ] && BASHBOT_CURL="${file}/curl" && return 0 + done + # curl not in PATH and not in usual locations + DETECTED_CURL="wget" + log_update "${warn}"; [ -n "${BASHBOTDEBUG}" ] && log_debug "${warn}" + return 1 +} # additional tests if we run in debug mode export BASHBOTDEBUG @@ -401,37 +422,6 @@ get_file() { printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')" } -# curl is preferred, try detect curl even not in PATH -# return TRUE if curl is found or custom curl detected -# return FALSE if no curl is found or wget is forced by BASHBOT_WGET -# sets BASHBOT_CURL to point to curl -DETECTED_CURL="curl" -function detect_curl() { - # custom curl command - [ -n "${BASHBOT_CURL}" ] && return 0 - # use wget - if [ -n "${BASHBOT_WGET}" ]; then - DETECTED_CURL="wget" - return 1 - fi - # default use curl in PATH - BASHBOT_CURL="curl" - _exists curl && return 0 - # search in usual locations - local file - for file in /usr/bin /bin /usr/local/bin; do - if [ -x "${file}/curl" ]; then - BASHBOT_CURL="${file}/curl" - return 0 - fi - done - # curl not in PATH and not in usual locations - DETECTED_CURL="wget" - local warn="Warning: Curl not detected, try fallback to wget! pls install curl or adjust BASHBOT_CURL/BASHBOT_WGET environment variables." - log_update "${warn}"; [ -n "${BASHBOTDEBUG}" ] && log_debug "${warn}" - return 1 -} - # iconv used to filter out broken utf characters, if not installed fake it if ! _exists iconv; then log_update "Warning: iconv not installed, pls imstall iconv!" From 8ae30faffc498c6942010a28bdb3973a1123cf09 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 22:56:43 +0100 Subject: [PATCH 77/98] modules: fix new_chat_invite --- bashbot.sh | 4 +++- modules/chatMember.sh | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index cd1bfed..67aebe6 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-12-g0739a51 +#### $$VERSION$$ v1.30-dev-13-g29fa5cf ################################################################## # emmbeded system may claim bash but it is not @@ -558,7 +558,9 @@ sendJsonResult(){ [ -n "${BASHBOTDEBUG}" ] && log_message "New Result ==========\n$1" BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$1")" if [ "${BOTSENT[OK]}" = "true" ]; then + BOTSENT[RESULT]="$(JsonGetString '"result"' <<< "$1")" BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$1")" + BOTSENT[CHAT]="$(JsonGetValue '"result","chat","id"' <<< "$1")" return # hot path everything OK! else diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 3c37035..7999a98 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.30-dev-11-gab71f37 +#### $$VERSION$$ v1.30-dev-13-g29fa5cf # will be automatically sourced from bashbot @@ -17,6 +17,7 @@ eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" # $1 chat new_chat_invite() { sendJson "$1" "" "${URL}/exportChatInviteLink" + [ "${BOTSENT[OK]}" = "true" ] && printf "%s\n" "${BOTSENT[RESULT]}" } # $1 chat, $2 title @@ -46,7 +47,7 @@ unpin_chat_message() { # $1 chat unpinall_chat_message() { - sendJson "$1" "" "${URL}/unpinAllChatMessage" + sendJson "$1" "" "${URL}/unpinAllChatMessages" } # $1 chat From 83990961a3a4c9f1e1a44d7d1a81e960a3ddfe8b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 12:40:08 +0100 Subject: [PATCH 78/98] modules: fix edit_message_caption --- modules/sendMessage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 6b3d214..60e9bdc 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.30-dev-8-gafade2e +#### $$VERSION$$ v1.30-dev-14-g8ae30fa # will be automatically sourced from bashbot @@ -77,7 +77,7 @@ edit_html_message() { # $1 chat $2 mesage_id, $3 caption edit_message_caption() { - sendJson "$1" ',"message_id":'"$2"',"caption":"'"$3"'"' "${URL}/editMessageCaption" + sendJson "$1" '"message_id":'"$2"',"caption":"'"$3"'"' "${URL}/editMessageCaption" } From 28ab301ce452179c74aa02f11264066562babd3e Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 12:43:12 +0100 Subject: [PATCH 79/98] bin: edit_message: add caption --- bin/send_edit_message.sh | 2 +- modules/sendMessage.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/send_edit_message.sh b/bin/send_edit_message.sh index 7892d07..f9b3182 100755 --- a/bin/send_edit_message.sh +++ b/bin/send_edit_message.sh @@ -22,7 +22,7 @@ USAGE='send_edit_message.sh [-h|--help] [format] "CHAT[ID]" "MESSAGE[ID]" "messa # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 16:52 # -#### $$VERSION$$ v1.25-dev-49-g41ce9cc +#### $$VERSION$$ v1.30-dev-15-g8399096 #=============================================================================== #### diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 60e9bdc..8c4e0e3 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.30-dev-14-g8ae30fa +#### $$VERSION$$ v1.30-dev-15-g8399096 # will be automatically sourced from bashbot From eab840868e43eee14640e6348bfb0fde4a25a99c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 12:45:53 +0100 Subject: [PATCH 80/98] bin: edit_message: add caption --- bin/send_edit_message.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/send_edit_message.sh b/bin/send_edit_message.sh index f9b3182..e74b73b 100755 --- a/bin/send_edit_message.sh +++ b/bin/send_edit_message.sh @@ -3,11 +3,11 @@ # # FILE: bin/send_message.sh # -USAGE='send_edit_message.sh [-h|--help] [format] "CHAT[ID]" "MESSAGE[ID]" "message ...." [debug]' +USAGE='send_edit_message.sh [-h|--help] [format|caption] "CHAT[ID]" "MESSAGE[ID]" "message ...." [debug]' # # DESCRIPTION: replace a message in the given user/group # -# OPTIONS: format - normal, markdown, html (optional) +# OPTIONS: format - normal, markdown, html or caption for file caption (optional) # CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself # MESSAGE[ID] - message to replace # message - message to send in specified format @@ -22,7 +22,7 @@ USAGE='send_edit_message.sh [-h|--help] [format] "CHAT[ID]" "MESSAGE[ID]" "messa # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 16:52 # -#### $$VERSION$$ v1.30-dev-15-g8399096 +#### $$VERSION$$ v1.30-dev-16-g28ab301 #=============================================================================== #### @@ -37,10 +37,14 @@ case "$1" in SEND="edit_markdownv2_message" shift ;; - "html") + "htm"*) SEND="edit_html_message" shift ;; + "cap"*) + SEND="edit_message_caption" + shift + ;; '') printf "missing arguments\n" ;& @@ -68,6 +72,7 @@ else fi # send message in selected format +set -x "${SEND}" "${CHAT}" "$2" "$3" # output send message result From abe058a53a368bbb0e272741fb0705b25f8792b7 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 12:48:15 +0100 Subject: [PATCH 81/98] bin: edit_message: remove set -x --- bin/send_edit_message.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/send_edit_message.sh b/bin/send_edit_message.sh index e74b73b..2730588 100755 --- a/bin/send_edit_message.sh +++ b/bin/send_edit_message.sh @@ -22,7 +22,7 @@ USAGE='send_edit_message.sh [-h|--help] [format|caption] "CHAT[ID]" "MESSAGE[ID] # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 16:52 # -#### $$VERSION$$ v1.30-dev-16-g28ab301 +#### $$VERSION$$ v1.30-dev-17-geab8408 #=============================================================================== #### @@ -72,7 +72,6 @@ else fi # send message in selected format -set -x "${SEND}" "${CHAT}" "$2" "$3" # output send message result From 079450675305a07525e6a5167c4213d5758bdcf9 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 13:09:32 +0100 Subject: [PATCH 82/98] bashbot.sh: jsonDecode: use printf --- bashbot.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 67aebe6..5999b46 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-13-g29fa5cf +#### $$VERSION$$ v1.30-dev-18-gabe058a ################################################################## # emmbeded system may claim bash but it is not @@ -146,7 +146,7 @@ export BASHBOTDEBUG # shellcheck disable=SC2094 debug_checks(){ { [ -z "${BASHBOTDEBUG}" ] && return - local where token; where="$1"; shift + local token where="$1"; shift printf "%(%c)T: debug_checks: %s: bashbot.sh %s\n" -1 "${where}" "${1##*/}" # shellcheck disable=SC2094 [ -z "${DEBUGLOG}" ] && printf "%(%c)T: %s\n" -1 "DEBUGLOG not set! ==========" @@ -651,15 +651,14 @@ getBotName() { # pure bash implementation, done by KayM (@gnadelwartz) # see https://stackoverflow.com/a/55666449/9381171 JsonDecode() { - local out="$1" remain="" U="" + local remain U out="$1" local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)' while [[ "${out}" =~ ${regexp} ]] ; do U=$(( ( (0xd${BASH_REMATCH[2]} & 0x3ff) <<10 ) | ( 0xd${BASH_REMATCH[3]} & 0x3ff ) + 0x10000 )) remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}" out="${BASH_REMATCH[1]}" done - #printf "%b\n" "${out}${remain}" # seems to work ... dealyed to next dev - echo -e "${out}${remain}" + printf "%b\n" "${out}${remain}" } JsonGetString() { From 541a279f2999099b16ec726edcbb1564a0527a73 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 14:06:10 +0100 Subject: [PATCH 83/98] dev: dev.inc.sh for BASE_DIR --- dev/all-tests.sh | 12 +++--------- dev/dev.inc.sh | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 dev/dev.inc.sh diff --git a/dev/all-tests.sh b/dev/all-tests.sh index f644247..3bf1c0f 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -5,17 +5,11 @@ # # Description: run all tests, exit after failed test # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-dev-19-g0794506 ############################################################# -# magic to ensure that we're always inside the root of our application, -# no matter from which directory we'll run script -GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "${GIT_DIR}" != "" ] ; then - cd "${GIT_DIR}/.." || exit 1 -else - printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 -fi +#shellcheck disable=SC1090 +source "${0%/*}/dev.inc.sh" ########################## # create test environment diff --git a/dev/dev.inc.sh b/dev/dev.inc.sh new file mode 100644 index 0000000..78882df --- /dev/null +++ b/dev/dev.inc.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +############################################################# +# +# File: dev/dev.inc.sh +# +# Description: common stuff for all dev scripts +# +#### $$VERSION$$ v1.30-dev-19-g0794506 +############################################################# + +# magic to ensure that we're always inside the root of our application, +# no matter from which directory we'll run script + +BASE_DIR=$(git rev-parse --show-toplevel 2>/dev/null) +# keep old for compatibility +# shellcheck disable=SC2034 +GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) +if [ "${BASE_DIR}" != "" ] ; then + cd "${BASE_DIR}" || exit 1 +else + printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 +fi + From 550a0defb36132707acb592214884e5d360c12c1 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 14:23:19 +0100 Subject: [PATCH 84/98] dev: use dev.inc.sh --- dev/dev.inc.sh | 5 ++--- dev/git-add.sh | 12 +++--------- dev/install-hooks.sh | 12 +++--------- dev/make-distribution.sh | 23 ++++++++--------------- dev/make-standalone.sh | 18 ++++++------------ dev/version.sh | 12 +++--------- 6 files changed, 25 insertions(+), 57 deletions(-) diff --git a/dev/dev.inc.sh b/dev/dev.inc.sh index 78882df..04f5263 100644 --- a/dev/dev.inc.sh +++ b/dev/dev.inc.sh @@ -5,16 +5,15 @@ # # Description: common stuff for all dev scripts # -#### $$VERSION$$ v1.30-dev-19-g0794506 +#### $$VERSION$$ v1.30-dev-20-g541a279 ############################################################# # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script -BASE_DIR=$(git rev-parse --show-toplevel 2>/dev/null) -# keep old for compatibility # shellcheck disable=SC2034 GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) +BASE_DIR=$(git rev-parse --show-toplevel 2>/dev/null) if [ "${BASE_DIR}" != "" ] ; then cd "${BASE_DIR}" || exit 1 else diff --git a/dev/git-add.sh b/dev/git-add.sh index c8da9f8..b8709fb 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,16 +3,10 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v1.25-dev-50-g427e4df +#### $$VERSION$$ v1.30-dev-20-g541a279 -# magic to ensure that we're always inside the root of our application, -# no matter from which directory we'll run script -GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "${GIT_DIR}" != "" ] ; then - cd "${GIT_DIR}/.." || exit 1 -else - printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 -fi +#shellcheck disable=SC1090 +source "${0%/*}/dev.inc.sh" [ ! -f .git/.lastcommit ] && printf "No previous commit or hooks not installed, use \"git add\" instead ... Abort\n" && exit diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 54f5adc..99697ff 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,16 +1,10 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-dev-20-g541a279 -# magic to ensure that we're always inside the root of our application, -# no matter from which directory we'll run script -GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "${GIT_DIR}" != "" ] ; then - cd "${GIT_DIR}/.." || exit 1 -else - printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 -fi +#shellcheck disable=SC1090 +source "${0%/*}/dev.inc.sh" HOOKDIR="dev/hooks" diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index b2d673e..0ab7118 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -7,18 +7,11 @@ # # Options: --notest - skip tests # -#### $$VERSION$$ v1.25-dev-42-gde24ded +#### $$VERSION$$ v1.30-dev-20-g541a279 ############################################################## -# magic to ensure that we're always inside the root of our application, -# no matter from which directory we'll run script -GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "${GIT_DIR}" != "" ] ; then - [[ "${GIT_DIR}" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}" - cd "${GIT_DIR}/.." || exit 1 -else - printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 -fi +#shellcheck disable=SC1090 +source "${0%/*}/dev.inc.sh" VERSION="$(git describe --tags | sed -e 's/-[0-9].*//' -e 's/v//')" @@ -60,12 +53,12 @@ printf "Create .dist files\n" for file in ${DISTFILESDIST} do [ "${file}" = "addons/*.sh" ] && continue - cp "${GIT_DIR}/../${file}" "${file}.dist" + cp "${BASE_DIR}/${file}" "${file}.dist" done # inject JSON.sh into distribution # shellcheck disable=SC1090 -source "${GIT_DIR}/../dev/inject-json.sh" +source "${BASE_DIR}/dev/inject-json.sh" # make html doc printf "Create html doc\n" @@ -76,8 +69,8 @@ source "../../dev/make-html.sh" cd .. || exit 1 printf "Create dist archives\n" # shellcheck disable=SC2046 -zip -rq - "${DISTNAME}" --exclude $(cat "${GIT_DIR}/../dev/${0##*/}.exclude") >"${DISTNAME}-${VERSION}.zip" -tar --exclude-ignore="${GIT_DIR}/../dev/${0##*/}.exclude" -czf "${DISTNAME}-${VERSION}.tar.gz" "${DISTNAME}" +zip -rq - "${DISTNAME}" --exclude $(cat "${BASE_DIR}/dev/${0##*/}.exclude") >"${DISTNAME}-${VERSION}.zip" +tar --exclude-ignore="${BASE_DIR}/dev/${0##*/}.exclude" -czf "${DISTNAME}-${VERSION}.tar.gz" "${DISTNAME}" printf "%s Done!\n" "$0" @@ -85,4 +78,4 @@ printf "%s Done!\n" "$0" ls -ld "${DISTNAME}-${VERSION}".* # an empty DEBUG.log is created ... :-( -rm -f "${GIT_DIR}/../test/"*.log +rm -f "${BASE_DIR}/test/"*.log diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index bfb0ea6..1cfbcd9 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -9,18 +9,12 @@ # 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-14-g2fe6d4b +#### $$VERSION$$ v1.30-dev-20-g541a279 ################################################################### -# magic to ensure that we're always inside the root of our application, -# no matter from which directory we'll run script -GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "${GIT_DIR}" != "" ] ; then - [[ "${GIT_DIR}" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}" - cd "${GIT_DIR}/.." || exit 1 -else - [ ! -f "bashbot.sh" ] && printf "bashbot.sh not found in %s\n" " $(pwd)" && exit 1 -fi +#shellcheck disable=SC1090 +source "${0%/*}/dev.inc.sh" +[ ! -f "bashbot.sh" ] && printf "bashbot.sh not found in %s\n" " $(pwd)" && exit 1 #DISTNAME="telegram-bot-bash" DISTDIR="./STANDALONE" @@ -37,7 +31,7 @@ cd "${DISTDIR}" || exit 1 # inject JSON.sh into distribution # shellcheck disable=SC1090 -source "${GIT_DIR}/../dev/inject-json.sh" +source "${BASE_DIR}/dev/inject-json.sh" ####################### # here the magic starts @@ -95,7 +89,7 @@ chmod +x bashbot.sh.min # make html doc printf "Create html doc\n" #shellcheck disable=SC1090 -source "${GIT_DIR}/../dev/make-html.sh" +source "${BASE_DIR}/dev/make-html.sh" printf "%s Done!\n" "$0" diff --git a/dev/version.sh b/dev/version.sh index 66f71a9..41e3143 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v1.25-dev-46-g8253a53 +#### $$VERSION$$ v1.30-dev-20-g541a279 # shellcheck disable=SC2016 # # Easy Versioning in git: @@ -34,14 +34,8 @@ # run this script to (re)place Version number in files # -# magic to ensure that we're always inside the root of our application, -# no matter from which directory we'll run script -GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) -if [ "${GIT_DIR}" != "" ] ; then - cd "${GIT_DIR}/.." || exit 1 -else - printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 -fi +#shellcheck disable=SC1090 +source "${0%/*}/dev.inc.sh" unset IFS # set -f # if you are paranoid use set -f to disable globbing From 0596983056767dc22ff0cb9bfc36db2219e59021 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 18:36:09 +0100 Subject: [PATCH 85/98] dev: fix make-standalone.sh --- dev/make-html.sh | 5 +++-- dev/make-standalone.sh | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/dev/make-html.sh b/dev/make-html.sh index c978c22..2b7fef5 100644 --- a/dev/make-html.sh +++ b/dev/make-html.sh @@ -7,7 +7,7 @@ # # Usage: source make-hmtl # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-dev-21-g550a0de ############################################################## # check for correct dir @@ -36,7 +36,8 @@ else '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\ + # shellcheck disable=SC2248 + 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' {} \; printf " Done!\n" fi diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index 1cfbcd9..723f193 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -6,10 +6,12 @@ # Description: # even after make-distribution.sh bashbot is not self contained as it was in the past. # +# Options: --notest +# # 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.30-dev-20-g541a279 +#### $$VERSION$$ v1.30-dev-21-g550a0de ################################################################### #shellcheck disable=SC1090 @@ -18,17 +20,26 @@ source "${0%/*}/dev.inc.sh" #DISTNAME="telegram-bot-bash" DISTDIR="./STANDALONE" -DISTFILES="bashbot.sh bashbot.rc commands.sh mycommands.sh dev/obfuscate.sh modules scripts logs LICENSE README.* doc botacl botconfig.jssh" +DISTMKDIR="data-bot-bash logs" +DISTFILES="bashbot.sh bashbot.rc commands.sh mycommands.sh dev/obfuscate.sh modules scripts addons LICENSE README.* doc botacl botconfig.jssh" # run pre_commit on files -dev/hooks/pre-commit.sh +[ "$1" != "--notest" ] && dev/hooks/pre-commit.sh # create dir for distribution and copy files +printf "Create directories and copy files\n" mkdir -p "${DISTDIR}" 2>/dev/null + # shellcheck disable=SC2086 cp -r ${DISTFILES} "${DISTDIR}" 2>/dev/null cd "${DISTDIR}" || exit 1 +# shellcheck disable=SC2250 +for dir in $DISTMKDIR +do + [ ! -d "${dir}" ] && mkdir "${dir}" +done + # inject JSON.sh into distribution # shellcheck disable=SC1090 source "${BASE_DIR}/dev/inject-json.sh" @@ -60,7 +71,7 @@ printf "\n... create unified bashbot.sh\n" { # first head of bashbot.sh - sed -n '0,/for modules in/ p' bashbot.sh | head -n -3 + sed -n '0,/for module in/ p' bashbot.sh | head -n -3 # then mycommands from first non comment line on printf '\n##############################\n# bashbot modules starts here ...\n' From 0f27e71b0fdf1e1094ad45a21b99f42e3ffd9beb Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 18:49:20 +0100 Subject: [PATCH 86/98] dev: make-stabdalone: only active addons --- dev/make-standalone.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index 723f193..32aabee 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -11,7 +11,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.30-dev-21-g550a0de +#### $$VERSION$$ v1.30-dev-22-g0596983 ################################################################### #shellcheck disable=SC1090 @@ -20,8 +20,8 @@ source "${0%/*}/dev.inc.sh" #DISTNAME="telegram-bot-bash" DISTDIR="./STANDALONE" -DISTMKDIR="data-bot-bash logs" -DISTFILES="bashbot.sh bashbot.rc commands.sh mycommands.sh dev/obfuscate.sh modules scripts addons LICENSE README.* doc botacl botconfig.jssh" +DISTMKDIR="data-bot-bash logs bin bin/logs addons" +DISTFILES="bashbot.sh bashbot.rc commands.sh mycommands.sh dev/obfuscate.sh modules bin scripts LICENSE README.* doc botacl botconfig.jssh $(echo "addons/"*.sh)" # run pre_commit on files [ "$1" != "--notest" ] && dev/hooks/pre-commit.sh From 277178389ae20bd448d2b4d64c41e621402966d8 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 19:05:53 +0100 Subject: [PATCH 87/98] some minor improvments --- bashbot.sh | 8 ++++---- dev/make-standalone.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 5999b46..edca11d 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -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) # -# Usage: bashbot.sh [-h|--help|BOTCOMMANDS] +# Usage: bashbot.sh BOTCOMMAND BOTCOMMANDS="-h help init start stop status suspendback resumeback killback" # # Exit Codes: @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-18-gabe058a +#### $$VERSION$$ v1.30-dev-23-g0f27e71 ################################################################## # emmbeded system may claim bash but it is not @@ -191,8 +191,8 @@ case "$1" in "") [ -z "${SOURCE}" ] && printf "${ORANGE}Available commands: ${GREY}${BOTCOMMANDS}${NN}" && exit ;; "-h"*) LOGO="${BASHBOT_HOME:-.}/doc/bashbot.ascii" - [ -r "${LOGO}" ] && cat "${LOGO}" - sed -nE -e '/(NOT EDIT)|(shellcheck)/d' -e '3,/###/p' <"$0" + { [ -r "${LOGO}" ] && cat "${LOGO}" + sed -nE -e '/(NOT EDIT)|(shellcheck)/d' -e '3,/###/p' <"$0"; } | more exit;; "help") HELP="${BASHBOT_HOME:-.}/README" if [ -n "${INTERACTIVE}" ];then diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index 32aabee..49ffb52 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -11,7 +11,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.30-dev-22-g0596983 +#### $$VERSION$$ v1.30-dev-23-g0f27e71 ################################################################### #shellcheck disable=SC1090 From ef972c571495f2d67b00355ad1c3cfbc99377f26 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 19:26:04 +0100 Subject: [PATCH 88/98] bashbot: use Json2Array UPD for response also --- bashbot.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index edca11d..c7eaa7f 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-23-g0f27e71 +#### $$VERSION$$ v1.30-dev-24-g2771783 ################################################################## # emmbeded system may claim bash but it is not @@ -555,21 +555,21 @@ sendJsonRetry(){ sendJsonResult(){ local offset=0 BOTSENT=( ) + Json2Array 'UPD' <<<"$1" [ -n "${BASHBOTDEBUG}" ] && log_message "New Result ==========\n$1" - BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$1")" + BOTSENT[OK]="${UPD["ok"]}" if [ "${BOTSENT[OK]}" = "true" ]; then - BOTSENT[RESULT]="$(JsonGetString '"result"' <<< "$1")" - BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$1")" - BOTSENT[CHAT]="$(JsonGetValue '"result","chat","id"' <<< "$1")" + BOTSENT[ID]="${UPD["result","message_id"]}" + BOTSENT[CHAT]="${UPD["result","chat","id"]}" + [ -n "${UPD["result"]}" ] && BOTSENT[RESULT]="${UPD["result"]}" return # hot path everything OK! else # oops something went wrong! if [ -n "$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")" + BOTSENT[ERROR]="${UPD["error_code"]}" + BOTSENT[DESCRIPTION]="${UPD["description"]}" + [ -n "${UPD["parameters","retry_after"]}" ] && BOTSENT[RETRY]="${UPD["parameters","retry_after"]}" else BOTSENT[OK]="false" BOTSENT[ERROR]="999" From d12ab8600dfb6d35a605190af6b216a0bde7e6db Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 19:40:31 +0100 Subject: [PATCH 89/98] minimize use of JsonGetXxx --- modules/sendMessage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 8c4e0e3..daf4d89 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.30-dev-15-g8399096 +#### $$VERSION$$ v1.30-dev-25-gef972c5 # will be automatically sourced from bashbot @@ -259,7 +259,7 @@ send_file(){ esac # get file_id and file_type if [ "${BOTSENT[OK]}" = "true" ]; then - BOTSENT[FILE_ID]="$(JsonGetString '.*,"file_id"' <<< "${res}")" + BOTSENT[FILE_ID]="${UPD["${what},0,file_id"]}" BOTSENT[FILE_TYPE]="${what}" fi return 0 From 6857a5558faf77f2a357fefabdc2b66661040e0a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 Jan 2021 20:07:00 +0100 Subject: [PATCH 90/98] doc: UPD contains full Telegram response --- doc/2_usage.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/doc/2_usage.md b/doc/2_usage.md index fae09b1..ed80a73 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -141,7 +141,8 @@ Note: to get help about a script in bin/ run `scriptname.sh --help` ---- ## Receive data -Evertime a Message is received, you can read incoming data using the following variables: +Evertime a Telegram update is received, you can read incoming data using the following variables: +In case you need other update values, the array `UDP` contains complete Telegram response. ### Regular Messages @@ -255,10 +256,12 @@ they contain the following variables only: * `${iQUERY[LAST_NAME]}`: User's last name -### Send Message Results +## Send data / get response -BOTSENT is set on every send_xxx action and only valid until next send action. For more on message results see. -[Advanced Usage](3_advanced.md) +After every `send_xxx` `get_xxx` call the array BOTSENT contains the most important values from Telegram response. +In case you need other response values , the array `UDP` contains complete Telegram response. + +### BOTSENT array * `$BOTSENT`: This array contains the parsed results from the last transmission to telegram. * `${BOTSENT[OK]}`: contains the string `true`: after a successful transmission @@ -266,6 +269,8 @@ BOTSENT is set on every send_xxx action and only valid until next send action. F * `${BOTSENT[FILE_ID]}`: unique identifier returned for an uploaded file or URL * `${BOTSENT[FILE_TYPE]}`: file type: photo, audio, video, sticker, voice, document + + ## Usage of bashbot functions #### sending messages @@ -346,5 +351,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.25-dev-42-gde24ded +#### $$VERSION$$ v1.30-dev-26-gd12ab86 From d269f9816de75f7c5e35d6483b949f157da24722 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 16 Jan 2021 09:20:17 +0100 Subject: [PATCH 91/98] dev: exclude bashbot.rc scripts: header --- dev/make-distribution.sh.exclude | 1 + doc/2_usage.md | 6 +++--- scripts/interactive.sh.clean | 15 +++++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dev/make-distribution.sh.exclude b/dev/make-distribution.sh.exclude index e93a029..7a277f1 100644 --- a/dev/make-distribution.sh.exclude +++ b/dev/make-distribution.sh.exclude @@ -1,5 +1,6 @@ data-bot-bash/* JSON.awk +bashbot.rc awk-patch.sh *.jssh* botacl diff --git a/doc/2_usage.md b/doc/2_usage.md index ed80a73..7d78516 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -142,7 +142,7 @@ Note: to get help about a script in bin/ run `scriptname.sh --help` ## Receive data Evertime a Telegram update is received, you can read incoming data using the following variables: -In case you need other update values, the array `UDP` contains complete Telegram response. +In case you need other update values, the array `UPD` contains complete Telegram response. ### Regular Messages @@ -259,7 +259,7 @@ they contain the following variables only: ## Send data / get response After every `send_xxx` `get_xxx` call the array BOTSENT contains the most important values from Telegram response. -In case you need other response values , the array `UDP` contains complete Telegram response. +In case you need other response values , the array `UPD` contains complete Telegram response. ### BOTSENT array @@ -351,5 +351,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.30-dev-26-gd12ab86 +#### $$VERSION$$ v1.30-dev-27-g6857a55 diff --git a/scripts/interactive.sh.clean b/scripts/interactive.sh.clean index 6d710bd..b9c6079 100755 --- a/scripts/interactive.sh.clean +++ b/scripts/interactive.sh.clean @@ -1,12 +1,19 @@ #!/bin/bash -# file: interactive.sh -# template for an interactive chat -# test: start_proc "${CHAT[ID]}" "./scripts/interactive.sh.clean" +######################################################################## +# +# File: interactive.sh +# +# Description: template for an interactive chat +# +# Usgage: start_proc "${CHAT[ID]}" ./scripts/interactive.sh.clean +# +# Test in CLI: ./scripts/interactive.sh.clean # # 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.30-dev-27-g6857a55 +######################################################################## ###### # parameters From a545bf1d8e408e21ada99272f4b7ae6c8f43748a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 16 Jan 2021 10:10:16 +0100 Subject: [PATCH 92/98] modules: chatMember: fix getChatMember URL --- bashbot.rc | 4 ++-- modules/chatMember.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 95648ff..c293a15 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.25-dev-51-gb2eecc5 +#### $$VERSION$$ v1.30-dev-28-gd269f98 # shellcheck disable=SC2009 # shellcheck disable=SC2181 @@ -60,7 +60,7 @@ case "$1" in 'status') ps -f -u "${runas}" | grep "${name}" | grep -qF "bashbot.sh startbot" if [ "$?" = "0" ]; then - printf "bashbot (%s) is runningi\n" "${name}" + printf "bashbot (%s) is running\n" "${name}" RETVAL=0 else printf "bashbot (%s) is stopped\n" "${name}" diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 7999a98..fdd983b 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.30-dev-13-g29fa5cf +#### $$VERSION$$ v1.30-dev-28-gd269f98 # will be automatically sourced from bashbot @@ -74,7 +74,7 @@ leave_chat() { # usage: status="$(get_chat_member_status "chat" "user")" # $1 chat # $2 user get_chat_member_status() { - sendJson "$1" '"user_id":'"$2"'' "${URL}/kickChatMember" + sendJson "$1" '"user_id":'"$2"'' "${URL}/getChatMember" # shellcheck disable=SC2154 JsonGetString '"result","status"' <<< "${res}" } From 6bfab171709330e150a743c30a042dc751f5fdf7 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 16 Jan 2021 10:30:39 +0100 Subject: [PATCH 93/98] dev: make-dist: exclude mycommands.sh --- dev/make-distribution.sh.exclude | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/make-distribution.sh.exclude b/dev/make-distribution.sh.exclude index 7a277f1..2a21666 100644 --- a/dev/make-distribution.sh.exclude +++ b/dev/make-distribution.sh.exclude @@ -1,6 +1,7 @@ data-bot-bash/* JSON.awk bashbot.rc +mycommands.sh awk-patch.sh *.jssh* botacl From 161e883a9a4eace04c7217ec0afa6bef33d3542e Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 16 Jan 2021 10:47:18 +0100 Subject: [PATCH 94/98] modules: sendMessage: fix send photo returns array --- modules/sendMessage.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index daf4d89..30cf8a0 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.30-dev-25-gef972c5 +#### $$VERSION$$ v1.30-dev-30-g6bfab17 # will be automatically sourced from bashbot @@ -186,7 +186,7 @@ UPLOADDIR="${BASHBOT_UPLOAD:-${DATADIR}/upload}" # supports local file, URL and file_id # $1 chat, $2 file https::// file_id:// , $3 caption, $4 extension (optional) send_file(){ - local url what stat err media capt file="$2" ext="$4" + local url what num stat err media capt file="$2" ext="$4" capt="$(JsonEscape "$3")" if [[ "${file}" =~ ^https*:// ]]; then media="URL" @@ -229,7 +229,7 @@ send_file(){ # select upload URL case "${ext}" in photo|png|jpg|jpeg|gif|pic) - url="${URL}/sendPhoto"; what="photo"; stat="upload_photo" + url="${URL}/sendPhoto"; what="photo"; num=",0"; stat="upload_photo" ;; audio|mp3|flac) url="${URL}/sendAudio"; what="audio"; stat="upload_audio" @@ -259,8 +259,8 @@ send_file(){ esac # get file_id and file_type if [ "${BOTSENT[OK]}" = "true" ]; then - BOTSENT[FILE_ID]="${UPD["${what},0,file_id"]}" - BOTSENT[FILE_TYPE]="${what}" + BOTSENT[FILE_ID]="${UPD["result,${what}${num},file_id"]}" + BOTSENT[FILE_TYPE]="${what}" fi return 0 } From 172a9e5461e8d42aaa327f20437f9a3f104377cd Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 16 Jan 2021 11:20:29 +0100 Subject: [PATCH 95/98] sed/grep no redirect from file --- bashbot.sh | 6 +++--- modules/jsonDB.sh | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index c7eaa7f..d3d763d 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-24-g2771783 +#### $$VERSION$$ v1.30-dev-31-g161e883 ################################################################## # emmbeded system may claim bash but it is not @@ -102,7 +102,7 @@ setConfigKey() { } getConfigKey() { [[ "$1" =~ ^[-${azAZo9},._]+$ ]] || return 3 - [ -r "${BOTCONFIG}.jssh" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' <"${BOTCONFIG}.jssh" | tail -n 1 + [ -r "${BOTCONFIG}.jssh" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' "${BOTCONFIG}.jssh" | tail -n 1 } # check if $1 seems a valid token # return true if token seems to be valid @@ -192,7 +192,7 @@ case "$1" in ;; "-h"*) LOGO="${BASHBOT_HOME:-.}/doc/bashbot.ascii" { [ -r "${LOGO}" ] && cat "${LOGO}" - sed -nE -e '/(NOT EDIT)|(shellcheck)/d' -e '3,/###/p' <"$0"; } | more + sed -nE -e '/(NOT EDIT)|(shellcheck)/d' -e '3,/###/p' "$0"; } | more exit;; "help") HELP="${BASHBOT_HOME:-.}/README" if [ -n "${INTERACTIVE}" ];then diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index 108438c..cc19d29 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.25-dev-30-gefca2e0 +#### $$VERSION$$ v1.30-dev-31-g161e883 # # source from commands.sh to use jsonDB functions # @@ -132,7 +132,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then [ -z "${DB}" ] && return 1 # start atomic delete here, exclusive max wait 1s { flock -s -w 1 200 - [ -r "${DB}" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' <"${DB}" | tail -n 1 + [ -r "${DB}" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' "${DB}" | tail -n 1 } 200>"${DB}${JSSH_LOCKNAME}" } @@ -298,7 +298,7 @@ jssh_getKeyDB_async() { [[ "$1" =~ ^${JSSH_KEYOK}+$ ]] || return 3 local DB; DB="$(jssh_checkDB "$2")" [ -z "${DB}" ] && return 1 - [ -r "${DB}" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' <"${DB}" | tail -n 1 + [ -r "${DB}" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' "${DB}" | tail -n 1 } jssh_countKeyDB_async() { @@ -313,7 +313,7 @@ jssh_countKeyDB_async() { Array2Json "oldARR" >"${DB}" elif [ -r "${DB}" ]; then # it's append, but last one counts, its a simple DB ... - VAL="$(sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' <"${DB}" | tail -n 1)" + VAL="$(sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' "${DB}" | tail -n 1)" printf '["%s"]\t"%s"\n' "${1//,/\",\"}" "$((++VAL))" >>"${DB}" fi } From d8453aad360c7885774f74f1c3949b265e33a67b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 16 Jan 2021 12:59:11 +0100 Subject: [PATCH 96/98] init: change bahsbot path in rc-file also --- bashbot.sh | 7 ++++--- modules/chatMember.sh | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index d3d763d..62dc1bf 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-31-g161e883 +#### $$VERSION$$ v1.30-dev-32-g172a9e5 ################################################################## # emmbeded system may claim bash but it is not @@ -1133,9 +1133,10 @@ bot_init() { # adjust values in bashbot.rc if [ -w "bashbot.rc" ]; then printf "Adjust user and botname in bashbot.rc ...\n" - sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'"${touser}"'"/' "bashbot.rc" + sed -i '/^[# ]*runas=/ s|runas=.*$|runas="'"${touser}"'"|' "bashbot.rc" + sed -i '/^[# ]*bashbot=/ s|bashbot=.*$|bashbot="cd '"${PWD}"'; '"${PWD}"'/'"${0##*/}"'"|' "bashbot.rc" botname="$(getConfigKey "botname")" - [ -n "${botname}" ] && sed -i '/^[# ]*name=/ s/name=.*$/name="'"${botname}"'"/' "bashbot.rc" + [ -n "${botname}" ] && sed -i '/^[# ]*name=/ s|name=.*$|name="'"${botname}"'"|' "bashbot.rc" printf "Done.\n" fi # ask to check bottoken online diff --git a/modules/chatMember.sh b/modules/chatMember.sh index fdd983b..d53b679 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.30-dev-28-gd269f98 +#### $$VERSION$$ v1.30-dev-31-g161e883 # will be automatically sourced from bashbot @@ -115,16 +115,16 @@ user_is_allowed() { [ -z "$1" ] && return 1 user_is_admin "$1" && return 0 # user can do everything - grep -F -xq "$1:*:*" <"${BOTACL}" && return 0 + grep -F -xq "$1:*:*" "${BOTACL}" && return 0 [ -z "$2" ] && return 1 # user is allowed todo one action in every chat - grep -F -xq "$1:$2:*" <"${BOTACL}" && return 0 + grep -F -xq "$1:$2:*" "${BOTACL}" && return 0 # all users are allowed to do one action in every chat - grep -F -xq "ALL:$2:*" <"${BOTACL}" && return 0 + grep -F -xq "ALL:$2:*" "${BOTACL}" && return 0 [ -z "$3" ] && return 1 # user is allowed to do one action in one chat - grep -F -xq "$1:$2:$3" <"${BOTACL}" && return 0 + grep -F -xq "$1:$2:$3" "${BOTACL}" && return 0 # all users are allowed to do one action in one chat - grep -F -xq "ALL:$2:$3" <"${BOTACL}" && return 0 + grep -F -xq "ALL:$2:$3" "${BOTACL}" && return 0 return 1 } From 3266427bccffaa008d63e44c985b9d28fbeec251 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 17 Jan 2021 09:55:13 +0100 Subject: [PATCH 97/98] getJson: remove unneeded extra logging --- bashbot.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 62dc1bf..5c4305e 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-32-g172a9e5 +#### $$VERSION$$ v1.30-dev-33-gd8453aa ################################################################## # emmbeded system may claim bash but it is not @@ -466,7 +466,6 @@ if detect_curl ; then [ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl" # $1 URL, $2 hack: log getJson if not "" getJson(){ - [[ -n "${BASHBOTDEBUG}" && -n "$2" ]] && log_debug "getJson (curl) URL=${1##*/}" # shellcheck disable=SC2086 "${BASHBOT_CURL}" -sL -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" "$1" } @@ -498,7 +497,6 @@ else # NO curl, try wget if _exists wget; then getJson(){ - [[ -n "${BASHBOTDEBUG}" && -z "$2" ]] && log_debug "getJson (wget) URL=${1##*/}" # shellcheck disable=SC2086 wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - "$1" } @@ -1009,7 +1007,6 @@ process_message() { ######################### # main get updates loop, should never terminate declare -A BASHBOTBLOCKED -export BASHBOT_UPDATELOG="${BASHBOT_UPDATELOG-nolog}" # allow to be "" start_bot() { local DEBUGMSG OFFSET=0 # adaptive sleep defaults @@ -1022,7 +1019,7 @@ start_bot() { # redirect to Debug.log [[ "$1" == *"debug" ]] && exec &>>"${DEBUGLOG}" log_debug "${DEBUGMSG}"; DEBUGMSG="$1" - [[ "${DEBUGMSG}" == "xdebug"* ]] && set -x && unset BASHBOT_UPDATELOG + [[ "${DEBUGMSG}" == "xdebug"* ]] && set -x # cleaup old pipes and empty logfiles find "${DATADIR}" -type p -delete find "${DATADIR}" -size 0 -name "*.log" -delete @@ -1057,7 +1054,7 @@ start_bot() { # adaptive sleep in ms rounded to next 0.1 s sleep "$(_round_float "${nextsleep}e-3" "1")" # get next update - UPDATE="$(getJson "${URL}/getUpdates?offset=${OFFSET}" "${BASHBOT_UPDATELOG}" 2>/dev/null | "${JSONSHFILE}" -b -n 2>/dev/null | iconv -f utf-8 -t utf-8 -c)" + UPDATE="$(getJson "${URL}/getUpdates?offset=${OFFSET}" 2>/dev/null | "${JSONSHFILE}" -b -n 2>/dev/null | iconv -f utf-8 -t utf-8 -c)" # did we get an response? if [ -n "${UPDATE}" ]; then # we got something, do processing From 5f21fcb0dcca59c525f0f186945971a0fd16a7bf Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 17 Jan 2021 09:57:08 +0100 Subject: [PATCH 98/98] Bashbot Version 1.30 --- README.html | 2 +- README.md | 2 +- README.txt | 2 +- addons/antiFlood.sh | 2 +- addons/example.sh | 2 +- bashbot.rc | 2 +- bashbot.sh | 2 +- bin/bashbot_env.inc.sh | 2 +- bin/bashbot_stats.sh | 2 +- bin/delete_message.sh | 2 +- bin/send_broadcast.sh | 2 +- bin/send_edit_message.sh | 2 +- bin/send_file.sh | 2 +- bin/send_message.sh | 2 +- commands.sh | 2 +- dev/all-tests.sh | 2 +- dev/dev.inc.sh | 2 +- dev/git-add.sh | 2 +- dev/hooks/post-commit.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/inject-json.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-distribution.sh | 2 +- dev/make-html.sh | 2 +- dev/make-standalone.sh | 2 +- dev/obfuscate.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- examples/README.md | 2 +- examples/background-scripts/run_diskusage.sh | 2 +- examples/background-scripts/run_filecontent.sh | 2 +- examples/background-scripts/run_filename.sh | 2 +- examples/background-scripts/run_notify.sh | 2 +- examples/bash2env.sh | 2 +- examples/bashbot-multi.sh | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/jsonDB-keyboard/mycommands.sh | 2 +- examples/notify.sh | 2 +- examples/question.sh | 2 +- examples/send-system-status/botacl | 2 +- examples/send-system-status/mycommands.sh | 2 +- modules/aliases.sh | 2 +- modules/answerInline.sh | 2 +- modules/background.sh | 2 +- modules/chatMember.sh | 2 +- modules/jsonDB.sh | 2 +- modules/sendMessage.sh | 2 +- mycommands.conf | 2 +- mycommands.sh | 2 +- mycommands.sh.clean | 2 +- scripts/interactive.sh.clean | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/a-commit-test.sh | 2 +- test/b-example-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_inline-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- test/e-env-test.sh | 2 +- 72 files changed, 72 insertions(+), 72 deletions(-) diff --git a/README.html b/README.html index bc896ba..dc43b96 100644 --- a/README.html +++ b/README.html @@ -390,6 +390,6 @@ It features background tasks and interactive chats, and can serve as an interfac

@Gnadelwartz

That's it all guys!

If you feel that there's something missing or if you found a bug, feel free to submit a pull request!

-

$$VERSION$$ v1.25-dev-39-gbd2d2e1

+

$$VERSION$$ v1.30-0-g3266427

diff --git a/README.md b/README.md index d52e813..87c5d05 100644 --- a/README.md +++ b/README.md @@ -238,4 +238,4 @@ See `mycommnds.sh.dist` for an example. If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.25-dev-39-gbd2d2e1 +#### $$VERSION$$ v1.30-0-g3266427 diff --git a/README.txt b/README.txt index 2ca2f52..c558942 100644 --- a/README.txt +++ b/README.txt @@ -309,5 +309,5 @@ That's it all guys! If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -$$VERSION$$ v1.25-dev-39-gbd2d2e1 +$$VERSION$$ v1.30-0-g3266427 diff --git a/addons/antiFlood.sh b/addons/antiFlood.sh index 3a4b5fd..b4012a3 100644 --- a/addons/antiFlood.sh +++ b/addons/antiFlood.sh @@ -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-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 # used events: # diff --git a/addons/example.sh b/addons/example.sh index 362392b..87a8caf 100644 --- a/addons/example.sh +++ b/addons/example.sh @@ -4,7 +4,7 @@ # Addons can register to bashbot events at startup # by providing their name and a callback per event # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 # # If an event occurs each registered event function is called. # diff --git a/bashbot.rc b/bashbot.rc index c293a15..9e51c8c 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.30-dev-28-gd269f98 +#### $$VERSION$$ v1.30-0-g3266427 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 5c4305e..a3a9958 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.30-dev-33-gd8453aa +#### $$VERSION$$ v1.30-0-g3266427 ################################################################## # emmbeded system may claim bash but it is not diff --git a/bin/bashbot_env.inc.sh b/bin/bashbot_env.inc.sh index 79961a5..b837412 100644 --- a/bin/bashbot_env.inc.sh +++ b/bin/bashbot_env.inc.sh @@ -13,7 +13,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 18.12.2020 12:27 # -#### $$VERSION$$ v1.25-dev-49-g41ce9cc +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== ############ diff --git a/bin/bashbot_stats.sh b/bin/bashbot_stats.sh index 8c5db20..53a6b25 100755 --- a/bin/bashbot_stats.sh +++ b/bin/bashbot_stats.sh @@ -16,7 +16,7 @@ USAGE='bashbot_stats.sh [-h|--help] [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 20:34 # -#### $$VERSION$$ v1.25-dev-49-g41ce9cc +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== #### diff --git a/bin/delete_message.sh b/bin/delete_message.sh index 41bc097..6d42a40 100755 --- a/bin/delete_message.sh +++ b/bin/delete_message.sh @@ -19,7 +19,7 @@ USAGE='delete_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 03.01.2021 15:37 # -#### $$VERSION$$ v1.25-dev-49-g41ce9cc +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== #### diff --git a/bin/send_broadcast.sh b/bin/send_broadcast.sh index 05ba7e6..9ccc90c 100755 --- a/bin/send_broadcast.sh +++ b/bin/send_broadcast.sh @@ -27,7 +27,7 @@ USAGE='broadcast_message.sh [-h|--help] [--doit] [--groups|--both|--db=file] [fo # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 16:14 # -#### $$VERSION$$ v1.25-dev-52-gb9c3235 +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== #### diff --git a/bin/send_edit_message.sh b/bin/send_edit_message.sh index 2730588..ad8bb38 100755 --- a/bin/send_edit_message.sh +++ b/bin/send_edit_message.sh @@ -22,7 +22,7 @@ USAGE='send_edit_message.sh [-h|--help] [format|caption] "CHAT[ID]" "MESSAGE[ID] # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 16:52 # -#### $$VERSION$$ v1.30-dev-17-geab8408 +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== #### diff --git a/bin/send_file.sh b/bin/send_file.sh index 37dd064..5a42b2c 100755 --- a/bin/send_file.sh +++ b/bin/send_file.sh @@ -24,7 +24,7 @@ USAGE='send_file.sh [-h|--help] "CHAT[ID]" "file|URL" "caption ...." [type] [deb # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 25.12.2020 20:24 # -#### $$VERSION$$ v1.25-dev-49-g41ce9cc +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== #### diff --git a/bin/send_message.sh b/bin/send_message.sh index 4da7646..21faf2c 100755 --- a/bin/send_message.sh +++ b/bin/send_message.sh @@ -21,7 +21,7 @@ USAGE='send_message.sh [-h|--help] [format] "CHAT[ID]" "message ...." [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 16.12.2020 11:34 # -#### $$VERSION$$ v1.25-dev-49-g41ce9cc +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== #### diff --git a/commands.sh b/commands.sh index d817662..f3f95a4 100644 --- a/commands.sh +++ b/commands.sh @@ -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-41-g37e4539 +#### $$VERSION$$ v1.30-0-g3266427 # # bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 3bf1c0f..d0a2051 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -5,7 +5,7 @@ # # Description: run all tests, exit after failed test # -#### $$VERSION$$ v1.30-dev-19-g0794506 +#### $$VERSION$$ v1.30-0-g3266427 ############################################################# #shellcheck disable=SC1090 diff --git a/dev/dev.inc.sh b/dev/dev.inc.sh index 04f5263..fa0fd75 100644 --- a/dev/dev.inc.sh +++ b/dev/dev.inc.sh @@ -5,7 +5,7 @@ # # Description: common stuff for all dev scripts # -#### $$VERSION$$ v1.30-dev-20-g541a279 +#### $$VERSION$$ v1.30-0-g3266427 ############################################################# # magic to ensure that we're always inside the root of our application, diff --git a/dev/git-add.sh b/dev/git-add.sh index b8709fb..39c94eb 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v1.30-dev-20-g541a279 +#### $$VERSION$$ v1.30-0-g3266427 #shellcheck disable=SC1090 source "${0%/*}/dev.inc.sh" diff --git a/dev/hooks/post-commit.sh b/dev/hooks/post-commit.sh index 934b57b..e988e64 100755 --- a/dev/hooks/post-commit.sh +++ b/dev/hooks/post-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 3db551e..8b44725 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index a34d01c..710c411 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/inject-json.sh b/dev/inject-json.sh index 8ad32d4..0936571 100644 --- a/dev/inject-json.sh +++ b/dev/inject-json.sh @@ -7,7 +7,7 @@ # # Usage: source inject-json.sh # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 ############################################################## # download JSON.sh diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 99697ff..e4e41b4 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -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.30-dev-20-g541a279 +#### $$VERSION$$ v1.30-0-g3266427 #shellcheck disable=SC1090 source "${0%/*}/dev.inc.sh" diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index 0ab7118..226cd28 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -7,7 +7,7 @@ # # Options: --notest - skip tests # -#### $$VERSION$$ v1.30-dev-20-g541a279 +#### $$VERSION$$ v1.30-0-g3266427 ############################################################## #shellcheck disable=SC1090 diff --git a/dev/make-html.sh b/dev/make-html.sh index 2b7fef5..f3cc5f8 100644 --- a/dev/make-html.sh +++ b/dev/make-html.sh @@ -7,7 +7,7 @@ # # Usage: source make-hmtl # -#### $$VERSION$$ v1.30-dev-21-g550a0de +#### $$VERSION$$ v1.30-0-g3266427 ############################################################## # check for correct dir diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index 49ffb52..a9f9e69 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -11,7 +11,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.30-dev-23-g0f27e71 +#### $$VERSION$$ v1.30-0-g3266427 ################################################################### #shellcheck disable=SC1090 diff --git a/dev/obfuscate.sh b/dev/obfuscate.sh index 3d64dd6..b921e13 100755 --- a/dev/obfuscate.sh +++ b/dev/obfuscate.sh @@ -2,7 +2,7 @@ # # joke hack to obfuscate bashbot.min.sh # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 # shellcheck disable=SC2028,SC2016,SC1117 infile="bashbot.sh" diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 0f99ebf..f43ba31 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,4 +1,4 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.30-0-g3266427 bashbot.rc mycommands.sh.clean diff --git a/dev/version.sh b/dev/version.sh index 41e3143..5090119 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v1.30-dev-20-g541a279 +#### $$VERSION$$ v1.30-0-g3266427 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index 5972732..199e604 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -132,5 +132,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-42-gde24ded +#### $$VERSION$$ v1.30-0-g3266427 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 4a67e48..173c936 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -65,5 +65,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.30-0-g3266427 diff --git a/doc/2_usage.md b/doc/2_usage.md index 7d78516..6ec08bf 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -351,5 +351,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.30-dev-27-g6857a55 +#### $$VERSION$$ v1.30-0-g3266427 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 6189159..8ba9cf4 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -302,5 +302,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v1.30-dev-9-g5f602a9 +#### $$VERSION$$ v1.30-0-g3266427 diff --git a/doc/4_expert.md b/doc/4_expert.md index b5a6f8c..f15d390 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -434,5 +434,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Advanced Use](3_advanced.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v1.25-dev-23-g8be95a3 +#### $$VERSION$$ v1.30-0-g3266427 diff --git a/doc/5_practice.md b/doc/5_practice.md index dd39426..85e9f1c 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -160,5 +160,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.30-0-g3266427 diff --git a/doc/6_reference.md b/doc/6_reference.md index 84a6933..463e13d 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -1269,5 +1269,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.30-dev-10-ge13b9eb +#### $$VERSION$$ v1.30-0-g3266427 diff --git a/doc/7_develop.md b/doc/7_develop.md index e5a14aa..ec96dc5 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -386,5 +386,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.25-dev-36-g58e789a +#### $$VERSION$$ v1.30-0-g3266427 diff --git a/examples/README.md b/examples/README.md index 5ac3794..1e89153 100644 --- a/examples/README.md +++ b/examples/README.md @@ -56,6 +56,6 @@ convert existing bots. **jsonDB-keybords** contains a stripped down real world example from my bot showing the usage of jsonDB to store and retrieve values plus use of keyboards in private chats. It's an extended version of mycommands.sh.dist. Messages and help are in german. -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.30-0-g3266427 diff --git a/examples/background-scripts/run_diskusage.sh b/examples/background-scripts/run_diskusage.sh index e0d3660..f5a5fbc 100755 --- a/examples/background-scripts/run_diskusage.sh +++ b/examples/background-scripts/run_diskusage.sh @@ -4,7 +4,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-7-g9ef8778 +#### $$VERSION$$ v1.30-0-g3266427 ###### # parameters diff --git a/examples/background-scripts/run_filecontent.sh b/examples/background-scripts/run_filecontent.sh index 8194ff9..67e35cb 100755 --- a/examples/background-scripts/run_filecontent.sh +++ b/examples/background-scripts/run_filecontent.sh @@ -2,7 +2,7 @@ # file: run_filename # background job to display content of all new files in WATCHDIR # -#### $$VERSION$$ v1.25-dev-7-g9ef8778 +#### $$VERSION$$ v1.30-0-g3266427 ###### # parameters diff --git a/examples/background-scripts/run_filename.sh b/examples/background-scripts/run_filename.sh index fb1a85e..0ade91d 100755 --- a/examples/background-scripts/run_filename.sh +++ b/examples/background-scripts/run_filename.sh @@ -2,7 +2,7 @@ # file: run_filename # background job to display all new files in WATCHDIR # -#### $$VERSION$$ v1.25-dev-7-g9ef8778 +#### $$VERSION$$ v1.30-0-g3266427 ###### # parameters diff --git a/examples/background-scripts/run_notify.sh b/examples/background-scripts/run_notify.sh index 3140de8..b27cb64 100755 --- a/examples/background-scripts/run_notify.sh +++ b/examples/background-scripts/run_notify.sh @@ -4,7 +4,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-7-g9ef8778 +#### $$VERSION$$ v1.30-0-g3266427 ###### # parameters diff --git a/examples/bash2env.sh b/examples/bash2env.sh index 98ff048..b7972ae 100755 --- a/examples/bash2env.sh +++ b/examples/bash2env.sh @@ -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.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/bashbot-multi.sh b/examples/bashbot-multi.sh index 3d1d9e8..c6fa3aa 100755 --- a/examples/bashbot-multi.sh +++ b/examples/bashbot-multi.sh @@ -2,7 +2,7 @@ # file. multibot.sh # description: run multiple telegram bots from one installation # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 if [ "$2" = "" ] || [ "$2" = "-h" ]; then echo "Usage: $0 botname command" diff --git a/examples/bashbot.cron b/examples/bashbot.cron index cdf5629..0a12049 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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.30-0-g3266427 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index d8316f5..7a1ce99 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -11,7 +11,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 ######################################################################## ###### diff --git a/examples/jsonDB-keyboard/mycommands.sh b/examples/jsonDB-keyboard/mycommands.sh index 7505c42..e1739ab 100644 --- a/examples/jsonDB-keyboard/mycommands.sh +++ b/examples/jsonDB-keyboard/mycommands.sh @@ -10,7 +10,7 @@ # AUTHOR: KayM (), kay@rrr.de # DATE: 19.12.2020 19:03 # -#### $$VERSION$$ v1.25-dev-7-g9ef8778 +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/examples/notify.sh b/examples/notify.sh index 8b57e76..b709668 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -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-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 ######################################################################## ###### diff --git a/examples/question.sh b/examples/question.sh index 614ac79..8b116a3 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -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-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 ######################################################################## ###### diff --git a/examples/send-system-status/botacl b/examples/send-system-status/botacl index 0d4c3a1..8fcce22 100644 --- a/examples/send-system-status/botacl +++ b/examples/send-system-status/botacl @@ -1,7 +1,7 @@ # file: botacl # a user not listed here, will return false from 'user_is_allowed' # -#### $$VERSION$$ v1.21-0-gc85af77 +#### $$VERSION$$ v1.30-0-g3266427 # Format: # user:resource:chat diff --git a/examples/send-system-status/mycommands.sh b/examples/send-system-status/mycommands.sh index 148437f..661497b 100644 --- a/examples/send-system-status/mycommands.sh +++ b/examples/send-system-status/mycommands.sh @@ -5,7 +5,7 @@ # to show how you can customize bashbot by only editing mycommands.sh # NOTE: this is not tested, simply copied from original source and reworked! # -#### $$VERSION$$ v1.25-dev-7-g9ef8778 +#### $$VERSION$$ v1.30-0-g3266427 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/modules/aliases.sh b/modules/aliases.sh index 214ffd6..0e551a7 100644 --- a/modules/aliases.sh +++ b/modules/aliases.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 # # will be automatically sourced from bashbot diff --git a/modules/answerInline.sh b/modules/answerInline.sh index 97d4563..76ffb64 100644 --- a/modules/answerInline.sh +++ b/modules/answerInline.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.30-dev-2-gcc299a5 +#### $$VERSION$$ v1.30-0-g3266427 # will be automatically sourced from bashbot diff --git a/modules/background.sh b/modules/background.sh index 69a7203..4409616 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117,SC2059 -#### $$VERSION$$ v1.25-dev-38-g1eafc91 +#### $$VERSION$$ v1.30-0-g3266427 # will be automatically sourced from bashbot diff --git a/modules/chatMember.sh b/modules/chatMember.sh index d53b679..2f9a316 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.30-dev-31-g161e883 +#### $$VERSION$$ v1.30-0-g3266427 # will be automatically sourced from bashbot diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index cc19d29..9c49c3c 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.30-dev-31-g161e883 +#### $$VERSION$$ v1.30-0-g3266427 # # source from commands.sh to use jsonDB functions # diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 30cf8a0..07f5613 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.30-dev-30-g6bfab17 +#### $$VERSION$$ v1.30-0-g3266427 # will be automatically sourced from bashbot diff --git a/mycommands.conf b/mycommands.conf index 4cf3c61..e06fe09 100644 --- a/mycommands.conf +++ b/mycommands.conf @@ -11,7 +11,7 @@ # Author: KayM (gnadelwartz), kay@rrr.de # Created: 09.01.2021 07:27 # -#### $$VERSION$$ v1.25-dev-44-g168584d +#### $$VERSION$$ v1.30-0-g3266427 ####################################################### ########## diff --git a/mycommands.sh b/mycommands.sh index b1bf008..bc27071 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -13,7 +13,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.30-dev-9-g5f602a9 +#### $$VERSION$$ v1.30-0-g3266427 ####################################################### # shellcheck disable=SC1117 diff --git a/mycommands.sh.clean b/mycommands.sh.clean index 0be2849..9ae73e2 100644 --- a/mycommands.sh.clean +++ b/mycommands.sh.clean @@ -10,7 +10,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-41-g37e4539 +#### $$VERSION$$ v1.30-0-g3266427 ####################################################### # shellcheck disable=SC1117 diff --git a/scripts/interactive.sh.clean b/scripts/interactive.sh.clean index b9c6079..bbb7434 100755 --- a/scripts/interactive.sh.clean +++ b/scripts/interactive.sh.clean @@ -12,7 +12,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.30-dev-27-g6857a55 +#### $$VERSION$$ v1.30-0-g3266427 ######################################################################## ###### diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 7300d1f..59b933b 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -10,7 +10,7 @@ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== # magic to ensure that we're always inside the root of our application, diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 02621a7..3f519fe 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -11,7 +11,7 @@ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== # common variables diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index d5b2887..dfb9ac9 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -10,7 +10,7 @@ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== ../dev/hooks/pre-commit.sh diff --git a/test/b-example-test.sh b/test/b-example-test.sh index c694c15..f60d0a6 100644 --- a/test/b-example-test.sh +++ b/test/b-example-test.sh @@ -10,7 +10,7 @@ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== # include common functions and definitions diff --git a/test/c-init-test.sh b/test/c-init-test.sh index a766074..aca8c1b 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -10,7 +10,7 @@ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== # include common functions and definitions diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 21adca1..bb996b7 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh index 6019a5d..c71808e 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -10,7 +10,7 @@ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== # include common functions and definitions diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 9faa0a3..502d4ad 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -10,7 +10,7 @@ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== # include common functions and definitions diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index 085054b..aadf8c9 100755 --- a/test/d-send_message-test.sh +++ b/test/d-send_message-test.sh @@ -10,7 +10,7 @@ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== # include common functions and definitions diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 65be377..9d2802e 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -10,7 +10,7 @@ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== # include common functions and definitions diff --git a/test/e-env-test.sh b/test/e-env-test.sh index 0a14607..f9e80dc 100755 --- a/test/e-env-test.sh +++ b/test/e-env-test.sh @@ -10,7 +10,7 @@ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-14-g2fe6d4b +#### $$VERSION$$ v1.30-0-g3266427 #=============================================================================== # include common functions and definitions