start of ready to use scripts

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2020-12-16 13:45:59 +01:00
parent 85ee75705a
commit e6223b6645
3 changed files with 82 additions and 3 deletions

View File

@ -11,7 +11,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ v1.2-dev2-28-g5b94265 #### $$VERSION$$ v1.2-dev2-29-g85ee757
# #
# Exit Codes: # Exit Codes:
# - 0 success (hopefully) # - 0 success (hopefully)
@ -560,6 +560,7 @@ sendJsonResult(){
if [ "${res}" != "" ]; then if [ "${res}" != "" ]; then
BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "${1}")" BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "${1}")"
BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "${1}")" BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "${1}")"
grep -qs -F '"parameters","retry_after"' <<< "${1}" &&\
BOTSENT[RETRY]="$(JsonGetValue '"parameters","retry_after"' <<< "${1}")" BOTSENT[RETRY]="$(JsonGetValue '"parameters","retry_after"' <<< "${1}")"
else else
BOTSENT[OK]="false" BOTSENT[OK]="false"

76
bin/send_message.sh Executable file
View File

@ -0,0 +1,76 @@
#!/bin/bash -
#===============================================================================
#
# FILE: send_message.sh
#
# 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)
# CHAT[ID] - ID number of CHAT
# 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
# CREATED: 16.12.2020 11:34:27
#
#### $$VERSION$$ v1.2-dev2-29-g85ee757
#===============================================================================
# set where your bashbot lives
# shellcheck disable=SC1090
BASHBOT_HOME="${BASHBOTHOME:-../}"
# check for botconfig.jssh
if [ ! -r "${BASHBOT_HOME}/botconfig.jssh" ]; then
echo "No bashbot config file in ${BASHBOT_HOME}"
exit 3
fi
# 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
;;
'')
echo "missing missing arguments"
;&
"-h"*)
echo "usage: send_message [-h|--help] [format] "CHAT[ID]" "message ...." [debug]"
exit 1
;;
'--h'*)
sed -n '3,/###/p' <"$0"
exit 1
;;
esac
if [[ "$1" == *[!0-9-]* ]]; then
echo "CHAT[ID] is not a number! use: $0 -h for help"
exit 2
fi
# source bashbot and send message
source "${BASHBOT_HOME}/bashbot.sh" source "$3"
"${SEND}" "$1" "$2"
# output result
jssh_printDB "BOTSENT" | sort -r

View File

@ -29,6 +29,8 @@ Have FUN!
├── commands.sh # command dispatcher - DO NOT EDIT! ├── commands.sh # command dispatcher - DO NOT EDIT!
├── JSON.sh # bashbots JSON parser, see https://github.com/dominictarr/JSON.sh ├── JSON.sh # bashbots JSON parser, see https://github.com/dominictarr/JSON.sh
├── bin # some ready to use scripts scripts, e.g. to send a message
├── scripts # place your bashbot interactive and background scripts here ├── scripts # place your bashbot interactive and background scripts here
│   └── interactive.sh.clean # interactive script template for new scripts │   └── interactive.sh.clean # interactive script template for new scripts
@ -298,5 +300,5 @@ send_action "${CHAT[ID]}" "action"
#### [Prev Create Bot](1_firstbot.md) #### [Prev Create Bot](1_firstbot.md)
#### [Next Advanced Usage](3_advanced.md) #### [Next Advanced Usage](3_advanced.md)
#### $$VERSION$$ v1.2-dev2-5-gda7a3f1 #### $$VERSION$$ v1.2-dev2-29-g85ee757