This commit is contained in:
Daniil Gentili 2016-01-02 21:51:45 +01:00
parent 46031627b7
commit b541042e79

View File

@ -26,19 +26,35 @@ send_photo() {
} }
readproc() { readproc() {
coproc="coproc$1" coproc="$1"
msg2send="${@/$1/}"
echo $msg2send >&${coproc["0"]}
}
sendproc() {
coproc="$1"
while true;do read msg <&${coproc["0"]}; [ "$?" != "0" ] && return || send_message "$TARGET" "$msg";done while true;do read msg <&${coproc["0"]}; [ "$?" != "0" ] && return || send_message "$TARGET" "$msg";done
} }
process_client() { process_client() {
local MESSAGE=$1 local MESSAGE=$1
local TARGET=$2 local TARGET=$2
local msg="" local msg=""
case $MESSAGE in local pid="coproc$TARGET"
'/info') msg="This is bashbot, the Telegram bot written entirely in bash.";; [ "$pid" = "" ] {
'/question') coproc "coproc$TARGET" { question; }; readproc $TARGET; return; case $MESSAGE in
*) msg="$MESSAGE";; '/info') msg="This is bashbot, the Telegram bot written entirely in bash.";;
esac '/question') coproc "$pid" { question; } &>&1; readproc $TARGET; return;;
send_message "$TARGET" "$msg"& *) msg="$MESSAGE";;
esac
send_message "$TARGET" "$msg"&
} || {
case $MESSAGE in
'/cancel') kill ${$pid};;
*) sendproc "$pid" "$MESSAGE";;
esac
} }
while true; do { while true; do {