mirror of
https://github.com/danog/id3bot.git
synced 2024-11-26 20:04:46 +01:00
Added custom keyboard function
This commit is contained in:
parent
b541042e79
commit
7ef846b8c0
58
bashbot.sh
58
bashbot.sh
@ -18,22 +18,45 @@ UPD_URL=$URL'/getUpdates?offset='
|
|||||||
OFFSET=0
|
OFFSET=0
|
||||||
|
|
||||||
send_message() {
|
send_message() {
|
||||||
res=$(curl "$MSG_URL" -F "chat_id=$1" -F "text=$2")
|
[ "$2" != "" ] && res=$(curl "$MSG_URL" -F "chat_id=$1" -F "text=$2")
|
||||||
|
}
|
||||||
|
send_keyboard() {
|
||||||
|
for f in ${@/1\|2/};do keyboard="$keyboard, [\"$f\"]";done
|
||||||
|
keyboard=${keyboard/^, /}
|
||||||
|
res=$(curl "$MSG_URL" -F "chat_id=$1" -F "text=$2" -F "reply_markup={\"keyboard\": $keyboard, \"one_time_keyboard\": true}")
|
||||||
}
|
}
|
||||||
|
|
||||||
send_photo() {
|
send_photo() {
|
||||||
res=$(curl "$PHO_URL" -F "chat_id=$1" -F "photo=@$2")
|
res=$(curl "$PHO_URL" -F "chat_id=$1" -F "photo=@$2")
|
||||||
}
|
}
|
||||||
|
|
||||||
readproc() {
|
question() {
|
||||||
coproc="$1"
|
TARGET="$1'
|
||||||
msg2send="${@/$1/}"
|
echo "Why hello there.
|
||||||
echo $msg2send >&${coproc["0"]}
|
Would you like some tea (y/n)?"
|
||||||
|
read answer
|
||||||
|
[[ $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
|
||||||
|
send_keyboard "$TARGET" "Do you like Music?" "Yass!" "No"
|
||||||
|
read answer
|
||||||
|
case $answer in
|
||||||
|
'Yass!') echo "Goody!";SUCCESS=y;;
|
||||||
|
'No') echo "Well that's weird";SUCCESS=y;;
|
||||||
|
*) SUCCESS=n;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
sendproc() {
|
inproc() {
|
||||||
coproc="$1"
|
copname="$1"
|
||||||
while true;do read msg <&${coproc["0"]}; [ "$?" != "0" ] && return || send_message "$TARGET" "$msg";done
|
msg="${@/1/}"
|
||||||
|
echo "$msg" >&${$1["0"]}
|
||||||
|
}
|
||||||
|
|
||||||
|
outproc() {
|
||||||
|
copname="$1"
|
||||||
|
TARGET="$2"
|
||||||
|
while true; do read msg <&${$copname["0"]}; [ "$?" != "0" ] && return || send_message "$TARGET" "$msg";done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -41,20 +64,22 @@ process_client() {
|
|||||||
local MESSAGE=$1
|
local MESSAGE=$1
|
||||||
local TARGET=$2
|
local TARGET=$2
|
||||||
local msg=""
|
local msg=""
|
||||||
local pid="coproc$TARGET"
|
local copname="coproc$TARGET"
|
||||||
[ "$pid" = "" ] {
|
local copidname="$copname"_PID
|
||||||
|
local copid="${$copid}"
|
||||||
|
[ "$copid" = "" ] {
|
||||||
case $MESSAGE in
|
case $MESSAGE in
|
||||||
'/info') msg="This is bashbot, the Telegram bot written entirely in bash.";;
|
'/info') send_message "$TARGET" "This is bashbot, the Telegram bot written entirely in bash.";;
|
||||||
'/question') coproc "$pid" { question; } &>&1; readproc $TARGET; return;;
|
'/question') coproc "$copname" { question "$TARGET"; } &>&1; outproc "$copname" "$TARGET"; return;;
|
||||||
*) msg="$MESSAGE";;
|
*) send_message "$TARGET" "$MESSAGE";;
|
||||||
esac
|
esac
|
||||||
send_message "$TARGET" "$msg"&
|
|
||||||
} || {
|
} || {
|
||||||
|
|
||||||
case $MESSAGE in
|
case $MESSAGE in
|
||||||
'/cancel') kill ${$pid};;
|
'/cancel') kill $copid;;
|
||||||
*) sendproc "$pid" "$MESSAGE";;
|
*) inproc "$copname" "$MESSAGE";;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while true; do {
|
while true; do {
|
||||||
@ -69,7 +94,6 @@ while true; do {
|
|||||||
|
|
||||||
if [ $OFFSET != 1 ]; then
|
if [ $OFFSET != 1 ]; then
|
||||||
process_client "$MESSAGE" "$TARGET"&
|
process_client "$MESSAGE" "$TARGET"&
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
} &>/dev/null; done
|
} &>/dev/null; done
|
||||||
|
Loading…
Reference in New Issue
Block a user