2020-12-18 13:53:44 +00:00
|
|
|
#!/bin/bash
|
2020-12-16 12:45:59 +00:00
|
|
|
#===============================================================================
|
|
|
|
#
|
2020-12-24 10:41:40 +00:00
|
|
|
# FILE: bin/send_message.sh
|
2020-12-16 12:45:59 +00:00
|
|
|
#
|
|
|
|
# USAGE: send_message.sh [-h|--help] [format] "CHAT[ID]" "message ...." [debug]
|
|
|
|
#
|
|
|
|
# DESCRIPTION: send a message to the given user/group
|
|
|
|
#
|
|
|
|
# OPTIONS: format - normal, markdown, html (optional)
|
2020-12-25 17:27:48 +00:00
|
|
|
# CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself
|
2020-12-16 12:45:59 +00:00
|
|
|
# message - message to send in specified format
|
|
|
|
# if no format is givern send_message() format is used
|
|
|
|
#
|
|
|
|
# -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
|
2020-12-18 13:53:44 +00:00
|
|
|
# CREATED: 16.12.2020 11:34
|
2020-12-16 12:45:59 +00:00
|
|
|
#
|
2021-01-03 21:39:36 +00:00
|
|
|
#### $$VERSION$$ v1.21-0-gc85af77
|
2020-12-16 12:45:59 +00:00
|
|
|
#===============================================================================
|
|
|
|
|
2020-12-18 13:53:44 +00:00
|
|
|
####
|
2020-12-16 12:45:59 +00:00
|
|
|
# parse args
|
|
|
|
SEND="send_message"
|
|
|
|
case "$1" in
|
|
|
|
"nor*"|"tex*")
|
|
|
|
SEND="send_normal_message"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
"mark"*)
|
|
|
|
SEND="send_markdownv2_message"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
"html")
|
|
|
|
SEND="send_html_message"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
'')
|
2020-12-26 19:48:13 +00:00
|
|
|
printf "missing arguments\n"
|
2020-12-16 12:45:59 +00:00
|
|
|
;&
|
|
|
|
"-h"*)
|
2020-12-26 19:48:13 +00:00
|
|
|
printf 'usage: send_message [-h|--help] [format] "CHAT[ID]" "message ...." [debug]\n'
|
2020-12-16 12:45:59 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
'--h'*)
|
|
|
|
sed -n '3,/###/p' <"$0"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-12-25 17:27:48 +00:00
|
|
|
# set bashbot environment
|
|
|
|
# shellcheck disable=SC1090
|
2020-12-25 17:43:36 +00:00
|
|
|
source "${0%/*}/bashbot_env.inc.sh" "$3" # $3 debug
|
2020-12-25 17:27:48 +00:00
|
|
|
|
2020-12-18 13:53:44 +00:00
|
|
|
####
|
|
|
|
# ready, do stuff here -----
|
2020-12-25 17:27:48 +00:00
|
|
|
if [ "$1" == "BOTADMIN" ]; then
|
2020-12-25 18:16:54 +00:00
|
|
|
CHAT="${BOT_ADMIN}"
|
2020-12-25 17:27:48 +00:00
|
|
|
else
|
|
|
|
CHAT="$1"
|
|
|
|
fi
|
2020-12-18 13:53:44 +00:00
|
|
|
|
|
|
|
# send message in selected format
|
2020-12-25 17:27:48 +00:00
|
|
|
"${SEND}" "${CHAT}" "$2"
|
2020-12-16 12:45:59 +00:00
|
|
|
|
2020-12-18 13:53:44 +00:00
|
|
|
# output send message result
|
2020-12-16 12:45:59 +00:00
|
|
|
jssh_printDB "BOTSENT" | sort -r
|
|
|
|
|