From 3cd6eebdf2df19832b26135017a4d069a8574fdb Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 27 Apr 2019 21:10:55 +0200 Subject: [PATCH] fix nasty workaround for external scripts --- README.md | 13 ++++-- README.txt | 23 ++++++----- modules/background.sh | 40 +++++++++---------- test/a-commit-test.sh | 0 test/d-JSON.sh-test.sh | 0 test/d-process_message-test.sh | 0 test/d-send_message-test.sh | 4 +- .../d-send_message-test.input | 1 + .../d-send_message-test.result | 5 +++ test/d-user_is-test.sh | 0 10 files changed, 50 insertions(+), 36 deletions(-) mode change 100755 => 100644 test/a-commit-test.sh mode change 100755 => 100644 test/d-JSON.sh-test.sh mode change 100755 => 100644 test/d-process_message-test.sh mode change 100755 => 100644 test/d-user_is-test.sh diff --git a/README.md b/README.md index e62c489..260babf 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ Most complete [UTF-8 support for bashbot](doc/4_expert.md#Bashbot-UTF-8-Support) Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Downloads](https://github.com/topkecleon/telegram-bot-bash/releases) are availible on www.github.com ## Documentation -* [Bots: Introduction for developers](https://core.telegram.org/bots) - * [The one to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot) +* [Introdution to Telegram Bots](https://core.telegram.org/bots) + * [One Bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot) * [Bot commands](https://core.telegram.org/bots#commands) * [Install Bashbot](doc/0_install.md) * Install release @@ -45,7 +45,11 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do * Seperate logic from commands * Test your Bot with shellcheck * [Bashbot function reference](doc/6_reference.md) -* [Notes for bashbot developers](doc/7_develop.md) +* [Deveoper Notess](doc/7_develop.md) + * Setup your environment + * Test, Add, Push changes + * Prepare a new version + * Bashbot testsuite * [Customize bashbot environment](doc/8_customize.md) @@ -82,10 +86,11 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from - easy to integrate with other shell script, e.g. for sending system message / health status - no need to install or learn a new programming language, library or framework - no database, not event driven, not OO ... + @Gnadelwartz ## That's it! If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-pre1-4-g0d38a67 +#### $$VERSION$$ v0.70-pre1-5-g07dc7b4 diff --git a/README.txt b/README.txt index b9ef8bf..7706193 100644 --- a/README.txt +++ b/README.txt @@ -27,8 +27,8 @@ are availible on www.github.com Documentation ~~~~~~~~~~~~~ -* https://core.telegram.org/bots[Bots: Introduction for developers] -** https://core.telegram.org/bots#3-how-do-i-create-a-bot[The one to +* https://core.telegram.org/bots[Introdution to Telegram Bots] +** https://core.telegram.org/bots#3-how-do-i-create-a-bot[One Bot to rule them all] ** https://core.telegram.org/bots#commands[Bot commands] * link:doc/0_install.md[Install Bashbot] @@ -56,7 +56,11 @@ rule them all] ** Seperate logic from commands ** Test your Bot with shellcheck * link:doc/6_reference.md[Bashbot function reference] -* link:doc/7_develop.md[Notes for bashbot developers] +* link:doc/7_develop.md[Deveoper Notess] +** Setup your environment +** Test, Add, Push changes +** Prepare a new version +** Bashbot testsuite * link:doc/8_customize.md[Customize bashbot environment] Security Considerations @@ -121,7 +125,7 @@ language, we have done our best to make it as secure as possible. But YOU are responsible for the bot commands you wrote and you should know about the risks ... -Why Bash and not the much better ...? +Why Bash and not the much better xyz? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Well, thats a damn good question ... may be because I'm an Unix/Linux @@ -129,12 +133,13 @@ admin from stone age. Nevertheless there are more reasons from my side: * bashbot will run everywhere where bash is availible, from ebedded linux to mainframe -* easy to integrate with other shell/bashscripts for system admins to -send status updates +* easy to integrate with other shell script, e.g. for sending system +message / health status * no need to install or learn a new programming language, library or -framwework +framework * no database, not event driven, not OO ... -* + +@Gnadelwartz That's it! ~~~~~~~~~~ @@ -142,5 +147,5 @@ That's it! If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -latexmath:[\[VERSION\]] v0.70-pre1-4-g0d38a67 +latexmath:[\[VERSION\]] v0.70-pre1-5-g07dc7b4 +++++++++++++++++++++++++++++++++++++++++++++ diff --git a/modules/background.sh b/modules/background.sh index 45cd601..d9e3dea 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.70-pre1-4-g0d38a67 +#### $$VERSION$$ v0.70-pre1-5-g07dc7b4 # source from commands.sh if you want ro use interactive or background jobs @@ -15,51 +15,49 @@ export res #### # I placed send_message here because main use case is interactive chats and background jobs send_message() { - local text arg keyboard btext burl no_keyboard file lat long title address sent [ "$2" = "" ] && return - local mychat="$1" - text="$(sed <<< "${2}" 's/ mynewlinestartshere/\r\n/g; s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - arg="$3" - [ "$arg" != "safe" ] && { + local text keyboard btext burl no_keyboard file lat long title address sent + text="$(sed <<< "${2}" 's/ *mynewlinestartshere */\r\n/g;s/ mykeyboardend.*//;s/ *my[a-z]\{3,15\}startshere.*//')$(sed <<< "${2}" -n '/mytextstartshere/ s/.*mytextstartshere//p')" + [ "$3" != "safe" ] && { no_keyboard="$(sed <<< "${2}" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" - keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - btext="$(sed <<< "${2}" '/mybtextstartshere /!d;s/.*mybtextstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - burl="$(sed <<< "${2}" '/myburlstartshere /!d;s/.*myburlstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - file="$(sed <<< "${2}" '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - lat="$(sed <<< "${2}" '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - long="$(sed <<< "${2}" '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - title="$(sed <<< "${2}" '/mytitlestartshere /!d;s/.*mytitlestartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - address="$(sed <<< "${2}" '/myaddressstartshere /!d;s/.*myaddressstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere *//;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')" + btext="$(sed <<< "${2}" '/mybtextstartshere /!d;s/.*mybtextstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')" + burl="$(sed <<< "${2}" '/myburlstartshere /!d;s/.*myburlstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//g;s/ *mykeyboardendshere.*//g')" + file="$(sed <<< "${2}" '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')" + lat="$(sed <<< "${2}" '/mylatstartshere /!d;s/.*mylatstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')" + long="$(sed <<< "${2}" '/mylongstartshere /!d;s/.*mylongstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')" + title="$(sed <<< "${2}" '/mytitlestartshere /!d;s/.*mytitlestartshere //;s/ *my[kfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')" + address="$(sed <<< "${2}" '/myaddressstartshere /!d;s/.*myaddressstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')" } if [ "$no_keyboard" != "" ]; then - remove_keyboard "$mychat" "$text" + remove_keyboard "$1" "$text" sent=y fi if [ "$keyboard" != "" ]; then if [[ "$keyboard" != *"["* ]]; then # pre 0.60 style keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]" fi - send_keyboard "$mychat" "$text" "$keyboard" + send_keyboard "$1" "$text" "$keyboard" sent=y fi if [ "$btext" != "" ] && [ "$burl" != "" ]; then - send_button "$mychat" "$text" "$btext" "$burl" + send_button "$1" "$text" "$btext" "$burl" sent=y fi if [ "$file" != "" ]; then - send_file "$mychat" "$file" "$text" + send_file "$1" "$file" "$text" sent=y fi if [ "$lat" != "" ] && [ "$long" != "" ]; then if [ "$address" != "" ] && [ "$title" != "" ]; then - send_venue "$mychat" "$lat" "$long" "$title" "$address" + send_venue "$1" "$lat" "$long" "$title" "$address" else - send_location "$mychat" "$lat" "$long" + send_location "$1" "$lat" "$long" fi sent=y fi if [ "$sent" != "y" ];then - send_text "$mychat" "$text" + send_text "$1" "$text" fi } diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh old mode 100755 new mode 100644 diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh old mode 100755 new mode 100644 diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh old mode 100755 new mode 100644 diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index e03236f..5a54f61 100755 --- a/test/d-send_message-test.sh +++ b/test/d-send_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-5-g07dc7b4 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -31,7 +31,7 @@ while IFS='' read -r line || [[ -n "$line" ]]; do done < "${INPUTFILE}" 2>>"${LOGFILE}" echo " done." -diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1 +{ diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1; } | cat -v echo " ... all \"send_message\" functions seems to work as expected." echo "${SUCCESS}" diff --git a/test/d-send_message-test/d-send_message-test.input b/test/d-send_message-test/d-send_message-test.input index d63cdde..f00eb65 100644 --- a/test/d-send_message-test/d-send_message-test.input +++ b/test/d-send_message-test/d-send_message-test.input @@ -15,3 +15,4 @@ All in one will appear in chat mykeyboardstartshere [ "Yep, sure" , "No, highly # test for new inline button Text plus keyboard will appear in chat mybtextstartshere Button Text myburlstartshere https://www... +STABILO 88/240 Fineliner point 88 mynewlinestartshere mynewlinestartshere [https://images-na.ssl-images-amazon.com/images/I/41oypA3kmHL.l_SX300.jpg] mynewlinestartshere mybtextstartshere Bei Amazon ansehen ... myburlstartshere https://www.amazon.de/dp/B014TN3JYW mytextstartshere second part of text diff --git a/test/d-send_message-test/d-send_message-test.result b/test/d-send_message-test/d-send_message-test.result index 4c3b28d..5ddf545 100644 --- a/test/d-send_message-test/d-send_message-test.result +++ b/test/d-send_message-test/d-send_message-test.result @@ -52,3 +52,8 @@ URL:https://api.telegram.org/botbashbottestscript/sendMessage chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"inline_keyboard": [ [ {"text":"Button Text", "url":"https://www..."}] ]} URL:https://api.telegram.org/botbashbottestscript/sendMessage +chat:123456 JSON:"text":"STABILO 88/240 Fineliner point 88 + +[https://images-na.ssl-images-amazon.com/images/I/41oypA3kmHL.l_SX300.jpg] second part of text", "reply_markup": {"inline_keyboard": [ [ {"text":"Bei Amazon ansehen ...", "url":"https://www.amazon.de/dp/B014TN3JYW"}] ]} +URL:https://api.telegram.org/botbashbottestscript/sendMessage + diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh old mode 100755 new mode 100644