2020-12-25 19:57:05 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#===============================================================================
|
|
|
|
#
|
|
|
|
# FILE: bin/send_file.sh
|
|
|
|
#
|
|
|
|
# USAGE: send_file.sh [-h|--help] "CHAT[ID]" "file" "caption ...." [debug]
|
|
|
|
#
|
|
|
|
# DESCRIPTION: send a file to the given user/group
|
|
|
|
#
|
|
|
|
# OPTIONS: CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself
|
|
|
|
# file - file to send, must be an absolute path or relative to pwd
|
|
|
|
# Note: must not contain .. or . and located below BASHBOT_ETC
|
|
|
|
# caption - message to send with file
|
|
|
|
#
|
|
|
|
# -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
|
|
|
|
#
|
2020-12-25 20:47:08 +00:00
|
|
|
#### $$VERSION$$ v1.20-0-g2ab00a2
|
2020-12-25 19:57:05 +00:00
|
|
|
#===============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
####
|
|
|
|
# parse args
|
|
|
|
SEND="upload_file"
|
|
|
|
case "$1" in
|
|
|
|
'')
|
|
|
|
echo "missing arguments"
|
|
|
|
;&
|
|
|
|
"-h"*)
|
|
|
|
echo 'usage: send_file [-h|--help] "CHAT[ID]" "file" "caption ...." [debug]'
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
'--h'*)
|
|
|
|
sed -n '3,/###/p' <"$0"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# set bashbot environment
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
source "${0%/*}/bashbot_env.inc.sh" "$4" # $4 debug
|
|
|
|
|
|
|
|
####
|
|
|
|
# ready, do stuff here -----
|
|
|
|
if [ "$1" == "BOTADMIN" ]; then
|
|
|
|
CHAT="${BOT_ADMIN}"
|
|
|
|
else
|
|
|
|
CHAT="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
FILE="$2"
|
|
|
|
[[ "$2" != "/"* ]] && FILE="${PWD}/$2"
|
|
|
|
|
|
|
|
# send message in selected format
|
|
|
|
"${SEND}" "${CHAT}" "${FILE}" "$3"
|
|
|
|
|
|
|
|
# output send message result
|
|
|
|
jssh_printDB "BOTSENT" | sort -r
|
|
|
|
|