2020-12-25 19:57:05 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#===============================================================================
|
|
|
|
#
|
|
|
|
# FILE: bin/send_file.sh
|
2021-01-09 21:14:44 +00:00
|
|
|
#
|
|
|
|
USAGE='send_file.sh [-h|--help] "CHAT[ID]" "file|URL" "caption ...." [type] [debug]'
|
2020-12-25 19:57:05 +00:00
|
|
|
#
|
|
|
|
# DESCRIPTION: send a file to the given user/group
|
|
|
|
#
|
|
|
|
# OPTIONS: CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself
|
2021-01-05 21:47:18 +00:00
|
|
|
# file - local file to send, must be an absolute path or relative to pwd
|
2020-12-25 19:57:05 +00:00
|
|
|
# Note: must not contain .. or . and located below BASHBOT_ETC
|
2021-01-05 21:47:18 +00:00
|
|
|
# URL - send an URL instead local file
|
|
|
|
#
|
2020-12-25 19:57:05 +00:00
|
|
|
# caption - message to send with file
|
2021-01-05 21:47:18 +00:00
|
|
|
# type - photo, video, sticker, voice, document (optional)
|
2020-12-25 19:57:05 +00:00
|
|
|
#
|
|
|
|
# -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: 25.12.2020 20:24
|
|
|
|
#
|
2021-01-10 14:51:16 +00:00
|
|
|
#### $$VERSION$$ v1.25-dev-49-g41ce9cc
|
2020-12-25 19:57:05 +00:00
|
|
|
#===============================================================================
|
|
|
|
|
|
|
|
####
|
|
|
|
# parse args
|
2021-01-07 12:15:18 +00:00
|
|
|
SEND="send_file"
|
2020-12-25 19:57:05 +00:00
|
|
|
case "$1" in
|
|
|
|
'')
|
2020-12-26 19:48:13 +00:00
|
|
|
printf "missing arguments\n"
|
2020-12-25 19:57:05 +00:00
|
|
|
;&
|
|
|
|
"-h"*)
|
2021-01-09 21:14:44 +00:00
|
|
|
printf 'usage: %s\n' "${USAGE}"
|
2020-12-25 19:57:05 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
'--h'*)
|
|
|
|
sed -n '3,/###/p' <"$0"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# set bashbot environment
|
|
|
|
# shellcheck disable=SC1090
|
2021-01-10 14:51:16 +00:00
|
|
|
source "${0%/*}/bashbot_env.inc.sh" "${5:-debug}" # $5 debug
|
2020-12-25 19:57:05 +00:00
|
|
|
|
|
|
|
####
|
|
|
|
# ready, do stuff here -----
|
|
|
|
if [ "$1" == "BOTADMIN" ]; then
|
|
|
|
CHAT="${BOT_ADMIN}"
|
|
|
|
else
|
|
|
|
CHAT="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
FILE="$2"
|
2021-01-05 21:01:32 +00:00
|
|
|
# convert to absolute path if not start with / or http://
|
2021-01-06 15:43:18 +00:00
|
|
|
[[ ! ( "$2" == "/"* || "$2" =~ ^https*:// || "$2" == "file_id://"*) ]] && FILE="${PWD}/$2"
|
2020-12-25 19:57:05 +00:00
|
|
|
|
|
|
|
# send message in selected format
|
2021-01-05 21:47:18 +00:00
|
|
|
"${SEND}" "${CHAT}" "${FILE}" "$3" "$4"
|
2020-12-25 19:57:05 +00:00
|
|
|
|
|
|
|
# output send message result
|
|
|
|
jssh_printDB "BOTSENT" | sort -r
|
|
|
|
|