mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-28 12:50:44 +00:00
bin: process-batch: implement startbot for webhook
This commit is contained in:
parent
dda86e3496
commit
5dd24c3958
@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb
|
||||
# 8 - curl/wget missing
|
||||
# 10 - not bash!
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-48-gf4d45d8
|
||||
#### $$VERSION$$ v1.45-dev-54-gdda86e3
|
||||
##################################################################
|
||||
|
||||
# are we running in a terminal?
|
||||
@ -830,6 +830,7 @@ if [ -z "${SOURCE}" ]; then
|
||||
# finally starts the read update loop, internal use only
|
||||
"startbot" )
|
||||
_exec_if_function start_bot "$2"
|
||||
_exec_if_function get_updates "$2"
|
||||
debug_checks "end startbot" "$@"
|
||||
exit
|
||||
;;
|
||||
|
@ -4,10 +4,11 @@
|
||||
#
|
||||
# FILE: bin/process_batch.sh
|
||||
#
|
||||
USAGE='process_update.sh [-h|--help] -w|--watch [-n|--lines n] [file] [debug]'
|
||||
USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] [file] [debug]'
|
||||
#
|
||||
# DESCRIPTION: processes last 10 telegram updates in file, one update per line
|
||||
#
|
||||
# -s --startbot load addons, start TIMER, trigger startup actions
|
||||
# -w --watch watch for new updates added to file
|
||||
# -n --lines read only last "n" lines
|
||||
# file to read updates from
|
||||
@ -20,7 +21,7 @@ USAGE='process_update.sh [-h|--help] -w|--watch [-n|--lines n] [file] [debug]'
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 27.02.2021 13:14
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-53-g941598d
|
||||
#### $$VERSION$$ v1.45-dev-54-gdda86e3
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -29,6 +30,10 @@ COMMAND="process_multi_updates"
|
||||
lines="-n 10"
|
||||
|
||||
case "$1" in
|
||||
"-s"|"--startbot")
|
||||
startbot="yes"
|
||||
shift
|
||||
;;
|
||||
"-f"|"--follow")
|
||||
follow="-f"
|
||||
shift
|
||||
@ -43,20 +48,29 @@ esac
|
||||
source "${0%/*}/bashbot_env.inc.sh" "debug" # debug
|
||||
print_help "${1:-nix}"
|
||||
|
||||
|
||||
# empty file is webhook
|
||||
file="${WEBHOOK}"
|
||||
[ -n "$1" ] && file="$1"
|
||||
|
||||
# start bot
|
||||
if [ -n "${startbot}" ]; then
|
||||
# warn when starting bot without pipe
|
||||
[ -p "${WEBHOOK}" ] || printf "%b\n" "${ORANGE}Warning${NC}: File is not a pipe:${GREY} ${file##*/}${NC}"
|
||||
start_bot "$2"
|
||||
fi
|
||||
# check file exist
|
||||
if [[ ! -r "${file}" || -d "${file}" ]]; then
|
||||
printf "%b\n" "File ${GREY}${file}${NC} is not readable or is a directory."
|
||||
printf "%b\n" "${RED}Error${NC}: File not readable:${GREY} ${file}${NC}."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
####
|
||||
# ready, do stuff here -----
|
||||
|
||||
# kill all sub processes on exit
|
||||
trap 'kill $(jobs -p) 2>/dev/null' EXIT HUP QUIT
|
||||
|
||||
# use tail to read appended updates
|
||||
# shellcheck disable=SC2086,SC2248
|
||||
tail ${follow} ${lines} "${file}" |\
|
||||
while IFS="" read -r input
|
||||
|
@ -4,7 +4,7 @@
|
||||
# File: processUpdates.sh
|
||||
# Note: DO NOT EDIT! this file will be overwritten on update
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-38-g882efa8
|
||||
#### $$VERSION$$ v1.45-dev-54-gdda86e3
|
||||
##################################################################
|
||||
|
||||
##############
|
||||
@ -301,7 +301,7 @@ start_bot() {
|
||||
log_debug "${DEBUGMSG}"; DEBUGMSG="$1"
|
||||
[[ "${DEBUGMSG}" == "xdebug"* ]] && set -x
|
||||
# cleaup old pipes and empty logfiles
|
||||
find "${DATADIR}" -type p -delete
|
||||
find "${DATADIR}" -type p -not -name "webhook-fifo-*" -delete
|
||||
find "${DATADIR}" -size 0 -name "*.log" -delete
|
||||
# load addons on startup
|
||||
for addons in "${ADDONDIR:-.}"/*.sh ; do
|
||||
@ -330,7 +330,6 @@ start_bot() {
|
||||
send_normal_message "$(getConfigKey "botadmin")" "Bot $(getConfigKey "botname") started ..." &
|
||||
##########
|
||||
# bot is ready, start processing updates ...
|
||||
get_updates "${DEBUGMSG}"
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user