file caption does not support \n

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2020-12-24 18:20:39 +01:00
parent 6173d77c4e
commit c39c1ca8f9
2 changed files with 23 additions and 16 deletions

View File

@ -3,12 +3,13 @@
# #
# FILE: bin/broadcast_message.sh # FILE: bin/broadcast_message.sh
# #
# USAGE: broadcast_message.sh [-h|--help] [--doit] [--groups] [format] "message ...." [debug] # USAGE: broadcast_message.sh [-h|--help] [--doit] [--groups|--both] [format] "message ...." [debug]
# #
# DESCRIPTION: send a message to all user the bot have seen (listet in count.jssh) # DESCRIPTION: send a message to all users the bot have seen (listet in count.jssh)
# #
# OPTIONS: --doit - broadcast is dangerous, simulate run without --doit # OPTIONS: --doit - broadcast is dangerous, simulate run without --doit
# --groups - send to groups also, by default we send only to users # --groups - send to groups instead of users
# --both - send to users and groups
# #
# format - normal, markdown, html (optional) # format - normal, markdown, html (optional)
# message - message to send in specified format # message - message to send in specified format
@ -23,7 +24,7 @@
# AUTHOR: KayM (gnadelwartz), kay@rrr.de # AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 16.12.2020 16:14 # CREATED: 16.12.2020 16:14
# #
#### $$VERSION$$ v1.2-dev2-62-gfa24673 #### $$VERSION$$ v1.2-dev2-67-g6173d77
#=============================================================================== #===============================================================================
# set bashbot environment # set bashbot environment
@ -32,16 +33,21 @@ source "${0%/*}/bashbot_env.inc.sh"
#### ####
# broadcast is dangerous, without --doit we do a dry run ... # broadcast is dangerous, without --doit we do a dry run ...
if [ "$1" == "--doit" ]; then if [ "$1" = "--doit" ]; then
DOIT="yes" DOIT="yes"
shift shift
fi fi
#### ####
# send to users by default, --group sends to groups also # send to users by default, --group sends groups, --both to both
if [ "$1" == "--groups" ]; then SENDTO="users"
if [ "$1" = "--both" ]; then
GROUPSALSO=" and groups" GROUPSALSO=" and groups"
shift shift
elif [ "$1" = "--groups" ]; then
SENDTO="groups"
GROUPSALSO=" only"
shift
fi fi
#### ####
@ -64,7 +70,7 @@ case "$1" in
echo "missing missing arguments" echo "missing missing arguments"
;& ;&
"-h"*) "-h"*)
echo 'usage: send_message [-h|--help] [format] "message ...." [debug]' echo 'usage: send_message [-h|--help] [--groups|--both] [format] "message ...." [debug]'
exit 1 exit 1
;; ;;
'--h'*) '--h'*)
@ -92,8 +98,10 @@ fi
for USER in ${!SENDALL[*]} for USER in ${!SENDALL[*]}
do do
# ignore everything not a user or group # send to users, groups or both ...
[[ -z "${GROUPSALSO}" && "${USER}" == *"-"* ]] && continue [[ -z "${GROUPSALSO}" && "${USER}" == *"-"* ]] && continue
[[ "${SENDTO}" != "users" && "${USER}" != *"-"* ]] && continue
# ignore everything not a user or group
[[ ! "${USER}" =~ ^[0-9-]*$ ]] && continue [[ ! "${USER}" =~ ^[0-9-]*$ ]] && continue
(( COUNT++ )) (( COUNT++ ))
if [ -z "${DOIT}" ]; then if [ -z "${DOIT}" ]; then
@ -104,5 +112,5 @@ fi
sleep 0.1 sleep 0.1
fi fi
done done
echo -e "${NC}\nMessage \"$1\" sent to ${COUNT} users${GROUPSALSO}." echo -e "${NC}\nMessage \"$1\" sent to ${COUNT} ${SENDTO}${GROUPSALSO}."
} | more } | more

View File

@ -6,7 +6,7 @@
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
# shellcheck disable=SC1117 # shellcheck disable=SC1117
#### $$VERSION$$ v1.2-dev2-19-g5ca6afc #### $$VERSION$$ v1.2-dev2-67-g6173d77
# will be automatically sourced from bashbot # will be automatically sourced from bashbot
@ -190,7 +190,7 @@ else
fi fi
upload_file(){ upload_file(){
local CUR_URL WHAT STATUS file="$2" local CUR_URL WHAT STATUS text=$3 file="$2"
# file access checks ... # file access checks ...
[[ "$file" = *'..'* ]] && return # no directory traversal [[ "$file" = *'..'* ]] && return # no directory traversal
[[ "$file" = '.'* ]] && return # no hidden or relative files [[ "$file" = '.'* ]] && return # no hidden or relative files
@ -236,7 +236,7 @@ upload_file(){
;; ;;
esac esac
send_action "${1}" "$STATUS" send_action "${1}" "$STATUS"
sendUpload "$1" "${WHAT}" "${file}" "${CUR_URL}" "$3" sendUpload "$1" "${WHAT}" "${file}" "${CUR_URL}" "${text}"
} }
# typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location # typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location
@ -279,8 +279,7 @@ send_message() {
local text keyboard btext burl no_keyboard file lat long title address sent local text keyboard btext burl no_keyboard file lat long title address sent
text="$(sed <<< "${2}" 's/ mykeyboardend.*//;s/ *my[kfltab][a-z]\{2,13\}startshere.*//')$(sed <<< "${2}" -n '/mytextstartshere/ s/.*mytextstartshere//p')" text="$(sed <<< "${2}" 's/ mykeyboardend.*//;s/ *my[kfltab][a-z]\{2,13\}startshere.*//')$(sed <<< "${2}" -n '/mytextstartshere/ s/.*mytextstartshere//p')"
#shellcheck disable=SC2001 #shellcheck disable=SC2001
text="$(sed <<< "${text}" 's/ *mynewlinestartshere */\\n/g')" text="$(sed <<< "${text}" 's/ *mynewlinestartshere */\n/g')"
text="${text//$'\n'/\\n}"
[ "$3" != "safe" ] && { [ "$3" != "safe" ] && {
no_keyboard="$(sed <<< "${2}" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" no_keyboard="$(sed <<< "${2}" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')"
keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere *//;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')" keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere *//;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
@ -308,7 +307,7 @@ send_message() {
sent=y sent=y
fi fi
if [ -n "$file" ]; then if [ -n "$file" ]; then
send_file "$1" "$file" "$text" upload_file "$1" "$file" "$text"
sent=y sent=y
fi fi
if [ -n "$lat" ] && [ -n "$long" ]; then if [ -n "$lat" ] && [ -n "$long" ]; then