Make it multitask again

This commit is contained in:
Daniil Gentili 2016-01-02 20:46:34 +01:00
parent c60aabb9ee
commit 46031627b7

View File

@ -26,9 +26,8 @@ send_photo() {
} }
readproc() { readproc() {
cur=test
coproc="coproc$1" coproc="coproc$1"
while [ "$cur" != "" ];do read cur <&${coproc["0"]};echo "$cur";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
@ -36,7 +35,7 @@ process_client() {
local msg="" local msg=""
case $MESSAGE in case $MESSAGE in
'/info') msg="This is bashbot, the Telegram bot written entirely in bash.";; '/info') msg="This is bashbot, the Telegram bot written entirely in bash.";;
'/question') coproc "coproc$TARGET" { question; }; msg="$(readproc $TARGET)" '/question') coproc "coproc$TARGET" { question; }; readproc $TARGET; return;
*) msg="$MESSAGE";; *) msg="$MESSAGE";;
esac esac
send_message "$TARGET" "$msg"& send_message "$TARGET" "$msg"&
@ -53,7 +52,7 @@ while true; do {
OFFSET=$((OFFSET+1)) OFFSET=$((OFFSET+1))
if [ $OFFSET != 1 ]; then if [ $OFFSET != 1 ]; then
process_client "$MESSAGE" "$TARGET" process_client "$MESSAGE" "$TARGET"&
fi fi