mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2025-02-04 19:38:24 +00:00
interactive working again, more logging
This commit is contained in:
parent
3f85134d2f
commit
601fe0ea51
19
bashbot.rc
19
bashbot.rc
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# description: Start or stop telegram-bash-bot
|
||||
#
|
||||
#### $$VERSION$$ v0.96-dev-7-g0153928
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
# shellcheck disable=SC2009
|
||||
# shellcheck disable=SC2181
|
||||
|
||||
@ -31,29 +31,22 @@ runcmd="echo Dry run:" # not actived until you edit lines below
|
||||
# runcmd="runuser $runas -s /bin/bash -c " # runasuser with *runuser*
|
||||
|
||||
# edit the values of the following lines to fit your config:
|
||||
start="/usr/local/telegram-bot-bash/bashbot.sh" # location of your bashbot.sh script
|
||||
start="cd /usr/local/telegram-bot-bash; /usr/local/telegram-bot-bash/bashbot.sh" # location of your bashbot.sh script
|
||||
name='' # your bot name as given to botfather, e.g. mysomething_bot
|
||||
|
||||
# END Configuration
|
||||
#######################
|
||||
|
||||
lockfile="$(dirname $start)/lockfile"
|
||||
[ "$name" = "" ] && name="$runas"
|
||||
|
||||
case "$1" in
|
||||
'start')
|
||||
$runcmd "$start start" # >/dev/null 2>&1 </dev/null
|
||||
RETVAL=$?
|
||||
if [ "$RETVAL" = "0" ]; then
|
||||
touch "$lockfile" >/dev/null 2>&1
|
||||
fi
|
||||
;;
|
||||
'stop')
|
||||
$runcmd "$start kill"
|
||||
RETVAL=$?
|
||||
if [ "$RETVAL" = "0" ]; then
|
||||
rm -f "$lockfile"
|
||||
fi
|
||||
;;
|
||||
'status')
|
||||
ps -f -u "$runas" | grep "$name" | grep -qF "bashbot.sh startbot"
|
||||
@ -76,10 +69,10 @@ case "$1" in
|
||||
'suspendback'|'resumeback'|'killback')
|
||||
$runcmd "$start $1"
|
||||
RETVAL=$?
|
||||
# kill inotifywait from runuser if long running bg scripts use it
|
||||
KILLINOTIFY=""
|
||||
if [ "$1" != "resumeback" ] && [ -n "${KILLINOTIFY}" ]; then
|
||||
kill -9 "$(ps -u "$runas" | grep inotifywait | sed 's/ .*//')" >/dev/null 2>&1
|
||||
# kill inotifywait from runuser
|
||||
if [ "$1" != "resumeback" ]; then
|
||||
# shellcheck disable=SC2046
|
||||
kill -9 $(ps -u "$runas" | grep inotifywait | sed 's/ .*//') >/dev/null 2>&1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
|
11
bashbot.sh
11
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$$ v0.96-dev3-8-gd42429e
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
@ -320,8 +320,9 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
||||
-H "Content-Type: application/json" | "${JSONSHFILE}" -s -b -n )"
|
||||
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${res}")"
|
||||
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "${res}")"
|
||||
[ "${BOTSENT[OK]}" != "true" ] && printf "%s: %s\n" "$(date)" "${res}" >>"${LOGDIR}/ERROR.log"
|
||||
[ "${SOURCE}" != "yes" ] && [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "$@" &
|
||||
[ "${BOTSENT[OK]}" != "true" ] &&\
|
||||
printf "%s: CHAT[ID]=%s ACTION=%s\nRESULT=%s\n" "$(date)" "${1}" "${2}" "${res}" >>"${LOGDIR}/ERROR.log"
|
||||
}
|
||||
#$1 Chat, $2 what , $3 file, $4 URL, $5 caption
|
||||
sendUpload() {
|
||||
@ -334,8 +335,9 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
||||
res="$(curl -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1" -F "$2=@$3;${3##*/}" | "${JSONSHFILE}" -s -b -n )"
|
||||
fi
|
||||
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${res}")"
|
||||
[ "${BOTSENT[OK]}" != "true" ] && printf "%s: %s\n" "$(date)" "${res}" >>"${LOGDIR}/ERROR.log"
|
||||
[ "${SOURCE}" != "yes" ] && [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" &
|
||||
[ "${BOTSENT[OK]}" != "true" ] &&\
|
||||
printf "%s: CHAT[ID]=%s ACTION=%s\nRESULT=%s\n" "$(date)" "${1}" "${2}" "${res}" >>"${LOGDIR}/ERROR.log"
|
||||
}
|
||||
else
|
||||
# simple curl or wget call outputs result to stdout
|
||||
@ -352,8 +354,9 @@ else
|
||||
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n )"
|
||||
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${res}")"
|
||||
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "${res}")"
|
||||
[ "${BOTSENT[OK]}" != "true" ] && printf "%s: %s\n" "$(date)" "${res}" >>"${LOGDIR}/ERROR.log"
|
||||
[ "${SOURCE}" != "yes" ] && [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "$@" &
|
||||
[ "${BOTSENT[OK]}" != "true" ] &&\
|
||||
printf "%s: CHAT[ID]=%s ACTION=%s\nRESULT=%s\n" "$(date)" "${1}" "${2}" "${res}" >>"${LOGDIR}/ERROR.log"
|
||||
}
|
||||
sendUpload() {
|
||||
printf "%s: %s\n" "$(date)" "Sorry, wget does not support file upload" >>"${LOGDIR}/ERROR.log"
|
||||
|
@ -15,7 +15,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ 0.96-dev2-9-ged14e85
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
#
|
||||
|
||||
# adjust your language setting here, e.g.when run from other user or cron.
|
||||
@ -126,7 +126,9 @@ if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then
|
||||
unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
||||
;;
|
||||
|
||||
*) # forward messages to optional dispatcher
|
||||
'/'*) # discard all unkown commands
|
||||
: ;;
|
||||
*) # forward message to interactive chats
|
||||
_exec_if_function send_interactive "${CHAT[ID]}" "${MESSAGE}"
|
||||
;;
|
||||
esac
|
||||
|
@ -1,10 +1,16 @@
|
||||
#!/bin/bash
|
||||
# file: run_diskcusage.sh
|
||||
# example for an background job display a system value
|
||||
|
||||
#
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#### $$VERSION$$ v0.96-dev-7-g0153928
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
@ -2,7 +2,13 @@
|
||||
# file: run_filename
|
||||
# background job to display content of all new files in WATCHDIR
|
||||
#
|
||||
#### $$VERSION$$ v0.96-dev-7-g0153928
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
@ -33,3 +39,4 @@ loop_callback() {
|
||||
}
|
||||
|
||||
watch_dir_loop "$WATCHDIR"
|
||||
|
||||
|
@ -2,7 +2,13 @@
|
||||
# file: run_filename
|
||||
# background job to display all new files in WATCHDIR
|
||||
#
|
||||
#### $$VERSION$$ v0.96-dev-7-g0153928
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
@ -31,3 +37,4 @@ loop_callback() {
|
||||
}
|
||||
|
||||
watch_dir_loop "$WATCHDIR"
|
||||
|
||||
|
@ -1,10 +1,16 @@
|
||||
#!/bin/bash
|
||||
# file: notify.sh
|
||||
# example for an background job, run with startback notify.sh
|
||||
|
||||
#
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#### $$VERSION$$ v0.96-dev-7-g0153928
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
@ -1,11 +1,18 @@
|
||||
#!/bin/bash
|
||||
# file: calc.sh
|
||||
# example for an interactive chat, run with startproc calc.sh
|
||||
|
||||
#
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
|
||||
#### $$VERSION$$ v0.96-dev-7-g0153928
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
INPUT="${3:-/dev/stdin}"
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
@ -18,11 +25,11 @@ unset IFS
|
||||
|
||||
echo 'Starting Calculator ...'
|
||||
echo 'Enter first number.'
|
||||
read -r A
|
||||
read -r A <"${INPUT}"
|
||||
echo 'Enter second number.'
|
||||
read -r B
|
||||
read -r B <"${INPUT}"
|
||||
echo 'Select Operation: mykeyboardstartshere [ "Addition" , "Subtraction" , "Multiplication" , "Division" , "Cancel" ]'
|
||||
read -r opt
|
||||
read -r opt <"${INPUT}"
|
||||
echo -n 'Result: '
|
||||
case $opt in
|
||||
'add'* | 'Add'* ) res="$(( A + B ))" ;;
|
||||
@ -34,3 +41,4 @@ case $opt in
|
||||
esac
|
||||
echo "$res"
|
||||
echo "Bye .."
|
||||
|
||||
|
@ -1,10 +1,16 @@
|
||||
#!/bin/bash
|
||||
# file: notify.sh
|
||||
# example for an background job, run with startback notify.sh
|
||||
|
||||
#
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#### $$VERSION$$ v0.96-dev-7-g0153928
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
@ -1,11 +1,19 @@
|
||||
#!/bin/bash
|
||||
# file: question.sh
|
||||
# example for an interactive chat, run with startproc question.sh
|
||||
|
||||
#
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $3 path to named pipe
|
||||
|
||||
INPUT="${3:-/dev/stdin}"
|
||||
|
||||
#### $$VERSION$$ v0.96-dev-7-g0153928
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
@ -18,16 +26,16 @@ unset IFS
|
||||
|
||||
echo "Why hello there.
|
||||
Would you like some tea (y/n)?"
|
||||
read -r answer
|
||||
read -r answer <"${INPUT}"
|
||||
[[ $answer =~ ^([yY][eE][sS]|[yY])$ ]] && echo "OK then, here you go: http://www.rivertea.com/blog/wp-content/uploads/2013/12/Green-Tea.jpg" || echo "OK then."
|
||||
until [ "$SUCCESS" = "y" ] ;do
|
||||
echo 'Do you like Music? mykeyboardstartshere "Yass!" , "No"'
|
||||
read -r answer
|
||||
read -r answer <"${INPUT}"
|
||||
case $answer in
|
||||
'Yass!') echo "Goody! mykeyboardendshere";SUCCESS=y;;
|
||||
'No') echo "Well that's weird. mykeyboardendshere";SUCCESS=y;;
|
||||
'') echo "empty answer!" && exit;;
|
||||
'') echo "empty answer!" && cleanup "$3";;
|
||||
*) SUCCESS=n;;
|
||||
esac
|
||||
done
|
||||
exit
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.96-dev3-11-g515e07d
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
|
||||
# source from commands.sh if you want ro use interactive or background jobs
|
||||
|
||||
@ -61,7 +61,8 @@ start_proc() {
|
||||
local fifo; fifo="${DATADIR:-.}/$(procname "$1")"
|
||||
kill_proc "$1"
|
||||
mkfifo "${fifo}"
|
||||
nohup bash -c "{ tail -f < \"${fifo}\" | $2 \"$3\" \"$4\" \"${fifo}\" | \"${SCRIPT}\" outproc \"${1}\" \"${fifo}\"; }" &>>"${fifo}.log" &
|
||||
nohup bash -c "{ $2 \"$4\" \"$5\" \"$fifo\" | \"${SCRIPT}\" outproc \"${1}\" \"${fifo}\"
|
||||
rm \"${fifo}\"; [ -s \"${fifo}.log\" ] || rm -f \"${fifo}.log\"; }" &>>"${fifo}.log" &
|
||||
}
|
||||
|
||||
|
||||
|
44
scripts/interactive.sh.clean
Executable file
44
scripts/interactive.sh.clean
Executable file
@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
# file: interactive.sh
|
||||
# template for an interactive chat
|
||||
# test it with: start_proc "${CHAT[ID]}" "./scripts/interactive.sh.clean"
|
||||
#
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.96-dev3-12-g3f85134
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $3 path to named pipe
|
||||
|
||||
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
export 'LC_ALL=C.UTF-8'
|
||||
export 'LANG=C.UTF-8'
|
||||
export 'LANGUAGE=C.UTF-8'
|
||||
|
||||
unset IFS
|
||||
# set -f # if you are paranoid use set -f to disable globbing
|
||||
|
||||
#######################
|
||||
# place your commands here
|
||||
#
|
||||
# IMPORTTANT: to read user input from $INPUT
|
||||
INPUT="${3:-/dev/stdin}"
|
||||
#
|
||||
# read -r variable <"${INPUT}"
|
||||
|
||||
# example wait form user input and echo it
|
||||
echo "Enter a message:"
|
||||
|
||||
read -r test <"${INPUT}"
|
||||
echo -e "Your Message: ${test}\nbye!"
|
||||
|
||||
|
||||
# your commands ends here
|
||||
######################
|
||||
|
Loading…
x
Reference in New Issue
Block a user