From 58fb001d1e4f3b68a1fe796b799059e12a365897 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 5 Feb 2021 14:25:21 +0100 Subject: [PATCH 01/43] clean escaped json before logging --- README.html | 2 +- README.txt | 2 +- bashbot.sh | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.html b/README.html index a51e2cb..7afb288 100644 --- a/README.html +++ b/README.html @@ -392,6 +392,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.40-dev-34-g1440d56

+

$$VERSION$$ v1.40-0-gf9dab50

diff --git a/README.txt b/README.txt index 9d6fbcb..c9150f8 100644 --- a/README.txt +++ b/README.txt @@ -318,5 +318,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.40-dev-34-g1440d56 +$$VERSION$$ v1.40-0-gf9dab50 diff --git a/bashbot.sh b/bashbot.sh index 404fad6..588619b 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.40-0-gf9dab50 +#### $$VERSION$$ v1.41-dev-0-gd15b4f5 ################################################################## # are we running in a terminal? @@ -99,12 +99,16 @@ getConfigKey() { [[ "$1" =~ ^[-${azAZo9},._]+$ ]] || return 3 [ -r "${BOTCONFIG}.jssh" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' "${BOTCONFIG}.jssh" | tail -n 1 } -# escape / remove text characters for json strings, eg. " -> \" -# $1 string -# output escaped string +# escape characters in json strings for telegram +# $1 string, output escaped string JsonEscape(){ sed 's/\([-"`´,§$%&/(){}#@!?*.\t]\)/\\\1/g' <<< "$1" } +# clean \ from escaped json string +# $1 string, output cleaned string +cleanEscaped(){ # remove " all \ but \n \n or \r + sed -E -e 's/\\"/+/g' -e 's/\\([^n])/\1/g' -e 's/(\r|\n)//g' <<<"$1" +} # check if $1 seems a valid token # return true if token seems to be valid check_token(){ @@ -461,7 +465,7 @@ sendJson(){ if [ -n "${BASHBOTDEBUG}" ] ; then log_update "sendJson (${DETECTED_CURL}) CHAT=${chat#*:} JSON=${2:0:100} URL=${3##*/}" # mask " and \ , remove newline from json - log_message "DEBUG sendJson ==========\n$("${JSONSHFILE}" -b -n <<<"$(sed -E -e 's/\\"/+/g' -e 's/\\/\\\\/g' -e 's/(\r|\n)//g' <<<"${json}")" 2>&1)" + log_message "DEBUG sendJson ==========\n$("${JSONSHFILE}" -b -n <<<"$(cleanEscaped "${json}")" 2>&1)" fi # chat id not a number if [[ "${chat}" == *"NAN\"," ]]; then From 5a689d22de1b4de1e77a25f3d9adc63af5468105 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 5 Feb 2021 14:46:11 +0100 Subject: [PATCH 02/43] JsonEscape: handle \r \n also --- bashbot.sh | 4 ++-- modules/sendMessage.sh | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 588619b..48b7ca4 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.41-dev-0-gd15b4f5 +#### $$VERSION$$ v1.41-dev-1-g58fb001 ################################################################## # are we running in a terminal? @@ -102,7 +102,7 @@ getConfigKey() { # escape characters in json strings for telegram # $1 string, output escaped string JsonEscape(){ - sed 's/\([-"`´,§$%&/(){}#@!?*.\t]\)/\\\1/g' <<< "$1" + sed -E -e 's/\r//g' -e 's/([-"`´,§$%&/(){}#@!?*.\t])/\\\1/g' <<< "${1//$'\n'/\\n}" } # clean \ from escaped json string # $1 string, output cleaned string diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 4185948..2d23e8c 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.40-0-gf9dab50 +#### $$VERSION$$ v1.41-dev-1-g58fb001 # will be automatically sourced from bashbot @@ -25,7 +25,6 @@ EDIT_URL=${URL}'/editMessageText' # $1 CHAT $2 message send_normal_message() { 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}" @@ -85,7 +84,6 @@ edit_message_caption() { # $1 CHAT $2 message $3 action $4 URL _format_message_url(){ 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" @@ -97,7 +95,6 @@ _format_message_url(){ # $1 CHAT $2 message $3 action $4 URL _markdownv2_message_url() { 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}")" From bc40a3fcbb418dc333dea4af1c840e48efb943ae Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 6 Feb 2021 11:04:39 +0100 Subject: [PATCH 03/43] change internal get_file / download_file API --- bashbot.sh | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 48b7ca4..d50a46f 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.41-dev-1-g58fb001 +#### $$VERSION$$ v1.41-dev-2-g5a689d2 ################################################################## # are we running in a terminal? @@ -392,16 +392,6 @@ if ! _is_function jssh_newDB; then exit_source 6 fi -# $1 URL, $2 filename in DATADIR -# outputs final filename -download() { - local empty="no.file" file="${2:-${empty}}" - 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}" -} - # $1 postfix, e.g. chatid # $2 prefix, back- or startbot- procname(){ @@ -437,12 +427,35 @@ delete_message() { sendJson "$1" '"message_id": '"$2"'' "${DELETE_URL}" } -# get download url for file id, $1 file_id +# URL path for file id, $1 file_id +# use download_file "path" to download file get_file() { [ -z "$1" ] && return sendJson "" '"file_id": "'"$1"'"' "${URL}/getFile" - printf "%s\n" "${URL}/${UPD["result,file_path"]}" + printf "%s\n" "${UPD["result,file_path"]}" } +# download file to DATADIR +# $1 URL path, $2 proposed filename (may modified/ignored) +# outputs final filename +# keep old function name for backward compatibility +alias download="download_file" +download_file() { + local url="$1" file="${2:-$1}" + # old mode if full URL is given + if [[ "${1}" =~ ^https*:// ]]; then + # download full URL with random filename + file="${RANDOM}" + else + # prefix https://api.telegram... + url="${URL}/${url}" + fi + # filename: replace "/" with "-", prefix random number if file exist + file="${file//\//-}" + while [ -f "${DATADIR:-.}/${file}" ] ; do file="${RANDOM}-${file}"; done + getJson "${url}" >"${DATADIR:-.}/${file}" || return + printf '%s\n' "${DATADIR:-.}/${file}" +} + # iconv used to filter out broken utf characters, if not installed fake it if ! _exists iconv; then From baa4e14ebc570fae76f773a783ad3bc874b15f6b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 6 Feb 2021 12:08:24 +0100 Subject: [PATCH 04/43] doc: adjust user visible changes to URLS and download_file --- doc/2_usage.md | 18 ++++++++++-------- doc/6_reference.md | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/doc/2_usage.md b/doc/2_usage.md index 4910931..149ae5b 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -186,13 +186,14 @@ The following variables are set if the message contains optional parts: * `${FORWARD[LAST_NAME]}`: Original user's' last name * `${FORWARD[USERNAME]}`: Original user's username * `$CAPTION`: Picture, Audio, Video, File Captions -* `$URLS`: This array contains documents, audio files, voice recordings and stickers as URL. - * `${URLS[AUDIO]}`: Audio files - * `${URLS[VIDEO]}`: Videos - * `${URLS[PHOTO]}`: Photos (maximum quality) - * `${URLS[VOICE]}`: Voice recordings - * `${URLS[STICKER]}`: Stickers - * `${URLS[DOCUMENT]}`: Any other file +* `$URLS`: This array contains `path` to document, audio file, voice recording and sticker for download from telegram server. + * `${URLS[AUDIO]}`: Path to audio file + * `${URLS[VIDEO]}`: Path to video + * `${URLS[PHOTO]}`: Path to photo (maximum quality) + * `${URLS[VOICE]}`: Path to voice recording + * `${URLS[STICKER]}`: Path to sticker + * `${URLS[DOCUMENT]}`: Path to any other file +**Important:** This is NO MORE a full URL, you must use `download_file` or `${URL}/${URLS[xxx]}` for manual download. * `$CONTACT`: This array contains info about contacts sent in a chat. * `${CONTACT[ID]}`: User id * `${CONTACT[NUMBER]}`: Phone number @@ -238,6 +239,7 @@ e.g. if a new user joins a chat MESSAGE is set to "/_new_chat_user". * `${MESSAGE}`: /_new_chat_title SENDER TEXT * `${SERVICE[NEWPHOTO]}`: New Chat Picture * `${MESSAGE}`: /_new_chat_picture SENDER URL +**Important:** SERVICE[NEWPHOTO] is NOT a full URL, you must use `download_file` or `${URL}/${SERVICE[NEWPHOTO]}` for manual download. * `${SERVICE[PINNED]}`: Pinned MESSAGE ID * `${MESSAGE}`: /_new_pinned_message SENDER ID * `${PINNED[ID]}`: Id of pinned message @@ -372,5 +374,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.41-dev-3-gbc40a3f diff --git a/doc/6_reference.md b/doc/6_reference.md index 30be34a..5d0e7ac 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -1398,18 +1398,40 @@ Do not use them in other files e.g. `bashbot.sh`, modules, addons etc. ### Helper functions -##### download -Download the given URL and returns the final filename in TMPDIR. If the given filename exists,the filename is prefixed with a -random number. Filename is not allowed to contain '/' or '..'. +##### download_file +`download_file` download a file to DATADIR and returns the PATH to the file, main use is to download files send to chats. +I tried to be as compatible as possible with old function `download`. -*usage:* download URL filename +*usage:* download_file path_to_ile prosed_filename + +*alias*: download + +*Note:* You must use `download_file` to download `URLS[...]` or `SERVICE[NEWPHOTO]` URLs from Telegram server. *example:* ```bash +######## +# download from Telegram server +# photo received in a chat +photo="${URLS[PHOTO]}")" +echo "$photo" -> photo/file_1234.jpg + +# first download +file="$(download_file "${photo}" +echo "$file" -> ./data-bot-bash/photo-file_1234.jpg + +# second, third etc. download +file="$(download_file "${photo}" +echo "$file" -> ./data-bot-bash/jkdfhihsdkf-photo-file_1234.jpg + + +######## +# download from other sources (full URL) file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg")" echo "$file" -> ./data-bot-bash/avatar.jpg + file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg")" -echo "$file" -> ./data-bot-bash/12345-avatar.jpg +echo "$file" -> ./data-bot-bash/jhsdfjkakshdfkja-avatar.jpg ``` ##### _exec_if_function @@ -1455,6 +1477,9 @@ _is_function "background" && _message "you can run background jobs!" ### Bashbot internal functions These functions are for internal use only and must not used in your bot commands. +##### get_file +*usage:* url="$(get_file "CHAT[ID]" "message")" + ##### procname Returns PrefixBotname_Postfix @@ -1506,11 +1531,6 @@ killallproc ---- -##### get_file -*usage:* url="$(get_file "CHAT[ID]" "message")" - ----- - ##### JsonDecode Outputs decoded string to STDOUT @@ -1578,5 +1598,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.40-0-gf9dab50 +#### $$VERSION$$ v1.41-dev-3-gbc40a3f From 54673ac3960dfc3897e9931e2cc050d7a9959e42 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 6 Feb 2021 14:05:50 +0100 Subject: [PATCH 05/43] doc: more/better download_file examples --- doc/2_usage.md | 10 ++++++---- doc/6_reference.md | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/doc/2_usage.md b/doc/2_usage.md index 149ae5b..2d15742 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -186,14 +186,15 @@ The following variables are set if the message contains optional parts: * `${FORWARD[LAST_NAME]}`: Original user's' last name * `${FORWARD[USERNAME]}`: Original user's username * `$CAPTION`: Picture, Audio, Video, File Captions -* `$URLS`: This array contains `path` to document, audio file, voice recording and sticker for download from telegram server. +* `$URLS`: This array contains the `path` on Telegram server for files send to chat, e.g. photo, video, audio file. * `${URLS[AUDIO]}`: Path to audio file * `${URLS[VIDEO]}`: Path to video * `${URLS[PHOTO]}`: Path to photo (maximum quality) * `${URLS[VOICE]}`: Path to voice recording * `${URLS[STICKER]}`: Path to sticker * `${URLS[DOCUMENT]}`: Path to any other file -**Important:** This is NO MORE a full URL, you must use `download_file` or `${URL}/${URLS[xxx]}` for manual download. +**Important:** This is NOT a full URL, you must use `download_file "${URLS[xxx]}"` or prefix path with telegram api url for manual download +(_e.g. `getJson "${URL}/${URLS[xxx]}" >file`_). * `$CONTACT`: This array contains info about contacts sent in a chat. * `${CONTACT[ID]}`: User id * `${CONTACT[NUMBER]}`: Phone number @@ -239,7 +240,8 @@ e.g. if a new user joins a chat MESSAGE is set to "/_new_chat_user". * `${MESSAGE}`: /_new_chat_title SENDER TEXT * `${SERVICE[NEWPHOTO]}`: New Chat Picture * `${MESSAGE}`: /_new_chat_picture SENDER URL -**Important:** SERVICE[NEWPHOTO] is NOT a full URL, you must use `download_file` or `${URL}/${SERVICE[NEWPHOTO]}` for manual download. +**Important:** SERVICE[NEWPHOTO] is NOT a full URL, you must use `download_file "${SERVICE[NEWPHOTO]}"` or prefix path with telegram api url for manual download +(_e.g. `getJson "${URL}/${SERVICE[NEWPHOTO]}" >file`_). * `${SERVICE[PINNED]}`: Pinned MESSAGE ID * `${MESSAGE}`: /_new_pinned_message SENDER ID * `${PINNED[ID]}`: Id of pinned message @@ -374,5 +376,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.41-dev-3-gbc40a3f +#### $$VERSION$$ v1.41-dev-4-gbaa4e14 diff --git a/doc/6_reference.md b/doc/6_reference.md index 5d0e7ac..b4a86ad 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -571,7 +571,6 @@ Returns the new invite link as String on success. ##### 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" @@ -1424,6 +1423,8 @@ echo "$file" -> ./data-bot-bash/photo-file_1234.jpg file="$(download_file "${photo}" echo "$file" -> ./data-bot-bash/jkdfhihsdkf-photo-file_1234.jpg +ls data-bot-bash/*.jpg +photo-file_1234.jpg jkdfhihsdkf-photo-file_1234.jpg ######## # download from other sources (full URL) @@ -1432,6 +1433,20 @@ echo "$file" -> ./data-bot-bash/avatar.jpg file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg")" echo "$file" -> ./data-bot-bash/jhsdfjkakshdfkja-avatar.jpg + +ls data-bot-bash/*.jpg +photo-file_1234.jpg jkdfhihsdkf-photo-file_1234.jpg +avatar.jpg jhsdfjkakshdfkja-avatar.jpg + +####### +# manually download files to current directory (not recommended) +getJson "https://avatars.githubusercontent.com/u/13046303" >"avatar.jpg" +getJson "i${URL}/${photo}" >"downloaded_photo.jpg" + +ls * +JSON.sh/ addons/ bin/ data-bot_bash/ doc/ modules/ scripts/ +avatar.jpg bashbot.sh commands.sh downloaded_photo.jpg LICENSE mycommands.conf mycommands.sh mycommands.sh + ``` ##### _exec_if_function @@ -1598,5 +1613,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.41-dev-3-gbc40a3f +#### $$VERSION$$ v1.41-dev-4-gbaa4e14 From 0702d58ab0237825de81d7982ae2747a15aa7a4a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 6 Feb 2021 15:30:31 +0100 Subject: [PATCH 06/43] download_file: use mktemp doc: do not download manually --- bashbot.sh | 19 +++++++++++-------- doc/6_reference.md | 26 +++++++++++++++----------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index d50a46f..5870750 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.41-dev-2-g5a689d2 +#### $$VERSION$$ v1.41-dev-5-g54673ac ################################################################## # are we running in a terminal? @@ -443,17 +443,20 @@ download_file() { local url="$1" file="${2:-$1}" # old mode if full URL is given if [[ "${1}" =~ ^https*:// ]]; then - # download full URL with random filename - file="${RANDOM}" + # random filename if not given for http + if [ -z "$2" ]; then + : "$(mktemp -u -p . "XXXXXXXXXX" 2>/dev/null)" + file="download-${_#./}" + fi else # prefix https://api.telegram... url="${URL}/${url}" fi - # filename: replace "/" with "-", prefix random number if file exist - file="${file//\//-}" - while [ -f "${DATADIR:-.}/${file}" ] ; do file="${RANDOM}-${file}"; done - getJson "${url}" >"${DATADIR:-.}/${file}" || return - printf '%s\n' "${DATADIR:-.}/${file}" + # filename: replace "/" with "-", use mktemp if exist + file="${DATADIR:-.}/${file//\//-}" + [ -f "${file}" ] && file="$(mktemp -p "${DATADIR:-.}" "XXXXX-${file##*/}" )" + getJson "${url}" >"${file}" || return + printf '%s\n' "${file}" } diff --git a/doc/6_reference.md b/doc/6_reference.md index b4a86ad..5d900b4 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -1419,33 +1419,37 @@ echo "$photo" -> photo/file_1234.jpg file="$(download_file "${photo}" echo "$file" -> ./data-bot-bash/photo-file_1234.jpg -# second, third etc. download +# second download file="$(download_file "${photo}" -echo "$file" -> ./data-bot-bash/jkdfhihsdkf-photo-file_1234.jpg +echo "$file" -> ./data-bot-bash/jkdfhi-photo-file_1234.jpg ls data-bot-bash/*.jpg -photo-file_1234.jpg jkdfhihsdkf-photo-file_1234.jpg +photo-file_1234.jpg jkdfhi-photo-file_1234.jpg + ######## # download from other sources (full URL) +file="$(download "https://avatars.githubusercontent.com/u/13046303")" +echo "$file" -> ./data-bot-bash/download-askjgftGJGdh1Z + file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg")" echo "$file" -> ./data-bot-bash/avatar.jpg file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg")" -echo "$file" -> ./data-bot-bash/jhsdfjkakshdfkja-avatar.jpg +echo "$file" -> ./data-bot-bash/jhsdf-avatar.jpg + +ls data-bot-bash/ +avatar.jpg jhsdf-avatar.jpg download-askjgftGJGdh1Z -ls data-bot-bash/*.jpg -photo-file_1234.jpg jkdfhihsdkf-photo-file_1234.jpg -avatar.jpg jhsdfjkakshdfkja-avatar.jpg ####### # manually download files to current directory (not recommended) getJson "https://avatars.githubusercontent.com/u/13046303" >"avatar.jpg" getJson "i${URL}/${photo}" >"downloaded_photo.jpg" -ls * -JSON.sh/ addons/ bin/ data-bot_bash/ doc/ modules/ scripts/ -avatar.jpg bashbot.sh commands.sh downloaded_photo.jpg LICENSE mycommands.conf mycommands.sh mycommands.sh +ls -F +JSON.sh/ bin/ modules/ data-bot-bash/ +avatar.jpg bashbot.sh* botconfig.jssh commands.sh count.jssh downloaded_photo.jpg mycommands.sh ... ``` @@ -1613,5 +1617,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.41-dev-4-gbaa4e14 +#### $$VERSION$$ v1.41-dev-5-g54673ac From 5212df422e6de99e2e9861a6c0697d1aa271f7f6 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 6 Feb 2021 16:05:18 +0100 Subject: [PATCH 07/43] fix never working file download --- bashbot.sh | 5 +++-- doc/6_reference.md | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 5870750..e28fd54 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.41-dev-5-g54673ac +#### $$VERSION$$ v1.41-dev-6-g0702d58 ################################################################## # are we running in a terminal? @@ -346,6 +346,7 @@ fi BASHBOT_RETRY="" # retry by default URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}" +FILEURL="${URL%%/bot*}/file/bot${BOTTOKEN}" ME_URL=${URL}'/getMe' ################# @@ -450,7 +451,7 @@ download_file() { fi else # prefix https://api.telegram... - url="${URL}/${url}" + url="${FILEURL}/${url}" fi # filename: replace "/" with "-", use mktemp if exist file="${DATADIR:-.}/${file//\//-}" diff --git a/doc/6_reference.md b/doc/6_reference.md index 5d900b4..5e80268 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -1444,8 +1444,8 @@ avatar.jpg jhsdf-avatar.jpg download-askjgftGJGdh1Z ####### # manually download files to current directory (not recommended) +getJson "${URL}/${photo}" >"downloaded_photo.jpg" getJson "https://avatars.githubusercontent.com/u/13046303" >"avatar.jpg" -getJson "i${URL}/${photo}" >"downloaded_photo.jpg" ls -F JSON.sh/ bin/ modules/ data-bot-bash/ @@ -1617,5 +1617,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.41-dev-5-g54673ac +#### $$VERSION$$ v1.41-dev-6-g0702d58 From b91e96dce1b049e21046ab385a1ba41ff0bbe0ea Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 6 Feb 2021 16:52:25 +0100 Subject: [PATCH 08/43] doc: use FILEURL --- doc/2_usage.md | 4 ++-- doc/6_reference.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/2_usage.md b/doc/2_usage.md index 2d15742..a0a5211 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -241,7 +241,7 @@ e.g. if a new user joins a chat MESSAGE is set to "/_new_chat_user". * `${SERVICE[NEWPHOTO]}`: New Chat Picture * `${MESSAGE}`: /_new_chat_picture SENDER URL **Important:** SERVICE[NEWPHOTO] is NOT a full URL, you must use `download_file "${SERVICE[NEWPHOTO]}"` or prefix path with telegram api url for manual download -(_e.g. `getJson "${URL}/${SERVICE[NEWPHOTO]}" >file`_). +(_e.g. `getJson "${FILEURL}/${SERVICE[NEWPHOTO]}" >file`_). * `${SERVICE[PINNED]}`: Pinned MESSAGE ID * `${MESSAGE}`: /_new_pinned_message SENDER ID * `${PINNED[ID]}`: Id of pinned message @@ -376,5 +376,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.41-dev-4-gbaa4e14 +#### $$VERSION$$ v1.41-dev-7-g5212df4 diff --git a/doc/6_reference.md b/doc/6_reference.md index 5e80268..c959d60 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -1444,7 +1444,7 @@ avatar.jpg jhsdf-avatar.jpg download-askjgftGJGdh1Z ####### # manually download files to current directory (not recommended) -getJson "${URL}/${photo}" >"downloaded_photo.jpg" +getJson "${FILEURL}/${photo}" >"downloaded_photo.jpg" getJson "https://avatars.githubusercontent.com/u/13046303" >"avatar.jpg" ls -F @@ -1617,5 +1617,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.41-dev-6-g0702d58 +#### $$VERSION$$ v1.41-dev-7-g5212df4 From 5294d00ae3e125fc7a72299bd9ac48150393c981 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 6 Feb 2021 17:19:07 +0100 Subject: [PATCH 09/43] doc: move get_file download_file to own section --- doc/6_reference.md | 150 ++++++++++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 70 deletions(-) diff --git a/doc/6_reference.md b/doc/6_reference.md index c959d60..107bc0f 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -534,6 +534,85 @@ edit_html_message "${CHAT[ID]}" "${saved-id}" "this is html text" *usage:* edit_message_caption "CHAT[ID]" "MESSAGE-ID" "caption" +---- + +### Get files from Telegram + +##### download_file +`download_file` download a file to DATADIR and returns the PATH to the file, main use is to download files send to chats. +I tried to be as compatible as possible with old function `download`. + +*usage:* download_file path_to_ile prosed_filename + +*alias*: download + +*Note:* You must use `download_file` to download `URLS[...]` or `SERVICE[NEWPHOTO]` URLs from Telegram server. + +*example:* +```bash +######## +# download from Telegram server +# photo received in a chat +photo="${URLS[PHOTO]}")" +echo "$photo" -> photo/file_1234.jpg + +# first download +file="$(download_file "${photo}" +echo "$file" -> ./data-bot-bash/photo-file_1234.jpg + +# second download +file="$(download_file "${photo}" +echo "$file" -> ./data-bot-bash/jkdfhi-photo-file_1234.jpg + +ls data-bot-bash/*.jpg +photo-file_1234.jpg jkdfhi-photo-file_1234.jpg + + +######## +# download from other sources (full URL) +file="$(download "https://avatars.githubusercontent.com/u/13046303")" +echo "$file" -> ./data-bot-bash/download-askjgftGJGdh1Z + +file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg")" +echo "$file" -> ./data-bot-bash/avatar.jpg + +file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg")" +echo "$file" -> ./data-bot-bash/jhsdf-avatar.jpg + +ls data-bot-bash/ +avatar.jpg jhsdf-avatar.jpg download-askjgftGJGdh1Z + + +####### +# manually download files to current directory (not recommended) +getJson "${FILEURL}/${photo}" >"downloaded_photo.jpg" +getJson "https://avatars.githubusercontent.com/u/13046303" >"avatar.jpg" + +ls -F +JSON.sh/ bin/ modules/ data-bot-bash/ +avatar.jpg bashbot.sh* botconfig.jssh commands.sh count.jssh downloaded_photo.jpg mycommands.sh ... + +``` + +##### get_file +`get_file` get the `path` to a file on Telegram server by it's `file_id`. File `path` is only valid for use with your bot token. + +*usage:* url="$(get_file "file_id")" + +*example*: + +```bash +# download file by file_id +file_id="kjhdsfhkj-kjshfbsdbfkjhsdkfjn" + +path="$(get_file "${file_id}")" +file="$(download_file "${path}")" + +# one line +file="$(download_file "$(get_file "${file_id}")")" + +``` + --- ### Manage Group @@ -1397,62 +1476,6 @@ Do not use them in other files e.g. `bashbot.sh`, modules, addons etc. ### Helper functions -##### download_file -`download_file` download a file to DATADIR and returns the PATH to the file, main use is to download files send to chats. -I tried to be as compatible as possible with old function `download`. - -*usage:* download_file path_to_ile prosed_filename - -*alias*: download - -*Note:* You must use `download_file` to download `URLS[...]` or `SERVICE[NEWPHOTO]` URLs from Telegram server. - -*example:* -```bash -######## -# download from Telegram server -# photo received in a chat -photo="${URLS[PHOTO]}")" -echo "$photo" -> photo/file_1234.jpg - -# first download -file="$(download_file "${photo}" -echo "$file" -> ./data-bot-bash/photo-file_1234.jpg - -# second download -file="$(download_file "${photo}" -echo "$file" -> ./data-bot-bash/jkdfhi-photo-file_1234.jpg - -ls data-bot-bash/*.jpg -photo-file_1234.jpg jkdfhi-photo-file_1234.jpg - - -######## -# download from other sources (full URL) -file="$(download "https://avatars.githubusercontent.com/u/13046303")" -echo "$file" -> ./data-bot-bash/download-askjgftGJGdh1Z - -file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg")" -echo "$file" -> ./data-bot-bash/avatar.jpg - -file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg")" -echo "$file" -> ./data-bot-bash/jhsdf-avatar.jpg - -ls data-bot-bash/ -avatar.jpg jhsdf-avatar.jpg download-askjgftGJGdh1Z - - -####### -# manually download files to current directory (not recommended) -getJson "${FILEURL}/${photo}" >"downloaded_photo.jpg" -getJson "https://avatars.githubusercontent.com/u/13046303" >"avatar.jpg" - -ls -F -JSON.sh/ bin/ modules/ data-bot-bash/ -avatar.jpg bashbot.sh* botconfig.jssh commands.sh count.jssh downloaded_photo.jpg mycommands.sh ... - -``` - ##### _exec_if_function Returns true, even if the given function does not exist. Return false if function exist but returns false. @@ -1496,9 +1519,6 @@ _is_function "background" && _message "you can run background jobs!" ### Bashbot internal functions These functions are for internal use only and must not used in your bot commands. -##### get_file -*usage:* url="$(get_file "CHAT[ID]" "message")" - ##### procname Returns PrefixBotname_Postfix @@ -1555,16 +1575,6 @@ Outputs decoded string to STDOUT *usage:* JsonDecode "string" -##### JsonGetString -Reads JSON from STDIN and Outputs found String to STDOUT - -*usage:* JsonGetString `"path","to","string"` - -##### JsonGetValue -Reads JSON from STDIN and Outputs found Value to STDOUT - -*usage:* JsonGetValue `"path","to","value"` - ##### Json2Array Read JSON.sh style data from STDIN and assign to given ARRAY @@ -1617,5 +1627,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.41-dev-7-g5212df4 +#### $$VERSION$$ v1.41-dev-8-gb91e96d From ccac62dd720335b71cb16ce7875d87cc390f21eb Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 6 Feb 2021 17:38:37 +0100 Subject: [PATCH 10/43] download_file: return normalised absolute path --- bashbot.sh | 5 +++-- doc/6_reference.md | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index e28fd54..cb11af8 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.41-dev-6-g0702d58 +#### $$VERSION$$ v1.41-dev-9-g5294d00 ################################################################## # are we running in a terminal? @@ -457,7 +457,8 @@ download_file() { file="${DATADIR:-.}/${file//\//-}" [ -f "${file}" ] && file="$(mktemp -p "${DATADIR:-.}" "XXXXX-${file##*/}" )" getJson "${url}" >"${file}" || return - printf '%s\n' "${file}" + # output absolute file path + printf "%s\n" "$(cd "${file%/*}" >/dev/null 2>&1 && pwd)/${file##*/}" } diff --git a/doc/6_reference.md b/doc/6_reference.md index 107bc0f..d4cf2da 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -539,7 +539,7 @@ edit_html_message "${CHAT[ID]}" "${saved-id}" "this is html text" ### Get files from Telegram ##### download_file -`download_file` download a file to DATADIR and returns the PATH to the file, main use is to download files send to chats. +`download_file` download a file to `DATADIR` and returns the local `path` to the file on disc, main use is to download files send to chats. I tried to be as compatible as possible with old function `download`. *usage:* download_file path_to_ile prosed_filename @@ -1627,5 +1627,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.41-dev-8-gb91e96d +#### $$VERSION$$ v1.41-dev-9-g5294d00 From ad1b91f3bce0456b6a7bdccb12b8e05c866ce4e3 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 6 Feb 2021 17:45:52 +0100 Subject: [PATCH 11/43] finish get_file rework: remove URLS[*] logging obfuscation --- bashbot.sh | 2 +- doc/6_reference.md | 2 +- modules/processUpdates.sh | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index cb11af8..0412470 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.41-dev-9-g5294d00 +#### $$VERSION$$ v1.41-dev-10-gccac62d ################################################################## # are we running in a terminal? diff --git a/doc/6_reference.md b/doc/6_reference.md index d4cf2da..3e69e8c 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -1627,5 +1627,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.41-dev-9-g5294d00 +#### $$VERSION$$ v1.41-dev-10-gccac62d diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index cb422e8..e41c251 100644 --- a/modules/processUpdates.sh +++ b/modules/processUpdates.sh @@ -4,7 +4,7 @@ # File: processUpdates.sh # Note: DO NOT EDIT! this file will be overwritten on update # -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.41-dev-10-gccac62d ################################################################## ############## @@ -82,7 +82,7 @@ process_update() { process_message "${num}" "${debug}" 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[*]//bot*:}"; printf "%s" "${_//[A-Z-]}")" >>"${UPDATELOG}" + "${MESSAGE:0:30}${CAPTION:0:30}${URLS[*]}" >>"${UPDATELOG}" fi ##### # process inline and message events From 9d36f23b14181a8e652025fde46d4e07dc5e76e2 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 6 Feb 2021 18:04:11 +0100 Subject: [PATCH 12/43] Version 1.41: fix never working file download --- README.html | 2 +- README.md | 2 +- README.txt | 2 +- bashbot.sh | 2 +- doc/2_usage.md | 2 +- doc/6_reference.md | 2 +- modules/processUpdates.sh | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.html b/README.html index 7afb288..11c7c50 100644 --- a/README.html +++ b/README.html @@ -392,6 +392,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.40-0-gf9dab50

