From e6223b66454bb4ba6216e2e24a72c87bbf35707c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 16 Dec 2020 13:45:59 +0100 Subject: [PATCH] start of ready to use scripts --- bashbot.sh | 5 +-- bin/send_message.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++ doc/2_usage.md | 4 ++- 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100755 bin/send_message.sh diff --git a/bashbot.sh b/bashbot.sh index 4c9e3ad..6cbcfcf 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.2-dev2-28-g5b94265 +#### $$VERSION$$ v1.2-dev2-29-g85ee757 # # Exit Codes: # - 0 success (hopefully) @@ -560,7 +560,8 @@ sendJsonResult(){ if [ "${res}" != "" ]; then BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "${1}")" BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "${1}")" - BOTSENT[RETRY]="$(JsonGetValue '"parameters","retry_after"' <<< "${1}")" + grep -qs -F '"parameters","retry_after"' <<< "${1}" &&\ + BOTSENT[RETRY]="$(JsonGetValue '"parameters","retry_after"' <<< "${1}")" else BOTSENT[OK]="false" BOTSENT[ERROR]="999" diff --git a/bin/send_message.sh b/bin/send_message.sh new file mode 100755 index 0000000..e1d59d8 --- /dev/null +++ b/bin/send_message.sh @@ -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 + diff --git a/doc/2_usage.md b/doc/2_usage.md index d4d1cf0..0313cfa 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -29,6 +29,8 @@ Have FUN! ├── commands.sh # command dispatcher - DO NOT EDIT! ├── 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 │   └── interactive.sh.clean # interactive script template for new scripts │ @@ -298,5 +300,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.2-dev2-5-gda7a3f1 +#### $$VERSION$$ v1.2-dev2-29-g85ee757