From d08d91205d9d0c29753c9b5a50fcb4f4e56d86f2 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 11 May 2019 18:36:40 +0200 Subject: [PATCH] move process_inline to bashbot.sh, documentation make-standalone.sh --- README.html | 4 +++- README.md | 8 +++++++- README.txt | 12 +++++++++++- bashbot.sh | 15 ++++++++++++--- commands.sh | 9 +++------ doc/7_develop.md | 18 ++++++++++++++++-- modules/inline.sh | 14 +------------- 7 files changed, 53 insertions(+), 27 deletions(-) diff --git a/README.html b/README.html index 8395305..06eff05 100644 --- a/README.html +++ b/README.html @@ -78,6 +78,8 @@
  • Customize bashbot environment
  • Examples
  • +

    I don’t like the many bashbot files

    +

    At the beginning bashbot was simply the file bashbot.sh I can copy everywhere and run the bot. Now we have ‘commands.sh’, ‘mycommands.sh’, ’modules/*.sh’ and much more. Hey no Problem, if you are finished with your cool bot simply run dev/make-standalone.sh to create a a stripped down Version containing only ‘bashbot.sh’ and ‘commands.sh’! For more information see Create a stripped down Version of your Bot

    Security Considerations

    Running a Telegram Bot means it is connected to the public and you never know whats send to your Bot.

    Bash scripts in general are not designed to be bullet proof, so consider this Bot as a proof of concept. Bash programmers often struggle with ‘quoting hell’ and globbing, see Implications of wrong quoting

    @@ -103,6 +105,6 @@

    @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.80-dev2-1-g0b36bc5

    +


    VERSION
    v0.80-dev2-4-gb7df57a

    diff --git a/README.md b/README.md index 2d09455..19d54da 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,12 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do * [Customize bashbot environment](doc/8_custom.md) * [Examples](examples/README.md) + +### I don't like the many bashbot files +At the beginning bashbot was simply the file ```bashbot.sh``` I can copy everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh', 'modules/*.sh' and much more. +Hey no Problem, if you are finished with your cool bot simply run ```dev/make-standalone.sh``` to create a a stripped down Version containing only +'bashbot.sh' and 'commands.sh'! For more information see [Create a stripped down Version of your Bot](doc/7_develop.md) + ## Security Considerations Running a Telegram Bot means it is connected to the public and you never know whats send to your Bot. @@ -98,4 +104,4 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-4-gb7df57a diff --git a/README.txt b/README.txt index bcf85c4..3953989 100644 --- a/README.txt +++ b/README.txt @@ -64,6 +64,16 @@ all](https://core.telegram.org/bots#3-how-do-i-create-a-bot) * [Customize bashbot environment](doc/8_custom.md) * [Examples](examples/README.md) + +### I don't like the many bashbot files +At the beginning bashbot was simply the file ```bashbot.sh``` I can copy +everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh', +'modules/*.sh' and much more. +Hey no Problem, if you are finished with your cool bot simply run +```dev/make-standalone.sh``` to create a a stripped down Version containing only +'bashbot.sh' and 'commands.sh'! For more information see [Create a stripped +down Version of your Bot](doc/7_develop.md) + ## Security Considerations Running a Telegram Bot means it is connected to the public and you never know whats send to your Bot. @@ -137,4 +147,4 @@ health status If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-4-gb7df57a diff --git a/bashbot.sh b/bashbot.sh index a5bf31e..8c5040d 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,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.80-dev2-2-g0c5e3dd +#### $$VERSION$$ v0.80-dev2-4-gb7df57a # # Exit Codes: # - 0 sucess (hopefully) @@ -144,8 +144,8 @@ UPD_URL=$URL'/getUpdates?offset=' GETFILE_URL=$URL'/getFile' unset USER -declare -A BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE -export BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE +declare -A BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY +export BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY COMMANDS="${BASHBOT_ETC:-.}/commands.sh" if [ "$1" != "source" ]; then @@ -412,6 +412,15 @@ JsonGetLine() { JsonGetValue() { sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]\([0-9.,]*\).*/\1/p' } + +process_inline() { + local num="${1}" + iQUERY[0]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",0,"inline_query","query"')")" + iQUERY[USER_ID]="$(JsonGetValue <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","id"')" + iQUERY[FIRST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","first_name"')")" + iQUERY[LAST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","last_name"')")" + iQUERY[USERNAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","username"')")" +} process_message() { local num="$1" local TMP="${TMPDIR:-.}/$RANDOM$RANDOM-MESSAGE" diff --git a/commands.sh b/commands.sh index 89c600d..be5fe65 100644 --- a/commands.sh +++ b/commands.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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-4-gb7df57a # # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -39,19 +39,16 @@ Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) ' if [ "${1}" != "source" ]; then - # load modules needed for commands.sh only # shellcheck source=./modules/aliases.sh [ -r "${MODULEDIR:-.}/aliases.sh" ] && source "${MODULEDIR:-.}/aliases.sh" # shellcheck source=./modules/background.sh [ -r "${MODULEDIR:-.}/background.sh" ] && source "${MODULEDIR:-.}/background.sh" + # shellcheck source=./modules/background.sh + [ -r "${MODULEDIR:-.}/inline.sh" ] && source "${MODULEDIR:-.}/inline.sh" else # defaults to no inline and nonsense home dir INLINE="0" FILE_REGEX='/home/user/allowed/.*' - - # load modules needed for bashbot.sh also - # shellcheck source=./modules/background.sh - [ -r "${MODULEDIR:-.}/inline.sh" ] && source "${MODULEDIR:-.}/inline.sh" fi # load mycommands diff --git a/doc/7_develop.md b/doc/7_develop.md index bb3f7cc..8dca1a6 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -4,7 +4,7 @@ This section is about help and best practices for new bashbot developers. The ma bashbot development is done on github. If you want to provide fixes or new features [fork bashbot on githup](https://help.github.com/en/articles/fork-a-repo) and provide changes as [pull request on github](https://help.github.com/en/articles/creating-a-pull-request). -### Debuging Bashbot +### Debugging Bashbot In normal mode of operation all bashbot output is discarded one more correct sent to TMUX console. To get these messages (and more) you can start bashbot in the current shell ```./bashbot.sh startbot```. Now you can see all output or erros from bashbot. In addition you can change the change the level of verbosity by adding a third argument after startbot. @@ -16,7 +16,19 @@ In addition you can change the change the level of verbosity by adding a third a "xdebugterm" same as xdebug but output and errors are sent to terminal ``` +### Create a stripped down Version of your Bot +Currently bashbot is more a bot development environment than a bot, containing examples, developer scripts, modules, documentation and more. +You don't need all these files after you're finished with your cool new bot. +Let's create a stripped down version: + +- delete all modules you do not need from 'modules', e.g. 'modules/inline.sh' if you don't use inline queries +- delete not needed standard commands and messages from 'commands.sh' +- delete not neede commands and functions from 'mycommands.sh' +- run ```dev/make-standalone.sh``` to create a a stripped down version of your bo + +Now have a look at the directory 'standalone', here you find the files 'bashbot.sh' and 'commands.sh' containing everything to run your bot. +[Download make-standalone.sh](https://github.com/topkecleon/telegram-bot-bash/blob/master/dev/make-standalone.sh) from github. ### Setup your develop environment @@ -48,6 +60,8 @@ Usually I start with pre versions and when everything looks good I push out a re v0.x-devx -> v0.x-prex -> v0.x-rc -> v0.x ... 0.x+1-dev ... ``` +If you release a new Version run ```dev/make-distribution.sh``` to create the zip and tar.gz archives in the dist directory and attach them to the github release. Do not forget to delete directory dist afterwards. + ### Versioning Bashbot is tagged with version numbers. If you start a new development cycle you can tag your fork with a version higher than the current version. @@ -131,5 +145,5 @@ fi #### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-4-gb7df57a diff --git a/modules/inline.sh b/modules/inline.sh index 1d2d4fa..5ad0edc 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -5,23 +5,11 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-4-gb7df57a # source from commands.sh to use the inline functions INLINE_QUERY=$URL'/answerInlineQuery' -declare -A iQUERY -export iQUERY - -process_inline() { - local num="${1}" - iQUERY[0]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",0,"inline_query","query"')")" - iQUERY[USER_ID]="$(JsonGetValue <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","id"')" - iQUERY[FIRST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","first_name"')")" - iQUERY[LAST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","last_name"')")" - iQUERY[USERNAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","username"')")" -} - answer_inline_query() { answer_inline_multi "${1}" "$(shift; inline_query_compose "$RANDOM" "$@")"