+

$$VERSION$$ v1.41-0-gad1b91f

diff --git a/README.md b/README.md index f5e0789..7756d42 100644 --- a/README.md +++ b/README.md @@ -241,4 +241,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.40-0-gf9dab50 +#### $$VERSION$$ v1.41-0-gad1b91f diff --git a/README.txt b/README.txt index c9150f8..dabcc49 100644 --- a/README.txt +++ b/README.txt @@ -318,5 +318,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.40-0-gf9dab50 +$$VERSION$$ v1.41-0-gad1b91f diff --git a/bashbot.sh b/bashbot.sh index 0412470..c381468 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.41-dev-10-gccac62d +#### $$VERSION$$ v1.41-0-gad1b91f ################################################################## # are we running in a terminal? diff --git a/doc/2_usage.md b/doc/2_usage.md index a0a5211..a5c31b9 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -376,5 +376,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.41-dev-7-g5212df4 +#### $$VERSION$$ v1.41-0-gad1b91f diff --git a/doc/6_reference.md b/doc/6_reference.md index 3e69e8c..758036c 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -1627,5 +1627,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.41-dev-10-gccac62d +#### $$VERSION$$ v1.41-0-gad1b91f diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index e41c251..9168e67 100644 --- a/modules/processUpdates.sh +++ b/modules/processUpdates.sh @@ -4,7 +4,7 @@ # File: processUpdates.sh # Note: DO NOT EDIT! this file will be overwritten on update # -#### $$VERSION$$ v1.41-dev-10-gccac62d +#### $$VERSION$$ v1.41-0-gad1b91f ################################################################## ############## From 34455c2c4cb032768c8b11dcf13f821c465a322e Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 10:20:09 +0100 Subject: [PATCH 13/43] modules: fix/improve error logging --- modules/chatMember.sh | 4 ++-- modules/sendMessage.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/chatMember.sh b/modules/chatMember.sh index ddaf992..237e9b0 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.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-0-g9d36f23 # will be automatically sourced from bashbot @@ -93,7 +93,7 @@ promote_chat_member() { *"invite"*) arg="can_invite_users";; *"restrict"*) arg="can_restrict_members";; *"promote"*) arg="can_promote_members";; - *) [ -n "${BASHBOTDEBUG}" ] && debug_log "${FUNCNAME[0]}: unknown promotion ${arg}" + *) [ -n "${BASHBOTDEBUG}" ] && log_debug "promote_chat_member: unknown promotion CHAT=${chat} USER=${user} PROM=${arg}" continue;; esac # compose json diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 2d23e8c..f441b99 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.41-dev-1-g58fb001 +#### $$VERSION$$ v1.45-dev-0-g9d36f23 # will be automatically sourced from bashbot @@ -260,7 +260,7 @@ send_file(){ BOTSENT[ERROR]="File not found: ${UPLOADDIR}/$2" fi;; esac - [ -n "${BASHBOTDEBUG}" ] && log_message "Error in upload_file: ${BOTSENT[ERROR]}" + [ -n "${BASHBOTDEBUG}" ] && log_debug "upload_file: CHAT=$1 FILE=$2 MSG=${BOTSENT[ERROR]}" return fi # file OK, let's continue From a6ff405cc5c3e91e7a8a1138d36b07e9beaae0e7 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 11:02:01 +0100 Subject: [PATCH 14/43] fix: alias not always working, init: improve for unprivileged user, guess touser from config file --- bashbot.sh | 12 +++++------- bin/bashbot_init.inc.sh | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index c381468..aa7a71e 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.41-0-gad1b91f +#### $$VERSION$$ v1.45-dev-1-g34455c2 ################################################################## # are we running in a terminal? @@ -178,10 +178,10 @@ RUNDIR="$(dirname "$0")" MODULEDIR="${SCRIPTDIR}/modules" # adjust stuff for source, use return from source without source -alias exit_source='exit' +exit_source() { exit "$1"; } if [[ "${SCRIPT}" != "${REALME}" || "$1" == "source" ]]; then SOURCE="yes" - [ -z "$1" ] && alias exit_source='printf "Exit from source ...\n";return' + [ -z "$1" ] && exit_source() { printf "Exit from source ...\n"; return "$1"; } fi # emmbeded system may claim bash but it is not @@ -282,16 +282,14 @@ if [ -z "${BOTTOKEN}" ]; then fi # check data dir file if [ ! -w "${DATADIR}" ]; then - printf "${RED}ERROR: ${DATADIR} does not exist or is not writeable!.${NN}" - exit_source 2 + printf "${RED}WARNING: ${DATADIR} does not exist or is not writeable!.${NN}" fi # setup count file if [ ! -f "${COUNTFILE}.jssh" ]; then printf '["counted_user_chat_id"]\t"num_messages_seen"\n' >> "${COUNTFILE}.jssh" elif [ ! -w "${COUNTFILE}.jssh" ]; then - printf "${RED}ERROR: Can't write to ${COUNTFILE}!.${NN}" + printf "${RED}WARNING: Can't write to ${COUNTFILE}!.${NN}" ls -l "${COUNTFILE}.jssh" - exit_source 2 fi # setup blocked file if [ ! -f "${BLOCKEDFILE}.jssh" ]; then diff --git a/bin/bashbot_init.inc.sh b/bin/bashbot_init.inc.sh index 382b0ec..7c918cf 100644 --- a/bin/bashbot_init.inc.sh +++ b/bin/bashbot_init.inc.sh @@ -5,13 +5,13 @@ # # USAGE: source bashbot_init.inc.sh # -# DESCRIPTION: extend / overwrite bashbot initialisation +# DESCRIPTION: extend / overwrite bashbot initialisation # # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.01.2021 13:42 # -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-1-g34455c2 #=============================================================================== # shellcheck disable=SC2059 @@ -54,17 +54,23 @@ bot_init() { [ -r "${addons}" ] && source "${addons}" "init" "${DEBUG}" done printf "Done.\n" - # ask for bashbot user - # shellcheck disable=SC2153 - runuser="${RUNUSER}"; [ "${UID}" = "0" ] && runuser="nobody" + # guess bashbot from botconfig.jssh owner:group + [ -f "${BOTCONFIG}.jssh" ] && runuser="$(stat -c '%U' "${BOTCONFIG}.jssh"):$(stat -c '%G' "${BOTCONFIG}.jssh")" + # empty or ":" use user running init, nobody for root + if [ "${#runuser}" -lt 3 ]; then + # shellcheck disable=SC2153 + runuser="${RUNUSER}" + [ "${UID}" = "0" ] && runuser="nobody" + fi printf "Enter User to run bashbot [${runuser}]: " read -r chown - [ -z "${chown}" ] && chown="${runuser}"; touser="${chown%:*}" + [ -z "${chown}" ] && chown="${runuser}" + touser="${chown%:*}" # check user ... if ! id "${touser}" &>/dev/null; then printf "${RED}User \"${touser}\" does not exist!${NN}" exit 3 - elif [[ "${UID}" != "0" && "${touser}" != "${runuser}" ]]; then + elif [[ "${UID}" != "0" && "${touser}" != "${RUNUSER}" ]]; then # different user but not root ... 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 From 429c2306274bc5d82235b15bfbdfa5e0e514fcdf Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 16:56:35 +0100 Subject: [PATCH 15/43] init: improve change user for regular users --- bashbot.sh | 47 +++++++++++++++++++++++------------------ bin/bashbot_init.inc.sh | 4 ++-- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index aa7a71e..14de2d1 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.45-dev-1-g34455c2 +#### $$VERSION$$ v1.45-dev-2-ga6ff405 ################################################################## # are we running in a terminal? @@ -161,7 +161,7 @@ debug_checks(){ { [ -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}" + } 2>/dev/null >>"${DEBUGLOG}" } # some Linux distributions (e.g. Manjaro) doesn't seem to have C locale activated by default @@ -275,25 +275,30 @@ if [ -z "${BOTTOKEN}" ]; then [ -z "${admin}" ] && admin='?' printf '["botadmin"]\t"%s"\n' "${admin}" >> "${BOTCONFIG}.jssh" fi - # setup botacl file - if [ ! -f "${BOTACL}" ]; then - printf "${GREY}Create initial ${BOTACL} file.${NN}" - printf '\n' >"${BOTACL}" - fi - # check data dir file - if [ ! -w "${DATADIR}" ]; then - printf "${RED}WARNING: ${DATADIR} does not exist or is not writeable!.${NN}" - fi - # setup count file - if [ ! -f "${COUNTFILE}.jssh" ]; then - printf '["counted_user_chat_id"]\t"num_messages_seen"\n' >> "${COUNTFILE}.jssh" - elif [ ! -w "${COUNTFILE}.jssh" ]; then - printf "${RED}WARNING: Can't write to ${COUNTFILE}!.${NN}" - ls -l "${COUNTFILE}.jssh" - fi - # setup blocked file - if [ ! -f "${BLOCKEDFILE}.jssh" ]; then - printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >>"${BLOCKEDFILE}.jssh" + + # skip on init + if [ "$1" != "init" ]; then + # setup botacl file + if [ ! -f "${BOTACL}" ]; then + printf "${GREY}Create initial ${BOTACL} file.${NN}" + printf '\n' >"${BOTACL}" + fi + # check data dir file + if [ ! -w "${DATADIR}" ]; then + printf "${RED}ERROR: ${DATADIR} does not exist or is not writeable!.${NN}" + exit_source 2 + fi + # setup count file + if [ ! -f "${COUNTFILE}.jssh" ]; then + printf '["counted_user_chat_id"]\t"num_messages_seen"\n' >> "${COUNTFILE}.jssh" + elif [ ! -w "${COUNTFILE}.jssh" ]; then + printf "${RED}WARNING: Can't write to ${COUNTFILE}!.${NN}" + ls -l "${COUNTFILE}.jssh" + fi + # setup blocked file + if [ ! -f "${BLOCKEDFILE}.jssh" ]; then + printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >>"${BLOCKEDFILE}.jssh" + fi fi fi diff --git a/bin/bashbot_init.inc.sh b/bin/bashbot_init.inc.sh index 7c918cf..48d7f13 100644 --- a/bin/bashbot_init.inc.sh +++ b/bin/bashbot_init.inc.sh @@ -11,7 +11,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.01.2021 13:42 # -#### $$VERSION$$ v1.45-dev-1-g34455c2 +#### $$VERSION$$ v1.45-dev-2-ga6ff405 #=============================================================================== # shellcheck disable=SC2059 @@ -70,7 +70,7 @@ bot_init() { if ! id "${touser}" &>/dev/null; then printf "${RED}User \"${touser}\" does not exist!${NN}" exit 3 - elif [[ "${UID}" != "0" && "${touser}" != "${RUNUSER}" ]]; then + elif [ "${UID}" != "0" ]; then # different user but not root ... 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 From 52d1ac56188c3d054b04adbc2289201e9328c06d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 17:05:34 +0100 Subject: [PATCH 16/43] modules: sendMessage: add copy_message --- bashbot.sh | 2 +- bin/bashbot_init.inc.sh | 4 ++-- modules/sendMessage.sh | 9 ++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 14de2d1..4a38194 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.45-dev-2-ga6ff405 +#### $$VERSION$$ v1.45-dev-3-g429c230 ################################################################## # are we running in a terminal? diff --git a/bin/bashbot_init.inc.sh b/bin/bashbot_init.inc.sh index 48d7f13..d5ece74 100644 --- a/bin/bashbot_init.inc.sh +++ b/bin/bashbot_init.inc.sh @@ -11,7 +11,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.01.2021 13:42 # -#### $$VERSION$$ v1.45-dev-2-ga6ff405 +#### $$VERSION$$ v1.45-dev-3-g429c230 #=============================================================================== # shellcheck disable=SC2059 @@ -104,13 +104,13 @@ bot_init() { fi # adjust permissions printf "Adjusting files and permissions for user \"${touser}\" ...\n" + chown -Rf "${chown}" . ./* 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 -Rf "${chown}" . ./* printf "Done.\n" # adjust values in bashbot.rc if [ -w "bashbot.rc" ]; then diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index f441b99..710f480 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.45-dev-0-g9d36f23 +#### $$VERSION$$ v1.45-dev-3-g429c230 # will be automatically sourced from bashbot @@ -340,8 +340,11 @@ forward_message() { [ -z "$3" ] && return sendJson "$1" '"from_chat_id": '"$2"', "message_id": '"$3"'' "${URL}/forwardMessage" } -forward() { # backward compatibility - forward_message "$@" || return + +# $1 CHAT $2 from chat $3 from msg id +copy_message() { + [ -z "$3" ] && return + sendJson "$1" '"from_chat_id": '"$2"', "message_id": '"$3"'' "${URL}/copyMessage" } # $1 CHAT $2 bashbot formatted message, see manual advanced usage From eee545823262e46e431e038dce4be4227584368d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 18:00:25 +0100 Subject: [PATCH 17/43] modules: add send_dice --- modules/sendMessage.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 710f480..fca6b6e 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.45-dev-3-g429c230 +#### $$VERSION$$ v1.45-dev-4-g52d1ac5 # will be automatically sourced from bashbot @@ -310,12 +310,31 @@ send_file(){ return 0 } -# $1 typing upload_photo record_video upload_video record_audio upload_audio upload_document find_location +# $1 chat $2 typing upload_photo record_video upload_video record_audio upload_audio upload_document find_location send_action() { [ -z "$2" ] && return sendJson "$1" '"action": "'"$2"'"' "${URL}/sendChatAction" & } +# $1 chat $2 emoji “🎲”, “🎯”, “🏀”, “⚽”, “🎰" +# code: \u201c\ud83c\udfb2\u201d \u201c\ud83c\udfaf\u201d \u201c\ud83c\udfc0\u201d \u201c\u26bd\u201d \u201c\ud83c\udfb0\u201d +# text: ":game_die:" "game" ":dart:" "dart" ":basketball:" "basket" ":soccer:" "soccer" :slot_machine:" "slot" +# $3 reply_to_id +send_dice() { + local emoji reply + [ -n "$3" ] && reply=',"reply_to_message_id":'"$3" + case "$2" in # must be single character + *🎲*|*game*) emoji='\u201c\ud83c\udfb2\u201d' ;; + *🎯*|*dart*) emoji='\u201c\ud83c\udfaf\u201d' ;; + *🏀*|*basket*) emoji='\u201c\ud83c\udfc0\u201d' ;; + *⚽*|*soccer*) emoji='\u201c\u26bd\u201d' ;; + *🎰*|*slot*) emoji='\u201c\ud83c\udfb0\u201d' ;; + *) # default emoji "🎲" + emoji='\u201c\ud83c\udfb2\u201d' ;; + esac + sendJson "$1" '"emoji": "'"${emoji}"'"'"${reply}" "${URL}/sendChatAction" & +} + # $1 CHAT $2 lat $3 long send_location() { [ -z "$3" ] && return From 2f6f3bd4d8d5e0e01c80daab1fe5c98d99db328f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 18:01:34 +0100 Subject: [PATCH 18/43] test: fix init test --- bashbot.sh | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 4a38194..6ca83d8 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.45-dev-3-g429c230 +#### $$VERSION$$ v1.45-dev-5-geee5458 ################################################################## # are we running in a terminal? @@ -276,29 +276,26 @@ if [ -z "${BOTTOKEN}" ]; then printf '["botadmin"]\t"%s"\n' "${admin}" >> "${BOTCONFIG}.jssh" fi - # skip on init - if [ "$1" != "init" ]; then - # setup botacl file - if [ ! -f "${BOTACL}" ]; then - printf "${GREY}Create initial ${BOTACL} file.${NN}" - printf '\n' >"${BOTACL}" - fi - # check data dir file - if [ ! -w "${DATADIR}" ]; then - printf "${RED}ERROR: ${DATADIR} does not exist or is not writeable!.${NN}" - exit_source 2 - fi - # setup count file - if [ ! -f "${COUNTFILE}.jssh" ]; then - printf '["counted_user_chat_id"]\t"num_messages_seen"\n' >> "${COUNTFILE}.jssh" - elif [ ! -w "${COUNTFILE}.jssh" ]; then - printf "${RED}WARNING: Can't write to ${COUNTFILE}!.${NN}" - ls -l "${COUNTFILE}.jssh" - fi - # setup blocked file - if [ ! -f "${BLOCKEDFILE}.jssh" ]; then - printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >>"${BLOCKEDFILE}.jssh" - fi + # setup botacl file + if [ ! -f "${BOTACL}" ]; then + printf "${GREY}Create initial ${BOTACL} file.${NN}" + printf '\n' >"${BOTACL}" + fi + # check data dir file + if [ ! -w "${DATADIR}" ]; then + printf "${RED}ERROR: ${DATADIR} does not exist or is not writeable!.${NN}" + [ "$1" != "init" ] && exit_source 2 # skip on init + fi + # setup count file + if [ ! -f "${COUNTFILE}.jssh" ]; then + printf '["counted_user_chat_id"]\t"num_messages_seen"\n' >> "${COUNTFILE}.jssh" + elif [ ! -w "${COUNTFILE}.jssh" ]; then + printf "${RED}WARNING: Can't write to ${COUNTFILE}!.${NN}" + ls -l "${COUNTFILE}.jssh" + fi + # setup blocked file + if [ ! -f "${BLOCKEDFILE}.jssh" ]; then + printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >>"${BLOCKEDFILE}.jssh" fi fi From a9ed5593831cf6d5665b84b9be1edd095788c7e2 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 18:35:19 +0100 Subject: [PATCH 19/43] modules: send_dice: accept more formats, allow false reply_to --- modules/sendMessage.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index fca6b6e..3a24c20 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.45-dev-4-g52d1ac5 +#### $$VERSION$$ v1.45-dev-6-g2f6f3bd # will be automatically sourced from bashbot @@ -317,22 +317,22 @@ send_action() { } # $1 chat $2 emoji “🎲”, “🎯”, “🏀”, “⚽”, “🎰" -# code: \u201c\ud83c\udfb2\u201d \u201c\ud83c\udfaf\u201d \u201c\ud83c\udfc0\u201d \u201c\u26bd\u201d \u201c\ud83c\udfb0\u201d -# text: ":game_die:" "game" ":dart:" "dart" ":basketball:" "basket" ":soccer:" "soccer" :slot_machine:" "slot" +# code: "\ud83c\udfb2" "\ud83c\udfaf" "\ud83c\udfc0" "\u26bd" "\ud83c\udfb0" +# text: ":game_die:" ":dart:" ":basketball:" ":soccer:" :slot_machine:" # $3 reply_to_id send_dice() { local emoji reply - [ -n "$3" ] && reply=',"reply_to_message_id":'"$3" - case "$2" in # must be single character - *🎲*|*game*) emoji='\u201c\ud83c\udfb2\u201d' ;; - *🎯*|*dart*) emoji='\u201c\ud83c\udfaf\u201d' ;; - *🏀*|*basket*) emoji='\u201c\ud83c\udfc0\u201d' ;; - *⚽*|*soccer*) emoji='\u201c\u26bd\u201d' ;; - *🎰*|*slot*) emoji='\u201c\ud83c\udfb0\u201d' ;; + [[ "$3" =~ ^[${o9o9o9}-]+$ ]] && reply=',"reply_to_message_id":'"$3"',"allow_sending_without_reply": true' + case "$2" in # convert input to single character emoji + *🎲*|*game* |*'dfb2'*|*'DFB2'*) emoji='\ud83c\udfb2' ;; + *🎯*|*dart* |*'dfaf'*|*'DFAF'*) emoji='\ud83c\udfaf' ;; + *🏀*|*basket*|*'dfc0'*|*'DFC0'*) emoji='\ud83c\udfc0' ;; + *⚽*|*soccer*|*'26bd'*|*'26BD'*) emoji='\u26bd' ;; + *🎰*|*slot* |*'dfb0'*|*'DFB0'*) emoji='\ud83c\udfb0' ;; *) # default emoji "🎲" - emoji='\u201c\ud83c\udfb2\u201d' ;; + emoji='\ud83c\udfb2' ;; esac - sendJson "$1" '"emoji": "'"${emoji}"'"'"${reply}" "${URL}/sendChatAction" & + sendJson "$1" '"emoji": "'"${emoji}"'"'"${reply}" "${URL}/sendDice" } # $1 CHAT $2 lat $3 long From 069570e4edbdeba91a97da36de8b63d52b29997c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 18:57:15 +0100 Subject: [PATCH 20/43] bin: add send_dice.sh --- bin/any_command.sh | 2 +- bin/send_dice.sh | 47 ++++++++++++++++++++++++++++++++++++++++++ modules/sendMessage.sh | 6 +++++- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100755 bin/send_dice.sh diff --git a/bin/any_command.sh b/bin/any_command.sh index fe8f3e7..2b62f19 100755 --- a/bin/any_command.sh +++ b/bin/any_command.sh @@ -21,7 +21,7 @@ USAGE='any_command.sh [-h|--help] [--force|--reference] bot_command args ...' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 30.01.2021 10:24 # -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-7-ga9ed559 #=============================================================================== #### diff --git a/bin/send_dice.sh b/bin/send_dice.sh new file mode 100755 index 0000000..d5406e5 --- /dev/null +++ b/bin/send_dice.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# shellcheck disable=SC1090,SC2034 +#=============================================================================== +# +# FILE: bin/send_dice.sh +# +USAGE='send_dice.sh [-h|--help] "CHAT[ID]" "emoji" [debug]' +# +# DESCRIPTION: send an animated emoji (dice) to given chat +# +# OPTIONS: CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself +# emoji - must be one of: “🎲”, “🎯”, “🏀”, “⚽”, or “🎰” +# ":text: ":game_die:" ":dart:" ":basketball:" ":soccer:" :slot_machine:" +# +# -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: 07.02.2021 18:45 +# +#### $$VERSION$$ v1.45-dev-7-ga9ed559 +#=============================================================================== + +#### +# parse args +SEND="send_dice" + +# set bashbot environment +source "${0%/*}/bashbot_env.inc.sh" "${3:-debug}" # $5 debug +print_help "$1" + +#### +# ready, do stuff here ----- +if [ "$1" == "BOTADMIN" ]; then + CHAT="${BOT_ADMIN}" +else + CHAT="$1" +fi + +# send message in selected format +"${SEND}" "${CHAT}" "$2" + +# output send message result +print_result diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 3a24c20..9994bfc 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.45-dev-6-g2f6f3bd +#### $$VERSION$$ v1.45-dev-7-ga9ed559 # will be automatically sourced from bashbot @@ -333,6 +333,10 @@ send_dice() { emoji='\ud83c\udfb2' ;; esac sendJson "$1" '"emoji": "'"${emoji}"'"'"${reply}" "${URL}/sendDice" + if [ "${BOTSENT[OK]}" = "true" ]; then + BOTSENT[DICE]="${UPD["result,dice,emoji"]}" + BOTSENT[RESULT]="${UPD["result,dice,value"]}" + fi } # $1 CHAT $2 lat $3 long From 62b6b618d5a11999998b83e5d22a3daf55ed9552 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 19:32:36 +0100 Subject: [PATCH 21/43] doc: add send_dice, sendMessage: optimze send_dice emoji selection --- bin/send_dice.sh | 4 ++-- doc/6_reference.md | 18 ++++++++++++++++-- modules/sendMessage.sh | 8 +++----- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/bin/send_dice.sh b/bin/send_dice.sh index d5406e5..dc81c4a 100755 --- a/bin/send_dice.sh +++ b/bin/send_dice.sh @@ -10,7 +10,7 @@ USAGE='send_dice.sh [-h|--help] "CHAT[ID]" "emoji" [debug]' # # OPTIONS: CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself # emoji - must be one of: “🎲”, “🎯”, “🏀”, “⚽”, or “🎰” -# ":text: ":game_die:" ":dart:" ":basketball:" ":soccer:" :slot_machine:" +# ":game_die:" ":dart:" ":basketball:" ":soccer:" :slot_machine:" # # -h - display short help # --help - this help @@ -21,7 +21,7 @@ USAGE='send_dice.sh [-h|--help] "CHAT[ID]" "emoji" [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 07.02.2021 18:45 # -#### $$VERSION$$ v1.45-dev-7-ga9ed559 +#### $$VERSION$$ v1.45-dev-8-g069570e #=============================================================================== #### diff --git a/doc/6_reference.md b/doc/6_reference.md index 758036c..fbb7b55 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -176,8 +176,22 @@ send_album "$(getConfigKey "botadmin")" "http://www.rrr.de/slider/main-image1.jp ##### 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" +*usage:* send_sticker "CHAT[ID]" "file_id" +##### send_dice +`send_dice` send an animated emoji and returns a value (_e.g. points shown on die_). + +*usage:* send_dice "CHAT[ID]" "emoji" + +Emoji must be one of '🎲', '🎯', '🏀', '⚽', '🎰' or ":game_die:" ":dart:" ":basketball:" ":soccer:" :slot_machine:". +Dice can have values 1-6 for '🎲' and '🎯', values 1-5 for '🏀' and '⚽', and values 1-64 for '🎰'. Defaults to '🎲' + +*example:* +```bash +# send die and output points +send_dice "${CHAT[ID]}" ":game_die:" +[ "$BOTSENT[ok]" = "true ] && send_markdownv2_message "*Congratulation* you got *${BOTSENT[RESULT]} Points*." +``` ---- @@ -1627,5 +1641,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.41-0-gad1b91f +#### $$VERSION$$ v1.45-dev-8-g069570e diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 9994bfc..52afdfe 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.45-dev-7-ga9ed559 +#### $$VERSION$$ v1.45-dev-8-g069570e # will be automatically sourced from bashbot @@ -321,16 +321,14 @@ send_action() { # text: ":game_die:" ":dart:" ":basketball:" ":soccer:" :slot_machine:" # $3 reply_to_id send_dice() { - local emoji reply + local reply emoji='\ud83c\udfb2' # default "🎲" [[ "$3" =~ ^[${o9o9o9}-]+$ ]] && reply=',"reply_to_message_id":'"$3"',"allow_sending_without_reply": true' case "$2" in # convert input to single character emoji - *🎲*|*game* |*'dfb2'*|*'DFB2'*) emoji='\ud83c\udfb2' ;; + *🎲*|*game*|*dice*|*'dfb2'*|*'DFB2'*) : ;; *🎯*|*dart* |*'dfaf'*|*'DFAF'*) emoji='\ud83c\udfaf' ;; *🏀*|*basket*|*'dfc0'*|*'DFC0'*) emoji='\ud83c\udfc0' ;; *⚽*|*soccer*|*'26bd'*|*'26BD'*) emoji='\u26bd' ;; *🎰*|*slot* |*'dfb0'*|*'DFB0'*) emoji='\ud83c\udfb0' ;; - *) # default emoji "🎲" - emoji='\ud83c\udfb2' ;; esac sendJson "$1" '"emoji": "'"${emoji}"'"'"${reply}" "${URL}/sendDice" if [ "${BOTSENT[OK]}" = "true" ]; then From b2fc4052fc7ebd197ef086a9f82aafb5fae2b740 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 20:44:58 +0100 Subject: [PATCH 22/43] mycommands.sh: add send_dice example --- commands.sh | 8 +++++--- doc/6_reference.md | 4 ++-- mycommands.sh | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/commands.sh b/commands.sh index 20e5beb..f6d45a0 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.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-9-g62b6b61 # # bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed @@ -42,10 +42,12 @@ bashbot_help=' *• /start*: _Start bot and get this message_. *• /help*: _Get this message_. *• /info*: _Get shorter info message about this bot_. -*• /question*: _Start interactive chat (mycommands.dist)_. -*• /cancel*: _Cancel any currently running interactive chat_. *• /kickme*: _You will be autokicked from the group_. *• /leavechat*: _The bot will leave the group with this command _. +Additional commands from mycommands.dist ... +*• /game*: _throw a die_. +*• /question*: _Start interactive chat_. +*• /cancel*: _Cancel any currently running interactive chat_. Written by Drew (@topkecleon) and KayM (@gnadelwartz). Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) ' diff --git a/doc/6_reference.md b/doc/6_reference.md index fbb7b55..3b68eef 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -190,7 +190,7 @@ Dice can have values 1-6 for '🎲' and '🎯', values 1-5 for '🏀' and '⚽', ```bash # send die and output points send_dice "${CHAT[ID]}" ":game_die:" -[ "$BOTSENT[ok]" = "true ] && send_markdownv2_message "*Congratulation* you got *${BOTSENT[RESULT]} Points*." +[ "${BOTSENT[OK]}" = "true" ] && send_markdownv2_message "${CHAT[ID]}" "*Congratulation* you got *${BOTSENT[RESULT]} Point(s)*." ``` ---- @@ -1641,5 +1641,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.45-dev-8-g069570e +#### $$VERSION$$ v1.45-dev-9-g62b6b61 diff --git a/mycommands.sh b/mycommands.sh index c8fcd2c..0b87ffd 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.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-9-g62b6b61 ####################################################### # shellcheck disable=SC1117 @@ -123,7 +123,20 @@ else case "${MESSAGE}" in ################## - # example commands, replace thm by your own + # example commands, replace them by your own + '/game'*) # send random dice 1-5 + send_dice "${CHAT[ID]}" "$(shuf -i "1-5" -n 1)" + if [ "${BOTSENT[OK]}" = "true" ]; then + local gameresult="*Congratulation* you got *${BOTSENT[RESULT]} Points*." + sleep 5 + case "${BOTSENT[RESULT]}" in + 1) gameresult="*Sorry* only *one Point* ...";; + 2) gameresult="*Hey*, 2 Points are *more then one!*";; + 64) gameresult="*JACKPOT! ${BOTSENT[RESULT]} Points!*" + esac + send_markdownv2_message "${CHAT[ID]}" "${gameresult}" + fi + ;; '/unpin'*) # unpin all messages if (bot)admin or allowed for user user_is_allowed "${USER[ID]}" "unpin" "${CHAT[ID]}" &&\ unpinall_chat_messages "${CHAT[ID]}" From 897458a37f823c681fbb8c51ac3d19b36deaf4ca Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 8 Feb 2021 17:17:44 +0100 Subject: [PATCH 23/43] mycommands: update send_dice example --- mycommands.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mycommands.sh b/mycommands.sh index 0b87ffd..2f53764 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.45-dev-9-g62b6b61 +#### $$VERSION$$ v1.45-dev-10-gb2fc405 ####################################################### # shellcheck disable=SC1117 @@ -124,15 +124,16 @@ else case "${MESSAGE}" in ################## # example commands, replace them by your own - '/game'*) # send random dice 1-5 - send_dice "${CHAT[ID]}" "$(shuf -i "1-5" -n 1)" + '/game'*) # send random dice, edit list to fit your needs + send_dice "${CHAT[ID]}" ":$(printf "slot_machine\ngame_die\ndart\nbasketball\nsoccer\nslot_machine"|sort -R|shuf -n 1shuf -n 1):" if [ "${BOTSENT[OK]}" = "true" ]; then local gameresult="*Congratulation* you got *${BOTSENT[RESULT]} Points*." sleep 5 case "${BOTSENT[RESULT]}" in 1) gameresult="*Sorry* only *one Point* ...";; 2) gameresult="*Hey*, 2 Points are *more then one!*";; - 64) gameresult="*JACKPOT! ${BOTSENT[RESULT]} Points!*" + 5|6) [[ "${BOTSENT[EMOJI]}" =~ fb0$ ]] || gameresult="*Super! ${BOTSENT[RESULT]} Points!*";; + 6*) gameresult="*JACKPOT! ${BOTSENT[RESULT]} Points!*";; esac send_markdownv2_message "${CHAT[ID]}" "${gameresult}" fi From 066274c943fa0af6a06674d2c70f7f05f9521eca Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 8 Feb 2021 17:55:43 +0100 Subject: [PATCH 24/43] add inital custom error processing --- bashbot.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 6ca83d8..7d5a9d5 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.45-dev-5-geee5458 +#### $$VERSION$$ v1.45-dev-11-g897458a ################################################################## # are we running in a terminal? @@ -460,7 +460,25 @@ download_file() { # output absolute file path printf "%s\n" "$(cd "${file%/*}" >/dev/null 2>&1 && pwd)/${file##*/}" } - +# notify mycommands about errors while sending +# $1 calling function $2 error $3 chat $4 user $5 error message $6 ... remaining args to calling function +# calls function based on error: bashbotError{function} basbotError{error} +# if no specific function exist try to call bashbotProcessError +processError(){ + [[ "$4" != "4"* ]] && return 1 + local func="$1" err="$2" chat="$3" user="$4" msg="$5"; shift 5 + # check for bashbotError${func} provided in mycommands + # shellcheck disable=SC2082 + if _is_function "bashbotError${func}"; then + "bashbotError${func}" "${err}" "${chat}" "${user}" "${msg}" "$@" + # check for bashbotError${err} provided in mycommands + elif _is_function "bashbotError${err}"; then + "bashbotError${err}" "${func}" "${chat}" "${user}" "${msg}" "$@" + # noting found, try bashbotProcessError + else + _exec_if_function bashbotProcessError "${func}" "${err}" "${chat}" "${user}" "${msg}" "$@" + fi +} # iconv used to filter out broken utf characters, if not installed fake it if ! _exists iconv; then From 117255a958602a2af4559dca46407f055347f958 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 8 Feb 2021 18:41:54 +0100 Subject: [PATCH 25/43] modules: implement processError in sendMessage.sh --- bashbot.sh | 14 ++++++------ modules/sendMessage.sh | 52 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 7d5a9d5..8f830a7 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.45-dev-11-g897458a +#### $$VERSION$$ v1.45-dev-12-g066274c ################################################################## # are we running in a terminal? @@ -466,17 +466,17 @@ download_file() { # if no specific function exist try to call bashbotProcessError processError(){ [[ "$4" != "4"* ]] && return 1 - local func="$1" err="$2" chat="$3" user="$4" msg="$5"; shift 5 + local func="$1" err="$2" # check for bashbotError${func} provided in mycommands # shellcheck disable=SC2082 - if _is_function "bashbotError${func}"; then - "bashbotError${func}" "${err}" "${chat}" "${user}" "${msg}" "$@" + if _is_function "bashbotError_${func}"; then + "bashbotError_${func}" "$@" # check for bashbotError${err} provided in mycommands - elif _is_function "bashbotError${err}"; then - "bashbotError${err}" "${func}" "${chat}" "${user}" "${msg}" "$@" + elif _is_function "bashbotError_${err}"; then + "bashbotError_${err}" "$@" # noting found, try bashbotProcessError else - _exec_if_function bashbotProcessError "${func}" "${err}" "${chat}" "${user}" "${msg}" "$@" + _exec_if_function bashbotProcessError "$@" fi } diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 52afdfe..d45c2a0 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.45-dev-8-g069570e +#### $$VERSION$$ v1.45-dev-12-g066274c # will be automatically sourced from bashbot @@ -37,46 +37,64 @@ send_normal_message() { text="${text:$((len+2))}" fi done + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" } # $1 CHAT $2 message send_markdown_message() { _format_message_url "$1" "$2" ',"parse_mode":"markdown"' "${MSG_URL}" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" } # $1 CHAT $2 message send_markdownv2_message() { _markdownv2_message_url "$1" "$2" ',"parse_mode":"markdownv2"' "${MSG_URL}" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" } # $1 CHAT $2 message send_html_message() { _format_message_url "$1" "$2" ',"parse_mode":"html"' "${MSG_URL}" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" } # $1 CHAT $2 msg-id $3 message edit_normal_message() { _format_message_url "$1" "$3" ',"message_id":'"$2"'' "${EDIT_URL}" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" } # $1 CHAT $2 msg-id $3 message edit_markdown_message() { _format_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"markdown"' "${EDIT_URL}" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" } # $1 CHAT $2 msg-id $3 message edit_markdownv2_message() { _markdownv2_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"markdownv2"' "${EDIT_URL}" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" } # $1 CHAT $2 msg-id $3 message edit_html_message() { _format_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"html"' "${EDIT_URL}" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" } # $1 chat $2 mesage_id, $3 caption edit_message_caption() { sendJson "$1" '"message_id":'"$2"',"caption":"'"$3"'"' "${URL}/editMessageCaption" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" } @@ -117,8 +135,10 @@ 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}" # '"text":"$2", "reply_markup": {"keyboard": [ $3 ], "one_time_keyboard": true}' + sendJson "$1" "${text}"', "reply_markup": {"keyboard": [ '"$3"' ] '"${one_time}"'}' "${MSG_URL}" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" } # $1 CHAT $2 message $3 remove @@ -130,8 +150,10 @@ remove_keyboard() { fi 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}' + [[ -z "$2" || -n "$3" ]] && delete_message "$1" "${BOTSENT[ID]}" "nolog" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" } # buttons will specified as "texts @@ -174,8 +196,10 @@ _button_row() { # raw inline functions, for special use # $1 CHAT $2 message-id $3 keyboard edit_inline_keyboard() { - sendJson "$1" '"message_id":'"$2"', "reply_markup": {"inline_keyboard": [ '"$3"' ]}' "${URL}/editMessageReplyMarkup" # JSON='"message_id":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}' + sendJson "$1" '"message_id":'"$2"', "reply_markup": {"inline_keyboard": [ '"$3"' ]}' "${URL}/editMessageReplyMarkup" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" } @@ -183,7 +207,8 @@ edit_inline_keyboard() { send_inline_keyboard() { local text; text='"text":"'$(JsonEscape "$2")'"'; [ -z "$2" ] && text='"text":"..."' sendJson "$1" "${text}"', "reply_markup": {"inline_keyboard": [ '"$3"' ]}' "${MSG_URL}" - # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}' + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" } # $1 callback id, $2 text to show, alert if not empty @@ -196,6 +221,8 @@ answer_callback_query() { # $1 chat, $2 file_id on telegram server send_sticker() { sendJson "$1" '"sticker": "'"$2"'"' "${URL}/sendSticker" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" } @@ -314,6 +341,8 @@ send_file(){ send_action() { [ -z "$2" ] && return sendJson "$1" '"action": "'"$2"'"' "${URL}/sendChatAction" & + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" } # $1 chat $2 emoji “🎲”, “🎯”, “🏀”, “⚽”, “🎰" @@ -334,6 +363,9 @@ send_dice() { if [ "${BOTSENT[OK]}" = "true" ]; then BOTSENT[DICE]="${UPD["result,dice,emoji"]}" BOTSENT[RESULT]="${UPD["result,dice,value"]}" + else + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" fi } @@ -341,14 +373,18 @@ send_dice() { send_location() { [ -z "$3" ] && return sendJson "$1" '"latitude": '"$2"', "longitude": '"$3"'' "${URL}/sendLocation" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" } -# $1 CHAT $2 lat $3 long $4 title $5 address $6 foursquard id +# $1 CHAT $2 lat $3 long $4 title $5 address $6 foursquare id send_venue() { local add="" [ -z "$5" ] && return [ -n "$6" ] && add=', "foursquare_id": '"$6"'' sendJson "$1" '"latitude": '"$2"', "longitude": '"$3"', "address": "'"$5"'", "title": "'"$4"'"'"${add}" "${URL}/sendVenue" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" "$4" "$5" "$6" } @@ -360,12 +396,16 @@ send_venue() { forward_message() { [ -z "$3" ] && return sendJson "$1" '"from_chat_id": '"$2"', "message_id": '"$3"'' "${URL}/forwardMessage" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" } # $1 CHAT $2 from chat $3 from msg id copy_message() { [ -z "$3" ] && return sendJson "$1" '"from_chat_id": '"$2"', "message_id": '"$3"'' "${URL}/copyMessage" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" } # $1 CHAT $2 bashbot formatted message, see manual advanced usage From f8427306456d1aed2658c22f7d6c5c36354631d4 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 8 Feb 2021 19:53:42 +0100 Subject: [PATCH 26/43] modules: fix ERROR description in error processing --- modules/sendMessage.sh | 44 +++++++++++++++++++++--------------------- mycommands.sh | 20 ++++++++++++++++++- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index d45c2a0..f3c8149 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.45-dev-12-g066274c +#### $$VERSION$$ v1.45-dev-13-g117255a # will be automatically sourced from bashbot @@ -38,63 +38,63 @@ send_normal_message() { fi done # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" } # $1 CHAT $2 message send_markdown_message() { _format_message_url "$1" "$2" ',"parse_mode":"markdown"' "${MSG_URL}" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" } # $1 CHAT $2 message send_markdownv2_message() { _markdownv2_message_url "$1" "$2" ',"parse_mode":"markdownv2"' "${MSG_URL}" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" } # $1 CHAT $2 message send_html_message() { _format_message_url "$1" "$2" ',"parse_mode":"html"' "${MSG_URL}" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" } # $1 CHAT $2 msg-id $3 message edit_normal_message() { _format_message_url "$1" "$3" ',"message_id":'"$2"'' "${EDIT_URL}" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" } # $1 CHAT $2 msg-id $3 message edit_markdown_message() { _format_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"markdown"' "${EDIT_URL}" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" } # $1 CHAT $2 msg-id $3 message edit_markdownv2_message() { _markdownv2_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"markdownv2"' "${EDIT_URL}" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" } # $1 CHAT $2 msg-id $3 message edit_html_message() { _format_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"html"' "${EDIT_URL}" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" } # $1 chat $2 mesage_id, $3 caption edit_message_caption() { sendJson "$1" '"message_id":'"$2"',"caption":"'"$3"'"' "${URL}/editMessageCaption" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" } @@ -138,7 +138,7 @@ send_keyboard() { # '"text":"$2", "reply_markup": {"keyboard": [ $3 ], "one_time_keyboard": true}' sendJson "$1" "${text}"', "reply_markup": {"keyboard": [ '"$3"' ] '"${one_time}"'}' "${MSG_URL}" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" } # $1 CHAT $2 message $3 remove @@ -153,7 +153,7 @@ remove_keyboard() { #JSON='"text":"$2", "reply_markup": {"remove_keyboard":true}' [[ -z "$2" || -n "$3" ]] && delete_message "$1" "${BOTSENT[ID]}" "nolog" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" } # buttons will specified as "texts @@ -199,7 +199,7 @@ edit_inline_keyboard() { # JSON='"message_id":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}' sendJson "$1" '"message_id":'"$2"', "reply_markup": {"inline_keyboard": [ '"$3"' ]}' "${URL}/editMessageReplyMarkup" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" } @@ -208,7 +208,7 @@ send_inline_keyboard() { local text; text='"text":"'$(JsonEscape "$2")'"'; [ -z "$2" ] && text='"text":"..."' sendJson "$1" "${text}"', "reply_markup": {"inline_keyboard": [ '"$3"' ]}' "${MSG_URL}" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" } # $1 callback id, $2 text to show, alert if not empty @@ -222,7 +222,7 @@ answer_callback_query() { send_sticker() { sendJson "$1" '"sticker": "'"$2"'"' "${URL}/sendSticker" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" } @@ -287,7 +287,7 @@ send_file(){ BOTSENT[ERROR]="File not found: ${UPLOADDIR}/$2" fi;; esac - [ -n "${BASHBOTDEBUG}" ] && log_debug "upload_file: CHAT=$1 FILE=$2 MSG=${BOTSENT[ERROR]}" + [ -n "${BASHBOTDEBUG}" ] && log_debug "upload_file: CHAT=$1 FILE=$2 MSG=${BOTSENT[DESCRIPTION]}" return fi # file OK, let's continue @@ -342,7 +342,7 @@ send_action() { [ -z "$2" ] && return sendJson "$1" '"action": "'"$2"'"' "${URL}/sendChatAction" & # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" } # $1 chat $2 emoji “🎲”, “🎯”, “🏀”, “⚽”, “🎰" @@ -365,7 +365,7 @@ send_dice() { BOTSENT[RESULT]="${UPD["result,dice,value"]}" else # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" + processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" fi } @@ -374,7 +374,7 @@ send_location() { [ -z "$3" ] && return sendJson "$1" '"latitude": '"$2"', "longitude": '"$3"'' "${URL}/sendLocation" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" } # $1 CHAT $2 lat $3 long $4 title $5 address $6 foursquare id @@ -384,7 +384,7 @@ send_venue() { [ -n "$6" ] && add=', "foursquare_id": '"$6"'' sendJson "$1" '"latitude": '"$2"', "longitude": '"$3"', "address": "'"$5"'", "title": "'"$4"'"'"${add}" "${URL}/sendVenue" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" "$4" "$5" "$6" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" "$4" "$5" "$6" } @@ -397,7 +397,7 @@ forward_message() { [ -z "$3" ] && return sendJson "$1" '"from_chat_id": '"$2"', "message_id": '"$3"'' "${URL}/forwardMessage" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" } # $1 CHAT $2 from chat $3 from msg id @@ -405,7 +405,7 @@ copy_message() { [ -z "$3" ] && return sendJson "$1" '"from_chat_id": '"$2"', "message_id": '"$3"'' "${URL}/copyMessage" # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[ERROR]}" "$2" "$3" + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" } # $1 CHAT $2 bashbot formatted message, see manual advanced usage diff --git a/mycommands.sh b/mycommands.sh index 2f53764..a08e360 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -295,6 +295,8 @@ else [ -f ".jssh" ] && printf "%s: %s\n" "$1" "Ups, found file \"${PWD:-.}/.jssh\"! ==========" } + ########################### + # example recover from telegram block function # called when bashbot send_xxx command failed because we can not connect to telegram # return 0 to retry, return non 0 to give up bashbotBlockRecover() { @@ -305,7 +307,22 @@ else return 1 } - # place your processing functions here + ########################### + # example error processing + # called when delete Message failed + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + bashbotError_delete_message() { + log_debug "errorProcessing for delete_message failed: ERR=$2 CHAT=$3 MSGID=$6 ERTXT=$5" + } + + # called when error 403 is returned (and no func processing) + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + bashbotError_403() { + log_debug "errorProcessing for error 403 in FUNC=$1 CHAT=$3 USER=${4:-no-user} MSGID=$6 ERTXT=$5" + } + + ########################### + # place your processing functions here -------------- # $1 search parameter my_image_search(){ @@ -321,3 +338,4 @@ else } fi + From d3a1cecf1fa6b9d5b92fc3b0bd6b93a4ede1b002 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 8 Feb 2021 19:56:01 +0100 Subject: [PATCH 27/43] add error process to delete_message --- bashbot.sh | 6 ++++-- mycommands.sh | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 8f830a7..3d810e4 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.45-dev-12-g066274c +#### $$VERSION$$ v1.45-dev-14-gf842730 ################################################################## # are we running in a terminal? @@ -426,6 +426,8 @@ 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}" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" } # URL path for file id, $1 file_id @@ -465,8 +467,8 @@ download_file() { # calls function based on error: bashbotError{function} basbotError{error} # if no specific function exist try to call bashbotProcessError processError(){ - [[ "$4" != "4"* ]] && return 1 local func="$1" err="$2" + [[ "${err}" != "4"* ]] && return 1 # check for bashbotError${func} provided in mycommands # shellcheck disable=SC2082 if _is_function "bashbotError_${func}"; then diff --git a/mycommands.sh b/mycommands.sh index a08e360..0ad8f69 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.45-dev-10-gb2fc405 +#### $$VERSION$$ v1.45-dev-13-g117255a ####################################################### # shellcheck disable=SC1117 From c58fa22b7ad1a2583096ae8ee50ab18a0784cf9b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 8 Feb 2021 20:01:20 +0100 Subject: [PATCH 28/43] modules: move delete_message to sendMessage.sh --- bashbot.sh | 12 +----------- modules/sendMessage.sh | 11 ++++++++++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 3d810e4..98dcda2 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.45-dev-14-gf842730 +#### $$VERSION$$ v1.45-dev-15-gd3a1cec ################################################################## # are we running in a terminal? @@ -420,16 +420,6 @@ killallproc() { 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}" - # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args - [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" -} - # URL path for file id, $1 file_id # use download_file "path" to download file get_file() { diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index f3c8149..6b1ec46 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.45-dev-13-g117255a +#### $$VERSION$$ v1.45-dev-15-gd3a1cec # will be automatically sourced from bashbot @@ -98,6 +98,15 @@ edit_message_caption() { } +# $ chat $2 msg_id $3 nolog +delete_message() { + [ -z "$3" ] && log_update "Delete Message CHAT=$1 MSG_ID=$2" + sendJson "$1" '"message_id": '"$2"'' "${URL}/deleteMessage" + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" "$3" +} + + # internal function, send/edit formatted message with parse_mode and URL # $1 CHAT $2 message $3 action $4 URL _format_message_url(){ From a7d85e352c15389b3978d728c094a8f508e8b43e Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 9 Feb 2021 07:31:12 +0100 Subject: [PATCH 29/43] modules: proseccUpdates: get sent dice --- modules/processUpdates.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index 9168e67..b37dbdc 100644 --- a/modules/processUpdates.sh +++ b/modules/processUpdates.sh @@ -4,7 +4,7 @@ # File: processUpdates.sh # Note: DO NOT EDIT! this file will be overwritten on update # -#### $$VERSION$$ v1.41-0-gad1b91f +#### $$VERSION$$ v1.45-dev-16-gc58fa22 ################################################################## ############## @@ -148,6 +148,10 @@ process_message() { # Message MESSAGE[0]+="$(JsonDecode "${UPD["result,${num},message,text"]}" | sed 's|\\/|/|g')" MESSAGE[ID]="${UPD["result,${num},message,message_id"]}" + MESSAGE[DICE]="${UPD["result,${num},message,dice,emoji"]}" + MESSAGE[RESULT]="${UPD["result,${num},message,dice,value"]}" + MESSAGE[CAPTION]="$(JsonDecode "${UPD["result,${num},message,caption"]}")" + CAPTION="${MESSAGE[CAPTION]}" # backward compatibility # Chat ID is now parsed when update is received CHAT[LAST_NAME]="$(JsonDecode "${UPD["result,${num},message,chat,last_name"]}")" @@ -212,9 +216,6 @@ process_message() { VENUE[FOURSQUARE]="${UPD["result,${num},message,venue,foursquare_id"]}" fi - # Caption - CAPTION="$(JsonDecode "${UPD["result,${num},message,caption"]}")" - # Location LOCATION[LONGITUDE]="${UPD["result,${num},message,location,longitude"]}" LOCATION[LATITUDE]="${UPD["result,${num},message,location,latitude"]}" From 193ca1e5b9f28263570737d68de793828727b96a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 9 Feb 2021 08:39:50 +0100 Subject: [PATCH 30/43] doc: add MESSAGE[DICE] MESSAGE[CAPTION] --- doc/2_usage.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/2_usage.md b/doc/2_usage.md index a5c31b9..1be84d5 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -172,6 +172,8 @@ These Variables are always present in regular messages: The following variables are set if the message contains optional parts: +* `MESSAGE[CAPTION]`: Picture, Audio, Video, File Captions +* `MESSAGE[DICE]`: Animated DICE Emoji DICE vlaues is contained in `MESSAGE[RESULT]` * `$REPLYTO`: Original message which was replied to * `$REPLYTO`: This array contains the First name, last name, username and user id of the ORIGINAL sender of the message REPLIED to. * `${REPLYTO[ID]}`: ID of message which was replied to @@ -185,7 +187,6 @@ The following variables are set if the message contains optional parts: * `${FORWARD[FIRST_NAME]}`: Original user's first name * `${FORWARD[LAST_NAME]}`: Original user's' last name * `${FORWARD[USERNAME]}`: Original user's username -* `$CAPTION`: Picture, Audio, Video, File Captions * `$URLS`: This array contains the `path` on Telegram server for files send to chat, e.g. photo, video, audio file. * `${URLS[AUDIO]}`: Path to audio file * `${URLS[VIDEO]}`: Path to video @@ -376,5 +377,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.41-0-gad1b91f +#### $$VERSION$$ v1.45-dev-17-ga7d85e3 From 429f271939f825d001f1bba95985ab2459c7d46c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 9 Feb 2021 20:12:22 +0100 Subject: [PATCH 31/43] modules: processUpdates: /_dice_received --- doc/2_usage.md | 2 +- modules/processUpdates.sh | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/doc/2_usage.md b/doc/2_usage.md index 1be84d5..66409a8 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -173,7 +173,7 @@ These Variables are always present in regular messages: The following variables are set if the message contains optional parts: * `MESSAGE[CAPTION]`: Picture, Audio, Video, File Captions -* `MESSAGE[DICE]`: Animated DICE Emoji DICE vlaues is contained in `MESSAGE[RESULT]` +* `MESSAGE[DICE]`: Animated DICE Emoji DICE values is contained in `MESSAGE[RESULT]` * `$REPLYTO`: Original message which was replied to * `$REPLYTO`: This array contains the First name, last name, username and user id of the ORIGINAL sender of the message REPLIED to. * `${REPLYTO[ID]}`: ID of message which was replied to diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index b37dbdc..3755115 100644 --- a/modules/processUpdates.sh +++ b/modules/processUpdates.sh @@ -4,7 +4,7 @@ # File: processUpdates.sh # Note: DO NOT EDIT! this file will be overwritten on update # -#### $$VERSION$$ v1.45-dev-16-gc58fa22 +#### $$VERSION$$ v1.45-dev-18-g193ca1e ################################################################## ############## @@ -128,7 +128,6 @@ process_inline_query() { } process_inline_button() { -# debugging for impelemetation local num="$1" iBUTTON[DATA]="${UPD["result,${num},callback_query,data"]}" iBUTTON[CHAT_ID]="${UPD["result,${num},callback_query,message,chat,id"]}" @@ -148,11 +147,14 @@ process_message() { # Message MESSAGE[0]+="$(JsonDecode "${UPD["result,${num},message,text"]}" | sed 's|\\/|/|g')" MESSAGE[ID]="${UPD["result,${num},message,message_id"]}" - MESSAGE[DICE]="${UPD["result,${num},message,dice,emoji"]}" - MESSAGE[RESULT]="${UPD["result,${num},message,dice,value"]}" MESSAGE[CAPTION]="$(JsonDecode "${UPD["result,${num},message,caption"]}")" CAPTION="${MESSAGE[CAPTION]}" # backward compatibility - + # dice received + MESSAGE[DICE]="${UPD["result,${num},message,dice,emoji"]}" + if [ -n "${MESSAGE[DICE]}" ]; then + MESSAGE[RESULT]="${UPD["result,${num},message,dice,value"]}" + MESSAGE[0]="/_dice_received ${MESSAGE[DICE]} ${MESSAGE[RESULT]}" + fi # Chat ID is now parsed when update is received CHAT[LAST_NAME]="$(JsonDecode "${UPD["result,${num},message,chat,last_name"]}")" CHAT[FIRST_NAME]="$(JsonDecode "${UPD["result,${num},message,chat,first_name"]}")" @@ -230,7 +232,6 @@ process_message() { NEWMEMBER[LAST_NAME]="$(JsonDecode "${UPD["result,${num},message,new_chat_member,last_name"]}")" NEWMEMBER[USERNAME]="$(JsonDecode "${UPD["result,${num},message,new_chat_member,username"]}")" NEWMEMBER[ISBOT]="${UPD["result,${num},message,new_chat_member,is_bot"]}" - [ -z "${MESSAGE[0]}" ] &&\ MESSAGE[0]="/_new_chat_member ${NEWMEMBER[ID]} ${NEWMEMBER[USERNAME]:=${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]}}" fi # left chat member @@ -241,16 +242,15 @@ process_message() { LEFTMEMBER[LAST_NAME]="$(JsonDecode "${UPD["result,${num},message,left_chat_member,last_name"]}")" LEFTMEBER[USERNAME]="$(JsonDecode "${UPD["result,${num},message,left_chat_member,username"]}")" LEFTMEMBER[ISBOT]="${UPD["result,${num},message,left_chat_member,is_bot"]}" - [ -z "${MESSAGE[0]}" ] &&\ MESSAGE[0]="/_left_chat_member ${LEFTMEMBER[ID]} ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}" fi # chat title / photo, check for any of them! if grep -qs -e '\["result",'"${num}"',"message","new_chat_[tp]' <<<"${UPDATE}"; then SERVICE[NEWTITLE]="$(JsonDecode "${UPD["result,${num},message,new_chat_title"]}")" - [ -z "${MESSAGE[0]}" ] && [ -n "${SERVICE[NEWTITLE]}" ] &&\ + [ -n "${SERVICE[NEWTITLE]}" ] &&\ MESSAGE[0]="/_new_chat_title ${USER[ID]} ${SERVICE[NEWTITLE]}" SERVICE[NEWPHOTO]="$(get_file "${UPD["result,${num},message,new_chat_photo,0,file_id"]}")" - [ -z "${MESSAGE[0]}" ] && [ -n "${SERVICE[NEWPHOTO]}" ] &&\ + [ -n "${SERVICE[NEWPHOTO]}" ] &&\ MESSAGE[0]="/_new_chat_photo ${USER[ID]} ${SERVICE[NEWPHOTO]}" fi # pinned message @@ -258,8 +258,7 @@ process_message() { SERVICE[PINNED]="${UPD["result,${num},message,pinned_message,message_id"]}" PINNED[ID]="${SERVICE[PINNED]}" PINNED[MESSAGE]="$(JsonDecode "${UPD["result,${num},message,pinned_message,text"]}")" - [ -z "${MESSAGE[0]}" ] &&\ - MESSAGE[0]="/_new_pinned_message ${USER[ID]} ${PINNED[ID]} ${PINNED[MESSAGE]}" + MESSAGE[0]="/_new_pinned_message ${USER[ID]} ${PINNED[ID]} ${PINNED[MESSAGE]}" fi # migrate to super group if [ -n "${UPD["result,${num},message,migrate_to_chat_id"]}" ]; then @@ -268,8 +267,7 @@ process_message() { # CHAT is already migrated, so set new chat id [ "${CHAT[ID]}" = "${MIGRATE[FROM]}" ] && CHAT[ID]="${MIGRATE[FROM]}" SERVICE[MIGRATE]="${MIGRATE[FROM]} ${MIGRATE[TO]}" - [ -z "${MESSAGE[0]}" ] &&\ - MESSAGE[0]="/_migrate_group ${SERVICE[MIGRATE]}" + MESSAGE[0]="/_migrate_group ${SERVICE[MIGRATE]}" fi # set SERVICE to yes if a service message was received [[ "${SERVICE[*]}" =~ ^[[:blank:]]*$ ]] || SERVICE[0]="yes" From 2f4ef6997152ca8673459a501571e971cb1ea93d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Feb 2021 09:05:00 +0100 Subject: [PATCH 32/43] test: process-message: add and fix tests --- test/d-process_message-test/d-process_message-test.input | 4 ++++ test/d-process_message-test/d-process_message-test.result | 4 +++- test/d-process_message-test/d-process_message-test2.result | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/test/d-process_message-test/d-process_message-test.input b/test/d-process_message-test/d-process_message-test.input index e166651..aebc236 100644 --- a/test/d-process_message-test/d-process_message-test.input +++ b/test/d-process_message-test/d-process_message-test.input @@ -89,3 +89,7 @@ ["result",0,"message","voice","duration"] 2 ["result",0,"message","voice","mime_type"] "audio/ogg" ["result",0,"message","voice","file_size"] 4262 +["result",0,"message","caption"] "Myproteine kein spell check" +["result","dice","emoji"] "\ud83c\udfb2" +["result","dice","value"] 5 + diff --git a/test/d-process_message-test/d-process_message-test.result b/test/d-process_message-test/d-process_message-test.result index 1f2586c..30f3e33 100644 --- a/test/d-process_message-test/d-process_message-test.result +++ b/test/d-process_message-test/d-process_message-test.result @@ -31,11 +31,13 @@ CONTACT: LAST_NAME Pannenhilfe CONTACT: NUMBER 222222 CONTACT: USER_ID CONTACT: VCARD BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD -CAPTION: 0 +CAPTION: 0 Myproteine kein spell check LOCATION: LATITUDE 49.631824 LOCATION: LONGITUDE 8.377072 MESSAGE: 0 😂😝👌☺❤😕😈#⃣🌏🎉🙊🙉☕🚀✈🚂💯✔〽🔚 MESSAGE: ID 6541 +MESSAGE: CAPTION Myproteine kein spell check +MESSAGE: DICE VENUE: ADDRESS Am Rhein 1 VENUE: FOURSQUARE 4c4321afce54e21eee980d1a VENUE: LATITUDE 49.631824 diff --git a/test/d-process_message-test/d-process_message-test2.result b/test/d-process_message-test/d-process_message-test2.result index b259507..65cc520 100644 --- a/test/d-process_message-test/d-process_message-test2.result +++ b/test/d-process_message-test/d-process_message-test2.result @@ -12,7 +12,9 @@ CHAT: USERNAME CAPTION: 0 LOCATION: LATITUDE LOCATION: LONGITUDE -MESSAGE: 0 /_new_chat_member 123456789 Gnadelwartz +MESSAGE: 0 /_new_pinned_message 123456789 3022 new pinned Message +MESSAGE: CAPTION +MESSAGE: DICE MESSAGE: ID 123456789 SERVICE: 0 yes SERVICE: LEFTMEMBER 123456789 @@ -29,5 +31,6 @@ LEFTMEMBER: FIRST_NAME Kay LEFTMEMBER: ID LEFTMEMBER: ISBOT false LEFTMEMBER: LAST_NAME M +LEFTMEMBER: USERNAME Kay M PINNED: ID 3022 PINNED: MESSAGE new pinned Message From e67e43dd2e3d0dfdf8c307d68bc372542f89a3f1 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Feb 2021 10:38:21 +0100 Subject: [PATCH 33/43] mycommands: react on user sent dice --- mycommands.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mycommands.sh b/mycommands.sh index 0ad8f69..e7d34bd 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.45-dev-13-g117255a +#### $$VERSION$$ v1.45-dev-20-g2f4ef69 ####################################################### # shellcheck disable=SC1117 @@ -124,10 +124,15 @@ else case "${MESSAGE}" in ################## # example commands, replace them by your own + '/_dice_re'*) # dice from user received + sleep 5 + local gameresult="*Congratulation ${USER[FIRST_NAME]} ${USER[LAST_NAME]}* you got *${MESSAGE[RESULT]} Points*." + send_markdownv2_message "${CHAT[ID]}" "${gameresult}" + ;; '/game'*) # send random dice, edit list to fit your needs send_dice "${CHAT[ID]}" ":$(printf "slot_machine\ngame_die\ndart\nbasketball\nsoccer\nslot_machine"|sort -R|shuf -n 1shuf -n 1):" if [ "${BOTSENT[OK]}" = "true" ]; then - local gameresult="*Congratulation* you got *${BOTSENT[RESULT]} Points*." + local gameresult="*Congratulation ${USER[FIRST_NAME]}* ${USER[LAST_NAME]} you got *${BOTSENT[RESULT]} Points*." sleep 5 case "${BOTSENT[RESULT]}" in 1) gameresult="*Sorry* only *one Point* ...";; From 6b07242179dd1c16ab4103fb2c002c165e644cf1 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Feb 2021 19:38:17 +0100 Subject: [PATCH 34/43] test: split process_message test files for better coverage --- dev/all-tests.sh | 2 +- test/ALL-tests.inc.sh | 8 +-- test/d-process_message-test.sh | 44 +++++-------- ...ocess_message-test-left_chat_member.input} | 0 ...cess_message-test-left_chat_member.result} | 0 ...t => d-process_message-test-mesage.result} | 0 ...t => d-process_message-test-message.input} | 0 .../d-process_message-test-message.result | 45 +++++++++++++ ...process_message-test-new_chat_member.input | 65 +++++++++++++++++++ ...rocess_message-test-new_chat_member.result | 36 ++++++++++ ...rocess_message-test-new_chat_picture.input | 65 +++++++++++++++++++ ...ocess_message-test-new_chat_picture.result | 36 ++++++++++ ...-process_message-test-pinned_message.input | 65 +++++++++++++++++++ ...process_message-test-pinned_message.result | 36 ++++++++++ 14 files changed, 370 insertions(+), 32 deletions(-) rename test/d-process_message-test/{d-process_message-test2.input => d-process_message-test-left_chat_member.input} (100%) rename test/d-process_message-test/{d-process_message-test2.result => d-process_message-test-left_chat_member.result} (100%) rename test/d-process_message-test/{d-process_message-test.result => d-process_message-test-mesage.result} (100%) rename test/d-process_message-test/{d-process_message-test.input => d-process_message-test-message.input} (100%) create mode 100644 test/d-process_message-test/d-process_message-test-message.result create mode 100644 test/d-process_message-test/d-process_message-test-new_chat_member.input create mode 100644 test/d-process_message-test/d-process_message-test-new_chat_member.result create mode 100644 test/d-process_message-test/d-process_message-test-new_chat_picture.input create mode 100644 test/d-process_message-test/d-process_message-test-new_chat_picture.result create mode 100644 test/d-process_message-test/d-process_message-test-pinned_message.input create mode 100644 test/d-process_message-test/d-process_message-test-pinned_message.result diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 9fb4847..8151a10 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.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-21-ge67e43d ############################################################# #shellcheck disable=SC1090 diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 66ac9a6..031b66e 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.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-21-ge67e43d #=============================================================================== # common variables @@ -39,12 +39,12 @@ export SUCCESS NOSUCCESS NOSUCCESS=" FAILED!" # default input, reference and output files -export INPUTFILE REFFILE INPUTFILE2 REFFILE2 OUTPUTFILE +export INPUTFILE REFFILE OUTPUTFILE INPUTFILELIST + # shellcheck disable=SC2125 + INPUTFILELIST="${DIRME}/${REFDIR}/${REFDIR}-"*".input" OUTPUTFILE="${TESTDIR}/${REFDIR}.out" INPUTFILE="${DIRME}/${REFDIR}/${REFDIR}.input" REFFILE="${DIRME}/${REFDIR}/${REFDIR}.result" - INPUTFILE2="${DIRME}/${REFDIR}/${REFDIR}2.input" - REFFILE2="${DIRME}/${REFDIR}/${REFDIR}2.result" # reset ENVIRONMENT export BASHBOT_URL TESTTOKEN BOTTOKEN BASHBOT_HOME BASHBOT_VAR BASHBOT_ETC diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index dd38dd8..b21760e 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.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-21-ge67e43d #=============================================================================== # include common functions and definitions @@ -38,34 +38,24 @@ declare -Ax UPD # run process_message -------------- ARRAYS="USER CHAT REPLYTO FORWARD URLS CONTACT CAPTION LOCATION MESSAGE VENUE SERVICE NEWMEMBER LEFTMEMBER PINNED" -printf "Check process_message regular message...\n" +printf "Check process_message ...\n" -UPDATE="$(< "${INPUTFILE}")" -Json2Array 'UPD' <"${INPUTFILE}" -set -x -{ pre_process_message "0"; process_message "0"; set +x; } >>"${LOGFILE}" 2>&1; -USER[ID]="123456789"; CHAT[ID]="123456789" +for testfile in ${INPUTFILELIST} +do + printf " ... %s\n" "${testfile##*/}" + testref="${testfile%.input}.result" + UPDATE="$(< "${testfile}")" + Json2Array 'UPD' <"${testfile}" + set -x + { pre_process_message "0"; process_message "0"; set +x; } >>"${LOGFILE}" 2>&1; + USER[ID]="123456789"; CHAT[ID]="123456789" -# output processed input -# shellcheck disable=SC2086 -print_array ${ARRAYS} >"${OUTPUTFILE}" -compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1 + # output processed input + # shellcheck disable=SC2086 + print_array ${ARRAYS} >"${OUTPUTFILE}" + compare_sorted "${testref}" "${OUTPUTFILE}" || exit 1 + printf "%s\n" "${SUCCESS}" -# run process_message ------------ -printf "Check process_message service message...\n" - -UPDATE="$(cat "${INPUTFILE2}")" -Json2Array 'UPD' <"${INPUTFILE2}" -set -x -{ pre_process_message "0"; process_message "0"; set +x; } >>"${LOGFILE}" 2>&1; -USER[ID]="123456789"; CHAT[ID]="123456789" - -# output processed input -# shellcheck disable=SC2086 -print_array ${ARRAYS} >"${OUTPUTFILE}" -compare_sorted "${REFFILE2}" "${OUTPUTFILE}" || exit 1 - - -printf "%s\n" "${SUCCESS}" +done cd "${DIRME}" || exit 1 diff --git a/test/d-process_message-test/d-process_message-test2.input b/test/d-process_message-test/d-process_message-test-left_chat_member.input similarity index 100% rename from test/d-process_message-test/d-process_message-test2.input rename to test/d-process_message-test/d-process_message-test-left_chat_member.input diff --git a/test/d-process_message-test/d-process_message-test2.result b/test/d-process_message-test/d-process_message-test-left_chat_member.result similarity index 100% rename from test/d-process_message-test/d-process_message-test2.result rename to test/d-process_message-test/d-process_message-test-left_chat_member.result diff --git a/test/d-process_message-test/d-process_message-test.result b/test/d-process_message-test/d-process_message-test-mesage.result similarity index 100% rename from test/d-process_message-test/d-process_message-test.result rename to test/d-process_message-test/d-process_message-test-mesage.result diff --git a/test/d-process_message-test/d-process_message-test.input b/test/d-process_message-test/d-process_message-test-message.input similarity index 100% rename from test/d-process_message-test/d-process_message-test.input rename to test/d-process_message-test/d-process_message-test-message.input diff --git a/test/d-process_message-test/d-process_message-test-message.result b/test/d-process_message-test/d-process_message-test-message.result new file mode 100644 index 0000000..26fc1a0 --- /dev/null +++ b/test/d-process_message-test/d-process_message-test-message.result @@ -0,0 +1,45 @@ +USER: FIRST_NAME Kay +USER: ID 123456789 +USER: LAST_NAME M +USER: USERNAME Gnadelwartz +CHAT: ALL_ADMIN +CHAT: FIRST_NAME Test +CHAT: ID 123456789 +CHAT: LAST_NAME Bot +CHAT: TITLE BotTestTitle +CHAT: TYPE private +CHAT: USERNAME BotTest +REPLYTO: 0 Ich bin der Deal-O-Mat Bot. Für eine Liste der Befehle sende /help +REPLYTO: FIRST_NAME dealzbot +REPLYTO: ID 6542 +REPLYTO: LAST_NAME +REPLYTO: UID 987654321 +REPLYTO: USERNAME Deal_O_Mat_bot +FORWARD: FIRST_NAME Kay +FORWARD: ID 6541 +FORWARD: LAST_NAME M +FORWARD: UID 123456789 +FORWARD: USERNAME Gnadelwartz +URLS: AUDIO audio-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +URLS: DOCUMENT document-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +URLS: PHOTO photo-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +URLS: STICKER sticker-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +URLS: VIDEO video-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +URLS: VOICE voice-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa +CONTACT: FIRST_NAME ADAC +CONTACT: LAST_NAME Pannenhilfe +CONTACT: NUMBER 222222 +CONTACT: USER_ID +CONTACT: VCARD BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD +CAPTION: 0 Myproteine kein spell check +LOCATION: LATITUDE 49.631824 +LOCATION: LONGITUDE 8.377072 +MESSAGE: 0 😂😝👌☺❤😕😈#⃣🌏🎉🙊🙉☕🚀✈🚂💯✔〽🔚 +MESSAGE: CAPTION Myproteine kein spell check +MESSAGE: DICE +MESSAGE: ID 6541 +VENUE: ADDRESS Am Rhein 1 +VENUE: FOURSQUARE 4c4321afce54e21eee980d1a +VENUE: LATITUDE 49.631824 +VENUE: LONGITUDE 8.377072 +VENUE: TITLE Kolb's Biergarten diff --git a/test/d-process_message-test/d-process_message-test-new_chat_member.input b/test/d-process_message-test/d-process_message-test-new_chat_member.input new file mode 100644 index 0000000..64c42e0 --- /dev/null +++ b/test/d-process_message-test/d-process_message-test-new_chat_member.input @@ -0,0 +1,65 @@ +["ok"] true +["result",0,"update_id"] 123456789 +["result",0,"message","message_id"] 123456789 +["result",0,"message","from","id"] 123456789 +["result",0,"message","from","is_bot"] false +["result",0,"message","from","first_name"] "Kay" +["result",0,"message","from","last_name"] "M" +["result",0,"message","from","username"] "Gnadelwartz" +["result",0,"message","from","language_code"] "de" +["result",0,"message","chat","id"] -123456789 +["result",0,"message","chat","title"] "Testgruppe bot only test" +["result",0,"message","chat","type"] "group" +["result",0,"message","chat","all_members_are_administrators"] true +["result",0,"message","date"] 1592372719 + +["result",0,"message","left_chat_participant","id"] 123456789 +["result",0,"message","left_chat_participant","is_bot"] false +["result",0,"message","left_chat_participant","first_name"] "Kay" +["result",0,"message","left_chat_participant","last_name"] "M" +["result",0,"message","left_chat_participant","username"] "Gnadelwartz" +["result",0,"message","left_chat_member","id"] 123456789 +["result",0,"message","left_chat_member","is_bot"] false +["result",0,"message","left_chat_member","first_name"] "Kay" +["result",0,"message","left_chat_member","last_name"] "M" +["result",0,"message","left_chat_member","username"] "Gnadelwartz" + +["result",0,"message","new_chat_participant","id"] 123456789 +["result",0,"message","new_chat_participant","is_bot"] false +["result",0,"message","new_chat_participant","first_name"] "Kay" +["result",0,"message","new_chat_participant","last_name"] "M" +["result",0,"message","new_chat_participant","username"] "Gnadelwartz" +["result",0,"message","new_chat_member","id"] 123456789 +["result",0,"message","new_chat_member","is_bot"] false +["result",0,"message","new_chat_member","first_name"] "Kay" +["result",0,"message","new_chat_member","last_name"] "M" +["result",0,"message","new_chat_member","username"] "Gnadelwartz" + +["result",0,"message","new_chat_photo",0,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE" +["result",0,"message","new_chat_photo",0,"file_unique_id"] "AQADK6S6ki4AAzdIAwAB" +["result",0,"message","new_chat_photo",0,"file_size"] 5939 +["result",0,"message","new_chat_photo",0,"width"] 160 +["result",0,"message","new_chat_photo",0,"height"] 160 +["result",0,"message","new_chat_photo",1,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANiAAM4SAMAARoE" +["result",0,"message","new_chat_photo",1,"file_unique_id"] "AQADK6S6ki4AAzhIAwAB" +["result",0,"message","new_chat_photo",1,"file_size"] 14124 +["result",0,"message","new_chat_photo",1,"width"] 320 +["result",0,"message","new_chat_photo",1,"height"] 320 +["result",0,"message","new_chat_photo",2,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANjAAM5SAMAARoE" +["result",0,"message","new_chat_photo",2,"file_unique_id"] "AQADK6S6ki4AAzlIAwAB" +["result",0,"message","new_chat_photo",2,"file_size"] 34052 +["result",0,"message","new_chat_photo",2,"width"] 640 +["result",0,"message","new_chat_photo",2,"height"] 640 + +["result",0,"message","pinned_message","message_id"] 3022 +["result",0,"message","pinned_message","from","id"] 796814662 +["result",0,"message","pinned_message","from","is_bot"] true +["result",0,"message","pinned_message","from","first_name"] "DealOMat" +["result",0,"message","pinned_message","from","username"] "Deal_O_Mat_bot" +["result",0,"message","pinned_message","chat","id"] -1001220313778 +["result",0,"message","pinned_message","chat","title"] "Testgruppe bot only test" +["result",0,"message","pinned_message","chat","type"] "supergroup" +["result",0,"message","pinned_message","date"] 1593121152 +["result",0,"message","pinned_message","text"] "new pinned Message" + +["result",0,"message","new_chat_title"] "new Testgruppe bot only" diff --git a/test/d-process_message-test/d-process_message-test-new_chat_member.result b/test/d-process_message-test/d-process_message-test-new_chat_member.result new file mode 100644 index 0000000..65cc520 --- /dev/null +++ b/test/d-process_message-test/d-process_message-test-new_chat_member.result @@ -0,0 +1,36 @@ +USER: FIRST_NAME Kay +USER: ID 123456789 +USER: LAST_NAME M +USER: USERNAME Gnadelwartz +CHAT: ALL_ADMIN true +CHAT: FIRST_NAME +CHAT: ID 123456789 +CHAT: LAST_NAME +CHAT: TITLE Testgruppe bot only test +CHAT: TYPE group +CHAT: USERNAME +CAPTION: 0 +LOCATION: LATITUDE +LOCATION: LONGITUDE +MESSAGE: 0 /_new_pinned_message 123456789 3022 new pinned Message +MESSAGE: CAPTION +MESSAGE: DICE +MESSAGE: ID 123456789 +SERVICE: 0 yes +SERVICE: LEFTMEMBER 123456789 +SERVICE: NEWMEMBER 123456789 +SERVICE: NEWPHOTO AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE +SERVICE: NEWTITLE new Testgruppe bot only +SERVICE: PINNED 3022 +NEWMEMBER: FIRST_NAME Kay +NEWMEMBER: ID 123456789 +NEWMEMBER: ISBOT false +NEWMEMBER: LAST_NAME M +NEWMEMBER: USERNAME Gnadelwartz +LEFTMEMBER: FIRST_NAME Kay +LEFTMEMBER: ID +LEFTMEMBER: ISBOT false +LEFTMEMBER: LAST_NAME M +LEFTMEMBER: USERNAME Kay M +PINNED: ID 3022 +PINNED: MESSAGE new pinned Message diff --git a/test/d-process_message-test/d-process_message-test-new_chat_picture.input b/test/d-process_message-test/d-process_message-test-new_chat_picture.input new file mode 100644 index 0000000..64c42e0 --- /dev/null +++ b/test/d-process_message-test/d-process_message-test-new_chat_picture.input @@ -0,0 +1,65 @@ +["ok"] true +["result",0,"update_id"] 123456789 +["result",0,"message","message_id"] 123456789 +["result",0,"message","from","id"] 123456789 +["result",0,"message","from","is_bot"] false +["result",0,"message","from","first_name"] "Kay" +["result",0,"message","from","last_name"] "M" +["result",0,"message","from","username"] "Gnadelwartz" +["result",0,"message","from","language_code"] "de" +["result",0,"message","chat","id"] -123456789 +["result",0,"message","chat","title"] "Testgruppe bot only test" +["result",0,"message","chat","type"] "group" +["result",0,"message","chat","all_members_are_administrators"] true +["result",0,"message","date"] 1592372719 + +["result",0,"message","left_chat_participant","id"] 123456789 +["result",0,"message","left_chat_participant","is_bot"] false +["result",0,"message","left_chat_participant","first_name"] "Kay" +["result",0,"message","left_chat_participant","last_name"] "M" +["result",0,"message","left_chat_participant","username"] "Gnadelwartz" +["result",0,"message","left_chat_member","id"] 123456789 +["result",0,"message","left_chat_member","is_bot"] false +["result",0,"message","left_chat_member","first_name"] "Kay" +["result",0,"message","left_chat_member","last_name"] "M" +["result",0,"message","left_chat_member","username"] "Gnadelwartz" + +["result",0,"message","new_chat_participant","id"] 123456789 +["result",0,"message","new_chat_participant","is_bot"] false +["result",0,"message","new_chat_participant","first_name"] "Kay" +["result",0,"message","new_chat_participant","last_name"] "M" +["result",0,"message","new_chat_participant","username"] "Gnadelwartz" +["result",0,"message","new_chat_member","id"] 123456789 +["result",0,"message","new_chat_member","is_bot"] false +["result",0,"message","new_chat_member","first_name"] "Kay" +["result",0,"message","new_chat_member","last_name"] "M" +["result",0,"message","new_chat_member","username"] "Gnadelwartz" + +["result",0,"message","new_chat_photo",0,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE" +["result",0,"message","new_chat_photo",0,"file_unique_id"] "AQADK6S6ki4AAzdIAwAB" +["result",0,"message","new_chat_photo",0,"file_size"] 5939 +["result",0,"message","new_chat_photo",0,"width"] 160 +["result",0,"message","new_chat_photo",0,"height"] 160 +["result",0,"message","new_chat_photo",1,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANiAAM4SAMAARoE" +["result",0,"message","new_chat_photo",1,"file_unique_id"] "AQADK6S6ki4AAzhIAwAB" +["result",0,"message","new_chat_photo",1,"file_size"] 14124 +["result",0,"message","new_chat_photo",1,"width"] 320 +["result",0,"message","new_chat_photo",1,"height"] 320 +["result",0,"message","new_chat_photo",2,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANjAAM5SAMAARoE" +["result",0,"message","new_chat_photo",2,"file_unique_id"] "AQADK6S6ki4AAzlIAwAB" +["result",0,"message","new_chat_photo",2,"file_size"] 34052 +["result",0,"message","new_chat_photo",2,"width"] 640 +["result",0,"message","new_chat_photo",2,"height"] 640 + +["result",0,"message","pinned_message","message_id"] 3022 +["result",0,"message","pinned_message","from","id"] 796814662 +["result",0,"message","pinned_message","from","is_bot"] true +["result",0,"message","pinned_message","from","first_name"] "DealOMat" +["result",0,"message","pinned_message","from","username"] "Deal_O_Mat_bot" +["result",0,"message","pinned_message","chat","id"] -1001220313778 +["result",0,"message","pinned_message","chat","title"] "Testgruppe bot only test" +["result",0,"message","pinned_message","chat","type"] "supergroup" +["result",0,"message","pinned_message","date"] 1593121152 +["result",0,"message","pinned_message","text"] "new pinned Message" + +["result",0,"message","new_chat_title"] "new Testgruppe bot only" diff --git a/test/d-process_message-test/d-process_message-test-new_chat_picture.result b/test/d-process_message-test/d-process_message-test-new_chat_picture.result new file mode 100644 index 0000000..65cc520 --- /dev/null +++ b/test/d-process_message-test/d-process_message-test-new_chat_picture.result @@ -0,0 +1,36 @@ +USER: FIRST_NAME Kay +USER: ID 123456789 +USER: LAST_NAME M +USER: USERNAME Gnadelwartz +CHAT: ALL_ADMIN true +CHAT: FIRST_NAME +CHAT: ID 123456789 +CHAT: LAST_NAME +CHAT: TITLE Testgruppe bot only test +CHAT: TYPE group +CHAT: USERNAME +CAPTION: 0 +LOCATION: LATITUDE +LOCATION: LONGITUDE +MESSAGE: 0 /_new_pinned_message 123456789 3022 new pinned Message +MESSAGE: CAPTION +MESSAGE: DICE +MESSAGE: ID 123456789 +SERVICE: 0 yes +SERVICE: LEFTMEMBER 123456789 +SERVICE: NEWMEMBER 123456789 +SERVICE: NEWPHOTO AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE +SERVICE: NEWTITLE new Testgruppe bot only +SERVICE: PINNED 3022 +NEWMEMBER: FIRST_NAME Kay +NEWMEMBER: ID 123456789 +NEWMEMBER: ISBOT false +NEWMEMBER: LAST_NAME M +NEWMEMBER: USERNAME Gnadelwartz +LEFTMEMBER: FIRST_NAME Kay +LEFTMEMBER: ID +LEFTMEMBER: ISBOT false +LEFTMEMBER: LAST_NAME M +LEFTMEMBER: USERNAME Kay M +PINNED: ID 3022 +PINNED: MESSAGE new pinned Message diff --git a/test/d-process_message-test/d-process_message-test-pinned_message.input b/test/d-process_message-test/d-process_message-test-pinned_message.input new file mode 100644 index 0000000..64c42e0 --- /dev/null +++ b/test/d-process_message-test/d-process_message-test-pinned_message.input @@ -0,0 +1,65 @@ +["ok"] true +["result",0,"update_id"] 123456789 +["result",0,"message","message_id"] 123456789 +["result",0,"message","from","id"] 123456789 +["result",0,"message","from","is_bot"] false +["result",0,"message","from","first_name"] "Kay" +["result",0,"message","from","last_name"] "M" +["result",0,"message","from","username"] "Gnadelwartz" +["result",0,"message","from","language_code"] "de" +["result",0,"message","chat","id"] -123456789 +["result",0,"message","chat","title"] "Testgruppe bot only test" +["result",0,"message","chat","type"] "group" +["result",0,"message","chat","all_members_are_administrators"] true +["result",0,"message","date"] 1592372719 + +["result",0,"message","left_chat_participant","id"] 123456789 +["result",0,"message","left_chat_participant","is_bot"] false +["result",0,"message","left_chat_participant","first_name"] "Kay" +["result",0,"message","left_chat_participant","last_name"] "M" +["result",0,"message","left_chat_participant","username"] "Gnadelwartz" +["result",0,"message","left_chat_member","id"] 123456789 +["result",0,"message","left_chat_member","is_bot"] false +["result",0,"message","left_chat_member","first_name"] "Kay" +["result",0,"message","left_chat_member","last_name"] "M" +["result",0,"message","left_chat_member","username"] "Gnadelwartz" + +["result",0,"message","new_chat_participant","id"] 123456789 +["result",0,"message","new_chat_participant","is_bot"] false +["result",0,"message","new_chat_participant","first_name"] "Kay" +["result",0,"message","new_chat_participant","last_name"] "M" +["result",0,"message","new_chat_participant","username"] "Gnadelwartz" +["result",0,"message","new_chat_member","id"] 123456789 +["result",0,"message","new_chat_member","is_bot"] false +["result",0,"message","new_chat_member","first_name"] "Kay" +["result",0,"message","new_chat_member","last_name"] "M" +["result",0,"message","new_chat_member","username"] "Gnadelwartz" + +["result",0,"message","new_chat_photo",0,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE" +["result",0,"message","new_chat_photo",0,"file_unique_id"] "AQADK6S6ki4AAzdIAwAB" +["result",0,"message","new_chat_photo",0,"file_size"] 5939 +["result",0,"message","new_chat_photo",0,"width"] 160 +["result",0,"message","new_chat_photo",0,"height"] 160 +["result",0,"message","new_chat_photo",1,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANiAAM4SAMAARoE" +["result",0,"message","new_chat_photo",1,"file_unique_id"] "AQADK6S6ki4AAzhIAwAB" +["result",0,"message","new_chat_photo",1,"file_size"] 14124 +["result",0,"message","new_chat_photo",1,"width"] 320 +["result",0,"message","new_chat_photo",1,"height"] 320 +["result",0,"message","new_chat_photo",2,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANjAAM5SAMAARoE" +["result",0,"message","new_chat_photo",2,"file_unique_id"] "AQADK6S6ki4AAzlIAwAB" +["result",0,"message","new_chat_photo",2,"file_size"] 34052 +["result",0,"message","new_chat_photo",2,"width"] 640 +["result",0,"message","new_chat_photo",2,"height"] 640 + +["result",0,"message","pinned_message","message_id"] 3022 +["result",0,"message","pinned_message","from","id"] 796814662 +["result",0,"message","pinned_message","from","is_bot"] true +["result",0,"message","pinned_message","from","first_name"] "DealOMat" +["result",0,"message","pinned_message","from","username"] "Deal_O_Mat_bot" +["result",0,"message","pinned_message","chat","id"] -1001220313778 +["result",0,"message","pinned_message","chat","title"] "Testgruppe bot only test" +["result",0,"message","pinned_message","chat","type"] "supergroup" +["result",0,"message","pinned_message","date"] 1593121152 +["result",0,"message","pinned_message","text"] "new pinned Message" + +["result",0,"message","new_chat_title"] "new Testgruppe bot only" diff --git a/test/d-process_message-test/d-process_message-test-pinned_message.result b/test/d-process_message-test/d-process_message-test-pinned_message.result new file mode 100644 index 0000000..65cc520 --- /dev/null +++ b/test/d-process_message-test/d-process_message-test-pinned_message.result @@ -0,0 +1,36 @@ +USER: FIRST_NAME Kay +USER: ID 123456789 +USER: LAST_NAME M +USER: USERNAME Gnadelwartz +CHAT: ALL_ADMIN true +CHAT: FIRST_NAME +CHAT: ID 123456789 +CHAT: LAST_NAME +CHAT: TITLE Testgruppe bot only test +CHAT: TYPE group +CHAT: USERNAME +CAPTION: 0 +LOCATION: LATITUDE +LOCATION: LONGITUDE +MESSAGE: 0 /_new_pinned_message 123456789 3022 new pinned Message +MESSAGE: CAPTION +MESSAGE: DICE +MESSAGE: ID 123456789 +SERVICE: 0 yes +SERVICE: LEFTMEMBER 123456789 +SERVICE: NEWMEMBER 123456789 +SERVICE: NEWPHOTO AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE +SERVICE: NEWTITLE new Testgruppe bot only +SERVICE: PINNED 3022 +NEWMEMBER: FIRST_NAME Kay +NEWMEMBER: ID 123456789 +NEWMEMBER: ISBOT false +NEWMEMBER: LAST_NAME M +NEWMEMBER: USERNAME Gnadelwartz +LEFTMEMBER: FIRST_NAME Kay +LEFTMEMBER: ID +LEFTMEMBER: ISBOT false +LEFTMEMBER: LAST_NAME M +LEFTMEMBER: USERNAME Kay M +PINNED: ID 3022 +PINNED: MESSAGE new pinned Message From 805a74eb6d90d3240c4764cac5ffbe53706cf04d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Feb 2021 19:52:52 +0100 Subject: [PATCH 35/43] test: process_message: fix test files --- test/d-process_message-test.sh | 2 +- ...rocess_message-test-left_chat_member.input | 40 ------------------- ...ocess_message-test-left_chat_member.result | 13 +----- ...process_message-test-new_chat_member.input | 40 ------------------- ...rocess_message-test-new_chat_member.result | 15 ++----- ...rocess_message-test-new_chat_picture.input | 35 ---------------- ...ocess_message-test-new_chat_picture.result | 19 +-------- ...-process_message-test-new_chat_title.input | 16 ++++++++ ...process_message-test-new_chat_title.result | 21 ++++++++++ ...-process_message-test-pinned_message.input | 38 ------------------ ...process_message-test-pinned_message.result | 14 +------ 11 files changed, 45 insertions(+), 208 deletions(-) create mode 100644 test/d-process_message-test/d-process_message-test-new_chat_title.input create mode 100644 test/d-process_message-test/d-process_message-test-new_chat_title.result diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index b21760e..fa7c971 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.45-dev-21-ge67e43d +#### $$VERSION$$ v1.45-dev-22-g6b07242 #=============================================================================== # include common functions and definitions diff --git a/test/d-process_message-test/d-process_message-test-left_chat_member.input b/test/d-process_message-test/d-process_message-test-left_chat_member.input index 64c42e0..86f3faa 100644 --- a/test/d-process_message-test/d-process_message-test-left_chat_member.input +++ b/test/d-process_message-test/d-process_message-test-left_chat_member.input @@ -23,43 +23,3 @@ ["result",0,"message","left_chat_member","first_name"] "Kay" ["result",0,"message","left_chat_member","last_name"] "M" ["result",0,"message","left_chat_member","username"] "Gnadelwartz" - -["result",0,"message","new_chat_participant","id"] 123456789 -["result",0,"message","new_chat_participant","is_bot"] false -["result",0,"message","new_chat_participant","first_name"] "Kay" -["result",0,"message","new_chat_participant","last_name"] "M" -["result",0,"message","new_chat_participant","username"] "Gnadelwartz" -["result",0,"message","new_chat_member","id"] 123456789 -["result",0,"message","new_chat_member","is_bot"] false -["result",0,"message","new_chat_member","first_name"] "Kay" -["result",0,"message","new_chat_member","last_name"] "M" -["result",0,"message","new_chat_member","username"] "Gnadelwartz" - -["result",0,"message","new_chat_photo",0,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE" -["result",0,"message","new_chat_photo",0,"file_unique_id"] "AQADK6S6ki4AAzdIAwAB" -["result",0,"message","new_chat_photo",0,"file_size"] 5939 -["result",0,"message","new_chat_photo",0,"width"] 160 -["result",0,"message","new_chat_photo",0,"height"] 160 -["result",0,"message","new_chat_photo",1,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANiAAM4SAMAARoE" -["result",0,"message","new_chat_photo",1,"file_unique_id"] "AQADK6S6ki4AAzhIAwAB" -["result",0,"message","new_chat_photo",1,"file_size"] 14124 -["result",0,"message","new_chat_photo",1,"width"] 320 -["result",0,"message","new_chat_photo",1,"height"] 320 -["result",0,"message","new_chat_photo",2,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANjAAM5SAMAARoE" -["result",0,"message","new_chat_photo",2,"file_unique_id"] "AQADK6S6ki4AAzlIAwAB" -["result",0,"message","new_chat_photo",2,"file_size"] 34052 -["result",0,"message","new_chat_photo",2,"width"] 640 -["result",0,"message","new_chat_photo",2,"height"] 640 - -["result",0,"message","pinned_message","message_id"] 3022 -["result",0,"message","pinned_message","from","id"] 796814662 -["result",0,"message","pinned_message","from","is_bot"] true -["result",0,"message","pinned_message","from","first_name"] "DealOMat" -["result",0,"message","pinned_message","from","username"] "Deal_O_Mat_bot" -["result",0,"message","pinned_message","chat","id"] -1001220313778 -["result",0,"message","pinned_message","chat","title"] "Testgruppe bot only test" -["result",0,"message","pinned_message","chat","type"] "supergroup" -["result",0,"message","pinned_message","date"] 1593121152 -["result",0,"message","pinned_message","text"] "new pinned Message" - -["result",0,"message","new_chat_title"] "new Testgruppe bot only" diff --git a/test/d-process_message-test/d-process_message-test-left_chat_member.result b/test/d-process_message-test/d-process_message-test-left_chat_member.result index 65cc520..4c930ca 100644 --- a/test/d-process_message-test/d-process_message-test-left_chat_member.result +++ b/test/d-process_message-test/d-process_message-test-left_chat_member.result @@ -12,25 +12,14 @@ CHAT: USERNAME CAPTION: 0 LOCATION: LATITUDE LOCATION: LONGITUDE -MESSAGE: 0 /_new_pinned_message 123456789 3022 new pinned Message +MESSAGE: 0 /_left_chat_member Kay M MESSAGE: CAPTION MESSAGE: DICE MESSAGE: ID 123456789 SERVICE: 0 yes SERVICE: LEFTMEMBER 123456789 -SERVICE: NEWMEMBER 123456789 -SERVICE: NEWPHOTO AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE -SERVICE: NEWTITLE new Testgruppe bot only -SERVICE: PINNED 3022 -NEWMEMBER: FIRST_NAME Kay -NEWMEMBER: ID 123456789 -NEWMEMBER: ISBOT false -NEWMEMBER: LAST_NAME M -NEWMEMBER: USERNAME Gnadelwartz LEFTMEMBER: FIRST_NAME Kay LEFTMEMBER: ID LEFTMEMBER: ISBOT false LEFTMEMBER: LAST_NAME M LEFTMEMBER: USERNAME Kay M -PINNED: ID 3022 -PINNED: MESSAGE new pinned Message diff --git a/test/d-process_message-test/d-process_message-test-new_chat_member.input b/test/d-process_message-test/d-process_message-test-new_chat_member.input index 64c42e0..b2478b7 100644 --- a/test/d-process_message-test/d-process_message-test-new_chat_member.input +++ b/test/d-process_message-test/d-process_message-test-new_chat_member.input @@ -13,17 +13,6 @@ ["result",0,"message","chat","all_members_are_administrators"] true ["result",0,"message","date"] 1592372719 -["result",0,"message","left_chat_participant","id"] 123456789 -["result",0,"message","left_chat_participant","is_bot"] false -["result",0,"message","left_chat_participant","first_name"] "Kay" -["result",0,"message","left_chat_participant","last_name"] "M" -["result",0,"message","left_chat_participant","username"] "Gnadelwartz" -["result",0,"message","left_chat_member","id"] 123456789 -["result",0,"message","left_chat_member","is_bot"] false -["result",0,"message","left_chat_member","first_name"] "Kay" -["result",0,"message","left_chat_member","last_name"] "M" -["result",0,"message","left_chat_member","username"] "Gnadelwartz" - ["result",0,"message","new_chat_participant","id"] 123456789 ["result",0,"message","new_chat_participant","is_bot"] false ["result",0,"message","new_chat_participant","first_name"] "Kay" @@ -34,32 +23,3 @@ ["result",0,"message","new_chat_member","first_name"] "Kay" ["result",0,"message","new_chat_member","last_name"] "M" ["result",0,"message","new_chat_member","username"] "Gnadelwartz" - -["result",0,"message","new_chat_photo",0,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE" -["result",0,"message","new_chat_photo",0,"file_unique_id"] "AQADK6S6ki4AAzdIAwAB" -["result",0,"message","new_chat_photo",0,"file_size"] 5939 -["result",0,"message","new_chat_photo",0,"width"] 160 -["result",0,"message","new_chat_photo",0,"height"] 160 -["result",0,"message","new_chat_photo",1,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANiAAM4SAMAARoE" -["result",0,"message","new_chat_photo",1,"file_unique_id"] "AQADK6S6ki4AAzhIAwAB" -["result",0,"message","new_chat_photo",1,"file_size"] 14124 -["result",0,"message","new_chat_photo",1,"width"] 320 -["result",0,"message","new_chat_photo",1,"height"] 320 -["result",0,"message","new_chat_photo",2,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANjAAM5SAMAARoE" -["result",0,"message","new_chat_photo",2,"file_unique_id"] "AQADK6S6ki4AAzlIAwAB" -["result",0,"message","new_chat_photo",2,"file_size"] 34052 -["result",0,"message","new_chat_photo",2,"width"] 640 -["result",0,"message","new_chat_photo",2,"height"] 640 - -["result",0,"message","pinned_message","message_id"] 3022 -["result",0,"message","pinned_message","from","id"] 796814662 -["result",0,"message","pinned_message","from","is_bot"] true -["result",0,"message","pinned_message","from","first_name"] "DealOMat" -["result",0,"message","pinned_message","from","username"] "Deal_O_Mat_bot" -["result",0,"message","pinned_message","chat","id"] -1001220313778 -["result",0,"message","pinned_message","chat","title"] "Testgruppe bot only test" -["result",0,"message","pinned_message","chat","type"] "supergroup" -["result",0,"message","pinned_message","date"] 1593121152 -["result",0,"message","pinned_message","text"] "new pinned Message" - -["result",0,"message","new_chat_title"] "new Testgruppe bot only" diff --git a/test/d-process_message-test/d-process_message-test-new_chat_member.result b/test/d-process_message-test/d-process_message-test-new_chat_member.result index 65cc520..cef706d 100644 --- a/test/d-process_message-test/d-process_message-test-new_chat_member.result +++ b/test/d-process_message-test/d-process_message-test-new_chat_member.result @@ -12,25 +12,16 @@ CHAT: USERNAME CAPTION: 0 LOCATION: LATITUDE LOCATION: LONGITUDE -MESSAGE: 0 /_new_pinned_message 123456789 3022 new pinned Message +MESSAGE: 0 /_new_chat_member 123456789 Gnadelwartz MESSAGE: CAPTION MESSAGE: DICE MESSAGE: ID 123456789 SERVICE: 0 yes -SERVICE: LEFTMEMBER 123456789 SERVICE: NEWMEMBER 123456789 -SERVICE: NEWPHOTO AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE -SERVICE: NEWTITLE new Testgruppe bot only -SERVICE: PINNED 3022 +SERVICE: NEWPHOTO +SERVICE: NEWTITLE NEWMEMBER: FIRST_NAME Kay NEWMEMBER: ID 123456789 NEWMEMBER: ISBOT false NEWMEMBER: LAST_NAME M NEWMEMBER: USERNAME Gnadelwartz -LEFTMEMBER: FIRST_NAME Kay -LEFTMEMBER: ID -LEFTMEMBER: ISBOT false -LEFTMEMBER: LAST_NAME M -LEFTMEMBER: USERNAME Kay M -PINNED: ID 3022 -PINNED: MESSAGE new pinned Message diff --git a/test/d-process_message-test/d-process_message-test-new_chat_picture.input b/test/d-process_message-test/d-process_message-test-new_chat_picture.input index 64c42e0..7d72c2b 100644 --- a/test/d-process_message-test/d-process_message-test-new_chat_picture.input +++ b/test/d-process_message-test/d-process_message-test-new_chat_picture.input @@ -13,28 +13,6 @@ ["result",0,"message","chat","all_members_are_administrators"] true ["result",0,"message","date"] 1592372719 -["result",0,"message","left_chat_participant","id"] 123456789 -["result",0,"message","left_chat_participant","is_bot"] false -["result",0,"message","left_chat_participant","first_name"] "Kay" -["result",0,"message","left_chat_participant","last_name"] "M" -["result",0,"message","left_chat_participant","username"] "Gnadelwartz" -["result",0,"message","left_chat_member","id"] 123456789 -["result",0,"message","left_chat_member","is_bot"] false -["result",0,"message","left_chat_member","first_name"] "Kay" -["result",0,"message","left_chat_member","last_name"] "M" -["result",0,"message","left_chat_member","username"] "Gnadelwartz" - -["result",0,"message","new_chat_participant","id"] 123456789 -["result",0,"message","new_chat_participant","is_bot"] false -["result",0,"message","new_chat_participant","first_name"] "Kay" -["result",0,"message","new_chat_participant","last_name"] "M" -["result",0,"message","new_chat_participant","username"] "Gnadelwartz" -["result",0,"message","new_chat_member","id"] 123456789 -["result",0,"message","new_chat_member","is_bot"] false -["result",0,"message","new_chat_member","first_name"] "Kay" -["result",0,"message","new_chat_member","last_name"] "M" -["result",0,"message","new_chat_member","username"] "Gnadelwartz" - ["result",0,"message","new_chat_photo",0,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE" ["result",0,"message","new_chat_photo",0,"file_unique_id"] "AQADK6S6ki4AAzdIAwAB" ["result",0,"message","new_chat_photo",0,"file_size"] 5939 @@ -50,16 +28,3 @@ ["result",0,"message","new_chat_photo",2,"file_size"] 34052 ["result",0,"message","new_chat_photo",2,"width"] 640 ["result",0,"message","new_chat_photo",2,"height"] 640 - -["result",0,"message","pinned_message","message_id"] 3022 -["result",0,"message","pinned_message","from","id"] 796814662 -["result",0,"message","pinned_message","from","is_bot"] true -["result",0,"message","pinned_message","from","first_name"] "DealOMat" -["result",0,"message","pinned_message","from","username"] "Deal_O_Mat_bot" -["result",0,"message","pinned_message","chat","id"] -1001220313778 -["result",0,"message","pinned_message","chat","title"] "Testgruppe bot only test" -["result",0,"message","pinned_message","chat","type"] "supergroup" -["result",0,"message","pinned_message","date"] 1593121152 -["result",0,"message","pinned_message","text"] "new pinned Message" - -["result",0,"message","new_chat_title"] "new Testgruppe bot only" diff --git a/test/d-process_message-test/d-process_message-test-new_chat_picture.result b/test/d-process_message-test/d-process_message-test-new_chat_picture.result index 65cc520..06013b0 100644 --- a/test/d-process_message-test/d-process_message-test-new_chat_picture.result +++ b/test/d-process_message-test/d-process_message-test-new_chat_picture.result @@ -12,25 +12,10 @@ CHAT: USERNAME CAPTION: 0 LOCATION: LATITUDE LOCATION: LONGITUDE -MESSAGE: 0 /_new_pinned_message 123456789 3022 new pinned Message +MESSAGE: 0 /_new_chat_photo 123456789 AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE MESSAGE: CAPTION MESSAGE: DICE MESSAGE: ID 123456789 SERVICE: 0 yes -SERVICE: LEFTMEMBER 123456789 -SERVICE: NEWMEMBER 123456789 SERVICE: NEWPHOTO AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE -SERVICE: NEWTITLE new Testgruppe bot only -SERVICE: PINNED 3022 -NEWMEMBER: FIRST_NAME Kay -NEWMEMBER: ID 123456789 -NEWMEMBER: ISBOT false -NEWMEMBER: LAST_NAME M -NEWMEMBER: USERNAME Gnadelwartz -LEFTMEMBER: FIRST_NAME Kay -LEFTMEMBER: ID -LEFTMEMBER: ISBOT false -LEFTMEMBER: LAST_NAME M -LEFTMEMBER: USERNAME Kay M -PINNED: ID 3022 -PINNED: MESSAGE new pinned Message +SERVICE: NEWTITLE diff --git a/test/d-process_message-test/d-process_message-test-new_chat_title.input b/test/d-process_message-test/d-process_message-test-new_chat_title.input new file mode 100644 index 0000000..d70ebb5 --- /dev/null +++ b/test/d-process_message-test/d-process_message-test-new_chat_title.input @@ -0,0 +1,16 @@ +["ok"] true +["result",0,"update_id"] 123456789 +["result",0,"message","message_id"] 123456789 +["result",0,"message","from","id"] 123456789 +["result",0,"message","from","is_bot"] false +["result",0,"message","from","first_name"] "Kay" +["result",0,"message","from","last_name"] "M" +["result",0,"message","from","username"] "Gnadelwartz" +["result",0,"message","from","language_code"] "de" +["result",0,"message","chat","id"] -123456789 +["result",0,"message","chat","title"] "Testgruppe bot only test" +["result",0,"message","chat","type"] "group" +["result",0,"message","chat","all_members_are_administrators"] true +["result",0,"message","date"] 1592372719 + +["result",0,"message","new_chat_title"] "new Testgruppe bot only" diff --git a/test/d-process_message-test/d-process_message-test-new_chat_title.result b/test/d-process_message-test/d-process_message-test-new_chat_title.result new file mode 100644 index 0000000..3c608ca --- /dev/null +++ b/test/d-process_message-test/d-process_message-test-new_chat_title.result @@ -0,0 +1,21 @@ +USER: FIRST_NAME Kay +USER: ID 123456789 +USER: LAST_NAME M +USER: USERNAME Gnadelwartz +CHAT: ALL_ADMIN true +CHAT: FIRST_NAME +CHAT: ID 123456789 +CHAT: LAST_NAME +CHAT: TITLE Testgruppe bot only test +CHAT: TYPE group +CHAT: USERNAME +CAPTION: 0 +LOCATION: LATITUDE +LOCATION: LONGITUDE +MESSAGE: 0 /_new_chat_title 123456789 new Testgruppe bot only +MESSAGE: CAPTION +MESSAGE: DICE +MESSAGE: ID 123456789 +SERVICE: 0 yes +SERVICE: NEWPHOTO +SERVICE: NEWTITLE new Testgruppe bot only diff --git a/test/d-process_message-test/d-process_message-test-pinned_message.input b/test/d-process_message-test/d-process_message-test-pinned_message.input index 64c42e0..3eafa2a 100644 --- a/test/d-process_message-test/d-process_message-test-pinned_message.input +++ b/test/d-process_message-test/d-process_message-test-pinned_message.input @@ -13,44 +13,6 @@ ["result",0,"message","chat","all_members_are_administrators"] true ["result",0,"message","date"] 1592372719 -["result",0,"message","left_chat_participant","id"] 123456789 -["result",0,"message","left_chat_participant","is_bot"] false -["result",0,"message","left_chat_participant","first_name"] "Kay" -["result",0,"message","left_chat_participant","last_name"] "M" -["result",0,"message","left_chat_participant","username"] "Gnadelwartz" -["result",0,"message","left_chat_member","id"] 123456789 -["result",0,"message","left_chat_member","is_bot"] false -["result",0,"message","left_chat_member","first_name"] "Kay" -["result",0,"message","left_chat_member","last_name"] "M" -["result",0,"message","left_chat_member","username"] "Gnadelwartz" - -["result",0,"message","new_chat_participant","id"] 123456789 -["result",0,"message","new_chat_participant","is_bot"] false -["result",0,"message","new_chat_participant","first_name"] "Kay" -["result",0,"message","new_chat_participant","last_name"] "M" -["result",0,"message","new_chat_participant","username"] "Gnadelwartz" -["result",0,"message","new_chat_member","id"] 123456789 -["result",0,"message","new_chat_member","is_bot"] false -["result",0,"message","new_chat_member","first_name"] "Kay" -["result",0,"message","new_chat_member","last_name"] "M" -["result",0,"message","new_chat_member","username"] "Gnadelwartz" - -["result",0,"message","new_chat_photo",0,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE" -["result",0,"message","new_chat_photo",0,"file_unique_id"] "AQADK6S6ki4AAzdIAwAB" -["result",0,"message","new_chat_photo",0,"file_size"] 5939 -["result",0,"message","new_chat_photo",0,"width"] 160 -["result",0,"message","new_chat_photo",0,"height"] 160 -["result",0,"message","new_chat_photo",1,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANiAAM4SAMAARoE" -["result",0,"message","new_chat_photo",1,"file_unique_id"] "AQADK6S6ki4AAzhIAwAB" -["result",0,"message","new_chat_photo",1,"file_size"] 14124 -["result",0,"message","new_chat_photo",1,"width"] 320 -["result",0,"message","new_chat_photo",1,"height"] 320 -["result",0,"message","new_chat_photo",2,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANjAAM5SAMAARoE" -["result",0,"message","new_chat_photo",2,"file_unique_id"] "AQADK6S6ki4AAzlIAwAB" -["result",0,"message","new_chat_photo",2,"file_size"] 34052 -["result",0,"message","new_chat_photo",2,"width"] 640 -["result",0,"message","new_chat_photo",2,"height"] 640 - ["result",0,"message","pinned_message","message_id"] 3022 ["result",0,"message","pinned_message","from","id"] 796814662 ["result",0,"message","pinned_message","from","is_bot"] true diff --git a/test/d-process_message-test/d-process_message-test-pinned_message.result b/test/d-process_message-test/d-process_message-test-pinned_message.result index 65cc520..4c896e4 100644 --- a/test/d-process_message-test/d-process_message-test-pinned_message.result +++ b/test/d-process_message-test/d-process_message-test-pinned_message.result @@ -17,20 +17,8 @@ MESSAGE: CAPTION MESSAGE: DICE MESSAGE: ID 123456789 SERVICE: 0 yes -SERVICE: LEFTMEMBER 123456789 -SERVICE: NEWMEMBER 123456789 -SERVICE: NEWPHOTO AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE +SERVICE: NEWPHOTO SERVICE: NEWTITLE new Testgruppe bot only SERVICE: PINNED 3022 -NEWMEMBER: FIRST_NAME Kay -NEWMEMBER: ID 123456789 -NEWMEMBER: ISBOT false -NEWMEMBER: LAST_NAME M -NEWMEMBER: USERNAME Gnadelwartz -LEFTMEMBER: FIRST_NAME Kay -LEFTMEMBER: ID -LEFTMEMBER: ISBOT false -LEFTMEMBER: LAST_NAME M -LEFTMEMBER: USERNAME Kay M PINNED: ID 3022 PINNED: MESSAGE new pinned Message From 785e769460821a2284b4f1428557cd0dd1db5d9f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Feb 2021 20:50:04 +0100 Subject: [PATCH 36/43] modules: chatMember: set_chat_photo --- modules/chatMember.sh | 30 +++++++++++++++++++++++++++++- modules/sendMessage.sh | 3 ++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 237e9b0..c21a331 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.45-dev-0-g9d36f23 +#### $$VERSION$$ v1.45-dev-23-g805a74e # will be automatically sourced from bashbot @@ -30,6 +30,34 @@ set_chat_description() { sendJson "$1" '"description": "'"$2"'"' "${URL}/setChatDescription" } +# $1 chat $2 file +set_chat_photo() { + local file=$2 +#XXX factor out to checkFileLocation ?? + [[ "${file}" = *'..'* || "${file}" = '.'* ]] && err=1 # no directory traversal + if [[ "${file}" = '/'* ]] ; then + [[ ! "${file}" =~ ${FILE_REGEX} ]] && err=2 # absolute must match REGEX + else + file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # others must be in UPLOADDIR + fi + [ ! -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_debug "set_chat_photo: CHAT=$1 FILE=$2 MSG=${BOTSENT[DESCRIPTION]}" + return + fi + sendUpload "$1" "photo" "${file}" "${URL}/setChatPhoto" +} # $1 chat delete_chat_photo() { sendJson "$1" "" "${URL}/deleteChatPhoto" diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 6b1ec46..bf6a78e 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.45-dev-15-gd3a1cec +#### $$VERSION$$ v1.45-dev-23-g805a74e # will be automatically sourced from bashbot @@ -277,6 +277,7 @@ send_file(){ else # we have a file, check file location ... media="FILE" +#XXX factor out to checkFileLocation ?? [[ "${file}" = *'..'* || "${file}" = '.'* ]] && err=1 # no directory traversal if [[ "${file}" = '/'* ]] ; then [[ ! "${file}" =~ ${FILE_REGEX} ]] && err=2 # absolute must match REGEX From b1f6a0b230d9ec4c814b769a7a3ffa3f4bd100be Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Feb 2021 21:11:15 +0100 Subject: [PATCH 37/43] modules: factor out checkUploadFile --- bashbot.sh | 32 +++++++++++++++++++++++++++++++- modules/chatMember.sh | 28 +++------------------------- modules/sendMessage.sh | 31 ++++--------------------------- 3 files changed, 38 insertions(+), 53 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 98dcda2..4b28dd2 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.45-dev-15-gd3a1cec +#### $$VERSION$$ v1.45-dev-24-g785e769 ################################################################## # are we running in a terminal? @@ -509,6 +509,36 @@ sendJson(){ [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@}" & } +UPLOADDIR="${BASHBOT_UPLOAD:-${DATADIR}/upload}" + +# $1 chat $2 file, $3 calling function +# return final file name or empty string on error +checkUploadFile() { + local err file="$2" + [[ "${file}" = *'..'* || "${file}" = '.'* ]] && err=1 # no directory traversal + if [[ "${file}" = '/'* ]] ; then + [[ ! "${file}" =~ ${FILE_REGEX} ]] && err=2 # absolute must match REGEX + else + file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # others must be in UPLOADDIR + fi + [ ! -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_debug "$3: CHAT=$1 FILE=$2 MSG=${BOTSENT[DESCRIPTION]}" + return 1 + fi +} + # # curl / wget specific functions diff --git a/modules/chatMember.sh b/modules/chatMember.sh index c21a331..dc2358a 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.45-dev-23-g805a74e +#### $$VERSION$$ v1.45-dev-24-g785e769 # will be automatically sourced from bashbot @@ -32,30 +32,8 @@ set_chat_description() { # $1 chat $2 file set_chat_photo() { - local file=$2 -#XXX factor out to checkFileLocation ?? - [[ "${file}" = *'..'* || "${file}" = '.'* ]] && err=1 # no directory traversal - if [[ "${file}" = '/'* ]] ; then - [[ ! "${file}" =~ ${FILE_REGEX} ]] && err=2 # absolute must match REGEX - else - file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # others must be in UPLOADDIR - fi - [ ! -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_debug "set_chat_photo: CHAT=$1 FILE=$2 MSG=${BOTSENT[DESCRIPTION]}" - return - fi + local file; file="$(checkUploadFile "$1" "$2" "set_chat_photo")" + [ -z "${file}" ] && return 1 sendUpload "$1" "photo" "${file}" "${URL}/setChatPhoto" } # $1 chat diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index bf6a78e..246ecb4 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.45-dev-23-g805a74e +#### $$VERSION$$ v1.45-dev-24-g785e769 # will be automatically sourced from bashbot @@ -262,12 +262,10 @@ else } fi -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 num stat err media capt file="$2" ext="$4" + local url what num stat media capt file="$2" ext="$4" capt="$(JsonEscape "$3")" if [[ "${file}" =~ ^https*:// ]]; then media="URL" @@ -277,29 +275,8 @@ send_file(){ else # we have a file, check file location ... media="FILE" -#XXX factor out to checkFileLocation ?? - [[ "${file}" = *'..'* || "${file}" = '.'* ]] && err=1 # no directory traversal - if [[ "${file}" = '/'* ]] ; then - [[ ! "${file}" =~ ${FILE_REGEX} ]] && err=2 # absolute must match REGEX - else - file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # others must be in UPLOADDIR - fi - [ ! -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_debug "upload_file: CHAT=$1 FILE=$2 MSG=${BOTSENT[DESCRIPTION]}" - return - fi + file="$(checkUploadFile "$1" "$2" "send_file")" + [ -z "${file}" ] && return 1 # file OK, let's continue fi From 82a57a77edb97479eb35db3d500e79aa84ab9ab9 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Feb 2021 21:16:03 +0100 Subject: [PATCH 38/43] modules: chatMember: set_chatadmin_title --- modules/chatMember.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/chatMember.sh b/modules/chatMember.sh index dc2358a..54462c6 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.45-dev-24-g785e769 +#### $$VERSION$$ v1.45-dev-25-gb1f6a0b # will be automatically sourced from bashbot @@ -20,6 +20,10 @@ new_chat_invite() { [ "${BOTSENT[OK]}" = "true" ] && printf "%s\n" "${BOTSENT[RESULT]}" } +# $1 chat, $2 user_id, $3 title +set_chatadmin_title() { + sendJson "$1" '"user_id":'"$2"',"custom_title": "'"$3"'"' "${URL}/setChatAdministratorCustomTitle" +} # $1 chat, $2 title set_chat_title() { sendJson "$1" '"title": "'"$2"'"' "${URL}/setChatTitle" From 77ffbabf22b95b6ee724e2ab7462cdc67e4b5d8f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 10 Feb 2021 21:30:42 +0100 Subject: [PATCH 39/43] unescape: keep \uxxx UTF-8 encoding --- bashbot.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 4b28dd2..3633fd4 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.45-dev-24-g785e769 +#### $$VERSION$$ v1.45-dev-26-g82a57a7 ################################################################## # are we running in a terminal? @@ -106,8 +106,8 @@ JsonEscape(){ } # clean \ from escaped json string # $1 string, output cleaned string -cleanEscaped(){ # remove " all \ but \n \n or \r - sed -E -e 's/\\"/+/g' -e 's/\\([^n])/\1/g' -e 's/(\r|\n)//g' <<<"$1" +cleanEscaped(){ # remove " all \ but \n\u \n or \r + sed -E -e 's/\\"/+/g' -e 's/\\([^nu])/\1/g' -e 's/(\r|\n)//g' <<<"$1" } # check if $1 seems a valid token # return true if token seems to be valid From 9958b5b5e13f3d6c837076287473a32d9315759f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 14 Feb 2021 10:46:26 +0100 Subject: [PATCH 40/43] fix dice cheating in example :-) --- mycommands.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mycommands.sh b/mycommands.sh index e7d34bd..0736616 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.45-dev-20-g2f4ef69 +#### $$VERSION$$ v1.45-dev-27-g77ffbab ####################################################### # shellcheck disable=SC1117 @@ -127,7 +127,7 @@ else '/_dice_re'*) # dice from user received sleep 5 local gameresult="*Congratulation ${USER[FIRST_NAME]} ${USER[LAST_NAME]}* you got *${MESSAGE[RESULT]} Points*." - send_markdownv2_message "${CHAT[ID]}" "${gameresult}" + [ -z "${FORWARD[UID]}" ] && send_markdownv2_message "${CHAT[ID]}" "${gameresult}" ;; '/game'*) # send random dice, edit list to fit your needs send_dice "${CHAT[ID]}" ":$(printf "slot_machine\ngame_die\ndart\nbasketball\nsoccer\nslot_machine"|sort -R|shuf -n 1shuf -n 1):" From d6f37afa3a6ee254d5cf05baa6a837ad0705a9b8 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 15 Feb 2021 15:17:50 +0100 Subject: [PATCH 41/43] example/webhook: add botname to fifo --- examples/webhook/README.md | 10 +++++----- examples/webhook/index.php | 22 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/examples/webhook/README.md b/examples/webhook/README.md index bae4124..7a55688 100644 --- a/examples/webhook/README.md +++ b/examples/webhook/README.md @@ -16,7 +16,7 @@ Prerequisite: An Apache webserver with a valid SLL certificate chain and php ena Prepare Apache to forward webhook to Bashbot: - install bashbot as described in [Bashbot Installation](../../doc/0_install.md) -- create file `data-bot-bash/webhook-fifo` +- create file `data-bot-bash/webhook-fifo-` (_ as in `botconfig.jssh`_) - run `bashbot.sh init` to setup bashbot to run as same user as Apache (_e.g. www_) - go to apache web root and create directory `telegram/` - copy all files from `examples/webhook` to new directory and change to it @@ -24,16 +24,16 @@ Prepare Apache to forward webhook to Bashbot: - execute `php index.php` Every call to webhook `https:///telegram//` will execute -`index.php` and write received JSON to file `data-bot-bash/webhook-fifo`. +`index.php` and write received JSON to file `data-bot-bash/webhook-fifo-botname`. E.g. the URL `https:///telegram//?json={"test":"me"}` -will append `{"test":"me"}` to the file `data-bot-bash/webhook-fifo`. +will append `{"test":"me"}` to the file `data-bot-bash/webhook-fifo-`. Now your Apache is ready to forward data to Bashbot. #### Simple update processing -To configure `Simple update processing` delete the file `data-bot-bash/webhook-fifo` after your webhook is working. +To configure `Simple update processing` delete the file `data-bot-bash/webhook-fifo-` after your webhook is working. All webhook calls are now forwarded to `bin/process_update.sh` for processing. To start `Simple processing ` enable webhook on Telegram (_see below_). @@ -76,5 +76,5 @@ To stop delivering of Telegram updates via webhook run `bin/any_command.sh delet **Important**: Only https connections with a valid certificate chain are allowed as endpoint for webhook. -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-28-g9958b5b diff --git a/examples/webhook/index.php b/examples/webhook/index.php index e7d97bf..e92e990 100644 --- a/examples/webhook/index.php +++ b/examples/webhook/index.php @@ -11,7 +11,7 @@ * @license http://www.wtfpl.net/txt/copying/ WTFPLv2 * @since 30.01.2021 20:24 * -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-28-g9958b5b ***********************************************************/ // bashbot home dir @@ -26,10 +26,26 @@ } } + // bashbot config file + $CONFIG=$BASHBOT_HOME.'/botconfig.jssh'; + // set botname here or read botname from config file if unknown + $botname="unknown"; + if ($botname == "unknown" && file_exists($CONFIG)) { + $prefix='["botname"] "'; + $len=strlen($prefix); + $arr = file($CONFIG, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + foreach ($arr as $line) { + if(substr($line, 0, $len) == $prefix) { + $botname=substr($line, $len, strlen($line)-$len-1); + } + } + + } + // script endpoint $cmd=$BASHBOT_HOME.'/bin/process_update.sh'; - // fifo endpoint - $fifo=$BASHBOT_HOME.'/data-bot-bash/webhook-fifo'; + // default fifo endpoint + $fifo=$BASHBOT_HOME.'/data-bot-bash/webhook-fifo-'.$botname; // prepeare read, e.g. run from CLI $data=''; From 8efbfcaab92280c3ac02eafedd775001ddece943 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 17 Feb 2021 08:35:17 +0100 Subject: [PATCH 42/43] modules: jsonDB: delete backticks in Json2Array input --- modules/jsonDB.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index dfaec7d..34728ff 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.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-29-gd6f37af # # source from commands.sh to use jsonDB functions # @@ -353,9 +353,10 @@ function jssh_updateArray_async() { # read JSON.sh style data and asssign to an ARRAY # $1 ARRAY name, must be declared with "declare -A ARRAY" before calling Json2Array() { - # match ["....."]\t and replace \t with = and print quote true false escape not escaped $ + # match ["....."]\t and replace \t with = and print delete ` quote true false escape not escaped $ # shellcheck disable=SC1091,SC1090 - [ -z "$1" ] || source <( printf "$1"'=( %s )' "$(sed -E -n -e '/\["[-0-9a-zA-Z_,."]+"\]\+*\t/ s/\t/=/p' -e 's/=(true|false)/="\1"/' -e 's/([^\]|^)\$/\1\\$/g')" ) + [ -z "$1" ] || source <( printf "$1"'=( %s )'\ + "$(sed -E -n -e '/\["[-0-9a-zA-Z_,."]+"\]\+*\t/ s/\t/=/p' -e 's/`//g' -e 's/=(true|false)/="\1"/' -e 's/([^\]|^)\$/\1\\$/g')" ) } # get Config Key from jssh file without jsshDB # output ARRAY as JSON.sh style data From 3f848ac17dfd975f33634d45e8e49aa1cc287e9a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 17 Feb 2021 08:49:39 +0100 Subject: [PATCH 43/43] fix: escape all $ for weebhook also --- bin/process_update.sh | 5 ++++- modules/jsonDB.sh | 2 +- modules/processUpdates.sh | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bin/process_update.sh b/bin/process_update.sh index 22b9898..98cb1f9 100755 --- a/bin/process_update.sh +++ b/bin/process_update.sh @@ -15,7 +15,7 @@ USAGE='process_update.sh [-h|--help] [debug] [/dev/null)" +# escape bash $ expansion bug +UPDATE="${UPDATE//$/\\$}" + # assign to bashbot ARRAY Json2Array 'UPD' <<<"${UPDATE}" diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index 34728ff..7bc2ddf 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.45-dev-29-gd6f37af +#### $$VERSION$$ v1.45-dev-30-g8efbfca # # source from commands.sh to use jsonDB functions # diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index 3755115..a7aa58c 100644 --- a/modules/processUpdates.sh +++ b/modules/processUpdates.sh @@ -4,7 +4,7 @@ # File: processUpdates.sh # Note: DO NOT EDIT! this file will be overwritten on update # -#### $$VERSION$$ v1.45-dev-18-g193ca1e +#### $$VERSION$$ v1.45-dev-30-g8efbfca ################################################################## ############## @@ -47,6 +47,8 @@ delete_webhook() { process_multi_updates() { local max num debug="$1" max="$(grep -F ',"update_id"]' <<< "${UPDATE}" | tail -1 | cut -d , -f 2 )" + # escape bash $ expansion bug + UPDATE="${UPDATE//$/\\$}" Json2Array 'UPD' <<<"${UPDATE}" for ((num=0; num<=max; num++)); do process_update "${num}" "${debug}" @@ -345,8 +347,6 @@ get_updates(){ log_error "Recovered from timeout/broken/no connection, continue with telegram updates" # calculate next sleep interval ((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep)) - # escape bash $ expansion bug - UPDATE="${UPDATE//$/\\$}" # warn if webhook is set if grep -q '^\["error_code"\] 409' <<<"${UPDATE}"; then [ "${OFFSET}" != "-999" ] && nextsleep="${stepsleep}"