first working version of send album for URLs

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2020-06-26 08:26:52 +02:00
parent 01a72e8a26
commit e3151626c0
4 changed files with 38 additions and 12 deletions

View File

@ -90,7 +90,7 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadel
<p>Contributions by JuanPotato, BigNerd95, TiagoDanin, and iicc1.</p>
<p>Released to the public domain wherever applicable. Elsewhere, consider it released under the <a href="http://www.wtfpl.net/txt/copying/">WTFPLv2</a>.</p>
<h2>Prerequisites</h2>
<p>Uses <a href="http://github.com/dominictarr/JSON.sh">JSON.sh</a>, but no more TMUX.</p>
<p>Uses <a href="http://github.com/dominictarr/JSON.sh">JSON.sh</a> and the magic of (gnu) sed.</p>
<p>Even bashbot is written in bash, it depends on commands typically available in a Unix/Linux Environment. More concret on the common commands provided by recent versions of <a href="https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands">coreutils</a>, <a href="https://en.wikipedia.org/wiki/BusyBox#Commands">busybox</a> or <a href="https://landley.net/toybox/help.html">toybox</a>, see <a href="doc/7_develop.md#common-commands">Developer Notes</a></p>
<p><em>Note for MacOS and BSD Users:</em> As bashbot heavily uses modern bash and (gnu) grep/sed features, bashbot will not run without installing additional software, see <a href="doc/0_install.md">Install Bashbot</a></p>
<p>Bashbot <a href="https://github.com/topkecleon/telegram-bot-bash">Documentation</a> and <a href="https://github.com/topkecleon/telegram-bot-bash/releases">Downloads</a> are available on www.github.com</p>
@ -225,7 +225,7 @@ It features background tasks and interactive chats, and can serve as an interfac
<h3>Why Bash and not the much better xyz?</h3>
<p>Well, that's a damn good question ... may be because I'm an Unix/Linux admin from stone age. Nevertheless there are more reasons from my side:</p>
<ul>
<li>bashbot will run everywhere where bash is available, from embedded linux to mainframe</li>
<li>bashbot will run everywhere where bash and (gnu) sed is available, from embedded linux to mainframe</li>
<li>easy to integrate with other shell script, e.g. for sending system message / health status</li>
<li>no need to install or learn a new programming language, library or framework</li>
<li>no database, not event driven, not OO ...</li>
@ -257,6 +257,6 @@ It features background tasks and interactive chats, and can serve as an interfac
<p>@Gnadelwartz</p>
<h2>That's it!</h2>
<p>If you feel that there's something missing or if you found a bug, feel free to submit a pull request!</p>
<h4>$$VERSION$$ v0.98-dev-70-g694ee61</h4>
<h4>$$VERSION$$ v0.98-pre-3-g0f24eb8</h4>
</body>
</html>

View File

@ -13,7 +13,8 @@ Elsewhere, consider it released under the
[WTFPLv2](http://www.wtfpl.net/txt/copying/).
## Prerequisites
Uses [JSON.sh](http://github.com/dominictarr/JSON.sh), but no more TMUX.
Uses [JSON.sh](http://github.com/dominictarr/JSON.sh) and the magic of (gnu)
sed.
Even bashbot is written in bash, it depends on commands typically available in
a Unix/Linux Environment.
@ -262,8 +263,8 @@ execution bug, pls update if you use an older version!
Well, that's a damn good question ... may be because I'm an Unix/Linux admin
from stone age. Nevertheless there are more reasons from my side:
- bashbot will run everywhere where bash is available, from embedded linux to
mainframe
- bashbot will run everywhere where bash and (gnu) sed is available, from
embedded linux to mainframe
- easy to integrate with other shell script, e.g. for sending system message /
health status
- no need to install or learn a new programming language, library or framework
@ -327,4 +328,4 @@ failed: Connection timed out.
If you feel that there's something missing or if you found a bug, feel free to
submit a pull request!
#### $$VERSION$$ v0.98-dev-70-g694ee61
#### $$VERSION$$ v0.98-pre-3-g0f24eb8

View File

@ -11,7 +11,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.98-dev-70-g694ee61
#### $$VERSION$$ v0.962-84-g86f8fbe
#
# Exit Codes:
# - 0 success (hopefully)
@ -973,7 +973,7 @@ bot_init() {
echo -e "${ORANGE}Bot config may not complete, pls check.${NC}"
fi
# show result
ls -ld "${DATADIR}" "${LOGDIR}" *.jssh* *.sh
ls -ld "${DATADIR}" "${LOGDIR}" ./*.jssh* ./*.sh
}
if ! _is_function send_message ; then

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.98-dev-70-g694ee61
#### $$VERSION$$ v0.962-85-g01a72e8
# will be automatically sourced from bashbot
@ -25,6 +25,7 @@ LOCATION_URL=$URL'/sendLocation'
VENUE_URL=$URL'/sendVenue'
ACTION_URL=$URL'/sendChatAction'
FORWARD_URL=$URL'/forwardMessage'
ALBUM_URL=$URL'/sendMediaGroup'
send_normal_message() {
local len text; text="$(JsonEscape "${2}")"
@ -114,11 +115,35 @@ UPLOADDIR="${BASHBOT_UPLOAD:-${DATADIR}/upload}"
# for now this can only send local files with curl!
# extend to allow send files by URL or telegram ID
send_file() {
[ -z "$2" ] && return
[[ "$2" = "http"* ]] && return # currently we do not support URL
upload_file "${@}"
}
if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
# there are no checks if URL or ID exists
# $1 chat $3 ... $n URL or ID
send_album(){
[ -z "${1}" ] && return 1
[ -z "${3}" ] && return 2 # minimum 2 files
local CHAT JSON IMAGE; CHAT="${1}"; shift
for IMAGE in "$@"
do
[ -n "${JSON}" ] && JSON+=","
JSON+='{"type":"photo","media":"'${IMAGE}'"}'
done
# shellcheck disable=SC2086
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "${ALBUM_URL}" -F "chat_id=${CHAT}"\
-F "media=[${JSON}]" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
sendJsonResult "${res}" "send_album (curl)" "${CHAT}" "$@"
[[ -z "${SOURCE}" && -n "${BASHBOT_EVENT_SEND[*]}" ]] && event_send "album" "$@" &
}
else
send_album(){
printf "%s: %s\n" "$(date)" "Sorry, wget Album upload not yet implemented\n" >>"${ERRORLOG}"
BOTSENT[OK]="false"
[[ -z "${SOURCE}" && -n "${BASHBOT_EVENT_SEND[*]}" ]] && event_send "album" "$@" &
}
fi
upload_file(){
local CUR_URL WHAT STATUS file="$2"
# file access checks ...