mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-26 01:07:34 +00:00
Add function remove_keyboard to disable the custom keyboard
This commit is contained in:
parent
da181e4454
commit
fd08cd7873
28
bashbot.sh
28
bashbot.sh
@ -62,22 +62,29 @@ urlencode() {
|
|||||||
send_message() {
|
send_message() {
|
||||||
[ "$2" = "" ] && return 1
|
[ "$2" = "" ] && return 1
|
||||||
local chat="$1"
|
local chat="$1"
|
||||||
local text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g')"
|
local text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
local arg="$3"
|
local arg="$3"
|
||||||
[ "$3" != "safe" ] && {
|
[ "$3" != "safe" ] && {
|
||||||
local keyboard="$(echo "$2" | sed '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g')"
|
local no_keyboard="$(echo $2 | sed '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')"
|
||||||
|
|
||||||
local file="$(echo "$2" | sed '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ mykeyboardstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g')"
|
local keyboard="$(echo "$2" | sed '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
local lat="$(echo "$2" | sed '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g')"
|
local file="$(echo "$2" | sed '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ mykeyboardstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
local long="$(echo "$2" | sed '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g')"
|
local lat="$(echo "$2" | sed '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
local title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g')"
|
local long="$(echo "$2" | sed '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
local address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g')"
|
local title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
|
local address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if [ "$no_keyboard" != "" ]; then
|
||||||
|
echo "remove_keyboard $chat $text" > /tmp/prova
|
||||||
|
remove_keyboard "$chat" "$text"
|
||||||
|
local sent=y
|
||||||
|
fi
|
||||||
if [ "$keyboard" != "" ]; then
|
if [ "$keyboard" != "" ]; then
|
||||||
send_keyboard "$chat" "$text" "$keyboard"
|
send_keyboard "$chat" "$text" "$keyboard"
|
||||||
local sent=y
|
local sent=y
|
||||||
@ -232,6 +239,13 @@ send_keyboard() {
|
|||||||
res=$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"keyboard\": [$keyboard],\"one_time_keyboard\": true}")
|
res=$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"keyboard\": [$keyboard],\"one_time_keyboard\": true}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove_keyboard() {
|
||||||
|
local chat="$1"
|
||||||
|
local text="$2"
|
||||||
|
shift 2
|
||||||
|
res=$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"remove_keyboard\": true}")
|
||||||
|
}
|
||||||
|
|
||||||
get_file() {
|
get_file() {
|
||||||
[ "$1" != "" ] && echo $FILE_URL$(curl -s "$GET_URL" -F "file_id=$1" | ./JSON.sh/JSON.sh -s | egrep '\["result","file_path"\]' | cut -f 2 | cut -d '"' -f 2)
|
[ "$1" != "" ] && echo $FILE_URL$(curl -s "$GET_URL" -F "file_id=$1" | ./JSON.sh/JSON.sh -s | egrep '\["result","file_path"\]' | cut -f 2 | cut -d '"' -f 2)
|
||||||
}
|
}
|
||||||
|
4
question
4
question
@ -11,8 +11,8 @@ until [ "$SUCCESS" = "y" ] ;do
|
|||||||
echo 'Do you like Music? mykeyboardstartshere "Yass!" "No"'
|
echo 'Do you like Music? mykeyboardstartshere "Yass!" "No"'
|
||||||
read answer
|
read answer
|
||||||
case $answer in
|
case $answer in
|
||||||
'Yass!') echo "Goody!";SUCCESS=y;;
|
'Yass!') echo "Goody! mykeyboardendshere";SUCCESS=y;;
|
||||||
'No') echo "Well that's weird.";SUCCESS=y;;
|
'No') echo "Well that's weird. mykeyboardendshere";SUCCESS=y;;
|
||||||
*) SUCCESS=n;;
|
*) SUCCESS=n;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user