telegram-bot-bash/examples/question.sh

58 lines
1.8 KiB
Bash
Raw Normal View History

2019-04-19 15:31:01 +00:00
#!/bin/bash
########################################################################
#
# File: question.sh
#
# Usage: runproc example/question.sh - or run in terminal
#
# Description: example for an interactive chat, see mycommands.sh.dist
#
2019-04-19 15:31:01 +00:00
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
2022-06-27 18:18:58 +00:00
#### $$VERSION$$ v1.52-1-g0dae2db
########################################################################
######
# parameters
2020-06-23 14:35:50 +00:00
# $1 $2 args as given to starct_proc chat script arg1 arg2
# $3 path to named pipe
INPUT="${3:-/dev/stdin}"
2019-04-19 15:31:01 +00:00
# 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
2021-06-03 11:28:29 +00:00
# kill interactive script if not finished in time, e.g. user away or error
MAXWAIT="1m"
2022-08-13 15:41:44 +00:00
{ sleep "${MAXWAIT}"; printf "Stopping questionnaire after %s. You've taken too long to finish! BYE\n" "${MAXWAIT}"; kill $$; wait 2>/dev/null ;} &
2021-06-03 11:28:29 +00:00
# simple yes/no question, defaults to no
printf "Hi, hello there\nWould you like some tea (y/n)?\n"
read -r answer <"${INPUT}"
if [[ ${answer,,} == "y"* ]]; then
printf "OK then, here you go: http://www.rivertea.com/blog/wp-content/uploads/2013/12/Green-Tea.jpg\n"
else
2022-08-13 15:11:27 +00:00
printf "OK then, no tea...\n"
fi
2022-08-13 15:41:44 +00:00
# question with keyboard, repeating until correct answer given
2021-01-04 22:08:09 +00:00
until [ "${SUCCESS}" = "y" ] ;do
2022-08-13 15:11:27 +00:00
printf 'Do you like music? mykeyboardstartshere "Yass!" , "No"\n'
read -r answer <"${INPUT}"
case ${answer,,} in
2022-08-13 15:11:27 +00:00
'') printf "Empty answer! Try again\n";;
'yass'*) printf "Goody! mykeyboardendshere\n";SUCCESS=y;;
'no'*) printf "Well that's weird. mykeyboardendshere\n";SUCCESS=y;;
2019-04-19 15:31:01 +00:00
*) SUCCESS=n;;
esac
done
printf "OK, Done!\n"