mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-29 02:36:26 +00:00
modules: send_file support for URL
This commit is contained in:
parent
4582efd556
commit
dd19f0f34e
@ -30,7 +30,7 @@
|
|||||||
# 8 - curl/wget missing
|
# 8 - curl/wget missing
|
||||||
# 10 - not bash!
|
# 10 - not bash!
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
|
#### $$VERSION$$ v1.25-dev-15-g4582efd
|
||||||
##################################################################
|
##################################################################
|
||||||
|
|
||||||
# emmbeded system may claim bash but it is not
|
# emmbeded system may claim bash but it is not
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||||
# CREATED: 25.12.2020 20:24
|
# CREATED: 25.12.2020 20:24
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
|
#### $$VERSION$$ v1.25-dev-15-g4582efd
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
####
|
####
|
||||||
@ -54,7 +54,8 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
FILE="$2"
|
FILE="$2"
|
||||||
[[ "$2" != "/"* ]] && FILE="${PWD}/$2"
|
# convert to absolute path if not start with / or http://
|
||||||
|
[[ ! ( "$2" == "/"* || "$2" =~ ^https*:// ) ]] && FILE="${PWD}/$2"
|
||||||
|
|
||||||
# send message in selected format
|
# send message in selected format
|
||||||
"${SEND}" "${CHAT}" "${FILE}" "$3"
|
"${SEND}" "${CHAT}" "${FILE}" "$3"
|
||||||
|
@ -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.25-dev-14-g2fe6d4b
|
#### $$VERSION$$ v1.25-dev-15-g4582efd
|
||||||
|
|
||||||
# will be automatically sourced from bashbot
|
# will be automatically sourced from bashbot
|
||||||
|
|
||||||
@ -205,9 +205,16 @@ send_file() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# supports http and local file
|
||||||
|
# $1 chat, $2 file, $3 caption, $4 extension (optional)
|
||||||
upload_file(){
|
upload_file(){
|
||||||
local CUR_URL WHAT STATUS text=$3 file="$2"
|
local CUR_URL WHAT STATUS media text file="$2" ext="$4"
|
||||||
# file access checks ...
|
text="$(JsonEscape "$3")"
|
||||||
|
if [[ "${file}" =~ ^https*:// ]]; then
|
||||||
|
media="URL"
|
||||||
|
else
|
||||||
|
# we have a file, check file location ...
|
||||||
|
media="FILE"
|
||||||
[[ "${file}" = *'..'* ]] && return 1 # no directory traversal
|
[[ "${file}" = *'..'* ]] && return 1 # no directory traversal
|
||||||
[[ "${file}" = '.'* ]] && return 1 # no hidden or relative files
|
[[ "${file}" = '.'* ]] && return 1 # no hidden or relative files
|
||||||
if [[ "${file}" = '/'* ]] ; then
|
if [[ "${file}" = '/'* ]] ; then
|
||||||
@ -216,8 +223,10 @@ upload_file(){
|
|||||||
file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # othiers must be in UPLOADDIR
|
file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # othiers must be in UPLOADDIR
|
||||||
fi
|
fi
|
||||||
[ ! -r "${file}" ] && return 3 # and file must exits of course
|
[ ! -r "${file}" ] && return 3 # and file must exits of course
|
||||||
|
fi
|
||||||
|
|
||||||
case "${file##*.}" in
|
[ -z "${ext}" ] && ext="${file##*.}"
|
||||||
|
case "${ext}" in
|
||||||
mp3|flac)
|
mp3|flac)
|
||||||
CUR_URL="${AUDIO_URL}"
|
CUR_URL="${AUDIO_URL}"
|
||||||
WHAT="audio"
|
WHAT="audio"
|
||||||
@ -250,8 +259,19 @@ upload_file(){
|
|||||||
STATUS="upload_document"
|
STATUS="upload_document"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# prepare to send FILE / URL
|
||||||
send_action "$1" "${STATUS}"
|
send_action "$1" "${STATUS}"
|
||||||
sendUpload "$1" "${WHAT}" "${file}" "${CUR_URL}" "${text//\\n/$'\n'}"
|
# select method to use
|
||||||
|
case "${media}" in
|
||||||
|
FILE) # send local file ...
|
||||||
|
sendUpload "$1" "${WHAT}" "${file}" "${CUR_URL}" "${text//\\n/$'\n'}";;
|
||||||
|
|
||||||
|
URL) # send URL, should also work for file_id ...
|
||||||
|
# e.g. '"photo":"https://dealz.rrr.de/assets/images/rbofd-1.gif","caption":"some text"'
|
||||||
|
sendJson "$1" '"'"${WHAT}"'":"'"${file}"'","caption":"'"${text//\\n/$'\n'}"'"' "${CUR_URL}"
|
||||||
|
esac
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location
|
# 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
|
||||||
|
Loading…
Reference in New Issue
Block a user