bin: less duplicate code

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-21 09:22:14 +01:00
parent 749eee74a4
commit 07f026c6a7
8 changed files with 48 additions and 114 deletions

View File

@ -13,7 +13,7 @@
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 18.12.2020 12:27
#
#### $$VERSION$$ v1.30-0-g3266427
#### $$VERSION$$ v1.31-dev-14-g749eee7
#===============================================================================
############
@ -63,3 +63,24 @@ BOT_NAME="$(getConfigKey "botname")"
[[ -z "${BOT_ADMIN}" || "${BOT_ADMIN}" == "?" ]] && printf "%s\n" "${ORANGE}Warning: Botadmin not set, did you forget to sent command${NC} /start"
[[ -z "${BOT_NAME}" ]] && printf "%s\n" "${ORANGE}Warning: Botname not set, did you ever run bashbot?"
# output command result or Telegram response
print_result() { jssh_printDB "BOTSENT" | sort -r; }
print_response() { jssh_printDB "UPD"; }
# check and output help
print_help() {
case "$1" in
'')
printf "missing arguments\n"
;&
"-h"*)
printf 'usage: %s\n' "${USAGE}"
exit 1
;;
'--h'*)
sed -n '/^#====/,/^#====/p' <"$0"
exit 1
;;
esac
}

View File

@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1090,SC2034
#===============================================================================
#
# FILE: bin/bashbot_stats.sh
@ -16,25 +17,12 @@ USAGE='bashbot_stats.sh [-h|--help] [debug]'
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 23.12.2020 20:34
#
#### $$VERSION$$ v1.30-0-g3266427
#### $$VERSION$$ v1.31-dev-14-g749eee7
#===============================================================================
####
# parse args
case "$1" in
"-h"*)
printf "usage: %s\n" "${USAGE}"
exit 1
;;
'--h'*)
sed -n '3,/###/p' <"$0"
exit 1
;;
esac
# set bashbot environment
# shellcheck disable=SC1090
source "${0%/*}/bashbot_env.inc.sh" "$1"
[ -n "$1" ] && print_help
####
# ready, do stuff here -----

View File

@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1090,SC2034
#===============================================================================
#
# FILE: bin/delete_message.sh
@ -19,32 +20,17 @@ USAGE='delete_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" [debug]'
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 03.01.2021 15:37
#
#### $$VERSION$$ v1.30-0-g3266427
#### $$VERSION$$ v1.31-dev-14-g749eee7
#===============================================================================
####
# parse args
DELETE="delete_message"
case "$1" in
'')
printf "missing arguments\n"
;&
"-h"*)
printf 'usage: %s\n' "${USAGE}"
exit 1
;;
'--h'*)
sed -n '3,/###/p' <"$0"
exit 1
;;
esac
# set bashbot environment
# shellcheck disable=SC1090
source "${0%/*}/bashbot_env.inc.sh" "${3:-debug}" # $3 debug
print_help
####
####
# ready, do stuff here -----
if [ "$1" == "BOTADMIN" ]; then
@ -59,5 +45,4 @@ fi
[ "${BOTSENT[OK]}" = "true" ] && BOTSENT[ID]="$2"
# output send message result
jssh_printDB "BOTSENT" | sort -r
print_result

View File

@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1090,SC2034
#===============================================================================
# shellcheck disable=SC2059
#
@ -27,7 +28,7 @@ USAGE='broadcast_message.sh [-h|--help] [--doit] [--groups|--both|--db=file] [fo
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 16.12.2020 16:14
#
#### $$VERSION$$ v1.30-0-g3266427
#### $$VERSION$$ v1.31-dev-14-g749eee7
#===============================================================================
####
@ -75,23 +76,11 @@ case "$1" in
SEND="send_html_message"
shift
;;
'')
printf "missing missing arguments\n"
;&
"-h"*)
printf 'usage: %s\n' "${USAGE}"
exit 1
;;
'--h'*)
sed -n -e '/# shellcheck /d' -e '3,/###/p' <"$0"
exit 1
;;
esac
# set bashbot environment
# shellcheck disable=SC1090
source "${0%/*}/bashbot_env.inc.sh" "$2" # $3 debug
print_help
# read in users from given DB or count.jssh
database="${USERDB:-${COUNTFILE}}"

View File

