mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-26 01:07:34 +00:00
file caption does not support \n
This commit is contained in:
parent
6173d77c4e
commit
c39c1ca8f9
@ -3,12 +3,13 @@
|
||||
#
|
||||
# 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
|
||||
# --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)
|
||||
# message - message to send in specified format
|
||||
@ -23,7 +24,7 @@
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 16.12.2020 16:14
|
||||
#
|
||||
#### $$VERSION$$ v1.2-dev2-62-gfa24673
|
||||
#### $$VERSION$$ v1.2-dev2-67-g6173d77
|
||||
#===============================================================================
|
||||
|
||||
# set bashbot environment
|
||||
@ -32,16 +33,21 @@ source "${0%/*}/bashbot_env.inc.sh"
|
||||
|
||||
####
|
||||
# broadcast is dangerous, without --doit we do a dry run ...
|
||||
if [ "$1" == "--doit" ]; then
|
||||
if [ "$1" = "--doit" ]; then
|
||||
DOIT="yes"
|
||||
shift
|
||||
fi
|
||||
|
||||
####
|
||||
# send to users by default, --group sends to groups also
|
||||
if [ "$1" == "--groups" ]; then
|
||||
# send to users by default, --group sends groups, --both to both
|
||||
SENDTO="users"
|
||||
if [ "$1" = "--both" ]; then
|
||||
GROUPSALSO=" and groups"
|
||||
shift
|
||||
elif [ "$1" = "--groups" ]; then
|
||||
SENDTO="groups"
|
||||
GROUPSALSO=" only"
|
||||
shift
|
||||
fi
|
||||
|
||||
####
|
||||
@ -64,7 +70,7 @@ case "$1" in
|
||||
echo "missing missing arguments"
|
||||
;&
|
||||
"-h"*)
|
||||
echo 'usage: send_message [-h|--help] [format] "message ...." [debug]'
|
||||
echo 'usage: send_message [-h|--help] [--groups|--both] [format] "message ...." [debug]'
|
||||
exit 1
|
||||
;;
|
||||
'--h'*)
|
||||
@ -92,8 +98,10 @@ fi
|
||||
|
||||
for USER in ${!SENDALL[*]}
|
||||
do
|
||||
# ignore everything not a user or group
|
||||
# send to users, groups or both ...
|
||||
[[ -z "${GROUPSALSO}" && "${USER}" == *"-"* ]] && continue
|
||||
[[ "${SENDTO}" != "users" && "${USER}" != *"-"* ]] && continue
|
||||
# ignore everything not a user or group
|
||||
[[ ! "${USER}" =~ ^[0-9-]*$ ]] && continue
|
||||
(( COUNT++ ))
|
||||
if [ -z "${DOIT}" ]; then
|
||||
@ -104,5 +112,5 @@ fi
|
||||
sleep 0.1
|
||||
fi
|
||||
done
|
||||
echo -e "${NC}\nMessage \"$1\" sent to ${COUNT} users${GROUPSALSO}."
|
||||
echo -e "${NC}\nMessage \"$1\" sent to ${COUNT} ${SENDTO}${GROUPSALSO}."
|
||||
} | more
|
||||
|
@ -6,7 +6,7 @@
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
# shellcheck disable=SC1117
|
||||
#### $$VERSION$$ v1.2-dev2-19-g5ca6afc
|
||||
#### $$VERSION$$ v1.2-dev2-67-g6173d77
|
||||
|
||||
# will be automatically sourced from bashbot
|
||||
|
||||
@ -190,7 +190,7 @@ else
|
||||
fi
|
||||
|
||||
upload_file(){
|
||||
local CUR_URL WHAT STATUS file="$2"
|
||||
local CUR_URL WHAT STATUS text=$3 file="$2"
|
||||
# file access checks ...
|
||||
[[ "$file" = *'..'* ]] && return # no directory traversal
|
||||
[[ "$file" = '.'* ]] && return # no hidden or relative files
|
||||
@ -236,7 +236,7 @@ upload_file(){
|
||||
;;
|
||||
esac
|
||||
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
|
||||
@ -279,8 +279,7 @@ send_message() {
|
||||
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')"
|
||||
#shellcheck disable=SC2001
|
||||
text="$(sed <<< "${text}" 's/ *mynewlinestartshere */\\n/g')"
|
||||
text="${text//$'\n'/\\n}"
|
||||
text="$(sed <<< "${text}" 's/ *mynewlinestartshere */\n/g')"
|
||||
[ "$3" != "safe" ] && {
|
||||
no_keyboard="$(sed <<< "${2}" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')"
|
||||
keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere *//;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
|
||||
@ -308,7 +307,7 @@ send_message() {
|
||||
sent=y
|
||||
fi
|
||||
if [ -n "$file" ]; then
|
||||
send_file "$1" "$file" "$text"
|
||||
upload_file "$1" "$file" "$text"
|
||||
sent=y
|
||||
fi
|
||||
if [ -n "$lat" ] && [ -n "$long" ]; then
|
||||
|
Loading…
Reference in New Issue
Block a user