@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1090,SC2034
#===============================================================================
#
# FILE: bin/send_message.sh
@ -24,29 +25,16 @@ USAGE='send_message.sh [-h|--help] "CHAT[ID]" "message" "text|url" ...'
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 18.01.2021 11:34
#
#### $$VERSION$$ v1.31-dev-10-gf95b6c2
#### $$VERSION$$ v1.31-dev-14-g749eee7
#===============================================================================
####
# parse args
SEND="send_inline_keyboard"
case "$1" in
'')
printf "missing arguments\n"
;&
"-h"*)
printf 'usage: %s\n' "${USAGE}"
exit 1
;;
'--h'*)
sed -n '3,/###/p' <"$0"
exit 1
;;
esac
# set bashbot environment
# shellcheck disable=SC1090
source "${0%/*}/bashbot_env.inc.sh" "debug"
print_help
####
# ready, do stuff here -----
@ -62,5 +50,4 @@ shift 2
"${SEND}" "${CHAT}" "${TEXT}" "$(_button_row "$@")"
# output send message result
jssh_printDB "BOTSENT" | sort -r
print_result

View File

@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1090,SC2034
#===============================================================================
#
# FILE: bin/send_message.sh
@ -22,7 +23,7 @@ USAGE='send_edit_message.sh [-h|--help] [format|caption] "CHAT[ID]" "MESSAGE[ID]
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 23.12.2020 16:52
#
#### $$VERSION$$ v1.30-0-g3266427
#### $$VERSION$$ v1.31-dev-14-g749eee7
#===============================================================================
####
@ -45,24 +46,12 @@ case "$1" in
SEND="edit_message_caption"
shift
;;
'')
printf "missing arguments\n"
;&
"-h"*)
printf 'usage: %s\n' "${USAGE}"
exit 1
;;
'--h'*)
sed -n '3,/###/p' <"$0"
exit 1
;;
esac
# set bashbot environment
# shellcheck disable=SC1090
source "${0%/*}/bashbot_env.inc.sh" "${4:-debug}" # $4 debug
print_help
####
####
# ready, do stuff here -----
if [ "$1" == "BOTADMIN" ]; then
@ -75,5 +64,4 @@ fi
"${SEND}" "${CHAT}" "$2" "$3"
# output send message result
jssh_printDB "BOTSENT" | sort -r
print_result

View File

@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1090,SC2034
#===============================================================================
#
# FILE: bin/send_file.sh
@ -24,29 +25,16 @@ USAGE='send_file.sh [-h|--help] "CHAT[ID]" "file|URL" "caption ...." [type] [deb
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 25.12.2020 20:24
#
#### $$VERSION$$ v1.30-0-g3266427
#### $$VERSION$$ v1.31-dev-14-g749eee7
#===============================================================================
####
# parse args
SEND="send_file"
case "$1" in
'')
printf "missing arguments\n"
;&
"-h"*)
printf 'usage: %s\n' "${USAGE}"
exit 1
;;
'--h'*)
sed -n '3,/###/p' <"$0"
exit 1
;;
esac
# set bashbot environment
# shellcheck disable=SC1090
source "${0%/*}/bashbot_env.inc.sh" "${5:-debug}" # $5 debug
print_help
####
# ready, do stuff here -----
@ -64,5 +52,4 @@ FILE="$2"
"${SEND}" "${CHAT}" "${FILE}" "$3" "$4"
# output send message result
jssh_printDB "BOTSENT" | sort -r
print_result

View File

@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1090,SC2034
#===============================================================================
#
# FILE: bin/send_message.sh
@ -21,7 +22,7 @@ USAGE='send_message.sh [-h|--help] [format] "CHAT[ID]" "message ...." [debug]'
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 16.12.2020 11:34
#
#### $$VERSION$$ v1.30-0-g3266427
#### $$VERSION$$ v1.31-dev-14-g749eee7
#===============================================================================
####
@ -40,22 +41,11 @@ case "$1" in
SEND="send_html_message"
shift
;;
'')
printf "missing arguments\n"
;&
"-h"*)
printf 'usage: %s\n' "${USAGE}"
exit 1
;;
'--h'*)
sed -n '3,/###/p' <"$0"
exit 1
;;
esac
# set bashbot environment
# shellcheck disable=SC1090
source "${0%/*}/bashbot_env.inc.sh" "${3:-debug}" # $3 debug
print_help "$1"
####
# ready, do stuff here -----
@ -69,5 +59,4 @@ fi
"${SEND}" "${CHAT}" "$2"
# output send message result
jssh_printDB "BOTSENT" | sort -r
print_result