From f59ddae61045d859e2a06b36d711933a2eba1f45 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 22 Apr 2019 20:34:43 +0200 Subject: [PATCH 01/63] start 0.7 dev2, add JSON.sh test --- .gitignore | 4 +- README.md | 8 ++-- README.txt | 12 ++--- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/hooks/pre-commit.sh | 12 ++--- dev/hooks/pre-push.sh | 10 ++-- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 56 ++++++++++++++++++++++ dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- test/ALL-tests.inc.sh | 5 +- test/ALL-tests.sh | 6 +-- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 35 ++++++++++++++ test/d-JSON.sh-test/JSON26783.log.result-1 | 22 +++++++++ test/d-JSON.sh-test/JSON26783.log.result-2 | 31 ++++++++++++ test/d-JSON.sh-test/JSON30458.log.result-1 | 19 ++++++++ test/d-JSON.sh-test/JSON30458.log.result-2 | 26 ++++++++++ test/d-JSON.sh-test/JSON32034.log.result-1 | 18 +++++++ test/d-JSON.sh-test/JSON32034.log.result-2 | 25 ++++++++++ test/d-process_message-test.sh | 2 +- 37 files changed, 283 insertions(+), 50 deletions(-) create mode 100755 dev/make-dist.sh mode change 100644 => 100755 test/a-commit-test.sh mode change 100644 => 100755 test/a-push-test.sh create mode 100755 test/d-JSON.sh-test.sh create mode 100644 test/d-JSON.sh-test/JSON26783.log.result-1 create mode 100644 test/d-JSON.sh-test/JSON26783.log.result-2 create mode 100644 test/d-JSON.sh-test/JSON30458.log.result-1 create mode 100644 test/d-JSON.sh-test/JSON30458.log.result-2 create mode 100644 test/d-JSON.sh-test/JSON32034.log.result-1 create mode 100644 test/d-JSON.sh-test/JSON32034.log.result-2 diff --git a/.gitignore b/.gitignore index cda6e25..b977922 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ *~ +/.github/ /count /token *.save *.log -/JSON.sh/* +/JSON.sh/ /tmp-bot-bash/ +/dist/ diff --git a/README.md b/README.md index 5a4d710..0ef3e69 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,11 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do 1. Go to the directory you want to install bashbot, e.g. * your $HOME directory (install and run with your user-ID) * /usr/local if you want to run as service -2. [Download latest release](https://github.com/topkecleon/telegram-bot-bash/releases) archive from github and extract all files. +2. [Download latest release zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) and extract all files. - As an alternative you can clone the github repository to get the latest, but possible unstable improvements. + As an alternative you can clone the github repository to get the latest improvements, run All-tests.sh to be shure. ``` - git clone https://github.com/topkecleon/telegram-bot-bash + git clone https://github.com/topkecleon/telegram-bot-bash; test/ALL-tests.sh ``` 3. Go to directory ```telegram-bot-bash```, run ```./bashbot.sh init``` and follow the instructions. At this point you are asked for your Bots token given by botfather. @@ -102,4 +102,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 diff --git a/README.txt b/README.txt index 56472e7..74c3ffc 100644 --- a/README.txt +++ b/README.txt @@ -31,13 +31,13 @@ Install bashbot * your $HOME directory (install and run with your user-ID) * /usr/local if you want to run as service 2. https://github.com/topkecleon/telegram-bot-bash/releases[Download -latest release] archive from github and extract all files. +latest release zip from github] and extract all files. + -As an alternative you can clone the github repository to get the latest, -but possible unstable improvements. +As an alternative you can clone the github repository to get the latest +improvements, run All-tests.sh to be shure. + .... -git clone https://github.com/topkecleon/telegram-bot-bash +git clone https://github.com/topkecleon/telegram-bot-bash; test/ALL-tests.sh .... 3. Go to directory `telegram-bot-bash`, run `./bashbot.sh init` and follow the instructions. At this point you are asked for your Bots token @@ -166,5 +166,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.62-0-g5d5dbae -++++++++++++++++++++++++++++++++++++++++ +latexmath:[\[VERSION\]] v0.70-dev2-0-g4fff4c3 ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index e729f9e..a422b62 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 84d5a4b..5dbd71e 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index 21df7ed..f5ee34e 100755 --- a/commands.sh +++ b/commands.sh @@ -4,7 +4,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.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 38cbc16..a627052 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -8,20 +8,18 @@ cd "$GIT_DIR/.." || exit 1 export HOOKDIR="dev/hooks" -echo "Running pre-commit hook" # if any command inside script returns error, exit and return that error set -e -# let's fake failing test for now -echo "Running tests" +echo "Running pre-commit hook" echo "............................" unset IFS; set -f # check for shellcheck if which shellcheck >/dev/null 2>&1; then - echo "Test all scripts with shellcheck ..." + echo " Test all scripts with shellcheck ..." else echo "Error: shellcheck is not installed. Install shellcheck or delete $0" exit 1 @@ -29,13 +27,13 @@ fi # run shellcheck before commit set +f -FILES="$(find ./* -name '*.sh')" +FILES="$(find ./* -name '*.sh' | grep -v 'dist\/' )" set -f FILES="${FILES} $(sed '/^#/d' <"dev/shellcheck.files")" if [ "$FILES" != "" ]; then # shellcheck disable=SC2086 shellcheck -x ${FILES} || exit 1 - echo "OK" + echo " OK" else # something went wrong exit 1 diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index 6b4179b..f79bb5f 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -11,13 +11,11 @@ export HOOKDIR="dev/hooks" REMOTEVER="$(git ls-remote -t --refs 2>/dev/null | tail -1 | sed 's/.*\/v//')" VERSION="$(git describe --tags | sed -e 's/-.*//' -e 's/v//')" -echo "Running pre-push hook" # if any command inside script returns error, exit and return that error set -e -# let's fake failing test for now -echo "Running tests" +echo "Running pre-push hook" echo "............................" unset IFS; set -f @@ -25,7 +23,9 @@ unset IFS; set -f # LOCAL version must greater than latest REMOTE release version if (( $(echo "${VERSION} > ${REMOTEVER}" | bc -l) )); then # update version in bashbot files on push - dev/version.sh 2>/dev/null + echo -n " " + dev/version.sh 2>/dev/null || exit 1 + echo " OK" else echo "Error: local version ${VERSION} must be greater than latest release version." echo "use \"git tag ...\" to create a local version greater than ${REMOTEVER}" diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 3b038c7..eec30a2 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh new file mode 100755 index 0000000..125df10 --- /dev/null +++ b/dev/make-dist.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# this has to run once atfer git clone +# and every time we create new hooks +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 + +# magic to ensure that we're always inside the root of our application, +# no matter from which directory we'll run script +GIT_DIR=$(git rev-parse --git-dir) +cd "$GIT_DIR/.." || exit 1 + +VERSION="$(git describe --tags | sed -e 's/-.*//' -e 's/v//')" + +DISTNAME="telegram-bot-bash" +DISTDIR="./dist/${DISTNAME}" +DISTFILES="bashbot.rc bashbot.sh commands.sh doc examples LICENSE README.md README.txt" + +# run tests first! + +for test in dev/hooks/* "test/ALL-tests.sh" +do + if ! "${test}" ; then + echo "Test ${test} failed, can't create dist!" + exit 1 + fi +done + +# create dir for sitribution and copy files +mkdir -p "${DISTDIR}" 2>/dev/null +# shellcheck disable=SC2086 +cp -r ${DISTFILES} "${DISTDIR}" +cd "${DISTDIR}" || exit 1 + +# additional stuff +mv "commands.sh" "commands.sh.dist" + +JSONSHFILE="JSON.sh/JSON.sh" +if [ ! -f "${JSONSHFILE}" ]; then + mkdir "JSON.sh" 2>/dev/null; + curl -sL -o "${JSONSHFILE}" "https://cdn.jsdelivr.net/gh/dominictarr/JSON.sh/JSON.sh" + chmod +x "${JSONSHFILE}" +fi + +# create archive +cd .. || exit 1 +zip -rq "${DISTNAME}-${VERSION}.zip" "${DISTNAME}" +tar -czf "${DISTNAME}-${VERSION}.tar.gz" "${DISTNAME}" + + +# shellcheck disable=SC2086 +ls -ld ${DISTNAME}-${VERSION}.* + +# remove temporary dist dir +cd "$GIT_DIR/.." || exit 1 +rm -rf ${DISTDIR} + + diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 24a3dc5..11dffe3 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 24f925c..92598c0 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 1c571da..eed1c90 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -61,5 +61,5 @@ group. This step is up to you actually. #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 diff --git a/doc/2_usage.md b/doc/2_usage.md index 08fa1aa..bd3b632 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -159,5 +159,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index fe18270..d4d0118 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 diff --git a/doc/4_expert.md b/doc/4_expert.md index 37ef179..594537f 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 diff --git a/doc/5_practice.md b/doc/5_practice.md index df7b663..e74fd19 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 diff --git a/doc/6_reference.md b/doc/6_reference.md index a4c52ff..050f00a 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -348,5 +348,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Developer Rules](7_develop.md) -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 diff --git a/doc/7_develop.md b/doc/7_develop.md index e439a72..e841540 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -70,5 +70,5 @@ fi #### [Prev Function Reference](6_function.md) -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 854c8c7..451ab81 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 97b3068..0f9c0af 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -3,7 +3,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.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index 378d6af..0370695 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -2,7 +2,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.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh index c9bfaf8..249dfca 100755 --- a/examples/question,sh +++ b/examples/question,sh @@ -3,7 +3,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.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index c9bfaf8..249dfca 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -3,7 +3,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.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index fd0193f..045cda4 100755 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME @@ -23,6 +23,7 @@ export SUCCESS NOSUCCESS NOSUCCESS=" FAILED!" # default input, reference and output files +export INPUTFILE REFFILE OUTPUTFILE INPUTFILE="${DIRME}/${REFDIR}/${REFDIR}.input" REFFILE="${DIRME}/${REFDIR}/${REFDIR}.result" OUTPUTFILE="${TESTDIR}/${REFDIR}.out" @@ -34,7 +35,7 @@ print_array() { for idx in "${arrays[@]}"; do declare -n temp="$idx" for t in "${!temp[@]}"; do - printf "%s:\t%s\t%s\n" "$idx" "$t" "${temp[$t]}" + printf '%s:\t%s\t%s\n' "$idx" "$t" "${temp[$t]}" done | sort done | grep -v '^USER: 0' } diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index 1604e96..86f237b 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -11,7 +11,7 @@ cd "${GIT_DIR}/.." || exit 1 # create test environment TESTENV="/tmp/bashbot.test$$" mkdir "${TESTENV}" -cp -r * "${TESTENV}" +cp -r ./* "${TESTENV}" cd "test" || exit 1 #set -e @@ -20,7 +20,7 @@ tests=0 passed=0 #all_tests=${__dirname:} #echo PLAN ${#all_tests} -for test in $(find ./${pass}*-test.sh | sort -u) ; +for test in $(find ./*-test.sh | sort -u) ; do [ "${test}" = "test/all-tests.sh" ] && continue [ ! -x "${test}" ] && continue diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh old mode 100644 new mode 100755 index b270ade..da6cc90 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh old mode 100644 new mode 100755 index 597b420..6200f4c --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index d545d3d..593ffa8 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh new file mode 100755 index 0000000..50fb2bc --- /dev/null +++ b/test/d-JSON.sh-test.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 + +# include common functions and definitions +# shellcheck source=test/ALL-tests.inc.sh +source "./ALL-tests.inc.sh" + +set -e + +# source bashbot.sh functionw +cd "${TESTDIR}" || exit 1 + +# run JSON.sh with and without options +cd "test" || exit 1 +echo "Check JSON.sh ..." +JSON="../JSON.sh/JSON.sh" + +for i in 1 2 +do + [ "${i}" = "1" ] && echo " ... JSON.sh -s -b -n" + [ "${i}" = "2" ] && echo " ... JSON.sh" + set +f + for jsonfile in ${REFDIR}/*.log + do + set -f + [ "${i}" = "1" ] && "${JSON}" -s -b -n <"${jsonfile}" >"${jsonfile}.out-${i}" + [ "${i}" = "2" ] && "${JSON}" <"${jsonfile}" >"${jsonfile}.out-${i}" + + # output processed input + diff -c "${jsonfile}.result-${i}" "${jsonfile}.out-${i}" || exit 1 + done + echo "${SUCCESS}" +done + +cd "${DIRME}" || exit 1 diff --git a/test/d-JSON.sh-test/JSON26783.log.result-1 b/test/d-JSON.sh-test/JSON26783.log.result-1 new file mode 100644 index 0000000..7810dc2 --- /dev/null +++ b/test/d-JSON.sh-test/JSON26783.log.result-1 @@ -0,0 +1,22 @@ +["ok"] true +["result",0,"update_id"] 146860898 +["result",0,"message","message_id"] 6620 +["result",0,"message","from","id"] 123456789 +["result",0,"message","from","is_bot"] false +["result",0,"message","from","first_name"] "Kay" +["result",0,"message","from","last_name"] "M" +["result",0,"message","from","username"] "Gnadelwartz" +["result",0,"message","from","language_code"] "de" +["result",0,"message","chat","id"] 123456789 +["result",0,"message","chat","first_name"] "Kay" +["result",0,"message","chat","last_name"] "M" +["result",0,"message","chat","username"] "Gnadelwartz" +["result",0,"message","chat","type"] "private" +["result",0,"message","date"] 1555934213 +["result",0,"message","location","latitude"] 49.630443 +["result",0,"message","location","longitude"] 8.361698 +["result",0,"message","venue","location","latitude"] 49.630443 +["result",0,"message","venue","location","longitude"] 8.361698 +["result",0,"message","venue","title"] "Vannini" +["result",0,"message","venue","address"] "K\u00e4mmererstr. 3" +["result",0,"message","venue","foursquare_id"] "4bf94ec05ec320a115f889d3" diff --git a/test/d-JSON.sh-test/JSON26783.log.result-2 b/test/d-JSON.sh-test/JSON26783.log.result-2 new file mode 100644 index 0000000..816e126 --- /dev/null +++ b/test/d-JSON.sh-test/JSON26783.log.result-2 @@ -0,0 +1,31 @@ +["ok"] true +["result",0,"update_id"] 146860898 +["result",0,"message","message_id"] 6620 +["result",0,"message","from","id"] 123456789 +["result",0,"message","from","is_bot"] false +["result",0,"message","from","first_name"] "Kay" +["result",0,"message","from","last_name"] "M" +["result",0,"message","from","username"] "Gnadelwartz" +["result",0,"message","from","language_code"] "de" +["result",0,"message","from"] {"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"} +["result",0,"message","chat","id"] 123456789 +["result",0,"message","chat","first_name"] "Kay" +["result",0,"message","chat","last_name"] "M" +["result",0,"message","chat","username"] "Gnadelwartz" +["result",0,"message","chat","type"] "private" +["result",0,"message","chat"] {"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"} +["result",0,"message","date"] 1555934213 +["result",0,"message","location","latitude"] 49.630443 +["result",0,"message","location","longitude"] 8.361698 +["result",0,"message","location"] {"latitude":49.630443,"longitude":8.361698} +["result",0,"message","venue","location","latitude"] 49.630443 +["result",0,"message","venue","location","longitude"] 8.361698 +["result",0,"message","venue","location"] {"latitude":49.630443,"longitude":8.361698} +["result",0,"message","venue","title"] "Vannini" +["result",0,"message","venue","address"] "K\u00e4mmererstr. 3" +["result",0,"message","venue","foursquare_id"] "4bf94ec05ec320a115f889d3" +["result",0,"message","venue"] {"location":{"latitude":49.630443,"longitude":8.361698},"title":"Vannini","address":"K\u00e4mmererstr. 3","foursquare_id":"4bf94ec05ec320a115f889d3"} +["result",0,"message"] {"message_id":6620,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934213,"location":{"latitude":49.630443,"longitude":8.361698},"venue":{"location":{"latitude":49.630443,"longitude":8.361698},"title":"Vannini","address":"K\u00e4mmererstr. 3","foursquare_id":"4bf94ec05ec320a115f889d3"}} +["result",0] {"update_id":146860898,"message":{"message_id":6620,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934213,"location":{"latitude":49.630443,"longitude":8.361698},"venue":{"location":{"latitude":49.630443,"longitude":8.361698},"title":"Vannini","address":"K\u00e4mmererstr. 3","foursquare_id":"4bf94ec05ec320a115f889d3"}}} +["result"] [{"update_id":146860898,"message":{"message_id":6620,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934213,"location":{"latitude":49.630443,"longitude":8.361698},"venue":{"location":{"latitude":49.630443,"longitude":8.361698},"title":"Vannini","address":"K\u00e4mmererstr. 3","foursquare_id":"4bf94ec05ec320a115f889d3"}}}] +[] {"ok":true,"result":[{"update_id":146860898,"message":{"message_id":6620,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934213,"location":{"latitude":49.630443,"longitude":8.361698},"venue":{"location":{"latitude":49.630443,"longitude":8.361698},"title":"Vannini","address":"K\u00e4mmererstr. 3","foursquare_id":"4bf94ec05ec320a115f889d3"}}}]} diff --git a/test/d-JSON.sh-test/JSON30458.log.result-1 b/test/d-JSON.sh-test/JSON30458.log.result-1 new file mode 100644 index 0000000..fa5a210 --- /dev/null +++ b/test/d-JSON.sh-test/JSON30458.log.result-1 @@ -0,0 +1,19 @@ +["ok"] true +["result",0,"update_id"] 146860896 +["result",0,"message","message_id"] 6618 +["result",0,"message","from","id"] 123456789 +["result",0,"message","from","is_bot"] false +["result",0,"message","from","first_name"] "Kay" +["result",0,"message","from","last_name"] "M" +["result",0,"message","from","username"] "Gnadelwartz" +["result",0,"message","from","language_code"] "de" +["result",0,"message","chat","id"] 123456789 +["result",0,"message","chat","first_name"] "Kay" +["result",0,"message","chat","last_name"] "M" +["result",0,"message","chat","username"] "Gnadelwartz" +["result",0,"message","chat","type"] "private" +["result",0,"message","date"] 1555934195 +["result",0,"message","voice","duration"] 1 +["result",0,"message","voice","mime_type"] "audio/ogg" +["result",0,"message","voice","file_id"] "AwADAgADKQMAAh638UnbhHGzIMozZgI" +["result",0,"message","voice","file_size"] 3963 diff --git a/test/d-JSON.sh-test/JSON30458.log.result-2 b/test/d-JSON.sh-test/JSON30458.log.result-2 new file mode 100644 index 0000000..7a26778 --- /dev/null +++ b/test/d-JSON.sh-test/JSON30458.log.result-2 @@ -0,0 +1,26 @@ +["ok"] true +["result",0,"update_id"] 146860896 +["result",0,"message","message_id"] 6618 +["result",0,"message","from","id"] 123456789 +["result",0,"message","from","is_bot"] false +["result",0,"message","from","first_name"] "Kay" +["result",0,"message","from","last_name"] "M" +["result",0,"message","from","username"] "Gnadelwartz" +["result",0,"message","from","language_code"] "de" +["result",0,"message","from"] {"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"} +["result",0,"message","chat","id"] 123456789 +["result",0,"message","chat","first_name"] "Kay" +["result",0,"message","chat","last_name"] "M" +["result",0,"message","chat","username"] "Gnadelwartz" +["result",0,"message","chat","type"] "private" +["result",0,"message","chat"] {"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"} +["result",0,"message","date"] 1555934195 +["result",0,"message","voice","duration"] 1 +["result",0,"message","voice","mime_type"] "audio/ogg" +["result",0,"message","voice","file_id"] "AwADAgADKQMAAh638UnbhHGzIMozZgI" +["result",0,"message","voice","file_size"] 3963 +["result",0,"message","voice"] {"duration":1,"mime_type":"audio/ogg","file_id":"AwADAgADKQMAAh638UnbhHGzIMozZgI","file_size":3963} +["result",0,"message"] {"message_id":6618,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934195,"voice":{"duration":1,"mime_type":"audio/ogg","file_id":"AwADAgADKQMAAh638UnbhHGzIMozZgI","file_size":3963}} +["result",0] {"update_id":146860896,"message":{"message_id":6618,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934195,"voice":{"duration":1,"mime_type":"audio/ogg","file_id":"AwADAgADKQMAAh638UnbhHGzIMozZgI","file_size":3963}}} +["result"] [{"update_id":146860896,"message":{"message_id":6618,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934195,"voice":{"duration":1,"mime_type":"audio/ogg","file_id":"AwADAgADKQMAAh638UnbhHGzIMozZgI","file_size":3963}}}] +[] {"ok":true,"result":[{"update_id":146860896,"message":{"message_id":6618,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934195,"voice":{"duration":1,"mime_type":"audio/ogg","file_id":"AwADAgADKQMAAh638UnbhHGzIMozZgI","file_size":3963}}}]} diff --git a/test/d-JSON.sh-test/JSON32034.log.result-1 b/test/d-JSON.sh-test/JSON32034.log.result-1 new file mode 100644 index 0000000..8e784c3 --- /dev/null +++ b/test/d-JSON.sh-test/JSON32034.log.result-1 @@ -0,0 +1,18 @@ +["ok"] true +["result",0,"update_id"] 146860897 +["result",0,"message","message_id"] 6619 +["result",0,"message","from","id"] 123456789 +["result",0,"message","from","is_bot"] false +["result",0,"message","from","first_name"] "Kay" +["result",0,"message","from","last_name"] "M" +["result",0,"message","from","username"] "Gnadelwartz" +["result",0,"message","from","language_code"] "de" +["result",0,"message","chat","id"] 586928566 +["result",0,"message","chat","first_name"] "Kay" +["result",0,"message","chat","last_name"] "M" +["result",0,"message","chat","username"] "Gnadelwartz" +["result",0,"message","chat","type"] "private" +["result",0,"message","date"] 1555934204 +["result",0,"message","contact","phone_number"] "222222" +["result",0,"message","contact","first_name"] "ADAC Pannenhilfe" +["result",0,"message","contact","vcard"] "BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD" diff --git a/test/d-JSON.sh-test/JSON32034.log.result-2 b/test/d-JSON.sh-test/JSON32034.log.result-2 new file mode 100644 index 0000000..eb36337 --- /dev/null +++ b/test/d-JSON.sh-test/JSON32034.log.result-2 @@ -0,0 +1,25 @@ +["ok"] true +["result",0,"update_id"] 146860897 +["result",0,"message","message_id"] 6619 +["result",0,"message","from","id"] 123456789 +["result",0,"message","from","is_bot"] false +["result",0,"message","from","first_name"] "Kay" +["result",0,"message","from","last_name"] "M" +["result",0,"message","from","username"] "Gnadelwartz" +["result",0,"message","from","language_code"] "de" +["result",0,"message","from"] {"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"} +["result",0,"message","chat","id"] 586928566 +["result",0,"message","chat","first_name"] "Kay" +["result",0,"message","chat","last_name"] "M" +["result",0,"message","chat","username"] "Gnadelwartz" +["result",0,"message","chat","type"] "private" +["result",0,"message","chat"] {"id":586928566,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"} +["result",0,"message","date"] 1555934204 +["result",0,"message","contact","phone_number"] "222222" +["result",0,"message","contact","first_name"] "ADAC Pannenhilfe" +["result",0,"message","contact","vcard"] "BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD" +["result",0,"message","contact"] {"phone_number":"222222","first_name":"ADAC Pannenhilfe","vcard":"BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD"} +["result",0,"message"] {"message_id":6619,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":586928566,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934204,"contact":{"phone_number":"222222","first_name":"ADAC Pannenhilfe","vcard":"BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD"}} +["result",0] {"update_id":146860897,"message":{"message_id":6619,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":586928566,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934204,"contact":{"phone_number":"222222","first_name":"ADAC Pannenhilfe","vcard":"BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD"}}} +["result"] [{"update_id":146860897,"message":{"message_id":6619,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":586928566,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934204,"contact":{"phone_number":"222222","first_name":"ADAC Pannenhilfe","vcard":"BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD"}}}] +[] {"ok":true,"result":[{"update_id":146860897,"message":{"message_id":6619,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":586928566,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934204,"contact":{"phone_number":"222222","first_name":"ADAC Pannenhilfe","vcard":"BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD"}}}]} diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 5de9895..f068e5b 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.62-0-g5d5dbae +#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 7ed47dd41bc900ec75e9e5dbb05461c131f5b79f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 22 Apr 2019 21:05:52 +0200 Subject: [PATCH 02/63] refactor options, startbot and init --- bashbot.sh | 129 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 76 insertions(+), 53 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 5dbd71e..640ed5c 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-1-gf59ddae # # Exit Codes: # - 0 sucess (hopefully) @@ -605,6 +605,50 @@ process_message() { NAME="$(echo "${URLS[*]}" | sed 's/.*\///g')" rm "$TMP" } + +# main get updates loop, should never terminate +start_bot() { + while true; do { + + UPDATE="$(curl -s "$UPD_URL$OFFSET" | ./${JSONSHFILE})" + + # Offset + OFFSET="$(echo "$UPDATE" | grep '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)" + OFFSET=$((OFFSET+1)) + + if [ "$OFFSET" != "1" ]; then + if [ "$2" = "test" ]; then + process_updates "$2" + else + process_updates "$2" & + fi + fi + + } + done +} + +# initialize bot environment, user and permissions +bot_init() { + [[ "$(id -u)" -eq "0" ]] && RUNUSER="nobody" + echo -n "Enter User to run basbot [$RUNUSER]: " + read -r TOUSER + [ "$TOUSER" = "" ] && TOUSER="$RUNUSER" + if ! compgen -u "$TOUSER" >/dev/null 2>&1; then + echo -e "${RED}User \"$TOUSER\" not found!${NC}" + exit 3 + else + echo "Adjusting user \"${TOUSER}\" files and permissions ..." + sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'$TOUSER'"/' bashbot.rc + chown -R "$TOUSER" . ./* + chmod 711 . + chmod -R a-w ./* + chmod -R u+w "${COUNTFILE}" "${TMPDIR}" "${BOTADMIN}" ./*.log 2>/dev/null + chmod -R o-r,o-w "${COUNTFILE}" "${TMPDIR}" "${TOKENFILE}" "${BOTADMIN}" "${BOTACL}" 2>/dev/null + ls -la + fi +} + # get bot name getBotName() { res="$(curl -s "$ME_URL")" @@ -649,34 +693,40 @@ fi # do not execute if read from other scripts if [ "$1" != "source" ]; then - while [ "$1" = "startbot" ]; do { - - UPDATE="$(curl -s "$UPD_URL$OFFSET" | ./${JSONSHFILE})" - - # Offset - OFFSET="$(echo "$UPDATE" | grep '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)" - OFFSET=$((OFFSET+1)) - - if [ "$OFFSET" != "1" ]; then - if [ "$2" = "test" ]; then - process_updates "$2" - else - process_updates "$2" & - fi - fi - - }; done - + ############## + # internal options only for use from bashbot and developers case "$1" in - "outproc") + "outproc") # forward output from interactive and jobs to chat until [ "$line" = "imprettydarnsuredatdisisdaendofdacmd" ];do line="" read -r -t 10 line [ "$line" != "" ] && [ "$line" != "imprettydarnsuredatdisisdaendofdacmd" ] && send_message "$2" "$line" done <"${TMPDIR:-.}/$3" rm -f -r "${TMPDIR:-.}/$3" + exit ;; + "startbot" ) + start_bot + exit + ;; + "source") # this should never arrive here + exit + ;; + "init") # adjust users and permissions + bot_init + exit + ;; + "attach") + tmux attach -t "$ME" + exit + ;; + esac + + + ############### + # "official" arguments as shown to users + case "$1" in "count") echo "A total of $(wc -l <"${COUNTFILE}") users used me." exit @@ -695,25 +745,11 @@ if [ "$1" != "source" ]; then echo "Tmux session name $ME" || echo -e "${RED}An error occurred while starting the bot. ${NC}" send_markdown_message "${CHAT[ID]}" "*Bot started*" ;; - "init") # adjust users and permissions - [[ "$(id -u)" -eq "0" ]] && RUNUSER="nobody" - echo -n "Enter User to run basbot [$RUNUSER]: " - read -r TOUSER - [ "$TOUSER" = "" ] && TOUSER="$RUNUSER" - if ! compgen -u "$TOUSER" >/dev/null 2>&1; then - echo -e "${RED}User \"$TOUSER\" not found!${NC}" - exit 3 - else - echo "Adjusting user \"${TOUSER}\" files and permissions ..." - sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'$TOUSER'"/' bashbot.rc - chown -R "$TOUSER" . ./* - chmod 711 . - chmod -R a-w ./* - chmod -R u+w "${COUNTFILE}" "${TMPDIR}" "${BOTADMIN}" ./*.log 2>/dev/null - chmod -R o-r,o-w "${COUNTFILE}" "${TMPDIR}" "${TOKENFILE}" "${BOTADMIN}" "${BOTACL}" 2>/dev/null - ls -la - exit - fi + "kill") + ${CLEAR} + tmux kill-session -t "$ME" &>/dev/null + send_markdown_message "${CHAT[ID]}" "*Bot stopped*" + echo -e "${GREEN}OK. Bot stopped successfully.${NC}" ;; "background" | "resumeback") ${CLEAR} @@ -736,12 +772,6 @@ if [ "$1" != "source" ]; then fi done ;; - "kill") - ${CLEAR} - tmux kill-session -t "$ME" &>/dev/null - send_markdown_message "${CHAT[ID]}" "*Bot stopped*" - echo -e "${GREEN}OK. Bot stopped successfully.${NC}" - ;; "killback" | "suspendback") ${CLEAR} echo -e "${GREEN}Stopping background processes ...${NC}" @@ -763,16 +793,9 @@ if [ "$1" != "source" ]; then less "README.txt" exit ;; - "attach") - tmux attach -t "$ME" - ;; - "source") - # this should never happen - echo "OK" - ;; *) echo -e "${RED}${ME}: BAD REQUEST${NC}" - echo -e "${RED}Available arguments: outproc, count, broadcast, start, suspendback, resumeback, kill, killback, help, attach${NC}" + echo -e "${RED}Available arguments: start, kill, count, broadcast, help, suspendback, resumeback, killback${NC}" exit 4 ;; esac From 65cd94a50da288adfee255812cd06b644909ac0b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 22 Apr 2019 21:24:34 +0200 Subject: [PATCH 03/63] first version of adaptive sleep for get updates --- commands.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands.sh b/commands.sh index f5ee34e..0111de9 100755 --- a/commands.sh +++ b/commands.sh @@ -4,7 +4,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-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-2-g7ed47dd # # shellcheck disable=SC2154 # shellcheck disable=SC2034 From 893ee61d61067b3ce08664d08d9c19f639e3c9f0 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 22 Apr 2019 21:50:38 +0200 Subject: [PATCH 04/63] slower adaptive sleep in pesudo ms --- bashbot.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 640ed5c..bed937c 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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-dev2-1-gf59ddae +#### $$VERSION$$ v0.70-dev2-3-g65cd94a # # Exit Codes: # - 0 sucess (hopefully) @@ -608,6 +608,9 @@ process_message() { # main get updates loop, should never terminate start_bot() { + local mysleep="100" # ms + local addsleep"50" + local maxsleep="${BASHBOTSLEEP:-5000}" while true; do { UPDATE="$(curl -s "$UPD_URL$OFFSET" | ./${JSONSHFILE})" @@ -617,13 +620,15 @@ start_bot() { OFFSET=$((OFFSET+1)) if [ "$OFFSET" != "1" ]; then - if [ "$2" = "test" ]; then - process_updates "$2" + mysleep="100" + if [ "$1" = "test" ]; then + process_updates "$1" else - process_updates "$2" & + process_updates "$1" & fi fi - + # adaptive sleep in ms rounded to next lower second + sleep "${mysleep%???}"; mysleep=$((mysleep+addsleep)); [ "${mysleep}" -gt "${maxsleep}" ] && mysleep="${maxsleep}" } done } @@ -679,9 +684,9 @@ else local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)' while [[ "${out}" =~ $regexp ]] ; do # match 2 \udxxx hex values, calculate new U, then split and replace - local W1="$(( ( 0xd${BASH_REMATCH[2]} & 0x3ff) <<10 ))" - local W2="$(( 0xd${BASH_REMATCH[3]} & 0x3ff ))" - U="$(( ( W1 | W2 ) + 0x10000 ))" + local W1=$(( ( 0xd${BASH_REMATCH[2]} & 0x3ff) <<10 )) + local W2=$(( 0xd${BASH_REMATCH[3]} & 0x3ff )) + local U=$(( ( W1 | W2 ) + 0x10000 )) remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}" out="${BASH_REMATCH[1]}" done @@ -707,7 +712,7 @@ if [ "$1" != "source" ]; then exit ;; "startbot" ) - start_bot + start_bot "$2" exit ;; "source") # this should never arrive here From fe5840d3fc5ebb9944ef96eb05a00e23f79c0815 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 11:45:03 +0200 Subject: [PATCH 05/63] start evironment config --- bashbot.sh | 8 ++-- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 4 +- doc/7_develop.md | 3 +- doc/8_custom.md | 81 ++++++++++++++++++++++++++++++++++ test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 2 +- test/d-process_message-test.sh | 6 +-- 12 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 doc/8_custom.md diff --git a/bashbot.sh b/bashbot.sh index bed937c..db3f090 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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-dev2-3-g65cd94a +#### $$VERSION$$ v0.70-dev2-4-g893ee61 # # Exit Codes: # - 0 sucess (hopefully) @@ -609,8 +609,8 @@ process_message() { # main get updates loop, should never terminate start_bot() { local mysleep="100" # ms - local addsleep"50" - local maxsleep="${BASHBOTSLEEP:-5000}" + local addsleep="50" + local maxsleep="${BASHBOT_SLEEP:-5000}" while true; do { UPDATE="$(curl -s "$UPD_URL$OFFSET" | ./${JSONSHFILE})" @@ -671,7 +671,7 @@ if [ "$ME" = "" ]; then fi # use phyton JSON to decode JSON UFT-8, provide bash implementaion as fallback -if [ "${BASHDECODE}" != "yes" ] && which python >/dev/null 2>&1 ; then +if [ "${BASHBOT_DECODE}" != "" ] && which python >/dev/null 2>&1 ; then JsonDecode() { printf '"%s\\n"' "${1//\"/\\\"}" | python -c 'import json, sys; sys.stdout.write(json.load(sys.stdin).encode("utf-8"))' } diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index eed1c90..7b76bca 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -61,5 +61,5 @@ group. This step is up to you actually. #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-4-g893ee61 diff --git a/doc/2_usage.md b/doc/2_usage.md index bd3b632..6aae752 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -159,5 +159,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-4-g893ee61 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index d4d0118..a7aac14 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-4-g893ee61 diff --git a/doc/4_expert.md b/doc/4_expert.md index 594537f..6a4ef00 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-4-g893ee61 diff --git a/doc/5_practice.md b/doc/5_practice.md index e74fd19..6adcde2 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-4-g893ee61 diff --git a/doc/6_reference.md b/doc/6_reference.md index 050f00a..4af79c2 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -346,7 +346,7 @@ The name of your bot is availible as bash variable "$ME", there is no need to ca Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) -#### [Next Developer Rules](7_develop.md) +#### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-4-g893ee61 diff --git a/doc/7_develop.md b/doc/7_develop.md index e841540..8eafcf2 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -69,6 +69,7 @@ fi ``` #### [Prev Function Reference](6_function.md) +#### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-4-g893ee61 diff --git a/doc/8_custom.md b/doc/8_custom.md new file mode 100644 index 0000000..df29da0 --- /dev/null +++ b/doc/8_custom.md @@ -0,0 +1,81 @@ +#### [Home](../README.md) +## Customize bashbots environment +This section describe how you can customize bashbot to your needs by setting environment variables. + + +### Change file locations +In standard setup bashbot is self containing, this means you can place 'telegram-bot-bash' on any location +and run it from there. All files - programm, config, data etc - will reside in 'telegram-bot-bash'. + +If you want other locations for config, data etc, define and export the following environment variables: + +#### BASHBOT_ETC +Location of the config files 'token', 'botadmin', 'botacl' ... +```bash + unset BASHBOT_ETC # keep in telegram-bot-bash (default) + export BASHBOT_ETC "" # keep in telegram-bot-bash + + export BASHBOT_ETC "/etc/bashbot" # unix like config location + + export BASHBOT_ETC "/etc/bashbot/bot1" # multibot configuration bot 1 + export BASHBOT_ETC "/etc/bashbot/bot2" # multibot configuration bot 2 +``` + + e.g. /etc/bashbot + +#### BASHBOT_VAR +Location of runtime data files 'data-bot-bash', 'count', downloaded files ... +```bash + unset BASHBOT_VAR # keep in telegram-bot-bash (default) + export BASHBOT_VAR "" # keep in telegram-bot-bash + + export BASHBOT_VAR "/var/spool/bashbot" # unix like config location + + export BASHBOT_VAR "/var/spool/bashbot/bot1" # multibot configuration bot 1 + export BASHBOT_VAR "/var/spool/bashbot/bot2" # multibot configuration bot 2 +``` + +#### BASHBOT_COMMANDS +Full path to bash script containing your commands, default: './commands.sh' +```bash + unset BASHBOT_COMMANDS # telegram-bot-bash/commands.sh (default) + export BASHBOT_COMMANDS "" # telegram-bot-bash/commands.sh + + export BASHBOT_COMMANDS "/etc/bashbot/commands.sh" # unix like config location + + export BASHBOT_COMMANDS "/etc/bashbot/bot1/commands.sh" # multibot configuration bot 1 + export BASHBOT_COMMANDS "/etc/bashbot/bot2/commands.sh" # multibot configuration bot 2 +``` + +### Change config values + +#### BASHBOT_DECODE +Bashbot offers two variants for decoding JSON UTF format to UTF-8. By default bashbot uses 'json.encode' if python is installed. +If 'BASHBOT_DECODE' is set to any value (not undefined or not empty) the bash only implementation will be used. +```bash + unset BASHBOT_DECODE # autodetect python (default) + export BASHBOT_DECODE "" # autodetect python + + export BASHBOT_DECODE "yes" # force internal + export BASHBOT_DECODE "no" # also force internal! +``` + + +#### BASHBOT_SLEEP +Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling. +If messages are recieved bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay +for every poll until the maximum of BASHBOT_SLEEP ms. +```bash + unset BASHBOT_SLEEP # 5000ms (default) + export BASHBOT_SLEEP "" # 5000ms + + export BASHBOT_SLEEP "1000" # 1s maximum sleep + export BASHBOT_SLEEP "10000" # 10s maximum sleep + export BASHBOT_SLEEP "1" # values < 1000 disables sleep (not recommended) + +``` + +#### [Prev Notes for Developers](7_develop.md) + +#### $$VERSION$$ v0.70-dev2-4-g893ee61 + diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 045cda4..cd660e5 100755 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-4-g893ee61 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index 86f237b..24e7bc9 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-4-g893ee61 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index f068e5b..ccc3481 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-4-g893ee61 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -26,8 +26,8 @@ echo "Check process_message ..." for i in 1 2 do [ "${i}" = "1" ] && ! which python >/dev/null 2>&1 && continue - [ "${i}" = "1" ] && echo " ... JsonDecode Phyton" - [ "${i}" = "2" ] && echo " ... JsonDecode Bash" && export BASHDECODE="yes" + [ "${i}" = "1" ] && echo " ... JsonDecode Phyton" && unset BASHBOT_DECODE + [ "${i}" = "2" ] && echo " ... JsonDecode Bash" && export BASHBOT_DECODE="yes" set -x { process_message "0"; set +x; } >>"${LOGFILE}" 2>&1; From c527d175f0b635ef42065738f4de11819b85ca33 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 12:17:39 +0200 Subject: [PATCH 06/63] add config examples --- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 51 +++++++++++++++++++++++++++++++++++++++++++--- 8 files changed, 55 insertions(+), 10 deletions(-) diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 7b76bca..d44c304 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -61,5 +61,5 @@ group. This step is up to you actually. #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-5-gfe5840d diff --git a/doc/2_usage.md b/doc/2_usage.md index 6aae752..aaa6e0d 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -159,5 +159,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-5-gfe5840d diff --git a/doc/3_advanced.md b/doc/3_advanced.md index a7aac14..d93a24b 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-5-gfe5840d diff --git a/doc/4_expert.md b/doc/4_expert.md index 6a4ef00..c707756 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-5-gfe5840d diff --git a/doc/5_practice.md b/doc/5_practice.md index 6adcde2..4f99ebc 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-5-gfe5840d diff --git a/doc/6_reference.md b/doc/6_reference.md index 4af79c2..6bdaa8b 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -348,5 +348,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-5-gfe5840d diff --git a/doc/7_develop.md b/doc/7_develop.md index 8eafcf2..4176ce9 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -71,5 +71,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-5-gfe5840d diff --git a/doc/8_custom.md b/doc/8_custom.md index df29da0..db1644e 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -4,10 +4,11 @@ This section describe how you can customize bashbot to your needs by setting env ### Change file locations -In standard setup bashbot is self containing, this means you can place 'telegram-bot-bash' on any location +In standard setup bashbot is self containing, this means you can place 'telegram-bot-bash' any location and run it from there. All files - programm, config, data etc - will reside in 'telegram-bot-bash'. -If you want other locations for config, data etc, define and export the following environment variables: +If you want to have other locations for config, data etc, define and export the following environment variables. +**Note: all specified directories and files must exist or running 'bashbot.sh' will fail.** #### BASHBOT_ETC Location of the config files 'token', 'botadmin', 'botacl' ... @@ -75,7 +76,51 @@ for every poll until the maximum of BASHBOT_SLEEP ms. ``` +### Testet location configs +**Note: Environment variables are not stored, you must setup them before every call to bashbot.sh, e.g. from a script.** + +#### simple Unix like config, mainly for one bot. bashbot is in '/usr/local/telegram-bot-bash' +```bash + # Note: all dirs and files must exist! + export BASHBOT_ETC "/etc/bashbot" + export BASHBOT_VAR "/var/spool/bashbot" + + /usr/local/telegram-bot-bash/bashbot.sh start +``` + +#### Unix like config, mainly for one bot. bashbot.sh is in '/usr/bin' +```bash + # Note: all dirs and files must exist! + export BASHBOT_ETC "/etc/bashbot" + export BASHBOT_VAR "/var/spool/bashbot" + export BASHBOT_JSONSH "/var/spool/bashbot" + export BASHBOT_COMMANDS "/etc/bashbot/commands.sh + + /usr/local/bin/bashbot.sh start +``` + +#### simple multibot config bashbot is in '/usr/local/telegram-bot-bash' +```bash + # config for running Bot 1 + # Note: all dirs and files must exist! + export BASHBOT_ETC "./mybot1" + export BASHBOT_VAR "./mybot1" + export BASHBOT_COMMANDS "./mybot1/commands.sh + + /usr/local/telegram-bot-bash/bashbot.sh start +``` + +```bash + # config for running Bot 2 + # Note: all dirs and files must exist! + export BASHBOT_ETC "./mybot2" + export BASHBOT_VAR "./mybot2" + export BASHBOT_COMMANDS "./mybot2/commands.sh + + /usr/local/telegram-bot-bash/bashbot.sh start +``` + #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-5-gfe5840d From 1957133d9bd67bca4aeab6de927a751db8ec4126 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 12:48:05 +0200 Subject: [PATCH 07/63] test and optimize adaptive polling --- README.md | 6 ++++-- bashbot.sh | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0ef3e69..81747c0 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do * /usr/local if you want to run as service 2. [Download latest release zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) and extract all files. - As an alternative you can clone the github repository to get the latest improvements, run All-tests.sh to be shure. + As an alternative you can clone the github repository to get the latest improvements/fixes, + run bashbot test suite ``All-tests.sh`` afterwards to see if code looks OK. ``` git clone https://github.com/topkecleon/telegram-bot-bash; test/ALL-tests.sh ``` @@ -55,6 +56,7 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do * Test your Bot with shellcheck * [Bashbot function reference](doc/6_reference.md) * [Notes for bashbot developers](doc/7_develop.md) +* [Customize bashbot environment](doc/8_customize.md) ## Note on Keyboards From Version 0.60 on keybord format for ```send_keyboard``` and ```send_message "mykeyboardstartshere ..."``` was changed. @@ -102,4 +104,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-5-gfe5840d diff --git a/bashbot.sh b/bashbot.sh index db3f090..0a1ecae 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-6-gc527d17 # # Exit Codes: # - 0 sucess (hopefully) @@ -609,8 +609,8 @@ process_message() { # main get updates loop, should never terminate start_bot() { local mysleep="100" # ms - local addsleep="50" - local maxsleep="${BASHBOT_SLEEP:-5000}" + local addsleep="100" + local maxsleep="$(( ${BASHBOT_SLEEP:-5000} + 100 ))" while true; do { UPDATE="$(curl -s "$UPD_URL$OFFSET" | ./${JSONSHFILE})" From f412a2921ace9b298dc8cd413fb6eb79b0d29a3b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 13:07:20 +0200 Subject: [PATCH 08/63] implement ENV varible usage --- bashbot.sh | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 0a1ecae..db8a5f3 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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-dev2-6-gc527d17 +#### $$VERSION$$ v0.70-dev2-7-g1957133 # # Exit Codes: # - 0 sucess (hopefully) @@ -29,22 +29,26 @@ if [ -t 1 ] && [ "$TERM" != "" ]; then NC='\e[0m' fi -# get location of bashbot.sh an change to bashbot dir -SCRIPT="./$(basename "$0")" +# get location and name of bashbot.sh +SCRIPT="$0" SCRIPTDIR="$(dirname "$0")" +RUNDIR="${BASHBOT_VAR:-${SCRIPTDIR}}" +[ "${RUNDIR}" = "${SCRIPTDIR}" ] && SCRIPT="./$(basename "${SCRIPT}")" + + RUNUSER="${USER}" # USER is overwritten by bashbot array, $USER may not work later on... -if [ "$1" != "source" ] && ! cd "${SCRIPTDIR}" ; then - echo -e "${RED}ERROR: Can't change to ${SCRIPTDIR} ...${NC}" +if [ "$1" != "source" ] && ! cd "${RUNDIR}" ; then + echo -e "${RED}ERROR: Can't change to ${RUNDIR} ...${NC}" exit 1 fi if [ ! -w "." ]; then - echo -e "${ORANGE}WARNING: ${SCRIPTDIR} is not writeable!${NC}" + echo -e "${ORANGE}WARNING: ${RUNDIR} is not writeable!${NC}" ls -ld . fi -TOKENFILE="./token" +TOKENFILE="${BASHBOT_ETC:-.}/token" if [ ! -f "${TOKENFILE}" ]; then if [ "${CLEAR}" = "" ] && [ "$1" != "init" ]; then echo "Running headless, run ${SCRIPT} init first!" @@ -58,7 +62,7 @@ if [ ! -f "${TOKENFILE}" ]; then fi fi -JSONSHFILE="JSON.sh/JSON.sh" +JSONSHFILE="${BASHBOT_JSONSH:-${RUNDIR}}/JSON.sh/JSON.sh" if [ ! -f "${JSONSHFILE}" ]; then echo "Seems to be first run, Downloading ${JSONSHFILE}..." mkdir "JSON.sh" 2>/dev/null; @@ -66,7 +70,7 @@ if [ ! -f "${JSONSHFILE}" ]; then chmod +x "${JSONSHFILE}" fi -BOTADMIN="./botadmin" +BOTADMIN="${BASHBOT_ETC:-.}/botadmin" if [ ! -f "${BOTADMIN}" ]; then if [ "${CLEAR}" = "" ]; then echo "Running headless, set botadmin to AUTO MODE!" @@ -81,13 +85,13 @@ if [ ! -f "${BOTADMIN}" ]; then fi fi -BOTACL="./botacl" +BOTACL="${BASHBOT_ETC:-.}/botacl" if [ ! -f "${BOTACL}" ]; then echo -e "${ORANGE}Create empty ${BOTACL} file.${NC}" echo "" >"${BOTACL}" fi -TMPDIR="./tmp-bot-bash" +TMPDIR="${BASHBOT_VAR:-.}/tmp-bot-bash" if [ ! -d "${TMPDIR}" ]; then mkdir "${TMPDIR}" elif [ ! -w "${TMPDIR}" ]; then @@ -97,7 +101,7 @@ elif [ ! -w "${TMPDIR}" ]; then exit 2 fi -COUNTFILE="./count" +COUNTFILE="${BASHBOT_VAR:-.}/count" if [ ! -f "${COUNTFILE}" ]; then echo "" >"${COUNTFILE}" elif [ ! -w "${COUNTFILE}" ]; then @@ -107,7 +111,7 @@ elif [ ! -w "${COUNTFILE}" ]; then exit 2 fi -COMMANDS="./commands.sh" +COMMANDS="${BASHBOT_COMMANDS:-${RUNDIR}}/commands.sh" if [ "$1" != "source" ]; then if [ ! -f "${COMMANDS}" ] || [ ! -r "${COMMANDS}" ]; then ${CLEAR} @@ -176,7 +180,7 @@ send_message() { } if [ "$no_keyboard" != "" ]; then - echo "remove_keyboard $chat $text" > ${TMPDIR:-.}/prova + echo "remove_keyboard $chat $text" > "${TMPDIR:-.}/prova" remove_keyboard "$chat" "$text" sent=y fi @@ -249,7 +253,7 @@ delete_message() { # usage: status="$(get_chat_member_status "chat" "user")" get_chat_member_status() { - curl -s "$GETMEMBER_URL" -F "chat_id=$1" -F "user_id=$2" | "./${JSONSHFILE}" -s -b -n | sed -n -e '/\["result","status"\]/ s/.*\][ \t]"\(.*\)"$/\1/p' + curl -s "$GETMEMBER_URL" -F "chat_id=$1" -F "user_id=$2" | "${JSONSHFILE}" -s -b -n | sed -n -e '/\["result","status"\]/ s/.*\][ \t]"\(.*\)"$/\1/p' } kick_chat_member() { @@ -393,7 +397,7 @@ remove_keyboard() { get_file() { [ "$1" = "" ] && return - echo "${FILE_URL}$(curl -s "${GET_URL}" -F "file_id=$1" | "./${JSONSHFILE}" -s -b -n | grep '\["result","file_path"\]' | cut -f 2 | cut -d '"' -f 2)" + echo "${FILE_URL}$(curl -s "${GET_URL}" -F "file_id=$1" | "${JSONSHFILE}" -s -b -n | grep '\["result","file_path"\]' | cut -f 2 | cut -d '"' -f 2)" } send_file() { @@ -523,7 +527,7 @@ process_client() { copname="$ME"_"${CHAT[ID]}" source commands.sh tmpcount="COUNT${CHAT[ID]}" - grep -q "$tmpcount" <"${COUNTFILE}" >/dev/null 2>&1 || echo "$tmpcount">>${COUNTFILE} + grep -q "$tmpcount" <"${COUNTFILE}" >/dev/null 2>&1 || echo "$tmpcount">>"${COUNTFILE}" # To get user count execute bash bashbot.sh count } JsonGetString() { @@ -613,7 +617,7 @@ start_bot() { local maxsleep="$(( ${BASHBOT_SLEEP:-5000} + 100 ))" while true; do { - UPDATE="$(curl -s "$UPD_URL$OFFSET" | ./${JSONSHFILE})" + UPDATE="$(curl -s "$UPD_URL$OFFSET" | "${JSONSHFILE}")" # Offset OFFSET="$(echo "$UPDATE" | grep '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)" @@ -657,7 +661,7 @@ bot_init() { # get bot name getBotName() { res="$(curl -s "$ME_URL")" - echo "$res" | "./${JSONSHFILE}" -s -b -n | JsonGetString '"result","username"' + echo "$res" | "${JSONSHFILE}" -s -b -n | JsonGetString '"result","username"' } ME="$(getBotName)" From 63ef6781a2ac33c079d217b4850342b381b02508 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 13:24:34 +0200 Subject: [PATCH 09/63] add simple check for correct JSON.sh and commands.sh file --- bashbot.sh | 12 ++++++++---- doc/8_custom.md | 11 ++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index db8a5f3..632c2ff 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,13 +10,13 @@ # 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-dev2-7-g1957133 +#### $$VERSION$$ v0.70-dev2-8-gf412a29 # # Exit Codes: # - 0 sucess (hopefully) # - 1 can't change to dir # - 2 can't write to tmp, count or token -# - 3 user / command not found +# - 3 user / command / file not found # - 4 unkown command # - 5 cannot connect to telegram bot @@ -62,7 +62,9 @@ if [ ! -f "${TOKENFILE}" ]; then fi fi -JSONSHFILE="${BASHBOT_JSONSH:-${RUNDIR}}/JSON.sh/JSON.sh" +JSONSHFILE="${BASHBOT_JSONSH:-${RUNDIR}/JSON.sh/JSON.sh}" +[[ "${JSONSHFILE}" != *"/JSON.sh" ]] && echo -e "${RED}ERROR: \"${JSONSHFILE}\" ends not with \"JSONS.sh\".${NC}" && exit 3 + if [ ! -f "${JSONSHFILE}" ]; then echo "Seems to be first run, Downloading ${JSONSHFILE}..." mkdir "JSON.sh" 2>/dev/null; @@ -111,7 +113,9 @@ elif [ ! -w "${COUNTFILE}" ]; then exit 2 fi -COMMANDS="${BASHBOT_COMMANDS:-${RUNDIR}}/commands.sh" +COMMANDS="${BASHBOT_COMMANDS:-${RUNDIR}/commands.sh}" +[[ "${COMMANDS}" != *".sh" ]] && echo -e "${RED}ERROR: \"${COMMANDS}\" ends not with \".sh\".${NC}" && exit 3 + if [ "$1" != "source" ]; then if [ ! -f "${COMMANDS}" ] || [ ! -r "${COMMANDS}" ]; then ${CLEAR} diff --git a/doc/8_custom.md b/doc/8_custom.md index db1644e..a2c140d 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -47,6 +47,15 @@ Full path to bash script containing your commands, default: './commands.sh' export BASHBOT_COMMANDS "/etc/bashbot/bot1/commands.sh" # multibot configuration bot 1 export BASHBOT_COMMANDS "/etc/bashbot/bot2/commands.sh" # multibot configuration bot 2 ``` +#### BASHBOT_JSONSH +Full path to JSON.sh script, default: './JSON.sh/JSON.sh' +```bash + unset BASHBOT_JSONSH # telegram-bot-bash/JSON.sh/JSON.sh (default) + export BASHBOT_JSONSH "" # telegram-bot-bash/JSON.sh/JSON.sh + + export BASHBOT_JSONSH "/usr/local/bin/JSON.sh" # installed in /usr/local/bin + +``` ### Change config values @@ -122,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-5-gfe5840d +#### $$VERSION$$ v0.70-dev2-8-gf412a29 From fa9e879e6aef34384e67f3712fd9e861888f8003 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 14:53:14 +0200 Subject: [PATCH 10/63] ADD-test-new.sh --- test/ADD-test-new.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 test/ADD-test-new.sh diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh new file mode 100755 index 0000000..5fb72d8 --- /dev/null +++ b/test/ADD-test-new.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# +# ADD a new test skeleton to test dir, but does not activate test +# +#### $$VERSION$$ v0.70-dev2-9-g63ef678 + +# magic to ensure that we're always inside the root of our application, +# no matter from which directory we'll run script +GIT_DIR=$(git rev-parse --git-dir) +cd "${GIT_DIR}/.." || exit 1 + +echo -ne "\\nDo your really want to create an new test for bashbot test suite? (y/N) N\\b" +read -r REALLY + +[ "${REALLY}" != "y" ] && echo "Aborting ..." && exit 1 + +# enter name +echo -ne "\\nEnter Name for the the new test, 6+ chars, no :space: (empty to abort) abort\\b\\b\\b\\b\\b" +read -r NAME + +if [ "${NAME}" = "" ] || [ "${NAME}" = "" ]; then echo "Aborting ..."; exit 1; fi + +# enter pass a-z +echo -ne "\\nEnter PASS \"a\" to \"z\" to execute the new test, d\\b" +read -r PASS + +# pass to lower, default pass d +PASS="${PASS,,}" +[ "${PASS}" = "" ] && PASS="d" +[ "${#PASS}" != '1' ] && echo "Sorry, PASS must exactly one charater from a to z, aborting ..." && exit 1 + +TEST="${PASS}-${NAME}-test" + +echo -e " OK! You entered name \"${NAME}\" and pass \"${PASS}\".\\n" + +# check if already exist +if [ -f "test/${TEST}.sh" ] || [ -d "test/${TEST}" ]; then + echo "TEST EXIST ALREADY! Aborting ..." + exit 1 +fi + +echo "The following files will be created for test \"${TEST}.sh\":" +echo -e " test/${TEST}.sh\\n test/${TEST}/${TEST}.input\\n test/${TEST}/${TEST}.result" + +echo -ne "\\nCreate the new test for bashbot test suite? (y/N) N\\b" +read -r REALLY + +[ "${REALLY}" != "y" ] && echo "Aborting ..." && exit 1 + +echo -e " OK!\\n" + +# create files +cat >"test/${TEST}.sh" < Date: Tue, 23 Apr 2019 15:48:58 +0200 Subject: [PATCH 11/63] user_is tests addded --- README.md | 2 +- README.txt | 8 +++-- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 29 +++++++++-------- doc/7_develop.md | 2 +- doc/8_custom.md | 6 ++-- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- test/ADD-test-new.sh | 8 ++++- test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 6 ++-- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-user_is-test.sh | 58 ++++++++++++++++++++++++++++++++++ 33 files changed, 118 insertions(+), 51 deletions(-) create mode 100755 test/d-user_is-test.sh diff --git a/README.md b/README.md index 81747c0..09b65f0 100644 --- a/README.md +++ b/README.md @@ -104,4 +104,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-5-gfe5840d +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 diff --git a/README.txt b/README.txt index 74c3ffc..4563418 100644 --- a/README.txt +++ b/README.txt @@ -34,7 +34,8 @@ Install bashbot latest release zip from github] and extract all files. + As an alternative you can clone the github repository to get the latest -improvements, run All-tests.sh to be shure. +improvements/fixes, run bashbot test suite `All-tests.sh` afterwards to +see if code looks OK. + .... git clone https://github.com/topkecleon/telegram-bot-bash; test/ALL-tests.sh @@ -76,6 +77,7 @@ Documentation ** Test your Bot with shellcheck * link:doc/6_reference.md[Bashbot function reference] * link:doc/7_develop.md[Notes for bashbot developers] +* link:doc/8_customize.md[Customize bashbot environment] Note on Keyboards ~~~~~~~~~~~~~~~~~ @@ -166,5 +168,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-dev2-0-g4fff4c3 -+++++++++++++++++++++++++++++++++++++++++++++ +latexmath:[\[VERSION\]] v0.70-dev2-10-gfa9e879 +++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index a422b62..58fa45d 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 632c2ff..cec73dd 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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-dev2-8-gf412a29 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index 0111de9..819970c 100755 --- a/commands.sh +++ b/commands.sh @@ -4,7 +4,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-dev2-2-g7ed47dd +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index a627052..4639c8c 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index f79bb5f..e9d6b1d 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index eec30a2..d3e6f3d 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 125df10..9ef2619 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 11dffe3..823234f 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 92598c0..6881cf1 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index d44c304..5519047 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -61,5 +61,5 @@ group. This step is up to you actually. #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-5-gfe5840d +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 diff --git a/doc/2_usage.md b/doc/2_usage.md index aaa6e0d..af1d19f 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -159,5 +159,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-5-gfe5840d +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index d93a24b..16cdf7d 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-5-gfe5840d +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 diff --git a/doc/4_expert.md b/doc/4_expert.md index c707756..a239660 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-5-gfe5840d +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 diff --git a/doc/5_practice.md b/doc/5_practice.md index 4f99ebc..08f534b 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-5-gfe5840d +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 diff --git a/doc/6_reference.md b/doc/6_reference.md index 6bdaa8b..fb42782 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -163,6 +163,20 @@ fi ``` ---- +### User Access Control + +##### user_is_botadmin +Return true (0) if user is owner / admin of bot. +Name or ID botadmin must be placed in './botadmin' file. + +*usage:* user_is_botadmin "${USER[ID]}" + +*alias:* _is_botadmin + +*example:* +```bash + _is_botadmin && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*." +``` ##### user_is_creator Return true (0) if user is creator of given chat or chat is a private chat. @@ -186,19 +200,6 @@ if _is_admin ; then fi ``` -##### user_is_botadmin -Return true (0) if user is owner / admin of bot. -Name or ID botadmin must be placed in './botadmin' file. - -*usage:* user_is_botadmin "${CHAT[ID]}" "${USER[ID]}" - -*alias:* _is_botadmin - -*example:* -```bash - _is_botadmin && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*." -``` - ##### user_is_allowed Bahsbot supports User Access Control, see [Advanced Usage](4_advanced.ma) @@ -348,5 +349,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-5-gfe5840d +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 diff --git a/doc/7_develop.md b/doc/7_develop.md index 4176ce9..87f81d3 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -71,5 +71,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-5-gfe5840d +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 diff --git a/doc/8_custom.md b/doc/8_custom.md index a2c140d..b37402d 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -37,7 +37,7 @@ Location of runtime data files 'data-bot-bash', 'count', downloaded files ... ``` #### BASHBOT_COMMANDS -Full path to bash script containing your commands, default: './commands.sh' +Full path to bash script containing your commandsm, default: './commands.sh', must end with '.sh' ```bash unset BASHBOT_COMMANDS # telegram-bot-bash/commands.sh (default) export BASHBOT_COMMANDS "" # telegram-bot-bash/commands.sh @@ -48,7 +48,7 @@ Full path to bash script containing your commands, default: './commands.sh' export BASHBOT_COMMANDS "/etc/bashbot/bot2/commands.sh" # multibot configuration bot 2 ``` #### BASHBOT_JSONSH -Full path to JSON.sh script, default: './JSON.sh/JSON.sh' +Full path to JSON.sh script, default: './JSON.sh/JSON.sh', must end with '/JSON.sh'. ```bash unset BASHBOT_JSONSH # telegram-bot-bash/JSON.sh/JSON.sh (default) export BASHBOT_JSONSH "" # telegram-bot-bash/JSON.sh/JSON.sh @@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-8-gf412a29 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 451ab81..c151f3e 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 0f9c0af..384664f 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -3,7 +3,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-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index 0370695..2445d63 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -2,7 +2,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-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh index 249dfca..c5ab386 100755 --- a/examples/question,sh +++ b/examples/question,sh @@ -3,7 +3,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-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index 249dfca..c5ab386 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -3,7 +3,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-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 5fb72d8..1c31425 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-9-g63ef678 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -60,6 +60,12 @@ source "./ALL-tests.inc.sh" set -e +cd "\${TESTDIR}" || exit 1 + +# source bashbot.sh function, uncomment if you want to test functions +# shellcheck source=./bashbot.sh +# source "\\${TESTDIR}/bashbot.sh" source + # start writing your tests here ... EOF diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index cd660e5..946f329 100755 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index 24e7bc9..ab797a6 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -45,8 +45,8 @@ if [ "$fail" -eq 0 ]; then else /bin/echo -n 'FAILURE ' exitcode=1 - rm -rf "${TESTENV}/test" - find "${TESTENV}/"* ! -name '[a-z]-*' -delete + #rm -rf "${TESTENV}/test" + #find "${TESTENV}/"* ! -name '[a-z]-*' -delete fi echo "${passed} / ${tests}" diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index da6cc90..8ad120f 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index 6200f4c..35ca2cf 100755 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 593ffa8..5fcb204 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 50fb2bc..b695f77 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-0-g4fff4c3 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index ccc3481..892c605 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-4-g893ee61 +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh new file mode 100755 index 0000000..23a4c11 --- /dev/null +++ b/test/d-user_is-test.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +#### $$VERSION$$ v0.70-dev2-10-gfa9e879 + +# include common functions and definitions +# shellcheck source=test/ALL-tests.inc.sh +source "./ALL-tests.inc.sh" + +set -e + +cd "${TESTDIR}" || exit 1 + +# source bashbot.sh function, uncomment if you want to test functions +# shellcheck source=./bashbot.sh +source "${TESTDIR}/bashbot.sh" source + +# start writing your tests here ... + +# first user asking for botadmin will botadmin +echo " test \"user_is_botadmin\" ..." +echo '?' >"${ADMINFILE}" # auto mode +user_is_botadmin "BOTADMIN" || exit 1 # should never fail + +user_is_botadmin "NOBOTADMIN" && exit 1 # should fail +user_is_botadmin "BOTADMIN" || exit 1 # same name as first one, should work + +if [ "$(cat "${ADMINFILE}")" = "BOTADMIN" ]; then + echo " ... \"user_is_botadmin\" seems to work as expected." +else + exit 1 +fi +echo "${SUCCESS}" + +# lets see If UAC works ... +echo " test \"user_is_allowed\" ..." +echo " ... with not rules" +user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should always fail because not rules exist +user_is_allowed "BOTADMIN" "ANYTHING" && exit 1 # should fail even is BOTADMIN +echo "${SUCCESS}" + +echo " ... with BOTADMIN:*:*" +echo 'BOTADMIN:*:*' >"${ACLFILE}" # RULE allow BOTADMIN everything + +user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should always work +user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should fail because user is not listed +echo "${SUCCESS}" + +echo " ... with NOBOTAMIN:SOMETHING:*" +echo 'NOBOTADMIN:SOMETHING:*' >>"${ACLFILE}" # RULE allow NOBOTADMIN something + +user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should always work +user_is_allowed "BOTADMIN" "SOMETHING" || exit 1 # should always work +user_is_allowed "NOBOTADMIN" "SOMETHING" || exit 1 # should work +user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should fail because only SOMETHING is listed + +echo "${SUCCESS}" + +echo " ... \"user_is_allowed\" seems to work as expected." + From aa938397f56bceae60b3dd3eff0b5d851df9e080 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 15:57:19 +0200 Subject: [PATCH 12/63] some minor correction to last user_is test --- test/ALL-tests.sh | 6 +++--- test/d-user_is-test.sh | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index ab797a6..c6eea8b 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-11-g8549727 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -45,8 +45,8 @@ if [ "$fail" -eq 0 ]; then else /bin/echo -n 'FAILURE ' exitcode=1 - #rm -rf "${TESTENV}/test" - #find "${TESTENV}/"* ! -name '[a-z]-*' -delete + rm -rf "${TESTENV}/test" + find "${TESTENV}/"* ! -name '[a-z]-*' -delete fi echo "${passed} / ${tests}" diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 23a4c11..a6e2bc8 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-11-g8549727 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -17,9 +17,10 @@ source "${TESTDIR}/bashbot.sh" source # first user asking for botadmin will botadmin echo " test \"user_is_botadmin\" ..." -echo '?' >"${ADMINFILE}" # auto mode -user_is_botadmin "BOTADMIN" || exit 1 # should never fail +echo '?' >"${ADMINFILE}" # auto mode + +user_is_botadmin "BOTADMIN" || exit 1 # should never fail user_is_botadmin "NOBOTADMIN" && exit 1 # should fail user_is_botadmin "BOTADMIN" || exit 1 # same name as first one, should work @@ -32,24 +33,25 @@ echo "${SUCCESS}" # lets see If UAC works ... echo " test \"user_is_allowed\" ..." + echo " ... with not rules" -user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should always fail because not rules exist +user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should always fail because no rules exist user_is_allowed "BOTADMIN" "ANYTHING" && exit 1 # should fail even is BOTADMIN echo "${SUCCESS}" echo " ... with BOTADMIN:*:*" echo 'BOTADMIN:*:*' >"${ACLFILE}" # RULE allow BOTADMIN everything -user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should always work +user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should work now user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should fail because user is not listed echo "${SUCCESS}" echo " ... with NOBOTAMIN:SOMETHING:*" echo 'NOBOTADMIN:SOMETHING:*' >>"${ACLFILE}" # RULE allow NOBOTADMIN something -user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should always work -user_is_allowed "BOTADMIN" "SOMETHING" || exit 1 # should always work -user_is_allowed "NOBOTADMIN" "SOMETHING" || exit 1 # should work +user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should work +user_is_allowed "BOTADMIN" "SOMETHING" || exit 1 # should work +user_is_allowed "NOBOTADMIN" "SOMETHING" || exit 1 # should work now user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should fail because only SOMETHING is listed echo "${SUCCESS}" From ca73be8c41883f4755932134173f23727235a672 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 18:11:24 +0200 Subject: [PATCH 13/63] rename tmp-bot-bash to data-bot-bash --- bashbot.sh | 13 +++++++++---- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 6 +++--- test/d-user_is-test.sh | 6 +++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index cec73dd..2e2a0ed 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-12-gaa93839 # # Exit Codes: # - 0 sucess (hopefully) @@ -36,7 +36,7 @@ RUNDIR="${BASHBOT_VAR:-${SCRIPTDIR}}" [ "${RUNDIR}" = "${SCRIPTDIR}" ] && SCRIPT="./$(basename "${SCRIPT}")" -RUNUSER="${USER}" # USER is overwritten by bashbot array, $USER may not work later on... +RUNUSER="${USER}" # USER is overwritten by bashbot array if [ "$1" != "source" ] && ! cd "${RUNDIR}" ; then echo -e "${RED}ERROR: Can't change to ${RUNDIR} ...${NC}" @@ -93,7 +93,7 @@ if [ ! -f "${BOTACL}" ]; then echo "" >"${BOTACL}" fi -TMPDIR="${BASHBOT_VAR:-.}/tmp-bot-bash" +TMPDIR="${BASHBOT_VAR:-.}/data-bot-bash" if [ ! -d "${TMPDIR}" ]; then mkdir "${TMPDIR}" elif [ ! -w "${TMPDIR}" ]; then @@ -155,7 +155,8 @@ GETMEMBER_URL=$URL'/getChatMember' FILE_URL='https://api.telegram.org/file/bot'$BOTTOKEN'/' UPD_URL=$URL'/getUpdates?offset=' GET_URL=$URL'/getFile' -OFFSET=0 + +unset USER declare -A USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO @@ -616,6 +617,7 @@ process_message() { # main get updates loop, should never terminate start_bot() { + local OFFSET=0 local mysleep="100" # ms local addsleep="100" local maxsleep="$(( ${BASHBOT_SLEEP:-5000} + 100 ))" @@ -643,6 +645,9 @@ start_bot() { # initialize bot environment, user and permissions bot_init() { + # move tmpdir to datadir + local OLDTMP="${BASHBOT_VAR:-.}/tmp-bot-bash" + [ -d "${OLDTMP}" ] && { mv -n "${OLDTMP}/"* "${TMPDIR}"; rmdir "${OLDTMP}"; } [[ "$(id -u)" -eq "0" ]] && RUNUSER="nobody" echo -n "Enter User to run basbot [$RUNUSER]: " read -r TOUSER diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index b695f77..0ea4597 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-12-gaa93839 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 892c605..2f5a2ae 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-12-gaa93839 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -26,8 +26,8 @@ echo "Check process_message ..." for i in 1 2 do [ "${i}" = "1" ] && ! which python >/dev/null 2>&1 && continue - [ "${i}" = "1" ] && echo " ... JsonDecode Phyton" && unset BASHBOT_DECODE - [ "${i}" = "2" ] && echo " ... JsonDecode Bash" && export BASHBOT_DECODE="yes" + [ "${i}" = "1" ] && echo " ... with JsonDecode Phyton" && unset BASHBOT_DECODE + [ "${i}" = "2" ] && echo " ... with JsonDecode Bash" && export BASHBOT_DECODE="yes" set -x { process_message "0"; set +x; } >>"${LOGFILE}" 2>&1; diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index a6e2bc8..e0b6b9b 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-11-g8549727 +#### $$VERSION$$ v0.70-dev2-12-gaa93839 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -16,7 +16,7 @@ source "${TESTDIR}/bashbot.sh" source # start writing your tests here ... # first user asking for botadmin will botadmin -echo " test \"user_is_botadmin\" ..." +echo "Check \"user_is_botadmin\" ..." echo '?' >"${ADMINFILE}" # auto mode @@ -32,7 +32,7 @@ fi echo "${SUCCESS}" # lets see If UAC works ... -echo " test \"user_is_allowed\" ..." +echo "Check \"user_is_allowed\" ..." echo " ... with not rules" user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should always fail because no rules exist From 56a45aa883cb5040131fb743e44795bde16c9b59 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 19:00:17 +0200 Subject: [PATCH 14/63] parse VCARD and VENUE from message --- bashbot.sh | 18 +++++++++++++----- doc/2_usage.md | 11 +++++++++-- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 4 ++-- .../d-process_message-test.result | 6 ++++++ test/d-user_is-test.sh | 2 +- 12 files changed, 38 insertions(+), 17 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 2e2a0ed..076ba95 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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-dev2-12-gaa93839 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # # Exit Codes: # - 0 sucess (hopefully) @@ -157,8 +157,8 @@ UPD_URL=$URL'/getUpdates?offset=' GET_URL=$URL'/getFile' unset USER -declare -A USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO - +declare -A USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE +export USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE send_message() { @@ -600,10 +600,18 @@ process_message() { URLS[VOICE]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","voice","file_id"' <"$TMP")")" # Contact - CONTACT[NUMBER]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","phone_number"' <"$TMP")")" + CONTACT[USER_ID]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","user_id"' <"$TMP")")" CONTACT[FIRST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","first_name"' <"$TMP")")" CONTACT[LAST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","last_name"' <"$TMP")")" - CONTACT[USER_ID]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","user_id"' <"$TMP")")" + CONTACT[NUMBER]="$(JsonGetString '"result",'"${num}"',"message","contact","phone_number"' <"$TMP")" + CONTACT[VCARD]="$(JsonGetString '"result",'"${num}"',"message","contact","vcard"' <"$TMP")" + + # vunue + VENUE[TITLE]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","venue","title"' <"$TMP")")" + VENUE[ADDRESS]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","venue","address"' <"$TMP")")" + VENUE[LONGITUDE]="$(JsonGetValue '"result",'"${num}"',"message","venue","location","longitude"' <"$TMP")" + VENUE[LATITUDE]="$(JsonGetValue '"result",'"${num}"',"message","venue","location","latitude"' <"$TMP")" + VENUE[FOURSQUARE]="$(JsonGetString '"result",'"${num}"',"message","venue","foursquare_id"' <"$TMP")" # Caption CAPTION="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","caption"' <"$TMP")")" diff --git a/doc/2_usage.md b/doc/2_usage.md index af1d19f..ee5a70d 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -74,13 +74,20 @@ Evertime a Message is recieved, you can read incoming data using the following v * ```${URLS[STICKER]}```: Stickers * ```${URLS[DOCUMENT]}```: Any other file * ```$CONTACT```: This array contains info about contacts sent in a chat. + * ```${CONTACT[ID]}```: User id * ```${CONTACT[NUMBER]}```: Phone number * ```${CONTACT[FIRST_NAME]}```: First name * ```${CONTACT[LAST_NAME]}```: Last name - * ```${CONTACT[ID]}```: User id + * ```${CONTACT[VCARD]}```: User's complete Vcard * ```$LOCATION```: This array contains info about locations sent in a chat. * ```${LOCATION[LONGITUDE]}```: Longitude * ```${LOCATION[LATITUDE]}```: Latitude +* ```$VENUE```: This array contains info about venue (a place) sent in a chat. + * ```${VENUE[TITLE]}```: Name of the place + * ```${VENUE[ADDRESS]}```: Address of the place + * ```${VENUE[LONGITUDE]}```: Longitude + * ```${VENUE[LATITUDE]}```: Latitude + * ```${VENUE[FOURSQUARE]}```: Fouresquare ID ## Usage of bashbot functions @@ -159,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 1c31425..1194755 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 946f329..bf360bb 100755 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index c6eea8b..f88147e 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-11-g8549727 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 8ad120f..e1df301 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index 35ca2cf..777e936 100755 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 5fcb204..7407863 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 0ea4597..3a0b03e 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-12-gaa93839 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 2f5a2ae..d8bfd18 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-12-gaa93839 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -32,7 +32,7 @@ do { process_message "0"; set +x; } >>"${LOGFILE}" 2>&1; # output processed input - print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" >"${OUTPUTFILE}" + print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" >"${OUTPUTFILE}" diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1 echo "${SUCCESS}" done diff --git a/test/d-process_message-test/d-process_message-test.result b/test/d-process_message-test/d-process_message-test.result index 116cf0d..b4cf952 100644 --- a/test/d-process_message-test/d-process_message-test.result +++ b/test/d-process_message-test/d-process_message-test.result @@ -30,8 +30,14 @@ CONTACT: FIRST_NAME ADAC CONTACT: LAST_NAME Pannenhilfe CONTACT: NUMBER 222222 CONTACT: USER_ID +CONTACT: VCARD BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD CAPTION: 0 LOCATION: LATITUDE 49.631824 LOCATION: LONGITUDE 8.377072 MESSAGE: 0 😂😝👌☺❤😕😈#⃣🌏🎉🙊🙉☕🚀✈🚂💯✔〽🔚 MESSAGE: ID 6541 +VENUE: ADDRESS Am Rhein 1 +VENUE: FOURSQUARE 4c4321afce54e21eee980d1a +VENUE: LATITUDE 49.631824 +VENUE: LONGITUDE 8.377072 +VENUE: TITLE Kolb's Biergarten diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index e0b6b9b..685be28 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-12-gaa93839 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 03f22c90c0826fe10d5f48505526dda442f36bd4 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 20:37:15 +0200 Subject: [PATCH 15/63] add _is_function --- bashbot.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bashbot.sh b/bashbot.sh index 076ba95..530239f 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-14-g56a45aa # # Exit Codes: # - 0 sucess (hopefully) @@ -516,6 +516,10 @@ inproc() { tmux send-keys -t "$copname" "${MESSAGE[0]} ${URLS[*]} " } +_is_function() +{ + [ "$(LC_ALL=C type -t "$1")" = "function" ] +} process_updates() { MAX_PROCESS_NUMBER=$(echo "$UPDATE" | sed '/\["result",[0-9]*\]/!d' | tail -1 | sed 's/\["result",//g;s/\].*//g') for ((PROCESS_NUMBER=0; PROCESS_NUMBER<=MAX_PROCESS_NUMBER; PROCESS_NUMBER++)); do From c6d40869c3bae432997a70e4dd1a9ee5d46fef17 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 21:52:57 +0200 Subject: [PATCH 16/63] add modules/alaises.sh and mycommands.sh --- commands.sh | 54 +++++++++++----------------------------------- dev/make-dist.sh | 9 +++----- modules/aliases.sh | 33 ++++++++++++++++++++++++++++ mycommands.sh | 47 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 47 deletions(-) mode change 100755 => 100644 commands.sh create mode 100644 modules/aliases.sh create mode 100644 mycommands.sh diff --git a/commands.sh b/commands.sh old mode 100755 new mode 100644 index 819970c..5b9fa33 --- a/commands.sh +++ b/commands.sh @@ -1,14 +1,14 @@ #!/bin/bash -# Edit your commands in this file. +# file: commands.sh +# do not edit this file, instead place all your commands in mycommands.sh # 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-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-15-g03f22c9 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 -SC2034="$CONTACT" # mute CONTACT not used ;-) # adjust your language setting here, e.g.when run from other user or cron. # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment @@ -20,8 +20,10 @@ unset IFS # set -f # if you are paranoid use set -f to disable globbing +# to change the default info and help messages copy bashbot_info() and bahsbot_help() +# to mycommands.sh and edit the messages there. + if [ "$1" != "source" ]; then - # change Info anf Help to fit your needs bashbot_info() { send_markdown_message "${1}" 'This is bashbot, the Telegram bot written entirely in bash. It features background tasks and interactive chats, and can serve as an interface for CLI programs. @@ -42,16 +44,12 @@ Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) ' } -# some handy shortcuts, e.g.: - _is_botadmin() { - user_is_botadmin "${USER[ID]}" - } - _is_admin() { - user_is_admin "${CHAT[ID]}" "${USER[ID]}" - } - _is_allowed() { # $1 = resource - user_is_allowed "${USER[ID]}" "$1" "${CHAT[ID]}" - } + # load additional modules + [ -r "modules/aliases.sh" ] && source "modules/aliases.sh" # some handy aliases, e.g. _is_admin and _message + # ... + # shellcheck source=./commands.sh + [ -r "mycommands.sh" ] && source "mycommands.sh" + fi if [ "$1" = "source" ];then @@ -96,33 +94,6 @@ else fi & fi case "$MESSAGE" in - '/question') - checkproc - if [ "$res" -gt 0 ] ; then - startproc "example/question" - else - send_normal_message "${CHAT[ID]}" "$MESSAGE already running ..." - fi - ;; - - '/run-notify') - myback="notify"; checkback "$myback" - if [ "$res" -gt 0 ] ; then - background "example/notify 60" "$myback" # notify every 60 seconds - else - send_normal_message "${CHAT[ID]}" "Background command $myback already running ..." - fi - ;; - '/stop-notify') - myback="notify"; checkback "$myback" - if [ "$res" -eq 0 ] ; then - killback "$myback" - send_normal_message "${CHAT[ID]}" "Background command $myback canceled." - else - send_normal_message "${CHAT[ID]}" "No background command $myback is currently running.." - fi - ;; - ################################################ # DEFAULT commands start here, edit messages only '/info') @@ -156,6 +127,7 @@ else ;; *) # forward input to interactive chat if running if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi + _is_function mycommands && mycommands ;; esac fi diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 9ef2619..f66d3ee 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-15-g03f22c9 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -12,7 +12,7 @@ VERSION="$(git describe --tags | sed -e 's/-.*//' -e 's/v//')" DISTNAME="telegram-bot-bash" DISTDIR="./dist/${DISTNAME}" -DISTFILES="bashbot.rc bashbot.sh commands.sh doc examples LICENSE README.md README.txt" +DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh doc examples modules LICENSE README.md README.txt" # run tests first! @@ -32,6 +32,7 @@ cd "${DISTDIR}" || exit 1 # additional stuff mv "commands.sh" "commands.sh.dist" +mv "mycommands.sh" "mycommands.sh.dist" JSONSHFILE="JSON.sh/JSON.sh" if [ ! -f "${JSONSHFILE}" ]; then @@ -49,8 +50,4 @@ tar -czf "${DISTNAME}-${VERSION}.tar.gz" "${DISTNAME}" # shellcheck disable=SC2086 ls -ld ${DISTNAME}-${VERSION}.* -# remove temporary dist dir -cd "$GIT_DIR/.." || exit 1 -rm -rf ${DISTDIR} - diff --git a/modules/aliases.sh b/modules/aliases.sh new file mode 100644 index 0000000..bf76c79 --- /dev/null +++ b/modules/aliases.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# file: modules/alaises.sh +# do not edit, this file will be overwritten on update + +# 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-dev2-15-g03f22c9 + +# source from commands.sh to use the aliases +# some handy aliases for use when processing messages: +_is_botadmin() { + user_is_botadmin "${USER[ID]}" +} +_is_admin() { + user_is_admin "${CHAT[ID]}" "${USER[ID]}" +} +_is_allowed() { + user_is_allowed "${USER[ID]}" "$1" "${CHAT[ID]}" +} +# same for easy sending messages of messages +_message() { + send_normal_message "${CHAT[ID]}" "$1" +} +_normal_message() { + send_normal_message "${CHAT[ID]}" "$1" +} +_html_message() { + send_html_message "${CHAT[ID]}" "$1" +} +_markdown_message() { + send_markdown_message "${CHAT[ID]}" "$1" +} diff --git a/mycommands.sh b/mycommands.sh new file mode 100644 index 0000000..9e6fd89 --- /dev/null +++ b/mycommands.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# files: mycommands.sh.dist +# copy to mycommands.sh and add all your commands and functions here ... +# +#### $$VERSION$$ v0.70-dev2-15-g03f22c9 +# +# shellcheck disable=SC2154 +# shellcheck disable=SC2034 + +# your additional bahsbot commands +mycommands() { + + case "$MESSAGE" in + '/echo'*) # example echo command + send_normal_message "${CHAT[ID]}" "$MESSAGE" + ;; + '/question') # start interactive questions + checkproc + if [ "$res" -gt 0 ] ; then + startproc "example/question" + else + send_normal_message "${CHAT[ID]}" "$MESSAGE already running ..." + fi + ;; + + '/run-notify') # start notify background job + myback="notify"; checkback "$myback" + if [ "$res" -gt 0 ] ; then + background "example/notify 60" "$myback" # notify every 60 seconds + else + send_normal_message "${CHAT[ID]}" "Background command $myback already running ..." + fi + ;; + '/stop-notify') # kill notify background job + myback="notify"; checkback "$myback" + if [ "$res" -eq 0 ] ; then + killback "$myback" + send_normal_message "${CHAT[ID]}" "Background command $myback canceled." + else + send_normal_message "${CHAT[ID]}" "No background command $myback is currently running.." + fi + ;; + + esac +} + +# place your processing functions here From 92ad9e42fc59faa4cac00456f6b132a70ab84115 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 24 Apr 2019 10:07:46 +0200 Subject: [PATCH 17/63] factor out background update doc --- README.md | 2 +- README.txt | 2 +- bashbot.rc | 2 +- bashbot.sh | 108 ++---------------------------- commands.sh | 6 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 103 +++++++++++++++++++++++----- doc/7_develop.md | 2 +- doc/8_custom.md | 4 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 5 +- modules/background.sh | 119 +++++++++++++++++++++++++++++++++ mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 36 files changed, 249 insertions(+), 156 deletions(-) create mode 100644 modules/background.sh mode change 100755 => 100644 test/ALL-tests.inc.sh diff --git a/README.md b/README.md index 09b65f0..c7271b2 100644 --- a/README.md +++ b/README.md @@ -104,4 +104,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/README.txt b/README.txt index 4563418..088a3b9 100644 --- a/README.txt +++ b/README.txt @@ -168,5 +168,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-dev2-10-gfa9e879 +latexmath:[\[VERSION\]] v0.70-dev2-16-gc6d4086 ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index 58fa45d..1162182 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 530239f..6df7a52 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -1,4 +1,6 @@ #!/bin/bash +# file: bashbot.sh +# do not edit, this file will be overwritten on update # bashbot, the Telegram bot written in bash. # Written by Drew (@topkecleon) and Daniil Gentili (@danogentili), KayM (@gnadelwartz). @@ -10,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.70-dev2-14-g56a45aa +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # # Exit Codes: # - 0 sucess (hopefully) @@ -161,73 +163,6 @@ declare -A USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE export USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE -send_message() { - local text arg keyboard file lat long title address sent - [ "$2" = "" ] && return 1 - local chat="$1" - 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')" - arg="$3" - [ "$arg" != "safe" ] && { - text="${text// mynewlinestartshere /$'\r\n'}" - no_keyboard="$(echo "$2" | sed '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" - - 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')" - - 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')" - - 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')" - - 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')" - - title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - - 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" > "${TMPDIR:-.}/prova" - remove_keyboard "$chat" "$text" - sent=y - fi - if [ "$keyboard" != "" ]; then - if [[ "$keyboard" != *"["* ]]; then # pre 0.60 style - keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]" - fi - send_keyboard "$chat" "$text" "$keyboard" - sent=y - fi - if [ "$file" != "" ]; then - send_file "$chat" "$file" "$text" - sent=y - fi - if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" = "" ] && [ "$title" = "" ]; then - send_location "$chat" "$lat" "$long" - sent=y - fi - if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" != "" ] && [ "$title" != "" ]; then - send_venue "$chat" "$lat" "$long" "$title" "$address" - sent=y - fi - if [ "$sent" != "y" ];then - send_text "$chat" "$text" - fi - -} - -send_text() { - case "$2" in - html_parse_mode*) - send_html_message "$1" "${2//html_parse_mode}" - ;; - markdown_parse_mode*) - send_markdown_message "$1" "${2//markdown_parse_mode}" - ;; - *) - send_normal_message "$1" "$2" - ;; - esac -} - send_normal_message() { text="$2" until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do @@ -480,42 +415,7 @@ forward() { # backward compatibility forward_message "$@" || return } -background() { - echo "${CHAT[ID]}:$2:$1" >"${TMPDIR:-.}/${copname}$2-back.cmd" - startproc "$1" "back-$2-" -} - -startproc() { - killproc "$2" - local fifo="$2${copname}" - mkfifo "${TMPDIR:-.}/${fifo}" - tmux new-session -d -s "${fifo}" "$1 &>${TMPDIR:-.}/${fifo}; echo imprettydarnsuredatdisisdaendofdacmd>${TMPDIR:-.}/${fifo}" - tmux new-session -d -s "sendprocess_${fifo}" "bash $SCRIPT outproc ${CHAT[ID]} ${fifo}" -} - - -checkback() { - checkproc "back-$1-" -} - -checkproc() { - tmux ls | grep -q "$1${copname}"; res=$?; return $? -} - -killback() { - killproc "back-$1-" - rm -f "${TMPDIR:-.}/${copname}$1-back.cmd" -} - -killproc() { - local fifo="$1${copname}" - (tmux kill-session -t "${fifo}"; echo imprettydarnsuredatdisisdaendofdacmd>"${TMPDIR:-.}/${fifo}"; tmux kill-session -t "sendprocess_${fifo}"; rm -f -r "${TMPDIR:-.}/${fifo}")2>/dev/null -} - -inproc() { - tmux send-keys -t "$copname" "${MESSAGE[0]} ${URLS[*]} -" -} +# returns true if function exist _is_function() { [ "$(LC_ALL=C type -t "$1")" = "function" ] diff --git a/commands.sh b/commands.sh index 5b9fa33..b7f8abe 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.70-dev2-15-g03f22c9 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -125,8 +125,8 @@ else checkprog if [ "$res" -eq 0 ] ; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi ;; - *) # forward input to interactive chat if running - if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi + *) # forward other messages to optional dispatcher + _is_function startproc && if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi _is_function mycommands && mycommands ;; esac diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 4639c8c..d98b2b6 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index e9d6b1d..c541c38 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index d3e6f3d..18a9eff 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index f66d3ee..821c6bf 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-15-g03f22c9 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 823234f..15e1dfb 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 6881cf1..8f7212d 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 5519047..14857f0 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -61,5 +61,5 @@ group. This step is up to you actually. #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/doc/2_usage.md b/doc/2_usage.md index ee5a70d..37865ca 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 16cdf7d..954d2c7 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/doc/4_expert.md b/doc/4_expert.md index a239660..7f6228a 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/doc/5_practice.md b/doc/5_practice.md index 08f534b..acea748 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/doc/6_reference.md b/doc/6_reference.md index fb42782..b1e3f6b 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -58,18 +58,7 @@ send_normal_message "${CHAT[ID]}" "bold italic> italic>/em> "${TMPDIR:-.}/prova" + remove_keyboard "$chat" "$text" + sent=y + fi + if [ "$keyboard" != "" ]; then + if [[ "$keyboard" != *"["* ]]; then # pre 0.60 style + keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]" + fi + send_keyboard "$chat" "$text" "$keyboard" + sent=y + fi + if [ "$file" != "" ]; then + send_file "$chat" "$file" "$text" + sent=y + fi + if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" = "" ] && [ "$title" = "" ]; then + send_location "$chat" "$lat" "$long" + sent=y + fi + if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" != "" ] && [ "$title" != "" ]; then + send_venue "$chat" "$lat" "$long" "$title" "$address" + sent=y + fi + if [ "$sent" != "y" ];then + send_text "$chat" "$text" + fi + +} + +send_text() { + case "$2" in + html_parse_mode*) + send_html_message "$1" "${2//html_parse_mode}" + ;; + markdown_parse_mode*) + send_markdown_message "$1" "${2//markdown_parse_mode}" + ;; + *) + send_normal_message "$1" "$2" + ;; + esac +} + +###### +# interactive and background functions + +background() { + echo "${CHAT[ID]}:$2:$1" >"${TMPDIR:-.}/${copname}$2-back.cmd" + startproc "$1" "back-$2-" +} + +startproc() { + killproc "$2" + local fifo="$2${copname}" + mkfifo "${TMPDIR:-.}/${fifo}" + tmux new-session -d -s "${fifo}" "$1 &>${TMPDIR:-.}/${fifo}; echo imprettydarnsuredatdisisdaendofdacmd>${TMPDIR:-.}/${fifo}" + tmux new-session -d -s "sendprocess_${fifo}" "bash $SCRIPT outproc ${CHAT[ID]} ${fifo}" +} + + +checkback() { + checkproc "back-$1-" +} + +checkproc() { + tmux ls | grep -q "$1${copname}"; res=$?; return $? +} + +killback() { + killproc "back-$1-" + rm -f "${TMPDIR:-.}/${copname}$1-back.cmd" +} + +killproc() { + local fifo="$1${copname}" + (tmux kill-session -t "${fifo}"; echo imprettydarnsuredatdisisdaendofdacmd>"${TMPDIR:-.}/${fifo}"; tmux kill-session -t "sendprocess_${fifo}"; rm -f -r "${TMPDIR:-.}/${fifo}")2>/dev/null +} + +inproc() { + tmux send-keys -t "$copname" "${MESSAGE[0]} ${URLS[*]} +" +} diff --git a/mycommands.sh b/mycommands.sh index 9e6fd89..19a5fab 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev2-15-g03f22c9 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 1194755..3c63971 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh old mode 100755 new mode 100644 index bf360bb..717dd5a --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index f88147e..02811b0 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index e1df301..e3085a3 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index 777e936..81b8654 100755 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 7407863..289a926 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 3a0b03e..b35a5a8 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index d8bfd18..15b8857 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 685be28..cf58280 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 097a8419618f3330ed921a8fa5233d877f9d6ef7 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 24 Apr 2019 10:17:29 +0200 Subject: [PATCH 18/63] factor out background, update doc --- README.md | 2 +- README.txt | 2 +- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 2 +- modules/background.sh | 23 +++++++++++++---------- mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 36 files changed, 48 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index c7271b2..dd7535e 100644 --- a/README.md +++ b/README.md @@ -104,4 +104,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 diff --git a/README.txt b/README.txt index 088a3b9..a921b12 100644 --- a/README.txt +++ b/README.txt @@ -168,5 +168,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-dev2-16-gc6d4086 +latexmath:[\[VERSION\]] v0.70-dev2-17-g92ad9e4 ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index 1162182..0be6b15 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 6df7a52..01ee635 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.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index b7f8abe..de98feb 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.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index d98b2b6..0adeed2 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index c541c38..b770112 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 18a9eff..68f8d6b 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 821c6bf..5dddca3 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 15e1dfb..6974a8e 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 8f7212d..faa37a4 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 14857f0..1577cf8 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -61,5 +61,5 @@ group. This step is up to you actually. #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 diff --git a/doc/2_usage.md b/doc/2_usage.md index 37865ca..7c383c3 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 954d2c7..b9266a1 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 diff --git a/doc/4_expert.md b/doc/4_expert.md index 7f6228a..8f2bb1c 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 diff --git a/doc/5_practice.md b/doc/5_practice.md index acea748..c34190a 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 diff --git a/doc/6_reference.md b/doc/6_reference.md index b1e3f6b..f1cf1c7 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -420,5 +420,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 diff --git a/doc/7_develop.md b/doc/7_develop.md index 211426c..cf91b0b 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -71,5 +71,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 diff --git a/doc/8_custom.md b/doc/8_custom.md index e5c9fa5..99c03af 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 80fbc99..cf3b696 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index e86c65a..14f9b51 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -3,7 +3,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-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index 04335ea..9b910a4 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -2,7 +2,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-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh index d76b556..885c726 100755 --- a/examples/question,sh +++ b/examples/question,sh @@ -3,7 +3,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-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index d76b556..885c726 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -3,7 +3,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-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/modules/aliases.sh b/modules/aliases.sh index c5c0ac2..ee377f5 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # source from commands.sh to use the aliases # some handy aliases for use when processing messages: diff --git a/modules/background.sh b/modules/background.sh index 8b16765..63b6b50 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -5,16 +5,19 @@ # 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-dev2-15-g03f22c9 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # source from commands.sh if you want ro use interactive or background jobs +## to statisfy shellcheck +export res + #### # I placed send_message here because main use case is interactive chats and background jobs send_message() { local text arg keyboard file lat long title address sent [ "$2" = "" ] && return 1 - local chat="$1" + local mychat="$1" 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')" arg="$3" [ "$arg" != "safe" ] && { @@ -35,31 +38,31 @@ send_message() { } if [ "$no_keyboard" != "" ]; then - echo "remove_keyboard $chat $text" > "${TMPDIR:-.}/prova" - remove_keyboard "$chat" "$text" + echo "remove_keyboard $mychat $text" > "${TMPDIR:-.}/prova" + remove_keyboard "$mychat" "$text" sent=y fi if [ "$keyboard" != "" ]; then if [[ "$keyboard" != *"["* ]]; then # pre 0.60 style keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]" fi - send_keyboard "$chat" "$text" "$keyboard" + send_keyboard "$mychat" "$text" "$keyboard" sent=y fi if [ "$file" != "" ]; then - send_file "$chat" "$file" "$text" + send_file "$mychat" "$file" "$text" sent=y fi if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" = "" ] && [ "$title" = "" ]; then - send_location "$chat" "$lat" "$long" + send_location "$mychat" "$lat" "$long" sent=y fi if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" != "" ] && [ "$title" != "" ]; then - send_venue "$chat" "$lat" "$long" "$title" "$address" + send_venue "$mychat" "$lat" "$long" "$title" "$address" sent=y fi if [ "$sent" != "y" ];then - send_text "$chat" "$text" + send_text "$mychat" "$text" fi } @@ -82,7 +85,7 @@ send_text() { # interactive and background functions background() { - echo "${CHAT[ID]}:$2:$1" >"${TMPDIR:-.}/${copname}$2-back.cmd" + echo "${CHAT[ID]}:$2:$1" >"${TMPDIR:-.}/${copname:--}$2-back.cmd" startproc "$1" "back-$2-" } diff --git a/mycommands.sh b/mycommands.sh index 19a5fab..71994c4 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 3c63971..2d83fbb 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 717dd5a..36dc856 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index 02811b0..e9840c6 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index e3085a3..babaa7c 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index 81b8654..b93d78c 100755 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 289a926..6916f5f 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index b35a5a8..d3803ff 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 15b8857..1089d38 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index cf58280..a0d379c 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-16-gc6d4086 +#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 262bb9e805c51097b3151509767eb5c8d83a9061 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 24 Apr 2019 13:34:44 +0200 Subject: [PATCH 19/63] more aliases, use aliases in commands.sh --- README.md | 2 +- README.txt | 2 +- bashbot.rc | 2 +- bashbot.sh | 4 ++-- commands.sh | 44 +++++++++++++++++----------------- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 29 ++++++++++++++++++++-- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 13 ++++++++-- modules/background.sh | 2 +- modules/inline.sh | 10 ++++++++ mycommands.sh | 10 +++++++- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 37 files changed, 112 insertions(+), 60 deletions(-) create mode 100644 modules/inline.sh diff --git a/README.md b/README.md index dd7535e..4516cde 100644 --- a/README.md +++ b/README.md @@ -104,4 +104,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 diff --git a/README.txt b/README.txt index a921b12..0fdb1cc 100644 --- a/README.txt +++ b/README.txt @@ -168,5 +168,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-dev2-17-g92ad9e4 +latexmath:[\[VERSION\]] v0.70-dev2-18-g097a841 ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index 0be6b15..dd4df67 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 01ee635..a920afc 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.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # # Exit Codes: # - 0 sucess (hopefully) @@ -666,7 +666,7 @@ if [ "$1" != "source" ]; then echo "Sending the broadcast $* to $NUMCOUNT users." [ "$NUMCOUNT" -gt "300" ] && sleep="sleep 0.5" shift - while read -r f; do send_message "${f//COUNT}" "$*"; $sleep; done <"${COUNTFILE}" + while read -r f; do send__markdown_message "${f//COUNT}" "$*"; $sleep; done <"${COUNTFILE}" ;; "start") ${CLEAR} diff --git a/commands.sh b/commands.sh index de98feb..e99b33c 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.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -20,19 +20,16 @@ unset IFS # set -f # if you are paranoid use set -f to disable globbing -# to change the default info and help messages copy bashbot_info() and bahsbot_help() -# to mycommands.sh and edit the messages there. if [ "$1" != "source" ]; then - bashbot_info() { - send_markdown_message "${1}" 'This is bashbot, the Telegram bot written entirely in bash. + # to change the default info message overwrite bashbot_info in mycommands.sh + bashbot_info='This is bashbot, the Telegram bot written entirely in bash. It features background tasks and interactive chats, and can serve as an interface for CLI programs. It currently can send, recieve and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files. ' - } - bashbot_help() { - send_markdown_message "${1}" '*Available commands*: + # to change the default help messages overwrite in mycommands.sh + bashbot_help='*Available commands*: *• /start*: _Start bot and get this message_. *• /info*: _Get shorter info message about this bot_. *• /question*: _Start interactive chat_. @@ -42,11 +39,13 @@ It currently can send, recieve and forward messages, custom keyboards, photos, a Written by Drew (@topkecleon), Daniil Gentili (@danogentili) and KayM(@gnadelwartz). Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) ' - } # load additional modules - [ -r "modules/aliases.sh" ] && source "modules/aliases.sh" # some handy aliases, e.g. _is_admin and _message - # ... + [ -r "modules/aliases.sh" ] && source "modules/aliases.sh" + [ -r "modules/background.sh" ] && source "modules/background.sh" + # ... more modules here ... + + # mycommands is the last "module" to source in # shellcheck source=./commands.sh [ -r "mycommands.sh" ] && source "mycommands.sh" @@ -60,6 +59,7 @@ if [ "$1" = "source" ];then FILE_REGEX='/home/user/allowed/.*' else if ! tmux ls | grep -v send | grep -q "$copname"; then + # interactive running? [ ! -z "${URLS[*]}" ] && { curl -s "${URLS[*]}" -o "$NAME" send_file "${CHAT[ID]}" "$NAME" "$CAPTION" @@ -91,42 +91,42 @@ else if [[ "$iQUERY_MSG" = "web" ]]; then answer_inline_query "$iQUERY_ID" "article" "GitHub" "http://github.com/topkecleon/telegram-bot-bash" fi - fi & + fi & # note the & ! fi case "$MESSAGE" in ################################################ # DEFAULT commands start here, edit messages only '/info') - bashbot_info "${CHAT[ID]}" + _markdown_message "${bashbot_info}" ;; '/start') send_action "${CHAT[ID]}" "typing" - _is_botadmin && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*." + _is_botadmin && _markdown_message "You are *BOTADMIN*." if _is_allowed "start" ; then - bot_help "${CHAT[ID]}" + _markdown_message "${bot_help}" else - send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot." + _message "You are not allowed to start Bot." fi ;; '/leavechat') # bot leave chat if user is admin in chat if _is_admin ; then - send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*" - leave_chat "${CHAT[ID]}" + _markdown_message "*LEAVING CHAT...*" + _leave fi ;; '/kickme') - kick_chat_member "${CHAT[ID]}" "${USER[ID]}" - unban_chat_member "${CHAT[ID]}" "${USER[ID]}" + _kick_user "${USER[ID]}" + _unban_user "${USER[ID]}" ;; '/cancel') checkprog - if [ "$res" -eq 0 ] ; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi + if [ "$res" -eq 0 ] ; then killproc && _message "Command canceled.";else _message "No command is currently running.";fi ;; *) # forward other messages to optional dispatcher - _is_function startproc && if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi + _is_function startproc && if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi # interactive running _is_function mycommands && mycommands ;; esac diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 0adeed2..a403d18 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index b770112..9b2b58e 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 68f8d6b..50214ac 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 5dddca3..5aba78c 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 6974a8e..1dd8b5f 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index faa37a4..80d85a7 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 1577cf8..db768e7 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -61,5 +61,5 @@ group. This step is up to you actually. #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 diff --git a/doc/2_usage.md b/doc/2_usage.md index 7c383c3..8e812f9 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index b9266a1..dabf50a 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 diff --git a/doc/4_expert.md b/doc/4_expert.md index 8f2bb1c..c24617d 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 diff --git a/doc/5_practice.md b/doc/5_practice.md index c34190a..0769e7b 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 diff --git a/doc/6_reference.md b/doc/6_reference.md index f1cf1c7..b37ee53 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -133,19 +133,24 @@ send_keyboard "${CHAT[ID]}" "Enter digit" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \ ##### kick_chat_member If your Bot is Admin of a chat he can kick and ban a user. -*usage:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}" +*usage:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}" +*alias* _kick_user "${USER[ID]}" ##### unban_chat_member If your Bot is Admin of a chat he can unban a kicked user. *usage:* unban_chat_member "${CHAT[ID]}" "${USER[ID]}" +*alias* _unban "${USER[ID]}" + ##### leave_chat Bot will leave given chat. *usage:* leave_chat "${CHAT[ID]}" +*alias* _leave + ```bash if _is_admin ; then send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*" @@ -229,6 +234,26 @@ You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to ---- +##### kick_chat_member + +*usage:* _kick_user "${USER[ID]}" + +*alias for* kick_chat_member "${CHAT[ID]}" "${USER[ID]}" + +##### unban_chat_member + +*usage:* _unban "${USER[ID]}" + +*alias for* unban_chat_member "${CHAT[ID]}" "${USER[ID]}" + +##### leave_chat + +*usage:* _leave + +*alias for* leave_chat "${CHAT[ID]}" + +---- + #### _message *usage:* _message "message" @@ -420,5 +445,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 diff --git a/doc/7_develop.md b/doc/7_develop.md index cf91b0b..442d6ed 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -71,5 +71,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 diff --git a/doc/8_custom.md b/doc/8_custom.md index 99c03af..2457cd8 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 diff --git a/examples/bashbot.cron b/examples/bashbot.cron index cf3b696..1565d4b 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 14f9b51..9fd26ae 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -3,7 +3,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-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index 9b910a4..48178b4 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -2,7 +2,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-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh index 885c726..c6f010e 100755 --- a/examples/question,sh +++ b/examples/question,sh @@ -3,7 +3,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-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index 885c726..c6f010e 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -3,7 +3,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-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/modules/aliases.sh b/modules/aliases.sh index ee377f5..53e4825 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # source from commands.sh to use the aliases # some handy aliases for use when processing messages: @@ -21,7 +21,16 @@ _is_creator() { _is_allowed() { user_is_allowed "${USER[ID]}" "$1" "${CHAT[ID]}" } -# same for easy sending messages of messages +_leave() { + leave_chat "${CHAT[ID]}" +} +_kick_user() { + kick_chat_member "${CHAT[ID]}" "${1}" +} +_unban_user() { + unban_chat_member "${CHAT[ID]}" "${1}" +} +# easy sending of messages of messages _message() { send_normal_message "${CHAT[ID]}" "$1" } diff --git a/modules/background.sh b/modules/background.sh index 63b6b50..5cc6164 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-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/inline.sh b/modules/inline.sh new file mode 100644 index 0000000..a690c92 --- /dev/null +++ b/modules/inline.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# file: modules/inline.sh +# do not edit, this file will be overwritten on update + +# 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-dev2-18-g097a841 + +# source from commands.sh to use the inline functions diff --git a/mycommands.sh b/mycommands.sh index 71994c4..c1afbb7 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,11 +2,19 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 + +# uncomment the following lines to overwrite info and hel messages +# bashbot_info='This is bashbot, the Telegram bot written entirely in bash.` +#' +# bashbot_help='*Available commands*: +#' + + # your additional bahsbot commands mycommands() { diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 2d83fbb..ec0ef1c 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 36dc856..025faac 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index e9840c6..840b340 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index babaa7c..687324c 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index b93d78c..f70c6c1 100755 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 6916f5f..0a1bcca 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index d3803ff..f8c449f 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 1089d38..6e78515 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index a0d379c..b9fee0b 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-17-g92ad9e4 +#### $$VERSION$$ v0.70-dev2-18-g097a841 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From a3b82f72e471f0b3c39141773644c89a8d6c01be Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 24 Apr 2019 13:40:59 +0200 Subject: [PATCH 20/63] fix wrong quoting --- mycommands.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mycommands.sh b/mycommands.sh index c1afbb7..f95aac1 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,14 +2,14 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-19-g262bb9e # # shellcheck disable=SC2154 # shellcheck disable=SC2034 -# uncomment the following lines to overwrite info and hel messages -# bashbot_info='This is bashbot, the Telegram bot written entirely in bash.` +# uncomment the following lines to overwrite info and help messages +# bashbot_info='This is bashbot, the Telegram bot written entirely in bash. #' # bashbot_help='*Available commands*: #' From 0cfb9f00dc920ac9af9b4995e44d991953aad05c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 24 Apr 2019 16:53:01 +0200 Subject: [PATCH 21/63] adjust doc to mycommands and new section installation --- README.md | 40 ++++----------------- bashbot.sh | 4 +-- doc/0_install.md | 65 ++++++++++++++++++++++++++++++++++ doc/1_firstbot.md | 3 +- doc/2_usage.md | 6 ++-- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 88 +++++++++++++++++++++++++++++++--------------- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- 11 files changed, 142 insertions(+), 74 deletions(-) create mode 100644 doc/0_install.md diff --git a/README.md b/README.md index 4516cde..17aa6a8 100644 --- a/README.md +++ b/README.md @@ -16,25 +16,12 @@ 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 -## Install bashbot -1. Go to the directory you want to install bashbot, e.g. - * your $HOME directory (install and run with your user-ID) - * /usr/local if you want to run as service -2. [Download latest release zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) and extract all files. - - As an alternative you can clone the github repository to get the latest improvements/fixes, - run bashbot test suite ``All-tests.sh`` afterwards to see if code looks OK. - ``` - git clone https://github.com/topkecleon/telegram-bot-bash; test/ALL-tests.sh - ``` -3. Go to directory ```telegram-bot-bash```, run ```./bashbot.sh init``` and follow the instructions. At this point you are asked for your Bots token given by botfather. - -## Update bashbot -1. [Download latest update zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) -2. Extract all files and copy them to your bashbot dir -3. Run ```sudo ./bashbot.sh init``` to setup your environment after the update - ## Documentation +* [Install Bashbot](doc/0_install.md) + * Install release + * Install from githup + * Update Bashbot + * Notes on Updates * [Create a new Telegram Bot with botfather](doc/1_firstbot.md) * [Getting Started](doc/2_usage.md) * Managing your Bot @@ -58,21 +45,6 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do * [Notes for bashbot developers](doc/7_develop.md) * [Customize bashbot environment](doc/8_customize.md) -## Note on Keyboards -From Version 0.60 on keybord format for ```send_keyboard``` and ```send_message "mykeyboardstartshere ..."``` was changed. -Keybords are now defined in JSON Array notation e.g. "[ \\"yes\\" , \\"no\\" ]". -This has the advantage that you can create any type of keyboard supported by Telegram. -The old format is supported for backward compatibility, but may fail for corner cases. - -*Example Keyboards*: - -- yes no in two rows: - - OLD format: 'yes' 'no' (two strings) - - NEW format: '[ "yes" ] , [ "no" ]' (two arrays with a string) -- new layouts made easy with NEW format: - - Yes No in one row: '[ "yes" , "no" ]' - - Yes No plus Maybe in 2.row: '[ "yes" , "no" ] , [ "maybe" ]' - - numpad style keyboard: '[ "1" , "2" , "3" ] , [ "4" , "5" , "6" ] , [ "7" , "8" , "9" ] , [ "0" ]' ## Security Considerations Running a Telegram Bot means it is connected to the public and you never know whats send to your Bot. @@ -104,4 +76,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 diff --git a/bashbot.sh b/bashbot.sh index a920afc..0768f98 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.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 # # Exit Codes: # - 0 sucess (hopefully) @@ -666,7 +666,7 @@ if [ "$1" != "source" ]; then echo "Sending the broadcast $* to $NUMCOUNT users." [ "$NUMCOUNT" -gt "300" ] && sleep="sleep 0.5" shift - while read -r f; do send__markdown_message "${f//COUNT}" "$*"; $sleep; done <"${COUNTFILE}" + while read -r f; do send_markdown_message "${f//COUNT}" "$*"; $sleep; done <"${COUNTFILE}" ;; "start") ${CLEAR} diff --git a/doc/0_install.md b/doc/0_install.md new file mode 100644 index 0000000..b4ac65b --- /dev/null +++ b/doc/0_install.md @@ -0,0 +1,65 @@ +#### [Home](../README.md) + +## Install bashbot + +1. Go to the directory you want to install bashbot, e.g. + * your $HOME directory (install and run with your user-ID) + * /usr/local if you want to run as service +2. [Download latest release zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) and extract all files. +3. Change into the directory ```telegram-bot-bash``` +4. Create default commands with ```cp commands.sh.dist commands.sh; cp mycommands.sh.dist mycommands.sh``` +5. Run ```./bashbot.sh init``` to setup the environment and enter your Bots token given by botfather. + +Now your Bot is ready to start ... + +### Install from Github + +As an alternative to donwload the zip files, you can clone the github repository to get the latest improvements/fixes. + +1. Go to the directory you want to install bashbot, e.g. + * your $HOME directory (install and run with your user-ID) + * /usr/local if you want to run as service + +2. Run ```git clone https://github.com/topkecleon/telegram-bot-bash;``` +3. Change into the directory ```telegram-bot-bash``` +4. Run ``` test/ALL-tests.sh``` and if everthing finish OK ... +5. Run ```./bashbot.sh init``` to setup the environment and enter your Bots token given by botfather. + +### Update bashbot + +1. Go to the directory where you had installed bashbot, e.g. + * your $HOME directory + * /usr/local +2. [Download latest release zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) +3. Extract all files to you existing bashbot dir **Note** all files execpt 'mycommands.sh' and 'commands.sh' may overwritten!** +4. Run ```sudo ./bashbot.sh init``` to setup your environment after the update + +### Notes on Updates + +#### Location of tmp / data dir +From version 0.70 on the tmp dir is renamed to 'data-bot-bash' to refelect the fact that not only temporyry files are stored. an existing 'tmp-bot-bash' will be automatically after update renamed. + +From version 0.50 on the temporary files are no more placed in '/tmp'. instead a dedicatet tmp dir is used. + +#### Changes to send_keyboard in v0.6 +From Version 0.60 on keybord format for ```send_keyboard``` and ```send_message "mykeyboardstartshere ..."``` was changed. +Keybords are now defined in JSON Array notation e.g. "[ \\"yes\\" , \\"no\\" ]". +This has the advantage that you can create any type of keyboard supported by Telegram. +The old format is supported for backward compatibility, but may fail for corner cases. + +*Example Keyboards*: + +- yes no in two rows: + - OLD format: 'yes' 'no' (two strings) + - NEW format: '[ "yes" ] , [ "no" ]' (two arrays with a string) +- new layouts made easy with NEW format: + - Yes No in one row: '[ "yes" , "no" ]' + - Yes No plus Maybe in 2.row: '[ "yes" , "no" ] , [ "maybe" ]' + - numpad style keyboard: '[ "1" , "2" , "3" ] , [ "4" , "5" , "6" ] , [ "7" , "8" , "9" ] , [ "0" ]' + + + +#### [Next Create Bot](1_firstbot.md) + +#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 + diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index db768e7..6bb2fa3 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -59,7 +59,8 @@ group. This step is up to you actually. 13. @botfather replies with `Success! The new status is: DISABLED. /help` +#### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 diff --git a/doc/2_usage.md b/doc/2_usage.md index 8e812f9..690ba18 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -1,9 +1,9 @@ #### [Home](../README.md) ## Gettting Started -All Commands for the Bot are in the ```commands.sh``` file (this should ease upgrades of the bot core). Here you find some examples how to process messages and send out text. +THe Bots standard commands are in the ```commands.sh``` file. Vou must not add your commands to 'commands.sh' instead place them in ```mycommands.sh```, there you also find examples how to process messages and send out text. -Once you're done editing start the Bot with ```./bashbot.sh start```. +Once you're done with editing 'mycommands.sh' start the Bot with ```./bashbot.sh start```. If some thing doesn't work as it should, debug with ```bash -x bashbot.sh```. To stop the Bot run ```./bashbot.sh kill``` To use the functions provided in this script in other scripts simply source bashbot: ```source bashbot.sh``` @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index dabf50a..6978135 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 diff --git a/doc/4_expert.md b/doc/4_expert.md index c24617d..0c962df 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 diff --git a/doc/5_practice.md b/doc/5_practice.md index 0769e7b..cf65014 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -1,49 +1,81 @@ #### [Home](../README.md) ## Best Practices -### Customize commands.sh only - -To ease Updates never change ```bashbot.sh```, instead individual commands should go to ```commands.sh``` . Insert your Bot commands in the ```case ... esac``` block: +### Add commands to mycommands.sh only +To ease Updates never change ```bashbot.sh```, instead your commands and functions must go to ```mycommands.sh``` . Insert your Bot commands in the ```case ... esac``` block of the 'mycommands()' function: ```bash - case "$MESSAGE" in - '/echo') # my first own command, echo MESSAGE - send_normal_message "${CHAT[ID]}" "${MESSAGE}" - ;; +# file: mycommands.sh +# your additional bahsbot commands +# uncomment the following lines to overwrite info and help messages + bashbot_info='This is *MY* variant of _bashbot_, the Telegram bot written entirely in bash. +' + + bashbot_help='*Available commands*: +/echo message - _echo the given messsage_ +' + +mycommands() { + + case "$MESSAGE" in + '/echo'*) # example echo command + send_normal_message "${CHAT[ID]}" "$MESSAGE" + ;; + # ..... + esac +} +``` + +### Reuse or disable standard commands +If you want to disable or reuse a standard bashbot command comment it out in 'commands.sh' by placing a '#' in front of +every line from ```'/command')``` to ```;;```. + +**Note: Never disable the catchall command ``*)```` in 'commands.sh'!!** +```bash +#!/bin/bash +# file: commands.sh + + case "$MESSAGE" in ################################################ - # DEFAULT commands start here, do not edit below this! - '/info') - bashbot_info "${CHAT[ID]}" + # DEFAULT commands start here, edit messages only + + #'/start') + # send_action "${CHAT[ID]}" "typing" + # _is_botadmin && _markdown_message "You are *BOTADMIN*." + # if _is_allowed "start" ; then + # _markdown_message "${bot_help}" + # else + # _message "You are not allowed to start Bot." + # fi + # ;; + + *) # forward other messages to optional dispatcher + _is_function startproc && if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi # interactive running + _is_function mycommands && mycommands ;; esac ``` + ### Seperate logic from commands -If a command need more than 2-3 lines of code, you should use a function to seperate logic from command. Place your functions in a seperate file, e.g. ```mycommands.inc.sh``` and source it from bashbot.sh. Example: +If a command need more than 2-3 lines of code, you should use a function to seperate logic from command. Place your functions in ```mycommands.sh``` and call the from you commands. Example: ```bash - source "mycommands.inc.sh" +#!/bin/bash +# file: mycommands.sh + +mycommands() { case "$MESSAGE" in '/process') # logic for /process is done in process_message result="$(process_message "$MESSAGE")" send_normal_message "${CHAT[ID]}" "$result" ;; - - ################################################ - # DEFAULT commands start here, do not edit below this! - '/info') - bashbot_info "${CHAT[ID]}" - ;; - '/start') - send_action "${CHAT[ID]}" "typing" - bashbot_help "${CHAT[ID]}" - ;; esac -``` -```bash -#!/bin/bash -# file: mycommands.inc.sh + +} + +# place your functions here process_message() { local ARGS="${1#/* }" # remove command @@ -53,7 +85,6 @@ process_message() { set -f for WORD in $ARGS do - set +f # process links if [[ "$WORD" == "https://"* ]]; then REPORT="$(dosomething_with_link "$WORD")" @@ -68,7 +99,6 @@ process_message() { done # return result, reset globbing in case we had no ARGS - set +f echo "${OUTPUT}${TEXT}" } @@ -112,5 +142,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 diff --git a/doc/6_reference.md b/doc/6_reference.md index b37ee53..b684625 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -445,5 +445,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 diff --git a/doc/7_develop.md b/doc/7_develop.md index 442d6ed..d57e30d 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -71,5 +71,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 diff --git a/doc/8_custom.md b/doc/8_custom.md index 2457cd8..b725cc8 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 From 991ecd44d830e58870fab42c72f0a9cd13699e1b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 24 Apr 2019 17:34:36 +0200 Subject: [PATCH 22/63] first version of send_inline_button --- README.md | 2 +- README.txt | 57 ++++------------------------------ bashbot.rc | 2 +- bashbot.sh | 11 ++++++- commands.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 20 ++++++------ doc/1_firstbot.md | 2 +- doc/2_usage.md | 4 +-- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 9 +++--- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 2 +- modules/background.sh | 2 +- modules/inline.sh | 2 +- mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 38 files changed, 65 insertions(+), 102 deletions(-) diff --git a/README.md b/README.md index 17aa6a8..899f65a 100644 --- a/README.md +++ b/README.md @@ -76,4 +76,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 diff --git a/README.txt b/README.txt index 0fdb1cc..f39b123 100644 --- a/README.txt +++ b/README.txt @@ -24,38 +24,14 @@ Bashbot https://github.com/topkecleon/telegram-bot-bash[Documentation] and https://github.com/topkecleon/telegram-bot-bash/releases[Downloads] are availible on www.github.com -Install bashbot -~~~~~~~~~~~~~~~ - -1. Go to the directory you want to install bashbot, e.g. -* your $HOME directory (install and run with your user-ID) -* /usr/local if you want to run as service -2. https://github.com/topkecleon/telegram-bot-bash/releases[Download -latest release zip from github] and extract all files. -+ -As an alternative you can clone the github repository to get the latest -improvements/fixes, run bashbot test suite `All-tests.sh` afterwards to -see if code looks OK. -+ -.... -git clone https://github.com/topkecleon/telegram-bot-bash; test/ALL-tests.sh -.... -3. Go to directory `telegram-bot-bash`, run `./bashbot.sh init` and -follow the instructions. At this point you are asked for your Bots token -given by botfather. - -Update bashbot -~~~~~~~~~~~~~~ - -1. https://github.com/topkecleon/telegram-bot-bash/releases[Download -latest update zip from github] -2. Extract all files and copy them to your bashbot dir -3. Run `sudo ./bashbot.sh init` to setup your environment after the -update - Documentation ~~~~~~~~~~~~~ +* link:doc/0_install.md[Install Bashbot] +** Install release +** Install from githup +** Update Bashbot +** Notes on Updates * link:doc/1_firstbot.md[Create a new Telegram Bot with botfather] * link:doc/2_usage.md[Getting Started] ** Managing your Bot @@ -79,27 +55,6 @@ Documentation * link:doc/7_develop.md[Notes for bashbot developers] * link:doc/8_customize.md[Customize bashbot environment] -Note on Keyboards -~~~~~~~~~~~~~~~~~ - -From Version 0.60 on keybord format for `send_keyboard` and -`send_message "mykeyboardstartshere ..."` was changed. Keybords are now -defined in JSON Array notation e.g. "[ \"yes\" , \"no\" ]". This has the -advantage that you can create any type of keyboard supported by -Telegram. The old format is supported for backward compatibility, but -may fail for corner cases. - -_Example Keyboards_: - -* yes no in two rows: -** OLD format: 'yes' 'no' (two strings) -** NEW format: '[ "yes" ] , [ "no" ]' (two arrays with a string) -* new layouts made easy with NEW format: -** Yes No in one row: '[ "yes" , "no" ]' -** Yes No plus Maybe in 2.row: '[ "yes" , "no" ] , [ "maybe" ]' -** numpad style keyboard: '[ "1" , "2" , "3" ] , [ "4" , "5" , "6" ] , [ -"7" , "8" , "9" ] , [ "0" ]' - Security Considerations ~~~~~~~~~~~~~~~~~~~~~~~ @@ -168,5 +123,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-dev2-18-g097a841 +latexmath:[\[VERSION\]] v0.70-dev2-21-g0cfb9f0 ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index dd4df67..087ce96 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 0768f98..34f7f37 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.70-dev2-20-ga3b82f7 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # # Exit Codes: # - 0 sucess (hopefully) @@ -334,6 +334,15 @@ remove_keyboard() { 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}")" } +send_inline_button() { + local chat='"chat_id": '"$1" + local text='"text": "'"$2"'"' + local button='{ "text" : "'"$3"' , "url": "'"$4"'" }' + local JSON='{ '"${chat}"' , '"${text}"' , "reply_markup": { "inline_keyboard": [[ '"${button}"' ]]} }' + # JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"inline_keyboard": [[ {"text":"$3", "url":"$4"} ]]} }' + + res="$(curl -d "$JSON" -H "Content-Type: application/json" -X POST "$MSG_URL")" +} get_file() { [ "$1" = "" ] && return diff --git a/commands.sh b/commands.sh index e99b33c..b936923 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.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index a403d18..4c2cef7 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index 9b2b58e..0568c7e 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 50214ac..82f48be 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 5aba78c..86ddad3 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 1dd8b5f..dcd6264 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 80d85a7..bad101b 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index b4ac65b..9f5c2b8 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -14,16 +14,15 @@ Now your Bot is ready to start ... ### Install from Github -As an alternative to donwload the zip files, you can clone the github repository to get the latest improvements/fixes. +As an alternative to download the zip files, you can clone the github repository to get the latest improvements/fixes. 1. Go to the directory you want to install bashbot, e.g. * your $HOME directory (install and run with your user-ID) * /usr/local if you want to run as service - -2. Run ```git clone https://github.com/topkecleon/telegram-bot-bash;``` +2. Run ```git clone https://github.com/topkecleon/telegram-bot-bash.git``` 3. Change into the directory ```telegram-bot-bash``` 4. Run ``` test/ALL-tests.sh``` and if everthing finish OK ... -5. Run ```./bashbot.sh init``` to setup the environment and enter your Bots token given by botfather. +5. Run ```sudo ./bashbot.sh init``` to setup the environment and enter your Bots token given by botfather. ### Update bashbot @@ -31,15 +30,16 @@ As an alternative to donwload the zip files, you can clone the github repository * your $HOME directory * /usr/local 2. [Download latest release zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) -3. Extract all files to you existing bashbot dir **Note** all files execpt 'mycommands.sh' and 'commands.sh' may overwritten!** +3. Extract all files to your existing bashbot dir + **Note: all files execpt 'mycommands.sh' and 'commands.sh' may overwritten!** 4. Run ```sudo ./bashbot.sh init``` to setup your environment after the update ### Notes on Updates #### Location of tmp / data dir -From version 0.70 on the tmp dir is renamed to 'data-bot-bash' to refelect the fact that not only temporyry files are stored. an existing 'tmp-bot-bash' will be automatically after update renamed. +From version 0.70 on the tmp dir is renamed to 'data-bot-bash' to reflect the fact that not only temporary files are stored. an existing 'tmp-bot-bash' will be automatically renamed after update. -From version 0.50 on the temporary files are no more placed in '/tmp'. instead a dedicatet tmp dir is used. +From version 0.50 on the temporary files are no more placed in '/tmp'. instead a dedicated tmp dir is used. #### Changes to send_keyboard in v0.6 From Version 0.60 on keybord format for ```send_keyboard``` and ```send_message "mykeyboardstartshere ..."``` was changed. @@ -50,8 +50,8 @@ The old format is supported for backward compatibility, but may fail for corner *Example Keyboards*: - yes no in two rows: - - OLD format: 'yes' 'no' (two strings) - - NEW format: '[ "yes" ] , [ "no" ]' (two arrays with a string) + - OLD format: 'yes' 'no' *(two strings)* + - NEW format: '[ "yes" ] , [ "no" ]' *(two arrays with a string)* - new layouts made easy with NEW format: - Yes No in one row: '[ "yes" , "no" ]' - Yes No plus Maybe in 2.row: '[ "yes" , "no" ] , [ "maybe" ]' @@ -61,5 +61,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 6bb2fa3..f699204 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -62,5 +62,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 diff --git a/doc/2_usage.md b/doc/2_usage.md index 690ba18..e45175b 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -1,7 +1,7 @@ #### [Home](../README.md) ## Gettting Started -THe Bots standard commands are in the ```commands.sh``` file. Vou must not add your commands to 'commands.sh' instead place them in ```mycommands.sh```, there you also find examples how to process messages and send out text. +The Bots standard commands are in ```commands.sh``` file. You must not add your commands to 'commands.sh', instead place them in ```mycommands.sh```, there you also find examples how to process messages and send out text. Once you're done with editing 'mycommands.sh' start the Bot with ```./bashbot.sh start```. If some thing doesn't work as it should, debug with ```bash -x bashbot.sh```. To stop the Bot run ```./bashbot.sh kill``` @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 6978135..24e40dc 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 diff --git a/doc/4_expert.md b/doc/4_expert.md index 0c962df..4b84eb9 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 diff --git a/doc/5_practice.md b/doc/5_practice.md index cf65014..1cdaafc 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -2,7 +2,7 @@ ## Best Practices ### Add commands to mycommands.sh only -To ease Updates never change ```bashbot.sh```, instead your commands and functions must go to ```mycommands.sh``` . Insert your Bot commands in the ```case ... esac``` block of the 'mycommands()' function: +To ease updates never change ```bashbot.sh```, instead your commands and functions must go to ```mycommands.sh``` . Insert your Bot commands in the ```case ... esac``` block of the 'mycommands()' function: ```bash # file: mycommands.sh # your additional bahsbot commands @@ -32,7 +32,6 @@ every line from ```'/command')``` to ```;;```. **Note: Never disable the catchall command ``*)```` in 'commands.sh'!!** ```bash -#!/bin/bash # file: commands.sh case "$MESSAGE" in @@ -59,10 +58,10 @@ every line from ```'/command')``` to ```;;```. ### Seperate logic from commands -If a command need more than 2-3 lines of code, you should use a function to seperate logic from command. Place your functions in ```mycommands.sh``` and call the from you commands. Example: +If a command need more than 2-3 lines of code, you should use a function to seperate logic from command. Place your functions in ```mycommands.sh``` and call the from your command. Example: ```bash -#!/bin/bash # file: mycommands.sh +# your additional bahsbot commands mycommands() { @@ -142,5 +141,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 diff --git a/doc/6_reference.md b/doc/6_reference.md index b684625..aa32776 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -445,5 +445,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 diff --git a/doc/7_develop.md b/doc/7_develop.md index d57e30d..1d6a772 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -71,5 +71,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 diff --git a/doc/8_custom.md b/doc/8_custom.md index b725cc8..6d1c1c9 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-20-ga3b82f7 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 1565d4b..ffec6a1 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 9fd26ae..ad1910b 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -3,7 +3,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-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index 48178b4..58e9bc0 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -2,7 +2,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-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh index c6f010e..15f9f51 100755 --- a/examples/question,sh +++ b/examples/question,sh @@ -3,7 +3,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-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index c6f010e..15f9f51 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -3,7 +3,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-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/modules/aliases.sh b/modules/aliases.sh index 53e4825..989744d 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # source from commands.sh to use the aliases # some handy aliases for use when processing messages: diff --git a/modules/background.sh b/modules/background.sh index 5cc6164..e523f07 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-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/inline.sh b/modules/inline.sh index a690c92..ac3af19 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -5,6 +5,6 @@ # 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-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # source from commands.sh to use the inline functions diff --git a/mycommands.sh b/mycommands.sh index f95aac1..d9ad854 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev2-19-g262bb9e +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index ec0ef1c..989047b 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 025faac..1ae11e0 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index 840b340..269085b 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 687324c..7f41bc8 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index f70c6c1..6f981eb 100755 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 0a1bcca..6f782ba 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index f8c449f..25c28b0 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 6e78515..6e5fb0a 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index b9fee0b..74f367b 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-18-g097a841 +#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From a7d14f673c7a0f4aa8368dabe70265f2315d2c1d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 24 Apr 2019 18:24:54 +0200 Subject: [PATCH 23/63] add send_inline_keyboard, start using sendJson --- bashbot.sh | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 34f7f37..9bb9082 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.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-22-g991ecd4 # # Exit Codes: # - 0 sucess (hopefully) @@ -322,28 +322,36 @@ old_send_keyboard() { send_keyboard() { if [[ "$3" != *'['* ]]; then old_send_keyboard "$@"; return; fi - local chat="$1" - local text="$2" + local chat='"chat_id":'"$1" + local text='"text":"'"$2"'"' local keyboard="$3" - 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}")" + local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"keyboard": [ '"${keyboard}"' ], "one_time_keyboard":true } }' + # '{"chat_id":$1, "text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true} }' + sendJson "$JSON" "$MSG_URL" } 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}")" + local chat='"chat_id":'"$1" + local text='"text":"'"$2"'"' + local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"remove_keyboard":true} }' + #JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"remove_keyboard":true} }' + sendJson "$JSON" "$MSG_URL" +} +send_inline_keyboard() { + local chat='"chat_id":'"$1" + local text='"text":"'"$2"'"' + local keyboard="$3" + local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"inline_keyboard": [ '"${keyboard}"' ]} }' + # JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"inline_keyboard": [[ {"text":"$3", "url":"$4"} ... ]]} }' + sendJson "$JSON" "$MSG_URL" } -send_inline_button() { - local chat='"chat_id": '"$1" - local text='"text": "'"$2"'"' - local button='{ "text" : "'"$3"' , "url": "'"$4"'" }' - local JSON='{ '"${chat}"' , '"${text}"' , "reply_markup": { "inline_keyboard": [[ '"${button}"' ]]} }' - # JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"inline_keyboard": [[ {"text":"$3", "url":"$4"} ]]} }' - res="$(curl -d "$JSON" -H "Content-Type: application/json" -X POST "$MSG_URL")" +# this will be the only send interface to telegram! +sendJson(){ + res="$(curl -d "$1" -H "Content-Type: application/json" -X POST "$2")" } + get_file() { [ "$1" = "" ] && return echo "${FILE_URL}$(curl -s "${GET_URL}" -F "file_id=$1" | "${JSONSHFILE}" -s -b -n | grep '\["result","file_path"\]' | cut -f 2 | cut -d '"' -f 2)" From fe4fb34e8ad7c3cbd51d53bcf986e198cbc6f144 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 25 Apr 2019 13:54:31 +0200 Subject: [PATCH 24/63] allow finish inline keyboard, allow keyboards without text --- bashbot.sh | 41 +++++++++++++++++++++++++---------------- dev/hooks/pre-push.sh | 11 +++++++++-- modules/aliases.sh | 33 +++++++++++++++++++++++++-------- 3 files changed, 59 insertions(+), 26 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 9bb9082..e06f63c 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.70-dev2-22-g991ecd4 +#### $$VERSION$$ v0.70-dev2-23-ga7d14f6 # # Exit Codes: # - 0 sucess (hopefully) @@ -159,8 +159,8 @@ UPD_URL=$URL'/getUpdates?offset=' GET_URL=$URL'/getFile' unset USER -declare -A USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE -export USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE +declare -A BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE +export BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE send_normal_message() { @@ -320,35 +320,44 @@ old_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}")" } +TEXTISEMPTY="MyTextIsEmpty" send_keyboard() { if [[ "$3" != *'['* ]]; then old_send_keyboard "$@"; return; fi - local chat='"chat_id":'"$1" - local text='"text":"'"$2"'"' - local keyboard="$3" - local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"keyboard": [ '"${keyboard}"' ], "one_time_keyboard":true } }' + local chat='"chat_id":'"${1}" + local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' + local one_time=', "one_time_keyboard":true' && [ "$4" != "" ] && one_time="" + local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"' } }' # '{"chat_id":$1, "text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true} }' sendJson "$JSON" "$MSG_URL" + [ "${text}" = '"text":"'"${TEXTISEMPTY}"'"' ] && delete_message "${1}" "${2}" } remove_keyboard() { - local chat='"chat_id":'"$1" - local text='"text":"'"$2"'"' + local chat='"chat_id":'"${1}" + local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"remove_keyboard":true} }' #JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"remove_keyboard":true} }' sendJson "$JSON" "$MSG_URL" + [ "${text}" = '"text":"'"${TEXTISEMPTY}"'"' ] && delete_message "${1}" "${2}" } send_inline_keyboard() { - local chat='"chat_id":'"$1" - local text='"text":"'"$2"'"' - local keyboard="$3" - local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"inline_keyboard": [ '"${keyboard}"' ]} }' - # JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"inline_keyboard": [[ {"text":"$3", "url":"$4"} ... ]]} }' + local chat='"chat_id":'"${1}" + local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' + local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]} }' + # JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]} }' sendJson "$JSON" "$MSG_URL" + [ "${text}" = '"text":"'"${TEXTISEMPTY}"'"' ] && delete_message "${1}" "${2}" +} +send_inline_button() { + send_inline_keyboard "${1}" "${2}" '[ {"text":"'"${3}"'", "url":"'"${4}"'"}]' + # JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"inline_keyboard": [[ {"text":"$3", "url":"$4"} ... ]]} }' } # this will be the only send interface to telegram! sendJson(){ - res="$(curl -d "$1" -H "Content-Type: application/json" -X POST "$2")" + res="$(curl -d "${1}" -H "Content-Type: application/json" -X POST "${2}" | "${JSONSHFILE}" -s -b -n )" + BOTSENT[OK]="$(echo "$res" | JsonGetLine '"ok"')" + BOTSENT[ID]="$(echo "$res" | JsonGetValue '"result","message_id"')" } @@ -460,7 +469,7 @@ JsonGetString() { sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]"\(.*\)"$/\1/p' } JsonGetLine() { - sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\]\][ \t]//p' + sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]//p' } JsonGetValue() { sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]\([0-9.,]*\).*/\1/p' diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index 0568c7e..092a526 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-23-ga7d14f6 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -8,6 +8,7 @@ cd "$GIT_DIR/.." || exit 1 export HOOKDIR="dev/hooks" +LASTPUSH='.git/.lastpush' REMOTEVER="$(git ls-remote -t --refs 2>/dev/null | tail -1 | sed 's/.*\/v//')" VERSION="$(git describe --tags | sed -e 's/-.*//' -e 's/v//')" @@ -23,8 +24,12 @@ unset IFS; set -f # LOCAL version must greater than latest REMOTE release version if (( $(echo "${VERSION} > ${REMOTEVER}" | bc -l) )); then # update version in bashbot files on push + set +f + [ -f "${LASTPUSH}" ] && LASTFILES="$(find ./* -newer "${LASTPUSH}")" + [ "${LASTFILES}" = "" ] && exit echo -n " " - dev/version.sh 2>/dev/null || exit 1 + # shellcheck disable=SC2086 + dev/version.sh ${LASTFILES} 2>/dev/null || exit 1 echo " OK" else echo "Error: local version ${VERSION} must be greater than latest release version." @@ -32,3 +37,5 @@ else exit 1 fi +# note date of last push for version +touch "${LASTPUSH}" diff --git a/modules/aliases.sh b/modules/aliases.sh index 989744d..11ab7eb 100644 --- a/modules/aliases.sh +++ b/modules/aliases.sh @@ -5,10 +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.70-dev2-21-g0cfb9f0 - +#### $$VERSION$$ v0.70-dev2-23-ga7d14f6 +# # source from commands.sh to use the aliases -# some handy aliases for use when processing messages: + +# easy handling of users: _is_botadmin() { user_is_botadmin "${USER[ID]}" } @@ -19,7 +20,7 @@ _is_creator() { user_is_creator "${CHAT[ID]}" "${USER[ID]}" } _is_allowed() { - user_is_allowed "${USER[ID]}" "$1" "${CHAT[ID]}" + user_is_allowed "${USER[ID]}" "${1}" "${CHAT[ID]}" } _leave() { leave_chat "${CHAT[ID]}" @@ -32,14 +33,30 @@ _unban_user() { } # easy sending of messages of messages _message() { - send_normal_message "${CHAT[ID]}" "$1" + send_normal_message "${CHAT[ID]}" "${1}" } _normal_message() { - send_normal_message "${CHAT[ID]}" "$1" + send_normal_message "${CHAT[ID]}" "${1}" } _html_message() { - send_html_message "${CHAT[ID]}" "$1" + send_html_message "${CHAT[ID]}" "${1}" } _markdown_message() { - send_markdown_message "${CHAT[ID]}" "$1" + send_markdown_message "${CHAT[ID]}" "${1}" +} +# easy handling of keyboards +_inline_button() { + send_inline_button "${CHAT[ID]}" "${1}" "${2}" "${3}" +} +_inline_keyboard() { + send_inline_keyboard "${CHAT[ID]}" "${1}" "${2}" +} +_keyboard_numpad() { + send_keyboard "${CHAT[ID]}" "${1}" '["1","2","3"],["4","5","6"],["7","8","9"],["-","0","."]' "yes" +} +_keyboard_yesno() { + send_keyboard "${CHAT[ID]}" "${1}" '["yes","no"]' +} +_del_keyboard() { + remove_keyboard "${CHAT[ID]}" "${1}" } From d55d311263e8550ed57d4efa0329e5f269d0f589 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 25 Apr 2019 14:01:42 +0200 Subject: [PATCH 25/63] minor test --- README.md | 2 +- README.txt | 2 +- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/hooks/pre-commit.sh | 25 +++++++++++++++++++++++-- dev/hooks/pre-push.sh | 22 +--------------------- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 2 +- modules/background.sh | 2 +- modules/inline.sh | 2 +- mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 38 files changed, 60 insertions(+), 59 deletions(-) mode change 100755 => 100644 test/a-push-test.sh diff --git a/README.md b/README.md index 899f65a..f36a86b 100644 --- a/README.md +++ b/README.md @@ -76,4 +76,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 diff --git a/README.txt b/README.txt index f39b123..276b564 100644 --- a/README.txt +++ b/README.txt @@ -123,5 +123,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-dev2-21-g0cfb9f0 +latexmath:[\[VERSION\]] v0.70-dev2-24-gfe4fb34 ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index 087ce96..452a54f 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index e06f63c..148747c 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.70-dev2-23-ga7d14f6 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index b936923..24221b3 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.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 4c2cef7..a45bc90 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -7,7 +7,7 @@ GIT_DIR=$(git rev-parse --git-dir) cd "$GIT_DIR/.." || exit 1 export HOOKDIR="dev/hooks" - +LASTPUSH='.git/.lastpush' # if any command inside script returns error, exit and return that error set -e @@ -38,3 +38,24 @@ else # something went wrong exit 1 fi + +REMOTEVER="$(git ls-remote -t --refs 2>/dev/null | tail -1 | sed 's/.*\/v//')" +VERSION="$(git describe --tags | sed -e 's/-.*//' -e 's/v//')" + + +# LOCAL version must greater than latest REMOTE release version +if (( $(echo "${VERSION} > ${REMOTEVER}" | bc -l) )); then + # update version in bashbot files on push + set +f + [ -f "${LASTPUSH}" ] && LASTFILES="$(find ./* -newer "${LASTPUSH}")" + [ "${LASTFILES}" = "" ] && exit + echo -n " " + # shellcheck disable=SC2086 + dev/version.sh ${LASTFILES} 2>/dev/null || exit 1 + echo " OK" +else + echo "Error: local version ${VERSION} must be greater than latest release version." + echo "use \"git tag ...\" to create a local version greater than ${REMOTEVER}" + exit 1 +fi + diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index 092a526..ffef601 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-23-ga7d14f6 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -7,11 +7,7 @@ GIT_DIR=$(git rev-parse --git-dir) cd "$GIT_DIR/.." || exit 1 export HOOKDIR="dev/hooks" - LASTPUSH='.git/.lastpush' -REMOTEVER="$(git ls-remote -t --refs 2>/dev/null | tail -1 | sed 's/.*\/v//')" -VERSION="$(git describe --tags | sed -e 's/-.*//' -e 's/v//')" - # if any command inside script returns error, exit and return that error set -e @@ -21,21 +17,5 @@ echo "............................" unset IFS; set -f -# LOCAL version must greater than latest REMOTE release version -if (( $(echo "${VERSION} > ${REMOTEVER}" | bc -l) )); then - # update version in bashbot files on push - set +f - [ -f "${LASTPUSH}" ] && LASTFILES="$(find ./* -newer "${LASTPUSH}")" - [ "${LASTFILES}" = "" ] && exit - echo -n " " - # shellcheck disable=SC2086 - dev/version.sh ${LASTFILES} 2>/dev/null || exit 1 - echo " OK" -else - echo "Error: local version ${VERSION} must be greater than latest release version." - echo "use \"git tag ...\" to create a local version greater than ${REMOTEVER}" - exit 1 -fi - # note date of last push for version touch "${LASTPUSH}" diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 82f48be..5a0a1c5 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 86ddad3..2c82941 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index dcd6264..f1ca336 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index bad101b..5771277 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index 9f5c2b8..12adb21 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -61,5 +61,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index f699204..9773c1f 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -62,5 +62,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 diff --git a/doc/2_usage.md b/doc/2_usage.md index e45175b..d6492f3 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 24e40dc..cd0184d 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 diff --git a/doc/4_expert.md b/doc/4_expert.md index 4b84eb9..c9df34e 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 diff --git a/doc/5_practice.md b/doc/5_practice.md index 1cdaafc..08e79ba 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -141,5 +141,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 diff --git a/doc/6_reference.md b/doc/6_reference.md index aa32776..15f79ee 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -445,5 +445,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 diff --git a/doc/7_develop.md b/doc/7_develop.md index 1d6a772..562bc3b 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -71,5 +71,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 diff --git a/doc/8_custom.md b/doc/8_custom.md index 6d1c1c9..2cd3790 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 diff --git a/examples/bashbot.cron b/examples/bashbot.cron index ffec6a1..d5bc695 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index ad1910b..b7284f6 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -3,7 +3,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-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index 58e9bc0..540c284 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -2,7 +2,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-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh index 15f9f51..732bbba 100755 --- a/examples/question,sh +++ b/examples/question,sh @@ -3,7 +3,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-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index 15f9f51..732bbba 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -3,7 +3,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-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/modules/aliases.sh b/modules/aliases.sh index 11ab7eb..6a4729b 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-dev2-23-ga7d14f6 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # # source from commands.sh to use the aliases diff --git a/modules/background.sh b/modules/background.sh index e523f07..0f194e2 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-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/inline.sh b/modules/inline.sh index ac3af19..df0008f 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -5,6 +5,6 @@ # 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-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # source from commands.sh to use the inline functions diff --git a/mycommands.sh b/mycommands.sh index d9ad854..d5157ab 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 989047b..077b91d 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 1ae11e0..8e5826d 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index 269085b..1a335aa 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 7f41bc8..0800e0e 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh old mode 100755 new mode 100644 index 6f981eb..35ef2d4 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 6f782ba..bb27462 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 25c28b0..6b1c014 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 6e5fb0a..573f9df 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 74f367b..322f402 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0 +#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 163635da75499b10c44fe112560cfd95e4dd78c7 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 25 Apr 2019 14:02:11 +0200 Subject: [PATCH 26/63] minor test --- README.md | 2 +- README.txt | 2 +- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 2 +- modules/background.sh | 2 +- modules/inline.sh | 2 +- mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 38 files changed, 38 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index f36a86b..2064b49 100644 --- a/README.md +++ b/README.md @@ -76,4 +76,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 diff --git a/README.txt b/README.txt index 276b564..ba2497a 100644 --- a/README.txt +++ b/README.txt @@ -123,5 +123,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-dev2-24-gfe4fb34 +latexmath:[\[VERSION\]] v0.70-dev2-25-gd55d311 ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index 452a54f..365fdc3 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 148747c..7cf0de9 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.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index 24221b3..2682826 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.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index a45bc90..f3e95ad 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index ffef601..f3a60b3 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 5a0a1c5..21f71c0 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 2c82941..26e22a7 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index f1ca336..863a29b 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 5771277..7cb77a9 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index 12adb21..af90580 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -61,5 +61,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 9773c1f..39c948a 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -62,5 +62,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 diff --git a/doc/2_usage.md b/doc/2_usage.md index d6492f3..92a3e93 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index cd0184d..edd7123 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 diff --git a/doc/4_expert.md b/doc/4_expert.md index c9df34e..c24fe8b 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 diff --git a/doc/5_practice.md b/doc/5_practice.md index 08e79ba..6e0f518 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -141,5 +141,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 diff --git a/doc/6_reference.md b/doc/6_reference.md index 15f79ee..7147945 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -445,5 +445,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 diff --git a/doc/7_develop.md b/doc/7_develop.md index 562bc3b..979b5a1 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -71,5 +71,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 diff --git a/doc/8_custom.md b/doc/8_custom.md index 2cd3790..0bf0059 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 diff --git a/examples/bashbot.cron b/examples/bashbot.cron index d5bc695..b6ef664 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index b7284f6..ab055a2 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -3,7 +3,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-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index 540c284..2878451 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -2,7 +2,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-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh index 732bbba..34d6890 100755 --- a/examples/question,sh +++ b/examples/question,sh @@ -3,7 +3,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-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index 732bbba..34d6890 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -3,7 +3,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-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/modules/aliases.sh b/modules/aliases.sh index 6a4729b..c22ddce 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # # source from commands.sh to use the aliases diff --git a/modules/background.sh b/modules/background.sh index 0f194e2..944e987 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-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/inline.sh b/modules/inline.sh index df0008f..ed29a5f 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -5,6 +5,6 @@ # 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-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # source from commands.sh to use the inline functions diff --git a/mycommands.sh b/mycommands.sh index d5157ab..0748d41 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 077b91d..b36926a 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 8e5826d..c84ef70 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index 1a335aa..1afeb09 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 0800e0e..fbac89f 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index 35ef2d4..448bfbf 100644 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index bb27462..22b8668 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 6b1c014..ce50564 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 573f9df..d809686 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 322f402..e6c3171 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-24-gfe4fb34 +#### $$VERSION$$ v0.70-dev2-25-gd55d311 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 2da31c1c6dd01dc51d6288af988ae6a2b341cbc1 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 25 Apr 2019 14:03:27 +0200 Subject: [PATCH 27/63] minor test --- README.md | 2 +- README.txt | 2 +- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 2 +- modules/background.sh | 2 +- modules/inline.sh | 2 +- mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 38 files changed, 38 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 2064b49..a62d5d8 100644 --- a/README.md +++ b/README.md @@ -76,4 +76,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d diff --git a/README.txt b/README.txt index ba2497a..b52566a 100644 --- a/README.txt +++ b/README.txt @@ -123,5 +123,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-dev2-25-gd55d311 +latexmath:[\[VERSION\]] v0.70-dev2-26-g163635d ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index 365fdc3..ca02ed2 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 7cf0de9..d8dbe00 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.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index 2682826..2c05895 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.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index f3e95ad..c67a68c 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index f3a60b3..3cad476 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 21f71c0..44385b5 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 26e22a7..654cbac 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 863a29b..aaffc33 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 7cb77a9..063ed7f 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index af90580..561283a 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -61,5 +61,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 39c948a..62c67f3 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -62,5 +62,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d diff --git a/doc/2_usage.md b/doc/2_usage.md index 92a3e93..b16f224 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d diff --git a/doc/3_advanced.md b/doc/3_advanced.md index edd7123..3d9317a 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d diff --git a/doc/4_expert.md b/doc/4_expert.md index c24fe8b..561cc13 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d diff --git a/doc/5_practice.md b/doc/5_practice.md index 6e0f518..ecb7007 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -141,5 +141,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d diff --git a/doc/6_reference.md b/doc/6_reference.md index 7147945..49a4859 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -445,5 +445,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d diff --git a/doc/7_develop.md b/doc/7_develop.md index 979b5a1..d07df44 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -71,5 +71,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d diff --git a/doc/8_custom.md b/doc/8_custom.md index 0bf0059..a07c1c5 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d diff --git a/examples/bashbot.cron b/examples/bashbot.cron index b6ef664..19d29bb 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index ab055a2..14e773f 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -3,7 +3,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-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index 2878451..e181a40 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -2,7 +2,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-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh index 34d6890..768751f 100755 --- a/examples/question,sh +++ b/examples/question,sh @@ -3,7 +3,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-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index 34d6890..768751f 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -3,7 +3,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-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/modules/aliases.sh b/modules/aliases.sh index c22ddce..982ce30 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # # source from commands.sh to use the aliases diff --git a/modules/background.sh b/modules/background.sh index 944e987..592777d 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-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/inline.sh b/modules/inline.sh index ed29a5f..075673e 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -5,6 +5,6 @@ # 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-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # source from commands.sh to use the inline functions diff --git a/mycommands.sh b/mycommands.sh index 0748d41..a637a65 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index b36926a..3cb1cf7 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index c84ef70..7796825 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index 1afeb09..8b476aa 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index fbac89f..327185b 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index 448bfbf..3cefc65 100644 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 22b8668..d89a300 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index ce50564..c4b6308 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index d809686..1a86fa7 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index e6c3171..e8a2674 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-25-gd55d311 +#### $$VERSION$$ v0.70-dev2-26-g163635d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 55dab95c0530436a057a86c0692bd3b5d0446f3a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 25 Apr 2019 14:24:41 +0200 Subject: [PATCH 28/63] new dev3 cycle --- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 3cb1cf7..dcd4f8a 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 7796825..6101d01 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index 8b476aa..27ef0d3 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 327185b..44d6177 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index 3cefc65..b835fcf 100644 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index d89a300..ef1117e 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index c4b6308..f5596f6 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 1a86fa7..5b4c1e5 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index e8a2674..5f4dcd5 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 96aae9d40ea7f1b7ccb628cf233e08706546b8e0 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 25 Apr 2019 14:45:16 +0200 Subject: [PATCH 29/63] finally auto add only changed files ... --- README.md | 2 +- README.txt | 2 +- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/git-add.sh | 21 +++++++++++++++++++++ dev/hooks/pre-commit.sh | 5 ++++- dev/hooks/pre-push.sh | 5 ++++- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 2 +- modules/background.sh | 2 +- modules/inline.sh | 2 +- mycommands.sh | 2 +- 30 files changed, 56 insertions(+), 29 deletions(-) create mode 100755 dev/git-add.sh diff --git a/README.md b/README.md index a62d5d8..fc8415a 100644 --- a/README.md +++ b/README.md @@ -76,4 +76,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 diff --git a/README.txt b/README.txt index b52566a..b3e2e30 100644 --- a/README.txt +++ b/README.txt @@ -123,5 +123,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-dev2-26-g163635d +latexmath:[\[VERSION\]] v0.70-dev2-27-g2da31c1 ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index ca02ed2..3d700cc 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index d8dbe00..97fb021 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.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev3-1-g55dab95 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index 2c05895..775fe99 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.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/git-add.sh b/dev/git-add.sh new file mode 100755 index 0000000..4ea7e2a --- /dev/null +++ b/dev/git-add.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# file: git-add.sh +# +# works together with git pre-push.sh and add all changed files sind last push + +#### $$VERSION$$ v0.70-dev3-1-g55dab95 + +# magic to ensure that we're always inside the root of our application, +# no matter from which directory we'll run script +GIT_DIR=$(git rev-parse --git-dir) +cd "$GIT_DIR/.." || exit 1 + +FILES="$(find ./* -newer .git/.lastpush)" +[ "${FILES}" = "" ] && echo "Noting changed since last push!" && exit + +# shellcheck disable=SC2086 +echo Add ${FILES} to repo ... + +# shellcheck disable=SC2086 +git add ${FILES} + diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index c67a68c..d753d0a 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev3-0-g2da31c1 + +############ +# NOTE: you MUST run install-hooks.sh again when updating this file! # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index 3cad476..6d64dd1 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev3-0-g2da31c1 + +############ +# NOTE: you MUST run install-hooks.sh again when updating this file! # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 44385b5..d528fb4 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 654cbac..c9f054d 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index aaffc33..71221af 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 063ed7f..e2a459a 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index 561283a..642c6e6 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -61,5 +61,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 62c67f3..6db34b0 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -62,5 +62,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 diff --git a/doc/2_usage.md b/doc/2_usage.md index b16f224..e4e211a 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 3d9317a..6ce711d 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 diff --git a/doc/4_expert.md b/doc/4_expert.md index 561cc13..9d985dd 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 diff --git a/doc/5_practice.md b/doc/5_practice.md index ecb7007..ef221a6 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -141,5 +141,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 diff --git a/doc/6_reference.md b/doc/6_reference.md index 49a4859..5548129 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -445,5 +445,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 diff --git a/doc/7_develop.md b/doc/7_develop.md index d07df44..41664cb 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -71,5 +71,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 diff --git a/doc/8_custom.md b/doc/8_custom.md index a07c1c5..ac762ea 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 19d29bb..ff544eb 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 14e773f..6ed05f1 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -3,7 +3,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-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index e181a40..0f49de6 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -2,7 +2,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-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh index 768751f..72578c0 100755 --- a/examples/question,sh +++ b/examples/question,sh @@ -3,7 +3,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-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index 768751f..72578c0 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -3,7 +3,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-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/modules/aliases.sh b/modules/aliases.sh index 982ce30..ea8e4b7 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # # source from commands.sh to use the aliases diff --git a/modules/background.sh b/modules/background.sh index 592777d..89579f4 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-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/inline.sh b/modules/inline.sh index 075673e..2a32637 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -5,6 +5,6 @@ # 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-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # source from commands.sh to use the inline functions diff --git a/mycommands.sh b/mycommands.sh index a637a65..d8b896f 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev2-26-g163635d +#### $$VERSION$$ v0.70-dev2-27-g2da31c1 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 From 0f220bdbc87cf2ea868640dbc99db219bd653139 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 25 Apr 2019 15:17:35 +0200 Subject: [PATCH 30/63] fix delete of empty messages for keyboards --- bashbot.sh | 36 ++++++++++++++++++------------------ dev/git-add.sh | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 97fb021..525598b 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -320,44 +320,44 @@ old_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}")" } -TEXTISEMPTY="MyTextIsEmpty" +TEXTISEMPTY="ThisTextIsEmptyAndWillBeDeleted" send_keyboard() { if [[ "$3" != *'['* ]]; then old_send_keyboard "$@"; return; fi - local chat='"chat_id":'"${1}" + local chat="${1}" local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' local one_time=', "one_time_keyboard":true' && [ "$4" != "" ] && one_time="" - local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"' } }' - # '{"chat_id":$1, "text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true} }' - sendJson "$JSON" "$MSG_URL" - [ "${text}" = '"text":"'"${TEXTISEMPTY}"'"' ] && delete_message "${1}" "${2}" + local JSON="${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"'}' + # '"text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true}' + sendJson "${chat}" "$JSON" "$MSG_URL" } remove_keyboard() { - local chat='"chat_id":'"${1}" + local chat="${1}" local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' - local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"remove_keyboard":true} }' - #JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"remove_keyboard":true} }' - sendJson "$JSON" "$MSG_URL" - [ "${text}" = '"text":"'"${TEXTISEMPTY}"'"' ] && delete_message "${1}" "${2}" + local JSON="${text}"', "reply_markup": {"remove_keyboard":true}' + #JSON='"text":"$2", "reply_markup": {"remove_keyboard":true}' + sendJson "${chat}" "$JSON" "$MSG_URL" } send_inline_keyboard() { - local chat='"chat_id":'"${1}" + local chat="${1}" local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' - local JSON='{'"${chat}"', '"${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]} }' - # JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]} }' - sendJson "$JSON" "$MSG_URL" - [ "${text}" = '"text":"'"${TEXTISEMPTY}"'"' ] && delete_message "${1}" "${2}" + local JSON="${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]}' + # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}' + sendJson "${chat}" "$JSON" "$MSG_URL" } send_inline_button() { send_inline_keyboard "${1}" "${2}" '[ {"text":"'"${3}"'", "url":"'"${4}"'"}]' - # JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"inline_keyboard": [[ {"text":"$3", "url":"$4"} ... ]]} }' + # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [[ {"text":"$3", "url":"$4"} ... ]]}' } # this will be the only send interface to telegram! +# usage: sendJson "chat" "JSON" "URL" sendJson(){ - res="$(curl -d "${1}" -H "Content-Type: application/json" -X POST "${2}" | "${JSONSHFILE}" -s -b -n )" + res="$(curl -d '{"chat_id":'"${1}"', '"$2"'}' -H "Content-Type: application/json" \ + -X POST "${3}" | "${JSONSHFILE}" -s -b -n )" BOTSENT[OK]="$(echo "$res" | JsonGetLine '"ok"')" BOTSENT[ID]="$(echo "$res" | JsonGetValue '"result","message_id"')" + [[ "${2}" = *"${TEXTISEMPTY}"* ]] && delete_message "${1}" "${BOTSENT[ID]}" } diff --git a/dev/git-add.sh b/dev/git-add.sh index 4ea7e2a..1073334 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # file: git-add.sh # -# works together with git pre-push.sh and add all changed files sind last push +# works together with git pre-push.sh and ADD all changed files since last push #### $$VERSION$$ v0.70-dev3-1-g55dab95 From 8f4b1688bdbb05a449afc550cb98c0a5e4763203 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 25 Apr 2019 15:39:42 +0200 Subject: [PATCH 31/63] more conversion to sendJson --- bashbot.sh | 15 +++++++-------- dev/git-add.sh | 13 +++++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 525598b..1db0d08 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.70-dev3-1-g55dab95 +#### $$VERSION$$ v0.70-dev3-3-g0f220bd # # Exit Codes: # - 0 sucess (hopefully) @@ -188,24 +188,25 @@ send_html_message() { } delete_message() { - res="$(curl -s "$DELETE_URL" -F "chat_id=$1" -F "message_id=$2")" + sendJson "$1" 'message_id: '"$2"'' "$DELETE_URL" } # usage: status="$(get_chat_member_status "chat" "user")" get_chat_member_status() { - curl -s "$GETMEMBER_URL" -F "chat_id=$1" -F "user_id=$2" | "${JSONSHFILE}" -s -b -n | sed -n -e '/\["result","status"\]/ s/.*\][ \t]"\(.*\)"$/\1/p' + sendJson "$1" 'user_id: '"$2"'' "$GETMEMBER_URL" + echo "$res" | JsonGetString '"result","status"' } kick_chat_member() { - res="$(curl -s "$KICK_URL" -F "chat_id=$1" -F "user_id=$2")" + sendJson "$1" 'user_id: '"$2"'' "$KICK_URL" } unban_chat_member() { - res="$(curl -s "$UNBAN_URL" -F "chat_id=$1" -F "user_id=$2")" + sendJson "$1" 'user_id: '"$2"'' "$UNBAN_URL" } leave_chat() { - res="$(curl -s "$LEAVE_URL" -F "chat_id=$1")" + sendJson "$1" "" "$LEAVE_URL" } user_is_creator() { @@ -347,10 +348,8 @@ send_inline_keyboard() { } send_inline_button() { send_inline_keyboard "${1}" "${2}" '[ {"text":"'"${3}"'", "url":"'"${4}"'"}]' - # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [[ {"text":"$3", "url":"$4"} ... ]]}' } -# this will be the only send interface to telegram! # usage: sendJson "chat" "JSON" "URL" sendJson(){ res="$(curl -d '{"chat_id":'"${1}"', '"$2"'}' -H "Content-Type: application/json" \ diff --git a/dev/git-add.sh b/dev/git-add.sh index 1073334..9385ef5 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v0.70-dev3-1-g55dab95 +#### $$VERSION$$ v0.70-dev3-3-g0f220bd # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -13,8 +13,17 @@ cd "$GIT_DIR/.." || exit 1 FILES="$(find ./* -newer .git/.lastpush)" [ "${FILES}" = "" ] && echo "Noting changed since last push!" && exit +# run pre_commit on files +dev/hooks/pre-commit.sh + +echo -n "Add files to repo: " # shellcheck disable=SC2086 -echo Add ${FILES} to repo ... +for file in ${FILES} +do + [ -d "${file}" ] && continue + git add "${file}" && echo -n "${file} " +done +echo "done." # shellcheck disable=SC2086 git add ${FILES} From 8b8da674654d5f6dd8e0895dcd6839781a526981 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 25 Apr 2019 16:59:17 +0200 Subject: [PATCH 32/63] add documentation for inline keyboards --- bashbot.sh | 10 ++++---- dev/git-add.sh | 5 +--- doc/6_reference.md | 60 +++++++++++++++++++++++++++++++++------------- modules/aliases.sh | 12 +++++----- 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 1db0d08..796bf8a 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.70-dev3-3-g0f220bd +#### $$VERSION$$ v0.70-dev3-4-g8f4b168 # # Exit Codes: # - 0 sucess (hopefully) @@ -166,7 +166,7 @@ export BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE send_normal_message() { text="$2" until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do - res="$(curl -s "$MSG_URL" -d "chat_id=$1" --data-urlencode "text=${text:0:4096}")" + sendJson "${1}" '"text":"'"${text:0:4096}"'"' "$MSG_URL" text="${text:4096}" done } @@ -174,7 +174,7 @@ send_normal_message() { send_markdown_message() { text="$2" until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do - res="$(curl -s "$MSG_URL" -d "chat_id=$1" --data-urlencode "text=${text:0:4096}" -d "parse_mode=markdown" -d "disable_web_page_preview=true")" + sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"markdown"' "$MSG_URL" text="${text:4096}" done } @@ -182,7 +182,7 @@ send_markdown_message() { send_html_message() { text="$2" until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do - res="$(curl -s "$MSG_URL" -d "chat_id=$1" --data-urlencode "text=${text:0:4096}" -d "parse_mode=html")" + sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"html"' "$MSG_URL" text="${text:4096}" done } @@ -352,7 +352,7 @@ send_inline_button() { # usage: sendJson "chat" "JSON" "URL" sendJson(){ - res="$(curl -d '{"chat_id":'"${1}"', '"$2"'}' -H "Content-Type: application/json" \ + res="$(curl -s -d '{"chat_id":'"${1}"', '"$2"'}' -H "Content-Type: application/json" \ -X POST "${3}" | "${JSONSHFILE}" -s -b -n )" BOTSENT[OK]="$(echo "$res" | JsonGetLine '"ok"')" BOTSENT[ID]="$(echo "$res" | JsonGetValue '"result","message_id"')" diff --git a/dev/git-add.sh b/dev/git-add.sh index 9385ef5..88ab807 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v0.70-dev3-3-g0f220bd +#### $$VERSION$$ v0.70-dev3-4-g8f4b168 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -25,6 +25,3 @@ do done echo "done." -# shellcheck disable=SC2086 -git add ${FILES} - diff --git a/doc/6_reference.md b/doc/6_reference.md index 5548129..220cf88 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -10,7 +10,6 @@ *"action":* ```typing```, ```upload_photo```, ```record_video```, ```upload_video```, ```record_audio```, ```upload_audio```, ```upload_document```, ```find_location```. - *example:* ```bash send_action "${CHAT[ID]}" "typing" @@ -37,8 +36,8 @@ Telegram supports a [reduced set of Markdown](https://core.telegram.org/bots/api *example:* ```bash -send_normal_message "${CHAT[ID]}" "this is a markdown message, next word is *bold*" -send_normal_message "${CHAT[ID]}" "*bold* _italic_ [text](link)" +send_markdown_message "${CHAT[ID]}" "this is a markdown message, next word is *bold*" +send_markdown_message "${CHAT[ID]}" "*bold* _italic_ [text](link)" ``` ##### send_html_message @@ -126,6 +125,33 @@ send_keyboard "${CHAT[ID]}" "Enter digit" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \ ##### remove_keyboard *usage:* remove_keybord "$CHAT[ID]" "message" +#### send_inline_button +*usage:* send_inine_button "chat-id" "message" "Button text" "Buttton URL" + +*alias:* _inline_button "Button text" "Buttton URL" + +*example:* +```bash +send_inline_button "${CHAT[ID]}" "MAKE MONEY FAST!!!" "Visit my Shop" "https://dealz.rrr.de" +``` + +#### send_inline_keyboard +An inline keyboard is used to place multiple inline buttons in a row. The inline buttons must specified as a JSON array in the following format. Each button consists of a text for the button and an URL to got to if the button is clicked, button definitions +are sourrounded by a pair of '**{ }**' and seperated by a '**,**'. + +```[ {"text":"text1", "url":"url1"}, ... {"text":"textN", "url":"urlN"} ]``` + +*usage:* send_inline_keyboard "chat-id" "message" "[{"text":"text", "url":"url"} ...]" + +*alias:* _inline_keyboard "[{"text":"text", "url":"url"} ...]" + +*example:* +```bash +send_inline_keyboard "${CHAT[ID]}" "MAKE MONEY FAST!!!" '[{"text":"Visit my Shop", url"":"https://dealz.rrr.de"}]' +send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"button 1", url"":"url 1"}, {"text":"button 2", url"":"url 2"} ]' +send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"b 1", url"":"u 1"}, {"text":"b 2", url"":"u 2"}, {"text":"b 2", url"":"u 2"} ]' +``` + ---- ### Manage users @@ -135,21 +161,21 @@ If your Bot is Admin of a chat he can kick and ban a user. *usage:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}" -*alias* _kick_user "${USER[ID]}" +*alias:* _kick_user "${USER[ID]}" ##### unban_chat_member If your Bot is Admin of a chat he can unban a kicked user. *usage:* unban_chat_member "${CHAT[ID]}" "${USER[ID]}" -*alias* _unban "${USER[ID]}" +*alias:* _unban "${USER[ID]}" ##### leave_chat Bot will leave given chat. *usage:* leave_chat "${CHAT[ID]}" -*alias* _leave +*alias:* _leave ```bash if _is_admin ; then @@ -218,19 +244,19 @@ You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to *usage:* _is_botadmin -*alias for* user_is_botadmin "${USER[ID]}" +*alias for:* user_is_botadmin "${USER[ID]}" #### _is_admin *usage:* _is_admin -*alias for* user_is_admin "${CHAT[ID]}" "${USER[ID]}" +*alias for:* user_is_admin "${CHAT[ID]}" "${USER[ID]}" #### _is_allowed *usage:* _is_allowed "what" -*alias for* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}" +*alias for:* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}" ---- @@ -238,19 +264,19 @@ You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to *usage:* _kick_user "${USER[ID]}" -*alias for* kick_chat_member "${CHAT[ID]}" "${USER[ID]}" +*alias for:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}" ##### unban_chat_member *usage:* _unban "${USER[ID]}" -*alias for* unban_chat_member "${CHAT[ID]}" "${USER[ID]}" +*alias for:* unban_chat_member "${CHAT[ID]}" "${USER[ID]}" ##### leave_chat *usage:* _leave -*alias for* leave_chat "${CHAT[ID]}" +*alias for:* leave_chat "${CHAT[ID]}" ---- @@ -258,25 +284,25 @@ You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to *usage:* _message "message" -*alias for* send_normal_message "${CHAT[ID]}" "message" +*alias for:* send_normal_message "${CHAT[ID]}" "message" #### _normal_message *usage:* _normal_message "message" -*alias for* send_normal_message "${CHAT[ID]}" "message" +*alias for:* send_normal_message "${CHAT[ID]}" "message" #### _html_message *usage:* _html_message "message" -*alias for* send_html_message "${CHAT[ID]}" "message" +*alias for:* send_html_message "${CHAT[ID]}" "message" #### _markdown_message *usage:* _markdown_message "message" -*alias for* send_markdown_message "${CHAT[ID]}" "message" +*alias for:* send_markdown_message "${CHAT[ID]}" "message" ---- @@ -445,5 +471,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-4-g8f4b168 diff --git a/modules/aliases.sh b/modules/aliases.sh index ea8e4b7..1e523e8 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-4-g8f4b168 # # source from commands.sh to use the aliases @@ -46,17 +46,17 @@ _markdown_message() { } # easy handling of keyboards _inline_button() { - send_inline_button "${CHAT[ID]}" "${1}" "${2}" "${3}" + send_inline_button "${CHAT[ID]}" "" "${1}" "${2}" } _inline_keyboard() { - send_inline_keyboard "${CHAT[ID]}" "${1}" "${2}" + send_inline_keyboard "${CHAT[ID]}" "" "${1}" } _keyboard_numpad() { - send_keyboard "${CHAT[ID]}" "${1}" '["1","2","3"],["4","5","6"],["7","8","9"],["-","0","."]' "yes" + send_keyboard "${CHAT[ID]}" "" '["1","2","3"],["4","5","6"],["7","8","9"],["-","0","."]' "yes" } _keyboard_yesno() { - send_keyboard "${CHAT[ID]}" "${1}" '["yes","no"]' + send_keyboard "${CHAT[ID]}" "" '["yes","no"]' } _del_keyboard() { - remove_keyboard "${CHAT[ID]}" "${1}" + remove_keyboard "${CHAT[ID]}" "" } From 034274c8d9925555cc2134adf16ffa1ba419f70f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 25 Apr 2019 17:46:47 +0200 Subject: [PATCH 33/63] convert more send_ functions to sendJson --- bashbot.sh | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 796bf8a..6117694 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.70-dev3-4-g8f4b168 +#### $$VERSION$$ v0.70-dev3-5-g8b8da67 # # Exit Codes: # - 0 sucess (hopefully) @@ -310,7 +310,7 @@ answer_inline_query() { old_send_keyboard() { local chat="$1" - local text="$2" + local text='"text":"'"${2}"'"' shift 2 local keyboard=init OLDIFS=$IFS @@ -318,7 +318,8 @@ old_send_keyboard() { for f in "$@" ;do [ "$f" != " " ] && keyboard="$keyboard, [\"$f\"]";done IFS=$OLDIFS keyboard=${keyboard/init, /} - 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}")" + local JSON="${text}"', "reply_markup": {"keyboard": [ '"${keyboard}"' ],"one_time_keyboard": true}' + sendJson "${chat}" "$JSON" "$MSG_URL" } TEXTISEMPTY="ThisTextIsEmptyAndWillBeDeleted" @@ -352,17 +353,19 @@ send_inline_button() { # usage: sendJson "chat" "JSON" "URL" sendJson(){ - res="$(curl -s -d '{"chat_id":'"${1}"', '"$2"'}' -H "Content-Type: application/json" \ + local chat='"chat_id":'"${1}"','; [ "${1}" = "" ] && chat="" + res="$(curl -s -d '{'"${chat} $2"'}' -H "Content-Type: application/json" \ -X POST "${3}" | "${JSONSHFILE}" -s -b -n )" BOTSENT[OK]="$(echo "$res" | JsonGetLine '"ok"')" BOTSENT[ID]="$(echo "$res" | JsonGetValue '"result","message_id"')" [[ "${2}" = *"${TEXTISEMPTY}"* ]] && delete_message "${1}" "${BOTSENT[ID]}" } - get_file() { [ "$1" = "" ] && return - echo "${FILE_URL}$(curl -s "${GET_URL}" -F "file_id=$1" | "${JSONSHFILE}" -s -b -n | grep '\["result","file_path"\]' | cut -f 2 | cut -d '"' -f 2)" + local JSON='"file_id": '"${1}" + sendJson "" "${JSON}" "${GET_URL}" + echo "${FILE_URL}$(echo "${res}" | jsonGetString '"result","file_path"')" } send_file() { @@ -417,24 +420,27 @@ send_file() { send_action() { [ "$2" = "" ] && return - res="$(curl -s "$ACTION_URL" -F "chat_id=$1" -F "action=$2")" + sendJson "${1}" '"action": "'"${2}"'"' "$ACTION_URL" } send_location() { [ "$3" = "" ] && return - res="$(curl -s "$LOCATION_URL" -F "chat_id=$1" -F "latitude=$2" -F "longitude=$3")" + local JSON='"latitude": '"${2}"', "longitude": '"${3}"'' + sendJson "${1}" "${JSON}" "$LOCATION_URL" } send_venue() { [ "$5" = "" ] && return - [ "$6" != "" ] add="-F \"foursquare_id=$6\"" - res="$(curl -s "$VENUE_URL" -F "chat_id=$1" -F "latitude=$2" -F "longitude=$3" -F "title=$4" -F "address=$5")" + local JSON='"latitude": '"${2}"', "longitude": '"${3}"', "title": "'"${4}"'"' + [ "$6" != "" ] JSON="$JSON"', "foursquare_id": '"$6"'' + sendJson "${1}" "${JSON}" "$VENUE_URL" } forward_message() { [ "$3" = "" ] && return - res="$(curl -s "$FORWARD_URL" -F "chat_id=$1" -F "from_chat_id=$2" -F "message_id=$3")" + local JSON='"from_chat_id": '"${2}"', "message_id": '"${3}"'' + sendJson "${1}" "${JSON}" "$FORWARD_URL" } forward() { # backward compatibility forward_message "$@" || return @@ -606,8 +612,8 @@ bot_init() { # get bot name getBotName() { - res="$(curl -s "$ME_URL")" - echo "$res" | "${JSONSHFILE}" -s -b -n | JsonGetString '"result","username"' + res="$(curl -s "$ME_URL" | "${JSONSHFILE}" -s -b -n )" + echo "$res" | JsonGetString '"result","username"' } ME="$(getBotName)" From d88d422fdd0d0ab2f2e062b3cc8bdd45fe6a51d8 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 25 Apr 2019 22:17:24 +0200 Subject: [PATCH 34/63] improve documentation --- doc/2_usage.md | 4 ++-- doc/3_advanced.md | 26 ++++++++++++-------- doc/6_reference.md | 60 ++++++++++++++++++++++++---------------------- 3 files changed, 49 insertions(+), 41 deletions(-) diff --git a/doc/2_usage.md b/doc/2_usage.md index e4e211a..670a6c5 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -1,7 +1,7 @@ #### [Home](../README.md) ## Gettting Started -The Bots standard commands are in ```commands.sh``` file. You must not add your commands to 'commands.sh', instead place them in ```mycommands.sh```, there you also find examples how to process messages and send out text. +The Bots standard commands are in ```commands.sh``` file. You must not add your commands to 'commands.sh', instead place them in ```mycommands.sh```, there you also find examples how to process messages and send out text. See [Best practices](5_practice.md) for more information. Once you're done with editing 'mycommands.sh' start the Bot with ```./bashbot.sh start```. If some thing doesn't work as it should, debug with ```bash -x bashbot.sh```. To stop the Bot run ```./bashbot.sh kill``` @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-6-g034274c diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 6ce711d..fda1985 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -2,7 +2,7 @@ ## Advanced Features ### Access control -Bashbot offers functions to check what Telegram capabilities like chat admin or chat creator the given user has: +Bashbot offers functions to check what Telegram capabilities like 'chat admin' or 'chat creator' the given user has: ```bash # return true if user is admin/owner of the bot @@ -21,7 +21,7 @@ user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are * user_is_admin "${CHAT[ID]}" "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *CHATADMIN*." ``` -In addition you can check individual capabilities of users as defined in the ```./botacl``` file: +In addition you can check individual capabilities of users as you must define in the file ```./botacl```: ```bash # file: botacl # a user not listed here, will return false from 'user_is_allowed' @@ -44,7 +44,7 @@ In addition you can check individual capabilities of users as defined in the ``` *:start:* *:*:98979695 ``` -you have to use the function ```user_is_allowed``` to check if a user has the capability to do something. Example check if user has capability to start bot: +You must use the function ```user_is_allowed``` to check if a user has the capability to do something. Example: Check if user has capability to start bot. ```bash case "$MESSAGE" in '/start') @@ -58,8 +58,14 @@ you have to use the function ```user_is_allowed``` to check if a user has the ca ``` ### Interactive Chats -To create interactive chats, write (or edit the exmaples/question.sh script) a normal bash (or C or python) script, chmod +x it and then change the argument of the startproc function to match the command you usually use to start the script. -The text that the script will output will be sent in real time to the user, and all user input will be sent to the script (as long as it's running or until the user kills it with /cancel). +To create interactive chats, write *(or edit the 'exmaples/question.sh' script)* a bash *(or C or python)* script, make it executable +and then use the 'startproc' function to start the script. +The output of the script will be sent to the user and user input will be sent to the script. +To stop the script use the function 'killprog' + +The output of the script will be processed by 'send_messages' to enable you to not only send text, but also keyboards, files, locations and more. +Each newline in the output will start an new message to the user, to have line breaks in your message you can use 'mynewlinestartshere'. + To open up a keyboard in an interactive script, print out the keyboard layout in the following way: ```bash echo "Text that will appear in chat? mykeyboardstartshere [ \"Yep, sure\" , \"No, highly unlikely\" ]" @@ -90,11 +96,11 @@ Note: Interactive Chats run independent from main bot and continue running until ### Background Jobs -A background job is similar to an interactive chat, but runs in the background and does only output massages instead of processing input from the user. In contrast to interactive chats it's possible to run multiple background jobs. To create a background job write a script or edit the examples/notify.sh script and use the funtion ```background``` to start it: +A background job is similar to an interactive chat, but runs in the background and does only output massages and does not get user input. In contrast to interactive chats it's possible to run multiple background jobs. To create a background job write a script or edit 'examples/notify.sh' script and use the funtion ```background``` to start it: ```bash background "examples/notify.sh" "jobname" ``` -All output of the script will be sent to the user or chat. To stop a background job use: +All output of the script will be sent to the user, to stop a background job use: ```bash killback "jobname" ``` @@ -109,7 +115,7 @@ If you want to kill all background jobs permantly run: ./bashbot.sh killback ``` -Note: Background Jobs run independent from main bot and continue running until your script exits or you stop if from your Bot. Backgound Jobs will continue running if your Bot is stoped (kill)!. +Note: Background Jobs run independent from main bot and continue running until your script exits or you stop if from your Bot. Backgound Jobs will continue running if your Bot is stopeda and must be terminated, e.g. by ```bashbot.sh killback``` ### Inline queries The following commands allows users to interact with your bot via *inline queries*. @@ -153,8 +159,8 @@ To send stickers through an *inline query*: ```bash answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" ``` -#### [Prev Advanced Usage](3_advanced.md) +#### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-6-g034274c diff --git a/doc/6_reference.md b/doc/6_reference.md index 220cf88..1288bd9 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -125,23 +125,24 @@ send_keyboard "${CHAT[ID]}" "Enter digit" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \ ##### remove_keyboard *usage:* remove_keybord "$CHAT[ID]" "message" -#### send_inline_button -*usage:* send_inine_button "chat-id" "message" "Button text" "Buttton URL" +##### send_inline_button +*usage:* send_inine_button "chat-id" "message" "text" "URL" -*alias:* _inline_button "Button text" "Buttton URL" +*alias:* _inline_button "text" "URL" *example:* ```bash send_inline_button "${CHAT[ID]}" "MAKE MONEY FAST!!!" "Visit my Shop" "https://dealz.rrr.de" ``` -#### send_inline_keyboard -An inline keyboard is used to place multiple inline buttons in a row. The inline buttons must specified as a JSON array in the following format. Each button consists of a text for the button and an URL to got to if the button is clicked, button definitions -are sourrounded by a pair of '**{ }**' and seperated by a '**,**'. +##### send_inline_keyboard +This allows to place multiple inline buttons in a row. The inline buttons must specified as a JSON array in the following format: ```[ {"text":"text1", "url":"url1"}, ... {"text":"textN", "url":"urlN"} ]``` -*usage:* send_inline_keyboard "chat-id" "message" "[{"text":"text", "url":"url"} ...]" +Each button consists of a pair of text and URL values, sourrounded by '**{ }**', multiple buttons are seperated by '**,**' and everthing is wrapped in '**[ ]**'. + +*usage:* send_inline_keyboard "chat-id" "message" "[ {"text":"text", "url":"url"} ...]" *alias:* _inline_keyboard "[{"text":"text", "url":"url"} ...]" @@ -157,21 +158,21 @@ send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"b 1", url"":"u 1"}, {"text":"b ### Manage users ##### kick_chat_member -If your Bot is Admin of a chat he can kick and ban a user. +If your Bot is a chat admin he can kick and ban a user. *usage:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}" *alias:* _kick_user "${USER[ID]}" ##### unban_chat_member -If your Bot is Admin of a chat he can unban a kicked user. +If your Bot is a chat admine can unban a kicked user. *usage:* unban_chat_member "${CHAT[ID]}" "${USER[ID]}" *alias:* _unban "${USER[ID]}" ##### leave_chat -Bot will leave given chat. +Your Bot will leave the chat. *usage:* leave_chat "${CHAT[ID]}" @@ -189,8 +190,7 @@ fi ### User Access Control ##### user_is_botadmin -Return true (0) if user is owner / admin of bot. -Name or ID botadmin must be placed in './botadmin' file. +Return true (0) if user is admin of bot, user id if botadmin is read from file './botadmin'. *usage:* user_is_botadmin "${USER[ID]}" @@ -238,21 +238,21 @@ fi ---- ### Aliases - shortcuts for often used funtions -You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to have the following functions availible. +You must not disable ```source modules/aliases.sh``` in 'commands.sh' to have the following functions availible. -#### _is_botadmin +##### _is_botadmin *usage:* _is_botadmin *alias for:* user_is_botadmin "${USER[ID]}" -#### _is_admin +##### _is_admin *usage:* _is_admin *alias for:* user_is_admin "${CHAT[ID]}" "${USER[ID]}" -#### _is_allowed +##### _is_allowed *usage:* _is_allowed "what" @@ -260,19 +260,19 @@ You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to ---- -##### kick_chat_member +##### _kick_user *usage:* _kick_user "${USER[ID]}" *alias for:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}" -##### unban_chat_member +##### _unban *usage:* _unban "${USER[ID]}" *alias for:* unban_chat_member "${CHAT[ID]}" "${USER[ID]}" -##### leave_chat +##### _leave *usage:* _leave @@ -280,25 +280,25 @@ You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to ---- -#### _message +##### _message *usage:* _message "message" *alias for:* send_normal_message "${CHAT[ID]}" "message" -#### _normal_message +##### _normal_message *usage:* _normal_message "message" *alias for:* send_normal_message "${CHAT[ID]}" "message" -#### _html_message +##### _html_message *usage:* _html_message "message" *alias for:* send_html_message "${CHAT[ID]}" "message" -#### _markdown_message +##### _markdown_message *usage:* _markdown_message "message" @@ -307,10 +307,10 @@ You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to ---- ### Interactive and backgound jobs -You must use ```source modules/background.sh``` in commands.sh or mycommands.sh to have the following functions availible. +You must not disable ```source modules/background.sh``` in 'commands.sh' to have the following functions availible. ##### startproc -```startproc``` starts a script (or C or python program etc.) running in parallel to your Bot. The text that the script outputs is sent to the user or chat, user input will be sent back to the script. see [Advanced Usage](3_advanced.md#Interactive-Chats) +```startproc``` starts a script, the output of the script is sent to the user or chat, user input will be sent back to the script. see [Advanced Usage](3_advanced.md#Interactive-Chats) *usage:* startproc "script" @@ -320,7 +320,7 @@ startproc 'examples/calc.sh' ``` ##### checkproc -Return true (0) if an interactive script active in the given chat. +Return true (0) if an interactive script is running in the chat. *usage:* checkprog @@ -335,6 +335,8 @@ fi ``` ##### killproc +Kill the interactive script running in the chat + *usage:* killproc *example:* @@ -350,7 +352,7 @@ fi ---- ##### background -```background``` starts a script / programm as a background job and attaches a jobname to it. All output from a background job is sent to the associated chat. +Starts a script as a background job and attaches a jobname to it. All output from a background job is sent to the associated chat. In contrast to interactive chats, background jobs do not recieve user input and can run forever. In addition you can suspend and restart running jobs, e.g. after reboot. @@ -406,7 +408,7 @@ The main use case for send_message is to process the output of interactive chats ### Helper functions -#### _is_function +##### _is_function Returns true if the given function exist, can be used to check if a module is loaded. *usage* _is_function function @@ -471,5 +473,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev3-4-g8f4b168 +#### $$VERSION$$ v0.70-dev3-6-g034274c From b8a23c45533480db9489cb26f8cb3b8ef1630e1b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 10:40:09 +0200 Subject: [PATCH 35/63] update doc 4 environment --- doc/5_practice.md | 4 ++-- doc/8_custom.md | 26 ++++++-------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/doc/5_practice.md b/doc/5_practice.md index ef221a6..48b7662 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -30,7 +30,7 @@ mycommands() { If you want to disable or reuse a standard bashbot command comment it out in 'commands.sh' by placing a '#' in front of every line from ```'/command')``` to ```;;```. -**Note: Never disable the catchall command ``*)```` in 'commands.sh'!!** +**Note: Never disable the catchall command ```*)``` in 'commands.sh'!!** ```bash # file: commands.sh @@ -141,5 +141,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-7-gd88d422 diff --git a/doc/8_custom.md b/doc/8_custom.md index ac762ea..32c3e8f 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -11,7 +11,7 @@ If you want to have other locations for config, data etc, define and export the **Note: all specified directories and files must exist or running 'bashbot.sh' will fail.** #### BASHBOT_ETC -Location of the config files 'token', 'botadmin', 'botacl' ... +Location of the files ```commands.sh```, ```mycommands.sh```, ```token```, ```botadmin```, ```botacl``` ... ```bash unset BASHBOT_ETC # keep in telegram-bot-bash (default) export BASHBOT_ETC "" # keep in telegram-bot-bash @@ -36,17 +36,6 @@ Location of runtime data files 'data-bot-bash', 'count', downloaded files ... export BASHBOT_VAR "/var/spool/bashbot/bot2" # multibot configuration bot 2 ``` -#### BASHBOT_COMMANDS -Full path to bash script containing your commands, default: './commands.sh', must end with '.sh' -```bash - unset BASHBOT_COMMANDS # telegram-bot-bash/commands.sh (default) - export BASHBOT_COMMANDS "" # telegram-bot-bash/commands.sh - - export BASHBOT_COMMANDS "/etc/bashbot/commands.sh" # unix like config location - - export BASHBOT_COMMANDS "/etc/bashbot/bot1/commands.sh" # multibot configuration bot 1 - export BASHBOT_COMMANDS "/etc/bashbot/bot2/commands.sh" # multibot configuration bot 2 -``` #### BASHBOT_JSONSH Full path to JSON.sh script, default: './JSON.sh/JSON.sh', must end with '/JSON.sh'. ```bash @@ -85,10 +74,10 @@ for every poll until the maximum of BASHBOT_SLEEP ms. ``` -### Testet location configs +### Testet configs as of v.07 release **Note: Environment variables are not stored, you must setup them before every call to bashbot.sh, e.g. from a script.** -#### simple Unix like config, mainly for one bot. bashbot is in '/usr/local/telegram-bot-bash' +#### simple Unix like config, for one bot. bashbot is installed in '/usr/local/telegram-bot-bash' ```bash # Note: all dirs and files must exist! export BASHBOT_ETC "/etc/bashbot" @@ -97,24 +86,22 @@ for every poll until the maximum of BASHBOT_SLEEP ms. /usr/local/telegram-bot-bash/bashbot.sh start ``` -#### Unix like config, mainly for one bot. bashbot.sh is in '/usr/bin' +#### Unix like config for one bot. bashbot.sh is installed in '/usr/bin' ```bash # Note: all dirs and files must exist! export BASHBOT_ETC "/etc/bashbot" export BASHBOT_VAR "/var/spool/bashbot" export BASHBOT_JSONSH "/var/spool/bashbot" - export BASHBOT_COMMANDS "/etc/bashbot/commands.sh /usr/local/bin/bashbot.sh start ``` -#### simple multibot config bashbot is in '/usr/local/telegram-bot-bash' +#### simple multibot config, everything is keept inside 'telegram-bot-bash' dir ```bash # config for running Bot 1 # Note: all dirs and files must exist! export BASHBOT_ETC "./mybot1" export BASHBOT_VAR "./mybot1" - export BASHBOT_COMMANDS "./mybot1/commands.sh /usr/local/telegram-bot-bash/bashbot.sh start ``` @@ -124,12 +111,11 @@ for every poll until the maximum of BASHBOT_SLEEP ms. # Note: all dirs and files must exist! export BASHBOT_ETC "./mybot2" export BASHBOT_VAR "./mybot2" - export BASHBOT_COMMANDS "./mybot2/commands.sh /usr/local/telegram-bot-bash/bashbot.sh start ``` #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-7-gd88d422 From d08d58131257843a6af3cb522338a9d48eec31e9 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 11:17:42 +0200 Subject: [PATCH 36/63] ajust develop and environmen doc --- bashbot.sh | 11 +++++------ commands.sh | 12 +++++++----- doc/7_develop.md | 27 ++++++++++++++++++++------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 6117694..e8fa6e3 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.70-dev3-5-g8b8da67 +#### $$VERSION$$ v0.70-dev3-8-gb8a23c4 # # Exit Codes: # - 0 sucess (hopefully) @@ -34,9 +34,10 @@ fi # get location and name of bashbot.sh SCRIPT="$0" SCRIPTDIR="$(dirname "$0")" -RUNDIR="${BASHBOT_VAR:-${SCRIPTDIR}}" -[ "${RUNDIR}" = "${SCRIPTDIR}" ] && SCRIPT="./$(basename "${SCRIPT}")" +MODULEDIR="${SCRIPTDIR}/modules" +RUNDIR="${SCRIPTDIR}" +[ "${RUNDIR}" = "${SCRIPTDIR}" ] && SCRIPT="./$(basename "${SCRIPT}")" RUNUSER="${USER}" # USER is overwritten by bashbot array @@ -115,9 +116,7 @@ elif [ ! -w "${COUNTFILE}" ]; then exit 2 fi -COMMANDS="${BASHBOT_COMMANDS:-${RUNDIR}/commands.sh}" -[[ "${COMMANDS}" != *".sh" ]] && echo -e "${RED}ERROR: \"${COMMANDS}\" ends not with \".sh\".${NC}" && exit 3 - +COMMANDS="${BASHBOT_ETC:-.}/commands.sh" if [ "$1" != "source" ]; then if [ ! -f "${COMMANDS}" ] || [ ! -r "${COMMANDS}" ]; then ${CLEAR} diff --git a/commands.sh b/commands.sh index 775fe99..44bb2a0 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.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-8-gb8a23c4 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -40,14 +40,16 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili) and KayM(@gnadelwar Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) ' - # load additional modules - [ -r "modules/aliases.sh" ] && source "modules/aliases.sh" - [ -r "modules/background.sh" ] && source "modules/background.sh" + # load modules + # 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" # ... more modules here ... # mycommands is the last "module" to source in # shellcheck source=./commands.sh - [ -r "mycommands.sh" ] && source "mycommands.sh" + [ -r "${BASHBOT_ETC:-.}/mycommands.sh" ] && source "${BASHBOT_ETC:-.}/mycommands.sh" fi diff --git a/doc/7_develop.md b/doc/7_develop.md index 41664cb..f6d271c 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -13,6 +13,19 @@ bashbot development is done on github. If you want to provide fixes or new featu 5. give your (dev) fork a new version tag: ```git tag vx.xx```, version must be higher than current version 6. setup github hooks by running ```dev/install-hooks.sh``` (optional) +### Test, Add, Push changes +A typical bashbot develop cycle looks as follow: + +1. 'git checkout develop' +2. start developing - *change, copy, edit bashbot files ...* +3. run 'dev/all-tests.sh' - *in case if errors back to 2.* +4. run 'dev/git-add.sh' - *check for changed files, update version string, run git add* +5. 'git commit' -m "COMMIT MESSAGE" +6. 'git push' + + +**If you setup with hooks and use the scripts above, versioning, addding and testing is done automatically.** + ### Versioning Bashbot is tagged with version numbers. If you start a new development cycle you must tag your fork with a version higher than the current version. @@ -22,7 +35,6 @@ To get the current version name of your develepment fork run ```git describe --t To update the Version Number in your scripts run ```dev/version.sh```, it will update the line '#### $$VERSION$$ ###' in all files to the current version name. -If you actived git hooks in Setup step 6, 'version.sh' updates the version name on every push ### Shellchecking @@ -32,17 +44,18 @@ In addition you can run ```dev/hooks/pre-commit.sh``` every time you want to she ## bashbot tests -Starting with version 0.70 bashbot has a test suite. To start testsuite run ```test/ALL-tests.sh```. ALL-tests.sh will only return 'SUCCESS' if all tests pass. +Starting with version 0.70 bashbot has a test suite. To start testsuite run ```dev/all-tests.sh```. all-tests.sh will return 'SUCCESS' only if all tests pass. ### enabling / disabling tests -All tests are placed in the directory ```test```. To disable a test remove the x flag from the '*-test.sh' test script, to (re)enable -a test make the script executable again. +All tests are placed in the directory ```test```. To disable a test remove the x flag from the '*-test.sh' test script, to (re)enable a test make the script executable again. ### creating new tests -Each test consists of a script script named like ```p-name-test.sh``` *(where p is test pass 'a-z' and name the name of your test)* and -an optional dir ```p-name-test/``` *(script name minus '.sh')* for additional files. +To create a new test run ```test/ADD-test-new.sh``` and answer the questions, afterwards you have the following described files and dirs: + +Each test consists of a script script named like ```p-name-test.sh``` *(where p is test pass 'a-z' and name the name +of your test)* and an optional dir ```p-name-test/``` *(script name minus '.sh')* for additional files. The file ```ALL-tests.inc.sh``` must be included from all tests, do not forget the shellcheck source directive to statisfy shellcheck. @@ -71,5 +84,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-8-gb8a23c4 From 81c8b041ec7d7c70ccae271669db9de0ffedbb54 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 11:28:51 +0200 Subject: [PATCH 37/63] better handling of moved files --- test/ALL-tests.sh => dev/all-tests.sh | 0 dev/git-add.sh | 5 +++-- doc/8_custom.md | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) rename test/ALL-tests.sh => dev/all-tests.sh (100%) diff --git a/test/ALL-tests.sh b/dev/all-tests.sh similarity index 100% rename from test/ALL-tests.sh rename to dev/all-tests.sh diff --git a/dev/git-add.sh b/dev/git-add.sh index 88ab807..a39227f 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v0.70-dev3-4-g8f4b168 +#### $$VERSION$$ v0.70-dev3-9-gd08d581 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -21,7 +21,8 @@ echo -n "Add files to repo: " for file in ${FILES} do [ -d "${file}" ] && continue - git add "${file}" && echo -n "${file} " + echo -n "${file} " done +git add . echo "done." diff --git a/doc/8_custom.md b/doc/8_custom.md index 32c3e8f..0770a92 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -25,7 +25,7 @@ Location of the files ```commands.sh```, ```mycommands.sh```, ```token```, ```bo e.g. /etc/bashbot #### BASHBOT_VAR -Location of runtime data files 'data-bot-bash', 'count', downloaded files ... +Location of runtime data ```data-bot-bash```, ```count``` ```bash unset BASHBOT_VAR # keep in telegram-bot-bash (default) export BASHBOT_VAR "" # keep in telegram-bot-bash @@ -117,5 +117,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev3-7-gd88d422 +#### $$VERSION$$ v0.70-dev3-9-gd08d581 From c835e0516cc327aec678a7e78969d0b1a34b0c46 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 11:41:25 +0200 Subject: [PATCH 38/63] more failsave module sourcing --- bashbot.sh | 2 +- commands.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index e8fa6e3..0595b9f 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.70-dev3-8-gb8a23c4 +#### $$VERSION$$ v0.70-dev3-10-g81c8b04 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index 44bb2a0..a13a9d4 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.70-dev3-8-gb8a23c4 +#### $$VERSION$$ v0.70-dev3-10-g81c8b04 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -42,9 +42,9 @@ Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) # load modules # shellcheck source=./modules/aliases.sh - [ -r "${MODULEDIR}/aliases.sh" ] && source "${MODULEDIR}/aliases.sh" + [ -r "${MODULEDIR:-.}/aliases.sh" ] && source "${MODULEDIR:-.}/aliases.sh" # shellcheck source=./modules/background.sh - [ -r "${MODULEDIR}/background.sh" ] && source "${MODULEDIR}/background.sh" + [ -r "${MODULEDIR:-.}/background.sh" ] && source "${MODULEDIR:-.}/background.sh" # ... more modules here ... # mycommands is the last "module" to source in From a288a8d1d4e6b72b8d81f40a8dfd77f8b9a1573b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 12:26:34 +0200 Subject: [PATCH 39/63] optimize sendJson usage --- bashbot.sh | 53 ++++++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 0595b9f..aa7abd8 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.70-dev3-10-g81c8b04 +#### $$VERSION$$ v0.70-dev3-11-gc835e05 # # Exit Codes: # - 0 sucess (hopefully) @@ -308,7 +308,6 @@ answer_inline_query() { old_send_keyboard() { - local chat="$1" local text='"text":"'"${2}"'"' shift 2 local keyboard=init @@ -317,34 +316,27 @@ old_send_keyboard() { for f in "$@" ;do [ "$f" != " " ] && keyboard="$keyboard, [\"$f\"]";done IFS=$OLDIFS keyboard=${keyboard/init, /} - local JSON="${text}"', "reply_markup": {"keyboard": [ '"${keyboard}"' ],"one_time_keyboard": true}' - sendJson "${chat}" "$JSON" "$MSG_URL" + sendJson "${1}" "${text}"', "reply_markup": {"keyboard": [ '"${keyboard}"' ],"one_time_keyboard": true}' "$MSG_URL" } -TEXTISEMPTY="ThisTextIsEmptyAndWillBeDeleted" +ISEMPTY="ThisTextIsEmptyAndWillBeDeleted" send_keyboard() { if [[ "$3" != *'['* ]]; then old_send_keyboard "$@"; return; fi - local chat="${1}" - local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' + local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${ISEMPTY}"'"' local one_time=', "one_time_keyboard":true' && [ "$4" != "" ] && one_time="" - local JSON="${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"'}' + sendJson "${1}" "${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"'}' "$MSG_URL" # '"text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true}' - sendJson "${chat}" "$JSON" "$MSG_URL" } remove_keyboard() { - local chat="${1}" - local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' - local JSON="${text}"', "reply_markup": {"remove_keyboard":true}' + local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${ISEMPTY}"'"' + sendJson "${1}" "${text}"', "reply_markup": {"remove_keyboard":true}' "$MSG_URL" #JSON='"text":"$2", "reply_markup": {"remove_keyboard":true}' - sendJson "${chat}" "$JSON" "$MSG_URL" } send_inline_keyboard() { - local chat="${1}" - local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${TEXTISEMPTY}"'"' - local JSON="${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]}' - # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}' - sendJson "${chat}" "$JSON" "$MSG_URL" + local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${ISEMPTY}"'"' + sendJson "${1}" "${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]}' "$MSG_URL" + # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}' } send_inline_button() { send_inline_keyboard "${1}" "${2}" '[ {"text":"'"${3}"'", "url":"'"${4}"'"}]' @@ -352,12 +344,13 @@ send_inline_button() { # usage: sendJson "chat" "JSON" "URL" sendJson(){ - local chat='"chat_id":'"${1}"','; [ "${1}" = "" ] && chat="" - res="$(curl -s -d '{'"${chat} $2"'}' -H "Content-Type: application/json" \ - -X POST "${3}" | "${JSONSHFILE}" -s -b -n )" - BOTSENT[OK]="$(echo "$res" | JsonGetLine '"ok"')" - BOTSENT[ID]="$(echo "$res" | JsonGetValue '"result","message_id"')" - [[ "${2}" = *"${TEXTISEMPTY}"* ]] && delete_message "${1}" "${BOTSENT[ID]}" + local chat=""; + [ "${1}" != "" ] && chat='"chat_id":'"${1}"',' + res="$(curl -s -d '{'"${chat} $2"'}' -X POST "${3}" \ + -H "Content-Type: application/json" | "${JSONSHFILE}" -s -b -n )" + BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")" + BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$res")" + [[ "${2}" = *"${ISEMPTY}"* ]] && delete_message "${1}" "${BOTSENT[ID]}" } get_file() { @@ -424,22 +417,20 @@ send_action() { send_location() { [ "$3" = "" ] && return - local JSON='"latitude": '"${2}"', "longitude": '"${3}"'' - sendJson "${1}" "${JSON}" "$LOCATION_URL" + sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"'' "$LOCATION_URL" } send_venue() { + local add="" [ "$5" = "" ] && return - local JSON='"latitude": '"${2}"', "longitude": '"${3}"', "title": "'"${4}"'"' - [ "$6" != "" ] JSON="$JSON"', "foursquare_id": '"$6"'' - sendJson "${1}" "${JSON}" "$VENUE_URL" + [ "$6" != "" ] add=', "foursquare_id": '"$6"'' + sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"', "title": "'"${4}"'"'"${add}" "$VENUE_URL" } forward_message() { [ "$3" = "" ] && return - local JSON='"from_chat_id": '"${2}"', "message_id": '"${3}"'' - sendJson "${1}" "${JSON}" "$FORWARD_URL" + sendJson "${1}" '"from_chat_id": '"${2}"', "message_id": '"${3}"'' "$FORWARD_URL" } forward() { # backward compatibility forward_message "$@" || return From 81b540a4d51a8b56532a558cd88b8ccfd4309bbf Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 13:19:34 +0200 Subject: [PATCH 40/63] some more conversion to sendJson --- bashbot.sh | 81 +++++++++++++++++++++++------------------------- doc/7_develop.md | 13 ++++---- 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index aa7abd8..fc5cad7 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.70-dev3-11-gc835e05 +#### $$VERSION$$ v0.70-dev3-12-ga288a8d # # Exit Codes: # - 0 sucess (hopefully) @@ -132,7 +132,6 @@ fi BOTTOKEN="$(cat "${TOKENFILE}")" URL='https://api.telegram.org/bot'$BOTTOKEN - MSG_URL=$URL'/sendMessage' LEAVE_URL=$URL'/leaveChat' KICK_URL=$URL'/kickChatMember' @@ -152,10 +151,8 @@ ME_URL=$URL'/getMe' DELETE_URL=$URL'/deleteMessage' GETMEMBER_URL=$URL'/getChatMember' - -FILE_URL='https://api.telegram.org/file/bot'$BOTTOKEN'/' UPD_URL=$URL'/getUpdates?offset=' -GET_URL=$URL'/getFile' +GETFILE_URL=$URL'/getFile' unset USER declare -A BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE @@ -163,37 +160,37 @@ export BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE send_normal_message() { - text="$2" - until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do - sendJson "${1}" '"text":"'"${text:0:4096}"'"' "$MSG_URL" + local text="${2}" + until [ -z "${text}" ]; do + sendJson "${1}" '"text":"'"${text:0:4096}"'"' "${MSG_URL}" text="${text:4096}" done } send_markdown_message() { - text="$2" - until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do - sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"markdown"' "$MSG_URL" + local text="${2}" + until [ -z "${text}" ]; do + sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"markdown"' "${MSG_URL}" text="${text:4096}" done } send_html_message() { - text="$2" - until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do - sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"html"' "$MSG_URL" + local text="${2}" + until [ -z "${text}" ]; do + sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"html"' "${MSG_URL}" text="${text:4096}" done } delete_message() { - sendJson "$1" 'message_id: '"$2"'' "$DELETE_URL" + sendJson "${1}" 'message_id: '"${2}"'' "${DELETE_URL}" } # usage: status="$(get_chat_member_status "chat" "user")" get_chat_member_status() { sendJson "$1" 'user_id: '"$2"'' "$GETMEMBER_URL" - echo "$res" | JsonGetString '"result","status"' + JsonGetString '"result","status"' <<< "$res" } kick_chat_member() { @@ -238,72 +235,72 @@ user_is_allowed() { } answer_inline_query() { - case "$2" in + local JSON + case "${2}" in "article") - InlineQueryResult='[{"type":"'$2'","id":"'$RANDOM'","title":"'$3'","message_text":"'$4'"}]' + JSON='[{"type":"'$2'","id":"'$RANDOM'","title":"'$3'","message_text":"'$4'"}]' ;; "photo") - InlineQueryResult='[{"type":"'$2'","id":"'$RANDOM'","photo_url":"'$3'","thumb_url":"'$4'"}]' + JSON='[{"type":"'$2'","id":"'$RANDOM'","photo_url":"'$3'","thumb_url":"'$4'"}]' ;; "gif") - InlineQueryResult='[{"type":"'$2'","id":"'$RANDOM'","gif_url":"'$3'", "thumb_url":"'$4'"}]' + JSON='[{"type":"'$2'","id":"'$RANDOM'","gif_url":"'$3'", "thumb_url":"'$4'"}]' ;; "mpeg4_gif") - InlineQueryResult='[{"type":"'$2'","id":"'$RANDOM'","mpeg4_url":"'$3'"}]' + JSON='[{"type":"'$2'","id":"'$RANDOM'","mpeg4_url":"'$3'"}]' ;; "video") - InlineQueryResult='[{"type":"'$2'","id":"'$RANDOM'","video_url":"'$3'","mime_type":"'$4'","thumb_url":"'$5'","title":"'$6'"}]' + JSON='[{"type":"'$2'","id":"'$RANDOM'","video_url":"'$3'","mime_type":"'$4'","thumb_url":"'$5'","title":"'$6'"}]' ;; "audio") - InlineQueryResult='[{"type":"'$2'","id":"'$RANDOM'","audio_url":"'$3'","title":"'$4'"}]' + JSON='[{"type":"'$2'","id":"'$RANDOM'","audio_url":"'$3'","title":"'$4'"}]' ;; "voice") - InlineQueryResult='[{"type":"'$2'","id":"'$RANDOM'","voice_url":"'$3'","title":"'$4'"}]' + JSON='[{"type":"'$2'","id":"'$RANDOM'","voice_url":"'$3'","title":"'$4'"}]' ;; "document") - InlineQueryResult='[{"type":"'$2'","id":"'$RANDOM'","title":"'$3'","caption":"'$4'","document_url":"'$5'","mime_type":"'$6'"}]' + JSON='[{"type":"'$2'","id":"'$RANDOM'","title":"'$3'","caption":"'$4'","document_url":"'$5'","mime_type":"'$6'"}]' ;; "location") - InlineQueryResult='[{"type":"'$2'","id":"'$RANDOM'","latitude":"'$3'","longitude":"'$4'","title":"'$5'"}]' + JSON='[{"type":"'$2'","id":"'$RANDOM'","latitude":"'$3'","longitude":"'$4'","title":"'$5'"}]' ;; "venue") - InlineQueryResult='[{"type":"'$2'","id":"'$RANDOM'","latitude":"'$3'","longitude":"'$4'","title":"'$5'","address":"'$6'"}]' + JSON='[{"type":"'$2'","id":"'$RANDOM'","latitude":"'$3'","longitude":"'$4'","title":"'$5'","address":"'$6'"}]' ;; "contact") - InlineQueryResult='[{"type":"'$2'","id":"'$RANDOM'","phone_number":"'$3'","first_name":"'$4'"}]' + JSON='[{"type":"'$2'","id":"'$RANDOM'","phone_number":"'$3'","first_name":"'$4'"}]' ;; # Cached media stored in Telegram server "cached_photo") - InlineQueryResult='[{"type":"photo","id":"'$RANDOM'","photo_file_id":"'$3'"}]' + JSON='[{"type":"photo","id":"'$RANDOM'","photo_file_id":"'$3'"}]' ;; "cached_gif") - InlineQueryResult='[{"type":"gif","id":"'$RANDOM'","gif_file_id":"'$3'"}]' + JSON='[{"type":"gif","id":"'$RANDOM'","gif_file_id":"'$3'"}]' ;; "cached_mpeg4_gif") - InlineQueryResult='[{"type":"mpeg4_gif","id":"'$RANDOM'","mpeg4_file_id":"'$3'"}]' + JSON='[{"type":"mpeg4_gif","id":"'$RANDOM'","mpeg4_file_id":"'$3'"}]' ;; "cached_sticker") - InlineQueryResult='[{"type":"sticker","id":"'$RANDOM'","sticker_file_id":"'$3'"}]' + JSON='[{"type":"sticker","id":"'$RANDOM'","sticker_file_id":"'$3'"}]' ;; "cached_document") - InlineQueryResult='[{"type":"document","id":"'$RANDOM'","title":"'$3'","document_file_id":"'$4'"}]' + JSON='[{"type":"document","id":"'$RANDOM'","title":"'$3'","document_file_id":"'$4'"}]' ;; "cached_video") - InlineQueryResult='[{"type":"video","id":"'$RANDOM'","video_file_id":"'$3'","title":"'$4'"}]' + JSON='[{"type":"video","id":"'$RANDOM'","video_file_id":"'$3'","title":"'$4'"}]' ;; "cached_voice") - InlineQueryResult='[{"type":"voice","id":"'$RANDOM'","voice_file_id":"'$3'","title":"'$4'"}]' + JSON='[{"type":"voice","id":"'$RANDOM'","voice_file_id":"'$3'","title":"'$4'"}]' ;; "cached_audio") - InlineQueryResult='[{"type":"audio","id":"'$RANDOM'","audio_file_id":"'$3'"}]' + JSON='[{"type":"audio","id":"'$RANDOM'","audio_file_id":"'$3'"}]' ;; esac - res="$(curl -s "$INLINE_QUERY" -F "inline_query_id=$1" -F "results=$InlineQueryResult")" - + sendJson "" '"inline_query_id": '"${1}"', "results": '"${JSON}" "${INLINE_QUERY}" } @@ -356,8 +353,8 @@ sendJson(){ get_file() { [ "$1" = "" ] && return local JSON='"file_id": '"${1}" - sendJson "" "${JSON}" "${GET_URL}" - echo "${FILE_URL}$(echo "${res}" | jsonGetString '"result","file_path"')" + sendJson "" "${JSON}" "${GETFILE_URL}" + echo "${URL}/$(echo "${res}" | jsonGetString '"result","file_path"')" } send_file() { @@ -602,8 +599,8 @@ bot_init() { # get bot name getBotName() { - res="$(curl -s "$ME_URL" | "${JSONSHFILE}" -s -b -n )" - echo "$res" | JsonGetString '"result","username"' + sendJson "" "" "$ME_URL" + JsonGetString '"result","username"' <<< "$res" } ME="$(getBotName)" diff --git a/doc/7_develop.md b/doc/7_develop.md index f6d271c..32bb665 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -16,12 +16,11 @@ bashbot development is done on github. If you want to provide fixes or new featu ### Test, Add, Push changes A typical bashbot develop cycle looks as follow: -1. 'git checkout develop' -2. start developing - *change, copy, edit bashbot files ...* -3. run 'dev/all-tests.sh' - *in case if errors back to 2.* -4. run 'dev/git-add.sh' - *check for changed files, update version string, run git add* -5. 'git commit' -m "COMMIT MESSAGE" -6. 'git push' +1. start developing - *change, copy, edit bashbot files ...* +2. after change to bash file: ```shellcheck -x file.sh``` +3. ```dev/all-tests.sh``` - *in case if errors back to 2.* +4. ```dev/git-add.sh``` - *check for changed files, update version string, run git add* +5. ```git commit' -m "COMMIT MESSAGE"; git push``` **If you setup with hooks and use the scripts above, versioning, addding and testing is done automatically.** @@ -84,5 +83,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev3-8-gb8a23c4 +#### $$VERSION$$ v0.70-dev3-12-ga288a8d From d26a992ecbabb9bf3f95b7436292b917e62655db Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 14:41:49 +0200 Subject: [PATCH 41/63] testsuite for send_message, fix 3 found problems --- bashbot.sh | 6 +-- modules/background.sh | 8 +-- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 38 +++++++++++++ .../d-send_message-test.input | 17 ++++++ .../d-send_message-test.result | 54 +++++++++++++++++++ 6 files changed, 117 insertions(+), 8 deletions(-) create mode 100755 test/d-send_message-test.sh create mode 100644 test/d-send_message-test/d-send_message-test.input create mode 100644 test/d-send_message-test/d-send_message-test.result diff --git a/bashbot.sh b/bashbot.sh index fc5cad7..a186c66 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.70-dev3-12-ga288a8d +#### $$VERSION$$ v0.70-dev3-13-g81b540a # # Exit Codes: # - 0 sucess (hopefully) @@ -420,8 +420,8 @@ send_location() { send_venue() { local add="" [ "$5" = "" ] && return - [ "$6" != "" ] add=', "foursquare_id": '"$6"'' - sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"', "title": "'"${4}"'"'"${add}" "$VENUE_URL" + [ "$6" != "" ] && add=', "foursquare_id": '"$6"'' + sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"', "address": "'"${5}"'", "title": "'"${4}"'"'"${add}" "$VENUE_URL" } diff --git a/modules/background.sh b/modules/background.sh index 89579f4..cc096c5 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-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-13-g81b540a # source from commands.sh if you want ro use interactive or background jobs @@ -16,7 +16,7 @@ export res # I placed send_message here because main use case is interactive chats and background jobs send_message() { local text arg keyboard file lat long title address sent - [ "$2" = "" ] && return 1 + [ "$2" = "" ] && return local mychat="$1" 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')" arg="$3" @@ -32,9 +32,9 @@ send_message() { 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')" - title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" + title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mytitlestartshere //g;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')" + address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*myaddressstartshere //g;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')" } if [ "$no_keyboard" != "" ]; then diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 5b4c1e5..0c235ae 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-13-g81b540a # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh new file mode 100755 index 0000000..59063f7 --- /dev/null +++ b/test/d-send_message-test.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +#### $$VERSION$$ v0.70-dev3-13-g81b540a + +# include common functions and definitions +# shellcheck source=test/ALL-tests.inc.sh +source "./ALL-tests.inc.sh" + +set -e + +cd "${TESTDIR}" || exit 1 + +# source bashbot.sh function, uncomment if you want to test functions +# shellcheck source=./bashbot.sh +source "${TESTDIR}/bashbot.sh" source +source "${TESTDIR}/modules/background.sh" + +# start writing your tests here ... + +# over write sendJson to output parameter only +sendJson() { + printf 'chat:%s\tJSON:%s\nURL:%s\n\n' "${1}" "${2}" "${3}" +} + +# send text input to send_message + +#set -x +echo -n " Send line ..." +while IFS='' read -r line || [[ -n "$line" ]]; do + echo -n "." + send_message "123456" "$line" >>"${OUTPUTFILE}" +done < "${INPUTFILE}" 2>>"${LOGFILE}" +echo " done." + +diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1 +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 new file mode 100644 index 0000000..8fdcafb --- /dev/null +++ b/test/d-send_message-test/d-send_message-test.input @@ -0,0 +1,17 @@ +# test for text only output +This is a normal text +This is a normal text mynewlinestartshere with a line break +html_parse_mode This is a HTML text +html_parse_mode This is a HTML text mynewlinestartshere with a line break +markdown_parse_mode This is a *MARKDOWN* text +markdown_parse_mode This is a *MARKDOWN* text mynewlinestartshere with a line break + +# test for keyboard, file, venue output +Text plus keyboard will appear in chat mykeyboardstartshere [ "Yep, sure" , "No, highly unlikely" ] +Text plus file will appear in chat myfilelocationstartshere /home/user/doge.jpg +Text plus location will appear in chat mylatstartshere la10 mylongstartshere lo20 +Text plus vuene will appear in chat mylatstartshere la10 mylongstartshere lo20 mytitlestartshere my home myaddressstartshere Diagon Alley N. 37 +All in one will appear in chat mykeyboardstartshere [ "Yep, sure" , "No, highly unlikely" ] myfilelocationstartshere /home/user/doge.jpg mylatstartshere la10 mylongstartshere lo20 + +# test for new inline button +Text plus keyboard will appear in chat mybuttonstartshere "Button Text" "https://www..." diff --git a/test/d-send_message-test/d-send_message-test.result b/test/d-send_message-test/d-send_message-test.result new file mode 100644 index 0000000..7721a3c --- /dev/null +++ b/test/d-send_message-test/d-send_message-test.result @@ -0,0 +1,54 @@ +chat:123456 JSON:"text":"# test for text only output" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":"This is a normal text" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":"This is a normal text +with a line break" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":" This is a HTML text","parse_mode":"html" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":" This is a HTML text +with a line break","parse_mode":"html" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":" This is a *MARKDOWN* text","parse_mode":"markdown" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":" This is a *MARKDOWN* text +with a line break","parse_mode":"markdown" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":"# test for keyboard, file, venue output" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"keyboard": [ [ "Yep, sure" , "No, highly unlikely" ] ] , "one_time_keyboard":true} +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"action": "upload_photo" +URL:https://api.telegram.org/botbashbottestscript/sendChatAction + +chat:123456 JSON:"latitude": la10, "longitude": lo20 +URL:https://api.telegram.org/botbashbottestscript/sendLocation + +chat:123456 JSON:"latitude": la10, "longitude": lo20, "address": "Diagon Alley N. 37", "title": "my home" +URL:https://api.telegram.org/botbashbottestscript/sendVenue + +chat:123456 JSON:"text":"All in one will appear in chat", "reply_markup": {"keyboard": [ [ "Yep, sure" , "No, highly unlikely" ] ] , "one_time_keyboard":true} +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"action": "upload_photo" +URL:https://api.telegram.org/botbashbottestscript/sendChatAction + +chat:123456 JSON:"latitude": la10, "longitude": lo20 +URL:https://api.telegram.org/botbashbottestscript/sendLocation + +chat:123456 JSON:"text":"# test for new inline button" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":"Text plus keyboard will appear in chat mybuttonstartshere "Button Text" "https://www..."" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + From fba89518c0e73eb9ed9294a797c5c1a7798f083d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 15:07:07 +0200 Subject: [PATCH 42/63] some improvements to send_message --- dev/all-tests.sh | 5 ++++- modules/background.sh | 31 +++++++++++++++---------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 27ef0d3..b064606 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-14-gd26a992 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -51,4 +51,7 @@ fi echo "${passed} / ${tests}" [ -d "${TESTENV}" ] && echo "Logfiles from run are in ${TESTENV}" + +ls -ld /tmp/bashbot.test* 2>/dev/null && echo "Don not forget to deleted bashbot test files in /tmp!!" + exit ${exitcode} diff --git a/modules/background.sh b/modules/background.sh index cc096c5..2db6f20 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-dev3-13-g81b540a +#### $$VERSION$$ v0.70-dev3-14-gd26a992 # source from commands.sh if you want ro use interactive or background jobs @@ -18,27 +18,26 @@ send_message() { local text arg keyboard file lat long title address sent [ "$2" = "" ] && return local mychat="$1" - 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')" + text="$(sed <<< "${2}" 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" arg="$3" [ "$arg" != "safe" ] && { text="${text// mynewlinestartshere /$'\r\n'}" - no_keyboard="$(echo "$2" | sed '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" + no_keyboard="$(sed <<< "${2}" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" - 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')" + keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - 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')" + file="$(sed <<< "${2}" '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ mykeyboardstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - 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')" + lat="$(sed <<< "${2}" '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - 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')" + long="$(sed <<< "${2}" '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mytitlestartshere //g;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" + title="$(sed <<< "${2}" '/mytitlestartshere /!d;s/.*mytitlestartshere //g;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*myaddressstartshere //g;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')" + address="$(sed <<< "${2}" '/myaddressstartshere /!d;s/.*myaddressstartshere //g;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 $mychat $text" > "${TMPDIR:-.}/prova" remove_keyboard "$mychat" "$text" sent=y fi @@ -53,12 +52,12 @@ send_message() { send_file "$mychat" "$file" "$text" sent=y fi - if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" = "" ] && [ "$title" = "" ]; then - send_location "$mychat" "$lat" "$long" - sent=y - fi - if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" != "" ] && [ "$title" != "" ]; then - send_venue "$mychat" "$lat" "$long" "$title" "$address" + if [ "$lat" != "" ] && [ "$long" != "" ]; then + if [ "$address" != "" ] && [ "$title" != "" ]; then + send_venue "$mychat" "$lat" "$long" "$title" "$address" + else + send_location "$mychat" "$lat" "$long" + fi sent=y fi if [ "$sent" != "y" ];then From d6d640a3d9e177b46e9d5251dee1220f7bf38eb2 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 16:45:39 +0200 Subject: [PATCH 43/63] optimize send_message --- README.md | 2 +- README.txt | 2 +- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/all-tests.sh | 2 +- dev/git-add.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 2 +- modules/background.sh | 24 ++++++++---------------- modules/inline.sh | 2 +- mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 40 files changed, 47 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index fc8415a..fa558b4 100644 --- a/README.md +++ b/README.md @@ -76,4 +76,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 diff --git a/README.txt b/README.txt index b3e2e30..fc19e9f 100644 --- a/README.txt +++ b/README.txt @@ -123,5 +123,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-dev2-27-g2da31c1 +latexmath:[\[VERSION\]] v0.70-dev3-15-gfba8951 ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index 3d700cc..9578d55 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index a186c66..5c18cb6 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.70-dev3-13-g81b540a +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index a13a9d4..3e44841 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.70-dev3-10-g81c8b04 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/all-tests.sh b/dev/all-tests.sh index b064606..3f69543 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev3-14-gd26a992 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/git-add.sh b/dev/git-add.sh index a39227f..354d109 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v0.70-dev3-9-gd08d581 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index d753d0a..eaa3950 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-0-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index 6d64dd1..595e209 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-0-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index d528fb4..45ec1ba 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index c9f054d..182cfb6 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 71221af..2fa51b3 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index e2a459a..4e9dc4d 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index 642c6e6..9872de0 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -61,5 +61,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 6db34b0..fa1ee8d 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -62,5 +62,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 diff --git a/doc/2_usage.md b/doc/2_usage.md index 670a6c5..d425aff 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev3-6-g034274c +#### $$VERSION$$ v0.70-dev3-15-gfba8951 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index fda1985..5305786 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -162,5 +162,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev3-6-g034274c +#### $$VERSION$$ v0.70-dev3-15-gfba8951 diff --git a/doc/4_expert.md b/doc/4_expert.md index 9d985dd..6759ac2 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 diff --git a/doc/5_practice.md b/doc/5_practice.md index 48b7662..2e95c9d 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -141,5 +141,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev3-7-gd88d422 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 diff --git a/doc/6_reference.md b/doc/6_reference.md index 1288bd9..45c8884 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -473,5 +473,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev3-6-g034274c +#### $$VERSION$$ v0.70-dev3-15-gfba8951 diff --git a/doc/7_develop.md b/doc/7_develop.md index 32bb665..59de434 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -83,5 +83,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev3-12-ga288a8d +#### $$VERSION$$ v0.70-dev3-15-gfba8951 diff --git a/doc/8_custom.md b/doc/8_custom.md index 0770a92..eacaad8 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -117,5 +117,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev3-9-gd08d581 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 diff --git a/examples/bashbot.cron b/examples/bashbot.cron index ff544eb..8fe59e5 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 6ed05f1..2bb61f3 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -3,7 +3,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-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index 0f49de6..a005940 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -2,7 +2,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-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh index 72578c0..258c851 100755 --- a/examples/question,sh +++ b/examples/question,sh @@ -3,7 +3,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-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index 72578c0..258c851 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -3,7 +3,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-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/modules/aliases.sh b/modules/aliases.sh index 1e523e8..bd598be 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-dev3-4-g8f4b168 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # # source from commands.sh to use the aliases diff --git a/modules/background.sh b/modules/background.sh index 2db6f20..fcc8e16 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-dev3-14-gd26a992 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # source from commands.sh if you want ro use interactive or background jobs @@ -18,24 +18,16 @@ send_message() { local text arg keyboard file lat long title address sent [ "$2" = "" ] && return local mychat="$1" - text="$(sed <<< "${2}" 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" + text="$(sed <<< "${2}" 's/ mynewlinestartshere /\r\n/g; s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" arg="$3" [ "$arg" != "safe" ] && { - text="${text// mynewlinestartshere /$'\r\n'}" no_keyboard="$(sed <<< "${2}" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" - - keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - - file="$(sed <<< "${2}" '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ mykeyboardstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - - lat="$(sed <<< "${2}" '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - - long="$(sed <<< "${2}" '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - - title="$(sed <<< "${2}" '/mytitlestartshere /!d;s/.*mytitlestartshere //g;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - - address="$(sed <<< "${2}" '/myaddressstartshere /!d;s/.*myaddressstartshere //g;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')" - + keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + file="$(sed <<< "${2}" '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + lat="$(sed <<< "${2}" '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + long="$(sed <<< "${2}" '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + title="$(sed <<< "${2}" '/mytitlestartshere /!d;s/.*mytitlestartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + address="$(sed <<< "${2}" '/myaddressstartshere /!d;s/.*myaddressstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" } if [ "$no_keyboard" != "" ]; then remove_keyboard "$mychat" "$text" diff --git a/modules/inline.sh b/modules/inline.sh index 2a32637..31308c6 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -5,6 +5,6 @@ # 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-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # source from commands.sh to use the inline functions diff --git a/mycommands.sh b/mycommands.sh index d8b896f..fbb3677 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index dcd4f8a..c2ae444 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 6101d01..16888ae 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 44d6177..d7a1108 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index b835fcf..84a7c29 100644 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index ef1117e..1b6709d 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index f5596f6..1e86bdd 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 0c235ae..211782e 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-13-g81b540a +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index 59063f7..e3ff8e5 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-dev3-13-g81b540a +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 5f4dcd5..f375de1 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-15-gfba8951 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 45f042d2cca6b12b49696bedb0eb9993f5bade7a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 17:19:48 +0200 Subject: [PATCH 44/63] buttons for send_message --- bashbot.sh | 4 ++-- dev/all-tests.sh | 4 ++-- doc/3_advanced.md | 6 ++++- doc/6_reference.md | 10 ++++---- modules/background.sh | 24 ++++++++++++------- .../d-send_message-test.input | 2 +- .../d-send_message-test.result | 2 +- 7 files changed, 31 insertions(+), 21 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 5c18cb6..eb9c3a4 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.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-dev3-16-gd6d640a # # Exit Codes: # - 0 sucess (hopefully) @@ -335,7 +335,7 @@ send_inline_keyboard() { sendJson "${1}" "${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]}' "$MSG_URL" # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}' } -send_inline_button() { +send_button() { send_inline_keyboard "${1}" "${2}" '[ {"text":"'"${3}"'", "url":"'"${4}"'"}]' } diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 3f69543..9a0edbc 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-dev3-16-gd6d640a # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -49,7 +49,7 @@ else find "${TESTENV}/"* ! -name '[a-z]-*' -delete fi -echo "${passed} / ${tests}" +echo -e "${passed} / ${tests}\\n" [ -d "${TESTENV}" ] && echo "Logfiles from run are in ${TESTENV}" ls -ld /tmp/bashbot.test* 2>/dev/null && echo "Don not forget to deleted bashbot test files in /tmp!!" diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 5305786..47ac999 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -74,6 +74,10 @@ Same goes for files: ```bash echo "Text that will appear in chat? myfilelocationstartshere /home/user/doge.jpg" ``` +And buttons: +```bash +echo "Text that will appear in chat. mybtextstartshere Klick me myburlstartshere https://dealz.rrr.de" +``` And locations: ```bash echo "Text that will appear in chat. mylatstartshere 45 mylongstartshere 45" @@ -162,5 +166,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-dev3-16-gd6d640a diff --git a/doc/6_reference.md b/doc/6_reference.md index 45c8884..449102b 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -125,14 +125,14 @@ send_keyboard "${CHAT[ID]}" "Enter digit" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \ ##### remove_keyboard *usage:* remove_keybord "$CHAT[ID]" "message" -##### send_inline_button -*usage:* send_inine_button "chat-id" "message" "text" "URL" +##### send_button +*usage:* send_button "chat-id" "message" "text" "URL" -*alias:* _inline_button "text" "URL" +*alias:* _button "text" "URL" *example:* ```bash -send_inline_button "${CHAT[ID]}" "MAKE MONEY FAST!!!" "Visit my Shop" "https://dealz.rrr.de" +send_button "${CHAT[ID]}" "MAKE MONEY FAST!!!" "Visit my Shop" "https://dealz.rrr.de" ``` ##### send_inline_keyboard @@ -473,5 +473,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-dev3-16-gd6d640a diff --git a/modules/background.sh b/modules/background.sh index fcc8e16..3c4822b 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-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-dev3-16-gd6d640a # source from commands.sh if you want ro use interactive or background jobs @@ -15,19 +15,21 @@ export res #### # I placed send_message here because main use case is interactive chats and background jobs send_message() { - local text arg keyboard file lat long title address sent + 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[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + text="$(sed <<< "${2}" 's/ mynewlinestartshere /\r\n/g; s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" arg="$3" [ "$arg" != "safe" ] && { no_keyboard="$(sed <<< "${2}" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" - keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - file="$(sed <<< "${2}" '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - lat="$(sed <<< "${2}" '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - long="$(sed <<< "${2}" '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - title="$(sed <<< "${2}" '/mytitlestartshere /!d;s/.*mytitlestartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - address="$(sed <<< "${2}" '/myaddressstartshere /!d;s/.*myaddressstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + 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')" } if [ "$no_keyboard" != "" ]; then remove_keyboard "$mychat" "$text" @@ -40,6 +42,10 @@ send_message() { send_keyboard "$mychat" "$text" "$keyboard" sent=y fi + if [ "$btext" != "" ] && [ "$burl" != "" ]; then + send_button "$mychat" "$text" "$btext" "$burl" + sent=y + fi if [ "$file" != "" ]; then send_file "$mychat" "$file" "$text" sent=y 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 8fdcafb..d63cdde 100644 --- a/test/d-send_message-test/d-send_message-test.input +++ b/test/d-send_message-test/d-send_message-test.input @@ -14,4 +14,4 @@ Text plus vuene will appear in chat mylatstartshere la10 mylongstartshere lo20 m All in one will appear in chat mykeyboardstartshere [ "Yep, sure" , "No, highly unlikely" ] myfilelocationstartshere /home/user/doge.jpg mylatstartshere la10 mylongstartshere lo20 # test for new inline button -Text plus keyboard will appear in chat mybuttonstartshere "Button Text" "https://www..." +Text plus keyboard will appear in chat mybtextstartshere Button Text myburlstartshere https://www... 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 7721a3c..4c3b28d 100644 --- a/test/d-send_message-test/d-send_message-test.result +++ b/test/d-send_message-test/d-send_message-test.result @@ -49,6 +49,6 @@ URL:https://api.telegram.org/botbashbottestscript/sendLocation chat:123456 JSON:"text":"# test for new inline button" URL:https://api.telegram.org/botbashbottestscript/sendMessage -chat:123456 JSON:"text":"Text plus keyboard will appear in chat mybuttonstartshere "Button Text" "https://www..."" +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 From 490c47249a1b6535061191b1cc54e7107ba5cb8f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 17:25:28 +0200 Subject: [PATCH 45/63] fix make-dist.sh --- dev/make-dist.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 182cfb6..e7997ec 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-dev3-17-g45f042d # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -16,7 +16,7 @@ DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh doc examples modu # run tests first! -for test in dev/hooks/* "test/ALL-tests.sh" +for test in "dev/all-tests.sh" do if ! "${test}" ; then echo "Test ${test} failed, can't create dist!" From bd4a1167e99000d24ae00287b0f60c241e8fb7dc Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 17:40:24 +0200 Subject: [PATCH 46/63] v0.70 pre1 --- README.md | 2 +- README.txt | 4 ++-- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/all-tests.sh | 2 +- dev/git-add.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 13 +++++++++++-- doc/8_custom.md | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question,sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 2 +- modules/background.sh | 2 +- modules/inline.sh | 2 +- mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 40 files changed, 51 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index fa558b4..0666eac 100644 --- a/README.md +++ b/README.md @@ -76,4 +76,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 diff --git a/README.txt b/README.txt index fc19e9f..e720a69 100644 --- a/README.txt +++ b/README.txt @@ -123,5 +123,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-dev3-15-gfba8951 -++++++++++++++++++++++++++++++++++++++++++++++ +latexmath:[\[VERSION\]] v0.70-pre1-0-g490c472 ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index 9578d55..f1fe816 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index eb9c3a4..90a4014 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.70-dev3-16-gd6d640a +#### $$VERSION$$ v0.70-pre1-0-g490c472 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index 3e44841..de71c7c 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.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 9a0edbc..ca15bbd 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev3-16-gd6d640a +#### $$VERSION$$ v0.70-pre1-0-g490c472 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/git-add.sh b/dev/git-add.sh index 354d109..12cc338 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index eaa3950..3dd31dc 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index 595e209..66d3712 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 45ec1ba..84229a3 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index e7997ec..3171168 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev3-17-g45f042d +#### $$VERSION$$ v0.70-pre1-0-g490c472 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 2fa51b3..cfedc86 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 4e9dc4d..2c24f94 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index 9872de0..6719128 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -61,5 +61,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index fa1ee8d..15de8d8 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -62,5 +62,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 diff --git a/doc/2_usage.md b/doc/2_usage.md index d425aff..43f639e 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 47ac999..a3099c0 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -166,5 +166,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev3-16-gd6d640a +#### $$VERSION$$ v0.70-pre1-0-g490c472 diff --git a/doc/4_expert.md b/doc/4_expert.md index 6759ac2..fa50955 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 diff --git a/doc/5_practice.md b/doc/5_practice.md index 2e95c9d..a673976 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -141,5 +141,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 diff --git a/doc/6_reference.md b/doc/6_reference.md index 449102b..94d3576 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -473,5 +473,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev3-16-gd6d640a +#### $$VERSION$$ v0.70-pre1-0-g490c472 diff --git a/doc/7_develop.md b/doc/7_develop.md index 59de434..509bfef 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -14,7 +14,7 @@ bashbot development is done on github. If you want to provide fixes or new featu 6. setup github hooks by running ```dev/install-hooks.sh``` (optional) ### Test, Add, Push changes -A typical bashbot develop cycle looks as follow: +A typical bashbot develop loop looks as follow: 1. start developing - *change, copy, edit bashbot files ...* 2. after change to bash file: ```shellcheck -x file.sh``` @@ -25,6 +25,15 @@ A typical bashbot develop cycle looks as follow: **If you setup with hooks and use the scripts above, versioning, addding and testing is done automatically.** +### Prepare a new version +After some development it may time to create a new version for the users. a new version can be in sub version upgrade, e.g. for fixes and smaller additions or +a new release version for new features. To mark a new version use ```git tag NEWVERSION``` and run ```dev/version.sh``` to update all version strings. + +Usually I start with some pre-x versions and when everything looks good I push out a release candidate (rc) and finally the new version. +``` + v0.x-dev -> v0.x-pre-x -> v0.x-rc -> v0.x ... 0.x+1-dev ... +``` + ### Versioning Bashbot is tagged with version numbers. If you start a new development cycle you must tag your fork with a version higher than the current version. @@ -83,5 +92,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 diff --git a/doc/8_custom.md b/doc/8_custom.md index eacaad8..5c57725 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -117,5 +117,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 8fe59e5..f8ed2ea 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 2bb61f3..a5df907 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -3,7 +3,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-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index a005940..13c8979 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -2,7 +2,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-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh index 258c851..42c634a 100755 --- a/examples/question,sh +++ b/examples/question,sh @@ -3,7 +3,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-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index 258c851..42c634a 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -3,7 +3,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-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/modules/aliases.sh b/modules/aliases.sh index bd598be..543eab8 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # # source from commands.sh to use the aliases diff --git a/modules/background.sh b/modules/background.sh index 3c4822b..f3056b4 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-dev3-16-gd6d640a +#### $$VERSION$$ v0.70-pre1-0-g490c472 # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/inline.sh b/modules/inline.sh index 31308c6..6fb26dc 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -5,6 +5,6 @@ # 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-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # source from commands.sh to use the inline functions diff --git a/mycommands.sh b/mycommands.sh index fbb3677..6c355fe 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index c2ae444..c5742e3 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 16888ae..500ab66 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index d7a1108..6f5a472 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index 84a7c29..c3b36a9 100644 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 1b6709d..b6d5e91 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 1e86bdd..7d54782 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 211782e..386a834 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index e3ff8e5..e03236f 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-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index f375de1..8df6fb0 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-pre1-0-g490c472 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 293ad088e13f1106e5ddd23bf1ef4de985e6f6d4 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 27 Apr 2019 13:02:10 +0200 Subject: [PATCH 47/63] add references to bashbot doc --- README.md | 5 ++++- README.txt | 6 +++++- doc/0_install.md | 4 +++- doc/1_firstbot.md | 7 ++++++- doc/2_usage.md | 3 ++- doc/3_advanced.md | 3 ++- doc/6_reference.md | 19 +++++++++++++++++-- doc/7_develop.md | 6 +++--- 8 files changed, 42 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0666eac..2337969 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,9 @@ 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) + * [Bot commands](https://core.telegram.org/bots#commands) * [Install Bashbot](doc/0_install.md) * Install release * Install from githup @@ -76,4 +79,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w 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-0-g490c472 +#### $$VERSION$$ v0.70-pre1-1-gbd4a116 diff --git a/README.txt b/README.txt index e720a69..2aae368 100644 --- a/README.txt +++ b/README.txt @@ -27,6 +27,10 @@ are availible on www.github.com Documentation ~~~~~~~~~~~~~ +* [Bots: Introduction for developers] (https://core.telegram.org/bots) +** https://core.telegram.org/bots#3-how-do-i-create-a-bot[The one to +rule them all] +** https://core.telegram.org/bots#commands[Bot commands] * link:doc/0_install.md[Install Bashbot] ** Install release ** Install from githup @@ -123,5 +127,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-0-g490c472 +latexmath:[\[VERSION\]] v0.70-pre1-1-gbd4a116 +++++++++++++++++++++++++++++++++++++++++++++ diff --git a/doc/0_install.md b/doc/0_install.md index 6719128..5a4b6d6 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -12,6 +12,8 @@ Now your Bot is ready to start ... +If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots) + ### Install from Github As an alternative to download the zip files, you can clone the github repository to get the latest improvements/fixes. @@ -61,5 +63,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-1-gbd4a116 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 15de8d8..dbc8744 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -1,5 +1,10 @@ #### [Home](../README.md) ## Create a Telegram Bot with botfather +[BotFather is the one bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot). It will help you create new bots and change settings for existing ones. + +[Commands known by Botfather](https://core.telegram.org/bots#generating-an-authorization-token) + +### Creating a new Bot 1. Message @botfather https://telegram.me/botfather with the following text: `/newbot` @@ -62,5 +67,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-1-gbd4a116 diff --git a/doc/2_usage.md b/doc/2_usage.md index 43f639e..513d2d8 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -162,9 +162,10 @@ Allowed values: typing for text messages, upload_photo for photos, record_video ```bash send_action "${CHAT[ID]}" "action" ``` +See also [Bashbot function reference](6_reference.md) #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-1-gbd4a116 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index a3099c0..ecef80a 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -56,6 +56,7 @@ You must use the function ```user_is_allowed``` to check if a user has the capab ;; esac ``` +See also [Bashbot User Access Control functions](6_functions.md#User_Access_Control) ### Interactive Chats To create interactive chats, write *(or edit the 'exmaples/question.sh' script)* a bash *(or C or python)* script, make it executable @@ -166,5 +167,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-1-gbd4a116 diff --git a/doc/6_reference.md b/doc/6_reference.md index 94d3576..8b847bb 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -59,6 +59,8 @@ send_normal_message "${CHAT[ID]}" "bold italic> italic>/em> v0.x-pre-x -> v0.x-rc -> v0.x ... 0.x+1-dev ... + v0.x-devx -> v0.x-prex -> v0.x-rc -> v0.x ... 0.x+1-dev ... ``` ### Versioning @@ -92,5 +92,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-1-gbd4a116 From 3719c81f9d6938473d5930bacaf1f83d1f5b2aa2 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 27 Apr 2019 13:36:32 +0200 Subject: [PATCH 48/63] commands may have @botname attached --- README.md | 4 ++-- README.txt | 4 ++-- commands.sh | 18 +++++++++++------- doc/0_install.md | 4 ++-- doc/1_firstbot.md | 6 ++---- doc/2_usage.md | 10 +++++----- doc/3_advanced.md | 8 +++++--- doc/5_practice.md | 24 ++++++++++++++++++------ doc/6_reference.md | 6 +++--- mycommands.sh | 9 +++++---- 10 files changed, 55 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 2337969..800e8d1 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ 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) +* [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) * [Bot commands](https://core.telegram.org/bots#commands) * [Install Bashbot](doc/0_install.md) @@ -79,4 +79,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w 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-1-gbd4a116 +#### $$VERSION$$ v0.70-pre1-2-g293ad08 diff --git a/README.txt b/README.txt index 2aae368..1eeefaf 100644 --- a/README.txt +++ b/README.txt @@ -27,7 +27,7 @@ are availible on www.github.com Documentation ~~~~~~~~~~~~~ -* [Bots: Introduction for developers] (https://core.telegram.org/bots) +* https://core.telegram.org/bots[Bots: Introduction for developers] ** https://core.telegram.org/bots#3-how-do-i-create-a-bot[The one to rule them all] ** https://core.telegram.org/bots#commands[Bot commands] @@ -127,5 +127,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-1-gbd4a116 +latexmath:[\[VERSION\]] v0.70-pre1-2-g293ad08 +++++++++++++++++++++++++++++++++++++++++++++ diff --git a/commands.sh b/commands.sh index de71c7c..c4d9000 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.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-2-g293ad08 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -31,6 +31,7 @@ It currently can send, recieve and forward messages, custom keyboards, photos, a # to change the default help messages overwrite in mycommands.sh bashbot_help='*Available commands*: *• /start*: _Start bot and get this message_. +*• /help*: _Get this message_. *• /info*: _Get shorter info message about this bot_. *• /question*: _Start interactive chat_. *• /cancel*: _Cancel any currently running interactive chats_. @@ -97,11 +98,11 @@ else fi case "$MESSAGE" in ################################################ - # DEFAULT commands start here, edit messages only - '/info') + # GLOBAL commands start here, edit messages only + '/info'*) _markdown_message "${bashbot_info}" ;; - '/start') + '/start'*) send_action "${CHAT[ID]}" "typing" _is_botadmin && _markdown_message "You are *BOTADMIN*." if _is_allowed "start" ; then @@ -111,19 +112,22 @@ else fi ;; - '/leavechat') # bot leave chat if user is admin in chat + '/help'*) + _markdown_message "${bot_help}" + ;; + '/leavechat'*) # bot leave chat if user is admin in chat if _is_admin ; then _markdown_message "*LEAVING CHAT...*" _leave fi ;; - '/kickme') + '/kickme'*) _kick_user "${USER[ID]}" _unban_user "${USER[ID]}" ;; - '/cancel') + '/cancel'*) checkprog if [ "$res" -eq 0 ] ; then killproc && _message "Command canceled.";else _message "No command is currently running.";fi ;; diff --git a/doc/0_install.md b/doc/0_install.md index 5a4b6d6..fd14b20 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -12,7 +12,7 @@ Now your Bot is ready to start ... -If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots) +**If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots)** ### Install from Github @@ -63,5 +63,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.70-pre1-1-gbd4a116 +#### $$VERSION$$ v0.70-pre1-2-g293ad08 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index dbc8744..819be0a 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -1,8 +1,6 @@ #### [Home](../README.md) ## Create a Telegram Bot with botfather -[BotFather is the one bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot). It will help you create new bots and change settings for existing ones. - -[Commands known by Botfather](https://core.telegram.org/bots#generating-an-authorization-token) +**[BotFather is the one bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot). It will help you create new bots and change settings for existing ones.** [Commands known by Botfather](https://core.telegram.org/bots#generating-an-authorization-token) ### Creating a new Bot @@ -67,5 +65,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-pre1-1-gbd4a116 +#### $$VERSION$$ v0.70-pre1-2-g293ad08 diff --git a/doc/2_usage.md b/doc/2_usage.md index 513d2d8..b4706cc 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -37,7 +37,7 @@ To send a broadcast to all of users that ever used the bot run the following com ## Recieve data Evertime a Message is recieved, you can read incoming data using the following variables: -* ```${MESSAGE}```: Current incoming messages +* ```${MESSAGE}```: Current message * ```${MESSAGE[ID]}```: ID of current message * ```$CAPTION```: Captions * ```$REPLYTO```: Original message wich was replied to @@ -66,7 +66,7 @@ Evertime a Message is recieved, you can read incoming data using the following v * ```${FORWARD[FIRST_NAME]}```: Original user's first name * ```${FORWARD[LAST_NAME]}```: Original user's' last name * ```${FORWARD[USERNAME]}```: Original user's username -* ```$URLS```: This array contains documents, audio files, stickers, voice recordings and stickers stored in the form of URLs. +* ```$URLS```: This array contains documents, audio files, voice recordings and stickers as URL. * ```${URLS[AUDIO]}```: Audio files * ```${URLS[VIDEO]}```: Videos * ```${URLS[PHOTO]}```: Photos (maximum quality) @@ -136,7 +136,7 @@ This function also allows a third parameter that disables additional function pa ```bash send_message "${CHAT[ID]}" "lol" "safe" ``` -More examples boutsend_message strings can be found in [Advanced Usage](3_advanced.md#Interactive-Chats) +**See also [Interactive chats](3_advanced.md#Interactive-Chats)** #### Send files, locations, keyboards. @@ -162,10 +162,10 @@ Allowed values: typing for text messages, upload_photo for photos, record_video ```bash send_action "${CHAT[ID]}" "action" ``` -See also [Bashbot function reference](6_reference.md) +**See also [Bashbot function reference](6_reference.md#Interactive_Chats)** #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-pre1-1-gbd4a116 +#### $$VERSION$$ v0.70-pre1-2-g293ad08 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index ecef80a..f9a187b 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -47,7 +47,9 @@ In addition you can check individual capabilities of users as you must define in You must use the function ```user_is_allowed``` to check if a user has the capability to do something. Example: Check if user has capability to start bot. ```bash case "$MESSAGE" in - '/start') + ################################################ + # GLOBAL commands start here, only edit messages + '/start'*) user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*." if user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then bot_help "${CHAT[ID]}" @@ -56,7 +58,7 @@ You must use the function ```user_is_allowed``` to check if a user has the capab ;; esac ``` -See also [Bashbot User Access Control functions](6_functions.md#User_Access_Control) +**See also [Bashbot User Access Control functions](6_functions.md#User_Access_Control)** ### Interactive Chats To create interactive chats, write *(or edit the 'exmaples/question.sh' script)* a bash *(or C or python)* script, make it executable @@ -167,5 +169,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-pre1-1-gbd4a116 +#### $$VERSION$$ v0.70-pre1-2-g293ad08 diff --git a/doc/5_practice.md b/doc/5_practice.md index a673976..6ed4b47 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -1,6 +1,14 @@ #### [Home](../README.md) ## Best Practices +### New to bot development? + +If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots) and consult [Telegram Bot API Documentaion](https://core.telegram.org/bots/api/). + +In addition you should know about [BotFatheri, the one bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot). It will help you create new bots and change settings for existing ones. [Commands known by Botfather](https://core.telegram.org/bots#generating-an-authorization-token) + +If you dont't have a gibtup account, it may time to [sepup a free account now](https://github.com/pricing) + ### Add commands to mycommands.sh only To ease updates never change ```bashbot.sh```, instead your commands and functions must go to ```mycommands.sh``` . Insert your Bot commands in the ```case ... esac``` block of the 'mycommands()' function: ```bash @@ -15,6 +23,7 @@ To ease updates never change ```bashbot.sh```, instead your commands and functio /echo message - _echo the given messsage_ ' +# NOTE: command can have @botname attached, you must add * in case tests... mycommands() { case "$MESSAGE" in @@ -26,19 +35,22 @@ mycommands() { } ``` -### Reuse or disable standard commands -If you want to disable or reuse a standard bashbot command comment it out in 'commands.sh' by placing a '#' in front of +### Reuse or disable global commands + +If you want to disable or reuse a global bashbot command comment it out in 'commands.sh' by placing a '#' in front of every line from ```'/command')``` to ```;;```. +**Learn more about [Bot (global) commands](https://core.telegram.org/bots#commands).** + **Note: Never disable the catchall command ```*)``` in 'commands.sh'!!** ```bash # file: commands.sh case "$MESSAGE" in ################################################ - # DEFAULT commands start here, edit messages only + # GLOBAL commands start here, edit messages only - #'/start') + #'/start'*) # send_action "${CHAT[ID]}" "typing" # _is_botadmin && _markdown_message "You are *BOTADMIN*." # if _is_allowed "start" ; then @@ -66,7 +78,7 @@ If a command need more than 2-3 lines of code, you should use a function to sepe mycommands() { case "$MESSAGE" in - '/process') # logic for /process is done in process_message + '/process'*) # logic for /process is done in process_message result="$(process_message "$MESSAGE")" send_normal_message "${CHAT[ID]}" "$result" ;; @@ -141,5 +153,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-2-g293ad08 diff --git a/doc/6_reference.md b/doc/6_reference.md index 8b847bb..7736238 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -194,7 +194,7 @@ if _is_admin ; then fi ``` -See also [kicki Chat Member](https://core.telegram.org/bots/api/#kickchatmember) +See also [kick Chat Member](https://core.telegram.org/bots/api/#kickchatmember) ---- @@ -234,7 +234,7 @@ if _is_admin ; then fi ``` -See also [ChatMember](https://core.telegram.org/bots/api/#chatmember) +See also [Chat Member](https://core.telegram.org/bots/api/#chatmember) ##### user_is_allowed Bahsbot supports User Access Control, see [Advanced Usage](4_advanced.md) @@ -488,5 +488,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-pre1-1-gbd4a116 +#### $$VERSION$$ v0.70-pre1-2-g293ad08 diff --git a/mycommands.sh b/mycommands.sh index 6c355fe..3bfe217 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-2-g293ad08 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -16,13 +16,14 @@ # your additional bahsbot commands +# NOTE: command can have @botname attached, you must add * in case tests... mycommands() { case "$MESSAGE" in '/echo'*) # example echo command send_normal_message "${CHAT[ID]}" "$MESSAGE" ;; - '/question') # start interactive questions + '/question'*) # start interactive questions checkproc if [ "$res" -gt 0 ] ; then startproc "example/question" @@ -31,7 +32,7 @@ mycommands() { fi ;; - '/run-notify') # start notify background job + '/run-notify'*) # start notify background job myback="notify"; checkback "$myback" if [ "$res" -gt 0 ] ; then background "example/notify 60" "$myback" # notify every 60 seconds @@ -39,7 +40,7 @@ mycommands() { send_normal_message "${CHAT[ID]}" "Background command $myback already running ..." fi ;; - '/stop-notify') # kill notify background job + '/stop-notify'*) # kill notify background job myback="notify"; checkback "$myback" if [ "$res" -eq 0 ] ; then killback "$myback" From 0d38a67cf521b304565bf50a8a95348f34468146 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 27 Apr 2019 15:48:03 +0200 Subject: [PATCH 49/63] fix stupid mynewlinestartshere mistake --- README.md | 11 ++++++++++- README.txt | 17 ++++++++++++++++- bashbot.rc | 8 ++++++-- modules/background.sh | 4 ++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 800e8d1..74dd967 100644 --- a/README.md +++ b/README.md @@ -75,8 +75,17 @@ To set access rights for your bashbot installation to a reasonable default run ` ### Is this Bot insecure? Bashbot is not more (in)secure as any other Bot written in any other 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 ...? +Well, thats a damn good question ... may be because I'm an Unix/Linux 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 +- no need to install or learn a new programming language, library or framwework +- no database, not event driven, not OO ... +- + ## 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-2-g293ad08 +#### $$VERSION$$ v0.70-pre1-3-g3719c81 diff --git a/README.txt b/README.txt index 1eeefaf..fc2cc5a 100644 --- a/README.txt +++ b/README.txt @@ -121,11 +121,26 @@ 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 ...? +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Well, thats a damn good question ... may be because I'm an Unix/Linux +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 +* no need to install or learn a new programming language, library or +framwework +* no database, not event driven, not OO ... +* + 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-2-g293ad08 +latexmath:[\[VERSION\]] v0.70-pre1-3-g3719c81 +++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index f1fe816..bcfc6e2 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-3-g3719c81 # shellcheck disable=SC2009 # shellcheck disable=SC2181 @@ -69,12 +69,16 @@ case "$1" in $0 stop; $0 start RETVAL=$? ;; +'restartback') + $0 suspendback; $0 resumeback + RETVAL=$? + ;; 'suspendback'|'resumeback'|'killback') $runcmd "$start $1" RETVAL=$? ;; *) - echo "Usage: $0 { start | stop | restart | reload | suspendback | resumeback | killback }" + echo "Usage: $0 { start | stop | restart | reload | restartback | suspendback | resumeback | killback }" RETVAL=1 ;; esac diff --git a/modules/background.sh b/modules/background.sh index f3056b4..21c5357 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-0-g490c472 +#### $$VERSION$$ v0.70-pre1-3-g3719c81 # source from commands.sh if you want ro use interactive or background jobs @@ -18,7 +18,7 @@ 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')" + text="$(sed <<< "${2}" 's/ mynewlinestartshere/\r\n/g; s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" arg="$3" [ "$arg" != "safe" ] && { no_keyboard="$(sed <<< "${2}" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" From 07dc7b443280d7ffb3d8e81640c2e47458fcd485 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 27 Apr 2019 16:28:17 +0200 Subject: [PATCH 50/63] why bash? --- README.md | 10 +++++----- README.txt | 2 +- bashbot.rc | 2 +- modules/background.sh | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 74dd967..e62c489 100644 --- a/README.md +++ b/README.md @@ -75,17 +75,17 @@ To set access rights for your bashbot installation to a reasonable default run ` ### Is this Bot insecure? Bashbot is not more (in)secure as any other Bot written in any other 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 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 -- no need to install or learn a new programming language, library or framwework +- 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-3-g3719c81 +#### $$VERSION$$ v0.70-pre1-4-g0d38a67 diff --git a/README.txt b/README.txt index fc2cc5a..b9ef8bf 100644 --- a/README.txt +++ b/README.txt @@ -142,5 +142,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-3-g3719c81 +latexmath:[\[VERSION\]] v0.70-pre1-4-g0d38a67 +++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index bcfc6e2..a8034b3 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-pre1-3-g3719c81 +#### $$VERSION$$ v0.70-pre1-4-g0d38a67 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/modules/background.sh b/modules/background.sh index 21c5357..45cd601 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-3-g3719c81 +#### $$VERSION$$ v0.70-pre1-4-g0d38a67 # source from commands.sh if you want ro use interactive or background jobs From 3cd6eebdf2df19832b26135017a4d069a8574fdb Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 27 Apr 2019 21:10:55 +0200 Subject: [PATCH 51/63] 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 From 02d9afbb22a8d55f2bb834d7c02322c16a07b8d6 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 27 Apr 2019 21:35:10 +0200 Subject: [PATCH 52/63] add mytextstartshere to doc --- README.md | 2 +- README.txt | 2 +- doc/3_advanced.md | 12 ++++++++++-- modules/background.sh | 2 +- test/a-commit-test.sh | 0 test/a-push-test.sh | 4 ---- test/d-JSON.sh-test.sh | 0 test/d-process_message-test.sh | 0 test/d-send_message-test.sh | 2 +- test/d-user_is-test.sh | 0 10 files changed, 14 insertions(+), 10 deletions(-) mode change 100644 => 100755 test/a-commit-test.sh delete mode 100644 test/a-push-test.sh mode change 100644 => 100755 test/d-JSON.sh-test.sh mode change 100644 => 100755 test/d-process_message-test.sh mode change 100644 => 100755 test/d-user_is-test.sh diff --git a/README.md b/README.md index 260babf..4cb1735 100644 --- a/README.md +++ b/README.md @@ -93,4 +93,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.70-pre1-5-g07dc7b4 +#### $$VERSION$$ v0.70-pre1-6-g3cd6eeb diff --git a/README.txt b/README.txt index 7706193..4486150 100644 --- a/README.txt +++ b/README.txt @@ -147,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-5-g07dc7b4 +latexmath:[\[VERSION\]] v0.70-pre1-6-g3cd6eeb +++++++++++++++++++++++++++++++++++++++++++++ diff --git a/doc/3_advanced.md b/doc/3_advanced.md index f9a187b..7005b25 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -95,10 +95,18 @@ echo "Text that will appear in chat? mykeyboardstartshere [ \"Yep, sure\" , \"No ``` Please note that you can either send a location or a venue, not both. To send a venue add the mytitlestartshere and the myaddressstartshere keywords. -To insert a linebreak in your message you can insert ```mynewlinestartshere``` in your echo command: +New in v0.6: To insert a linebreak in your message you can insert ```mynewlinestartshere``` in your echo command: ```bash echo "Text that will appear in one message mynewlinestartshere with this text on a new line" ``` + +New in v0.7: In case you must extend a message already containing a location, a file, a keyboard etc., +with additionial text simply add ``` mytextstartshere additional text``` at the end of the string: +```bash +out="Text that will appear mylatstartshere 45 mylongstartshere 45" +[[ "$out" != *'in chat'* ]] && out="$out mytextstartshere in chat." +echo "$out" +``` Note: Interactive Chats run independent from main bot and continue running until your script exits or you /cancel if from your Bot. ### Background Jobs @@ -169,5 +177,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-pre1-2-g293ad08 +#### $$VERSION$$ v0.70-pre1-6-g3cd6eeb diff --git a/modules/background.sh b/modules/background.sh index d9e3dea..84b5091 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-5-g07dc7b4 +#### $$VERSION$$ v0.70-pre1-6-g3cd6eeb # source from commands.sh if you want ro use interactive or background jobs diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh old mode 100644 new mode 100755 diff --git a/test/a-push-test.sh b/test/a-push-test.sh deleted file mode 100644 index c3b36a9..0000000 --- a/test/a-push-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -#### $$VERSION$$ v0.70-pre1-0-g490c472 - -../dev/hooks/pre-push.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh old mode 100644 new mode 100755 diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh old mode 100644 new mode 100755 diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index 5a54f61..c520690 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-5-g07dc7b4 +#### $$VERSION$$ v0.70-pre1-6-g3cd6eeb # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh old mode 100644 new mode 100755 From fcca1391b51e94fa7f6ab86af950d22783ef6c1f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 27 Apr 2019 23:15:05 +0200 Subject: [PATCH 53/63] some doc typos --- doc/3_advanced.md | 4 ++-- doc/5_practice.md | 10 +++++----- doc/6_reference.md | 13 +++++++------ doc/7_develop.md | 8 ++++---- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 7005b25..dc9c24a 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -58,7 +58,7 @@ You must use the function ```user_is_allowed``` to check if a user has the capab ;; esac ``` -**See also [Bashbot User Access Control functions](6_functions.md#User_Access_Control)** +**See also [Bashbot User Access Control functions](6_reference.md#User_Access_Control)** ### Interactive Chats To create interactive chats, write *(or edit the 'exmaples/question.sh' script)* a bash *(or C or python)* script, make it executable @@ -177,5 +177,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-pre1-6-g3cd6eeb +#### $$VERSION$$ v0.70-pre1-7-g02d9afb diff --git a/doc/5_practice.md b/doc/5_practice.md index 6ed4b47..a677596 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -3,11 +3,11 @@ ### New to bot development? -If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots) and consult [Telegram Bot API Documentaion](https://core.telegram.org/bots/api/). +If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots) and consult [Telegram Bot API Documentation](https://core.telegram.org/bots/api/). -In addition you should know about [BotFatheri, the one bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot). It will help you create new bots and change settings for existing ones. [Commands known by Botfather](https://core.telegram.org/bots#generating-an-authorization-token) +In addition you should know about [BotFather, the one bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot). It will help you create new bots and change settings for existing ones. [Commands known by Botfather](https://core.telegram.org/bots#generating-an-authorization-token) -If you dont't have a gibtup account, it may time to [sepup a free account now](https://github.com/pricing) +If you dont't have a github account, it may time to [sepup a free account now](https://github.com/pricing) ### Add commands to mycommands.sh only To ease updates never change ```bashbot.sh```, instead your commands and functions must go to ```mycommands.sh``` . Insert your Bot commands in the ```case ... esac``` block of the 'mycommands()' function: @@ -40,7 +40,7 @@ mycommands() { If you want to disable or reuse a global bashbot command comment it out in 'commands.sh' by placing a '#' in front of every line from ```'/command')``` to ```;;```. -**Learn more about [Bot (global) commands](https://core.telegram.org/bots#commands).** +**Learn more about [Bot commands](https://core.telegram.org/bots#commands).** **Note: Never disable the catchall command ```*)``` in 'commands.sh'!!** ```bash @@ -153,5 +153,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-pre1-2-g293ad08 +#### $$VERSION$$ v0.70-pre1-7-g02d9afb diff --git a/doc/6_reference.md b/doc/6_reference.md index 7736238..3dcf124 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -69,6 +69,7 @@ If your Bot is admin of a Chat he can delete every message, if not he can delete *usage:* delete_message "${CHAT[ID]}" "${MESSAGE[ID]}" See also [deleteMessage limitations](https://core.telegram.org/bots/api#deletemessage) + ---- ##### answer_inline_query @@ -128,7 +129,7 @@ send_keyboard "${CHAT[ID]}" "Enter digit" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \ ##### remove_keyboard *usage:* remove_keybord "$CHAT[ID]" "message" -See also: [Keyboard Markup](https://core.telegram.org/bots/api/#replykeyboardmarkup) +*See also: [Keyboard Markup](https://core.telegram.org/bots/api/#replykeyboardmarkup)* ---- @@ -147,7 +148,7 @@ This allows to place multiple inline buttons in a row. The inline buttons must s ```[ {"text":"text1", "url":"url1"}, ... {"text":"textN", "url":"urlN"} ]``` -Each button consists of a pair of text and URL values, sourrounded by '**{ }**', multiple buttons are seperated by '**,**' and everthing is wrapped in '**[ ]**'. +Each button consists of a pair of text and URL values, sourrounded by '{ }', multiple buttons are seperated by '**,**' and everthing is wrapped in '[ ]'. *usage:* send_inline_keyboard "chat-id" "message" "[ {"text":"text", "url":"url"} ...]" @@ -160,7 +161,7 @@ send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"button 1", url"":"url 1"}, {"te send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"b 1", url"":"u 1"}, {"text":"b 2", url"":"u 2"}, {"text":"b 2", url"":"u 2"} ]' ``` -See also [Inline keyboard markup](https://core.telegram.org/bots/api/#inlinekeyboardmarkup) +*See also [Inline keyboard markup](https://core.telegram.org/bots/api/#inlinekeyboardmarkup)* ---- @@ -194,7 +195,7 @@ if _is_admin ; then fi ``` -See also [kick Chat Member](https://core.telegram.org/bots/api/#kickchatmember) +'See also [kick Chat Member](https://core.telegram.org/bots/api/#kickchatmember)* ---- @@ -234,7 +235,7 @@ if _is_admin ; then fi ``` -See also [Chat Member](https://core.telegram.org/bots/api/#chatmember) +*See also [Chat Member](https://core.telegram.org/bots/api/#chatmember)* ##### user_is_allowed Bahsbot supports User Access Control, see [Advanced Usage](4_advanced.md) @@ -488,5 +489,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-pre1-2-g293ad08 +#### $$VERSION$$ v0.70-pre1-7-g02d9afb diff --git a/doc/7_develop.md b/doc/7_develop.md index 7810d4e..1ee20e3 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -1,6 +1,6 @@ #### [Home](../README.md) ## Notes for bashbot developers -This section is about help and best pratices for new bashbot developers. The main focus on is creating new versions of bashbot, not on develop your individual bot. Nevertheless the rules and tools described here can also help you with your bot development. +This section is about help and best practices for new bashbot developers. The main focus on is creating new versions of bashbot, not on develop your individual bot. Nevertheless the rules and tools described here can also help you with your bot development. 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). @@ -17,13 +17,13 @@ bashbot development is done on github. If you want to provide fixes or new featu A typical bashbot develop loop looks as follow: 1. start developing - *change, copy, edit bashbot files ...* -2. after change to bash file: ```shellcheck -x file.sh``` +2. after changing a bash sript: ```shellcheck -x scipt.sh``` 3. ```dev/all-tests.sh``` - *in case if errors back to 2.* 4. ```dev/git-add.sh``` - *check for changed files, update version string, run git add* 5. ```git commit' -m "COMMIT MESSAGE"; git push``` -**If you setup with hooks and use the scripts above, versioning, addding and testing is done automatically.** +**If you setup iyou dev environment with hooks and use the scripts above, versioning, addding and testing is done automatically.** ### Prepare a new version After some development it may time to create a new version for the users. a new version can be in sub version upgrade, e.g. for fixes and smaller additions or @@ -92,5 +92,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-pre1-1-gbd4a116 +#### $$VERSION$$ v0.70-pre1-7-g02d9afb From b831e60cbeb8e10d67125c2beada5f06f92a376d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 28 Apr 2019 09:54:51 +0200 Subject: [PATCH 54/63] create README.txt and .html --- README.html | 101 ++++++++++++++++++++ README.txt | 228 +++++++++++++++++++++------------------------- dev/version.sh | 5 +- doc/3_advanced.md | 4 +- 4 files changed, 211 insertions(+), 127 deletions(-) create mode 100644 README.html diff --git a/README.html b/README.html new file mode 100644 index 0000000..9be0a30 --- /dev/null +++ b/README.html @@ -0,0 +1,101 @@ + + + + + + + Bashbot README + + + + +

bashbot

+

A Telegram bot written in bash.

+

Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadelwartz).

+

Contributions by JuanPotato, BigNerd95, TiagoDanin, and iicc1.

+

Released to the public domain wherever applicable. Elsewhere, consider it released under the WTFPLv2.

+

Prerequisites

+

Depends on tmux. Uses JSON.sh.

+

Most complete UTF-8 support for bashbot is availible if phyton is installed (optional).

+

Bashbot Documentation and Downloads are availible on www.github.com

+

Documentation

+ +

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. More concret examples of security problems are: bash’s ‘quoting hell’ and globbing. Implications of wrong quoting

+

Whenever you are processing input from from untrusted sources (messages, files, network) you must be as carefull as possible, e.g. set IFS appropriate, disable globbing (set -f) and quote everthing. In addition disable not used Bot commands and delete unused scripts from your Bot, e.g. example scripts ‘notify’, ‘calc’, ‘question’,

+

A powerful tool to improve your scripts robustness is shellcheck. You can use it online or install shellcheck locally. All bashbot scripts are checked by shellcheck.

+

Run your Bot as a restricted user

+

I recommend to run your bot as a user, with almost no access rights. All files your Bot have write access to are in danger to be overwritten/deleted if your bot is hacked. For the same reason ervery file your Bot can read is in danger to be disclosed. Restict your Bots access rigths to the absolute minimum.

+

Never run your Bot as root, this is the most dangerous you can do! Usually the user ‘nobody’ has almost no rights on Unix/Linux systems. See Expert use on how to run your Bot as an other user.

+

Secure your Bot installation

+

Your Bot configuration must no be readable from other users. Everyone who can read your Bots token can act as your Bot and has access to all chats your Bot is in!

+

Everyone with read access to your Bot files can extract your Bots data. Especially your Bot Token in token must be protected against other users. No one exept you must have write access to the Bot files. The Bot must be restricted to have write access to count and tmp-bot-bash only, all other files must be write protected.

+

To set access rights for your bashbot installation to a reasonable default run sudo ./bashbot.sh init after every update or change to your installation directory.

+

Is this Bot insecure?

+

Bashbot is not more (in)secure as any other Bot written in any other 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 xyz?

+

Well, thats a damn good question … may be because I’m an Unix/Linux 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 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-6-g3cd6eeb

+ + diff --git a/README.txt b/README.txt index 4486150..ff9cd1f 100644 --- a/README.txt +++ b/README.txt @@ -1,151 +1,133 @@ -bashbot -------- - +# bashbot A Telegram bot written in bash. -Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M +Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadelwartz). Contributions by JuanPotato, BigNerd95, TiagoDanin, and iicc1. -Released to the public domain wherever applicable. Elsewhere, consider -it released under the http://www.wtfpl.net/txt/copying/[WTFPLv2]. +Released to the public domain wherever applicable. +Elsewhere, consider it released under the +[WTFPLv2](http://www.wtfpl.net/txt/copying/). -Prerequisites -~~~~~~~~~~~~~ +## Prerequisites +Depends on [tmux](http://github.com/tmux/tmux). +Uses [JSON.sh](http://github.com/dominictarr/JSON.sh). -Depends on http://github.com/tmux/tmux[tmux]. Uses -http://github.com/dominictarr/JSON.sh[JSON.sh]. +Most complete [UTF-8 support for +bashbot](doc/4_expert.md#Bashbot-UTF-8-Support) is availible if phyton is +installed (optional). -Most complete link:doc/4_expert.md#Bashbot-UTF-8-Support[UTF-8 support -for bashbot] is availible if phyton is installed (optional). +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 -Bashbot https://github.com/topkecleon/telegram-bot-bash[Documentation] -and https://github.com/topkecleon/telegram-bot-bash/releases[Downloads] -are availible on www.github.com +## Documentation +* [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 + * Install from githup + * Update Bashbot + * Notes on Updates +* [Create a new Telegram Bot with botfather](doc/1_firstbot.md) +* [Getting Started](doc/2_usage.md) + * Managing your Bot + * Recieve data + * Send messages + * Send files, locations, keyboards +* [Advanced Features](doc/3_advanced.md) + * Access Control + * Interactive Chats + * Background Jobs + * Inline queries +* [Expert Use](doc/4_expert.md) + * Handling UTF-8 character sets + * Run as other user or system service + * Scedule bashbot from Cron +* [Best Practices](doc/5_practice.md) + * Customize commands.sh + * Seperate logic from commands + * Test your Bot with shellcheck +* [Bashbot function reference](doc/6_reference.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) -Documentation -~~~~~~~~~~~~~ -* 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] -** Install release -** Install from githup -** Update Bashbot -** Notes on Updates -* link:doc/1_firstbot.md[Create a new Telegram Bot with botfather] -* link:doc/2_usage.md[Getting Started] -** Managing your Bot -** Recieve data -** Send messages -** Send files, locations, keyboards -* link:doc/3_advanced.md[Advanced Features] -** Access Control -** Interactive Chats -** Background Jobs -** Inline queries -* link:doc/4_expert.md[Expert Use] -** Handling UTF-8 character sets -** Run as other user or system service -** Scedule bashbot from Cron -* link:doc/5_practice.md[Best Practices] -** Customize commands.sh -** Seperate logic from commands -** Test your Bot with shellcheck -* link:doc/6_reference.md[Bashbot function reference] -* 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 +Running a Telegram Bot means it is connected to the public and you never know +whats send to your Bot. -Security Considerations -~~~~~~~~~~~~~~~~~~~~~~~ +Bash scripts in general are not designed to be bullet proof, so consider this +Bot as a proof of concept. More concret examples of security problems are: +bash's 'quoting hell' and globbing. [Implications of wrong +quoting](https://unix.stackexchange.com/questions/171346/security-implications-o +f-forgetting-to-quote-a-variable-in-bash-posix-shells) -Running a Telegram Bot means it is connected to the public and you never -know whats send to your Bot. +Whenever you are processing input from from untrusted sources (messages, files, +network) you must be as carefull as possible, e.g. set IFS appropriate, disable +globbing (set -f) and quote everthing. In addition disable not used Bot +commands and delete unused scripts from your Bot, e.g. example scripts +'notify', 'calc', 'question', -Bash scripts in general are not designed to be bullet proof, so consider -this Bot as a proof of concept. More concret examples of security -problems are: bash's 'quoting hell' and globbing. -https://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells[Implications -of wrong quoting] +A powerful tool to improve your scripts robustness is ```shellcheck```. You can +[use it online](https://www.shellcheck.net/) or [install shellcheck +locally](https://github.com/koalaman/shellcheck#installing). All bashbot +scripts are checked by shellcheck. -Whenever you are processing input from from untrusted sources (messages, -files, network) you must be as carefull as possible, e.g. set IFS -appropriate, disable globbing (set -f) and quote everthing. In addition -disable not used Bot commands and delete unused scripts from your Bot, -e.g. example scripts 'notify', 'calc', 'question', +### Run your Bot as a restricted user +**I recommend to run your bot as a user, with almost no access rights.** +All files your Bot have write access to are in danger to be overwritten/deleted +if your bot is hacked. +For the same reason ervery file your Bot can read is in danger to be disclosed. +Restict your Bots access rigths to the absolute minimum. -A powerful tool to improve your scripts robustness is `shellcheck`. You -can https://www.shellcheck.net/[use it online] or -https://github.com/koalaman/shellcheck#installing[install shellcheck -locally]. All bashbot scripts are checked by shellcheck. +**Never run your Bot as root, this is the most dangerous you can do!** Usually +the user 'nobody' has almost no rights on Unix/Linux systems. See [Expert +use](doc/4_expert.md) on how to run your Bot as an other user. -Run your Bot as a restricted user -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +### Secure your Bot installation +**Your Bot configuration must no be readable from other users.** Everyone who +can read your Bots token can act as your Bot and has access to all chats your +Bot is in! -*I recommend to run your bot as a user, with almost no access rights.* -All files your Bot have write access to are in danger to be -overwritten/deleted if your bot is hacked. For the same reason ervery -file your Bot can read is in danger to be disclosed. Restict your Bots -access rigths to the absolute minimum. +Everyone with read access to your Bot files can extract your Bots data. +Especially your Bot Token in ```token``` must be protected against other users. +No one exept you must have write access to the Bot files. The Bot must be +restricted to have write access to ```count``` and ```tmp-bot-bash``` only, +all other files must be write protected. -*Never run your Bot as root, this is the most dangerous you can do!* -Usually the user 'nobody' has almost no rights on Unix/Linux systems. -See link:doc/4_expert.md[Expert use] on how to run your Bot as an other -user. +To set access rights for your bashbot installation to a reasonable default run +```sudo ./bashbot.sh init``` after every update or change to your installation +directory. -Secure your Bot installation -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +### Is this Bot insecure? +Bashbot is not more (in)secure as any other Bot written in any other 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 ... -*Your Bot configuration must no be readable from other users.* Everyone -who can read your Bots token can act as your Bot and has access to all -chats your Bot is in! +### Why Bash and not the much better xyz? +Well, thats a damn good question ... may be because I'm an Unix/Linux admin +from stone age. Nevertheless there are more reasons from my side: -Everyone with read access to your Bot files can extract your Bots data. -Especially your Bot Token in `token` must be protected against other -users. No one exept you must have write access to the Bot files. The Bot -must be restricted to have write access to `count` and `tmp-bot-bash` -only, all other files must be write protected. - -To set access rights for your bashbot installation to a reasonable -default run `sudo ./bashbot.sh init` after every update or change to -your installation directory. - -Is this Bot insecure? -^^^^^^^^^^^^^^^^^^^^^ - -Bashbot is not more (in)secure as any other Bot written in any other -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 xyz? -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Well, thats a damn good question ... may be because I'm an Unix/Linux -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 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 ... +- bashbot will run everywhere where bash is availible, from ebedded linux to +mainframe +- 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! -~~~~~~~~~~ +## That's it! -If you feel that there's something missing or if you found a bug, feel -free to submit a pull request! +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-6-g3cd6eeb -+++++++++++++++++++++++++++++++++++++++++++++ +#### $$VERSION$$ v0.70-pre1-6-g3cd6eeb diff --git a/dev/version.sh b/dev/version.sh index 2c24f94..d465a6c 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-8-gfcca139 # shellcheck disable=SC2016 # # Easy Versioning in git: @@ -57,6 +57,7 @@ do done # try to compile README.txt echo -n " README.txt" >&2 -pandoc -f markdown -t asciidoc README.md | sed '/^\[\[/d' >README.txt +type -f pandoc >/dev/null && pandoc -s -S -M "title=Bashbot README" README.md >README.html +fold -s README.md >README.txt echo " done." diff --git a/doc/3_advanced.md b/doc/3_advanced.md index dc9c24a..aa99445 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -58,7 +58,7 @@ You must use the function ```user_is_allowed``` to check if a user has the capab ;; esac ``` -**See also [Bashbot User Access Control functions](6_reference.md#User_Access_Control)** +**See also [Bashbot User Access Control functions](6_reference.md#User-Access-Control)** ### Interactive Chats To create interactive chats, write *(or edit the 'exmaples/question.sh' script)* a bash *(or C or python)* script, make it executable @@ -177,5 +177,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-pre1-7-g02d9afb +#### $$VERSION$$ v0.70-pre1-8-gfcca139 From 5269b54aec3e0bfb5f9f47a48507bae302467ade Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 28 Apr 2019 10:32:06 +0200 Subject: [PATCH 55/63] create html doc for dist --- dev/make-dist.sh | 10 +- html/0_install.html | 76 ++++++++++ html/1_firstbot.html | 53 +++++++ html/2_usage.html | 179 ++++++++++++++++++++++ html/3_advanced.html | 161 ++++++++++++++++++++ html/4_expert.html | 124 ++++++++++++++++ html/5_practice.html | 178 ++++++++++++++++++++++ html/6_reference.html | 334 ++++++++++++++++++++++++++++++++++++++++++ html/7_develop.html | 113 ++++++++++++++ html/8_custom.html | 130 ++++++++++++++++ 10 files changed, 1356 insertions(+), 2 deletions(-) create mode 100644 html/0_install.html create mode 100644 html/1_firstbot.html create mode 100644 html/2_usage.html create mode 100644 html/3_advanced.html create mode 100644 html/4_expert.html create mode 100644 html/5_practice.html create mode 100644 html/6_reference.html create mode 100644 html/7_develop.html create mode 100644 html/8_custom.html diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 3171168..0481060 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.70-pre1-9-gb831e60 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -24,7 +24,7 @@ do fi done -# create dir for sitribution and copy files +# create dir for distribution and copy files mkdir -p "${DISTDIR}" 2>/dev/null # shellcheck disable=SC2086 cp -r ${DISTFILES} "${DISTDIR}" @@ -41,6 +41,12 @@ if [ ! -f "${JSONSHFILE}" ]; then chmod +x "${JSONSHFILE}" fi +# make html doc +mkdir html +cp README.html html/index.html +find ./doc -iname "*.md" -type f -exec sh -c 'pandoc -s -S -M "title=Bashobot Documentation - ${0%.md}.html" "${0}" -o "./html/$(basename ${0%.md}.html)"' {} \; +find README.html html -iname "*.html" -type f -exec sh -c 'sed -i -E "s/href=\"(.*).md\"/href=\"\1.html\"/g" ${0}' {} \; + # create archive cd .. || exit 1 zip -rq "${DISTNAME}-${VERSION}.zip" "${DISTNAME}" diff --git a/html/0_install.html b/html/0_install.html new file mode 100644 index 0000000..3d34bc6 --- /dev/null +++ b/html/0_install.html @@ -0,0 +1,76 @@ + + + + + + + Bashobot Documentation - 0_install.html + + + + +

Home

+

Install bashbot

+
    +
  1. Go to the directory you want to install bashbot, e.g. +
      +
    • your $HOME directory (install and run with your user-ID)
    • +
    • /usr/local if you want to run as service
    • +
  2. +
  3. Download latest release zip from github and extract all files.
  4. +
  5. Change into the directory telegram-bot-bash
  6. +
  7. Create default commands with cp commands.sh.dist commands.sh; cp mycommands.sh.dist mycommands.sh
  8. +
  9. Run ./bashbot.sh init to setup the environment and enter your Bots token given by botfather.
  10. +
+

Now your Bot is ready to start …

+

If you are new to Bot development read Bots: An introduction for developers

+

Install from Github

+

As an alternative to download the zip files, you can clone the github repository to get the latest improvements/fixes.

+
    +
  1. Go to the directory you want to install bashbot, e.g. +
      +
    • your $HOME directory (install and run with your user-ID)
    • +
    • /usr/local if you want to run as service
    • +
  2. +
  3. Run git clone https://github.com/topkecleon/telegram-bot-bash.git
  4. +
  5. Change into the directory telegram-bot-bash
  6. +
  7. Run test/ALL-tests.sh and if everthing finish OK …
  8. +
  9. Run sudo ./bashbot.sh init to setup the environment and enter your Bots token given by botfather.
  10. +
+

Update bashbot

+
    +
  1. Go to the directory where you had installed bashbot, e.g. +
      +
    • your $HOME directory
    • +
    • /usr/local
    • +
  2. +
  3. Download latest release zip from github
  4. +
  5. Extract all files to your existing bashbot dir Note: all files execpt ‘mycommands.sh’ and ‘commands.sh’ may overwritten!
  6. +
  7. Run sudo ./bashbot.sh init to setup your environment after the update
  8. +
+

Notes on Updates

+

Location of tmp / data dir

+

From version 0.70 on the tmp dir is renamed to ‘data-bot-bash’ to reflect the fact that not only temporary files are stored. an existing ‘tmp-bot-bash’ will be automatically renamed after update.

+

From version 0.50 on the temporary files are no more placed in ‘/tmp’. instead a dedicated tmp dir is used.

+

Changes to send_keyboard in v0.6

+

From Version 0.60 on keybord format for send_keyboard and send_message "mykeyboardstartshere ..." was changed. Keybords are now defined in JSON Array notation e.g. “[ \“yes\” , \“no\” ]”. This has the advantage that you can create any type of keyboard supported by Telegram. The old format is supported for backward compatibility, but may fail for corner cases.

+

Example Keyboards:

+
    +
  • yes no in two rows: +
      +
    • OLD format: ‘yes’ ‘no’ (two strings)
    • +
    • NEW format: ‘[ “yes” ] , [ “no” ]’ (two arrays with a string)
    • +
  • +
  • new layouts made easy with NEW format: +
      +
    • Yes No in one row: ‘[ “yes” , “no” ]’
    • +
    • Yes No plus Maybe in 2.row: ‘[ “yes” , “no” ] , [ “maybe” ]’
    • +
    • numpad style keyboard: ‘[ “1” , “2” , “3” ] , [ “4” , “5” , “6” ] , [ “7” , “8” , “9” ] , [ “0” ]’
    • +
  • +
+

Next Create Bot

+


VERSION
v0.70-pre1-2-g293ad08

+ + diff --git a/html/1_firstbot.html b/html/1_firstbot.html new file mode 100644 index 0000000..8ddab68 --- /dev/null +++ b/html/1_firstbot.html @@ -0,0 +1,53 @@ + + + + + + + Bashobot Documentation - 1_firstbot.html + + + + +

Home

+

Create a Telegram Bot with botfather

+

BotFather is the one bot to rule them all. It will help you create new bots and change settings for existing ones. Commands known by Botfather

+

Creating a new Bot

+
    +
  1. Message @botfather https://telegram.me/botfather with the following text: /newbot If you don’t know how to message by username, click the search field on your Telegram app and type @botfather, you should be able to initiate a conversation. Be careful not to send it to the wrong contact, because some users has similar usernames to botfather.
  2. +
+
+botfather initial conversation +

botfather initial conversation

+
+
    +
  1. @botfather replies with Alright, a new bot. How are we going to call it? Please choose a name for your bot.

  2. +
  3. Type whatever name you want for your bot.

  4. +
  5. @botfather replies with Good. Now let's choose a username for your bot. It must end in bot. Like this, for example: TetrisBot or tetris_bot.

  6. +
  7. Type whatever username you want for your bot, minimum 5 characters, and must end with bot. For example: telesample_bot

  8. +
  9. @botfather replies with:

    +

    Done! Congratulations on your new bot. You will find it at telegram.me/telesample_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands.

    +

    Use this token to access the HTTP API: 123456789:AAG90e14-0f8-40183D-18491dDE

    +

    For a description of the Bot API, see this page: https://core.telegram.org/bots/api

  10. +
  11. Note down the ‘token’ mentioned above.

  12. +
  13. Type /setprivacy to @botfather.

  14. +
+
+botfather later conversation +

botfather later conversation

+
+
    +
  1. @botfather replies with Choose a bot to change group messages settings.

  2. +
  3. Type @telesample_bot (change to the username you set at step 5 above, but start it with @)

  4. +
  5. @botfather replies with

    +

    ‘Enable’ - your bot will only receive messages that either start with the ‘/’ symbol or mention the bot by username. ‘Disable’ - your bot will receive all messages that people send to groups. Current status is: ENABLED

  6. +
  7. Type Disable to let your bot receive all messages sent to a group. This step is up to you actually.

  8. +
  9. @botfather replies with Success! The new status is: DISABLED. /help

  10. +
+

Prev Installation

+

Next Getting started

+


VERSION
v0.70-pre1-2-g293ad08

+ + diff --git a/html/2_usage.html b/html/2_usage.html new file mode 100644 index 0000000..3f3579e --- /dev/null +++ b/html/2_usage.html @@ -0,0 +1,179 @@ + + + + + + + Bashobot Documentation - 2_usage.html + + + + + +

Home

+

Gettting Started

+

The Bots standard commands are in commands.sh file. You must not add your commands to ‘commands.sh’, instead place them in mycommands.sh, there you also find examples how to process messages and send out text. See Best practices for more information.

+

Once you’re done with editing ‘mycommands.sh’ start the Bot with ./bashbot.sh start. If some thing doesn’t work as it should, debug with bash -x bashbot.sh. To stop the Bot run ./bashbot.sh kill

+

To use the functions provided in this script in other scripts simply source bashbot: source bashbot.sh

+

Have FUN!

+

Managing your own Bot

+

Note: running bashbot as root is highly danger and not recommended. See Expert use.

+

Start / Stop

+

Start or Stop your Bot use the following commands:

+
./bashbot.sh start
+
./bashbot.sh kill
+

User count

+

To count the total number of users that ever used the bot run the following command:

+
./bashbot.sh count
+

Sending broadcasts to all users

+

To send a broadcast to all of users that ever used the bot run the following command:

+
./bashbot.sh broadcast "Hey! I just wanted to let you know that the bot's been updated!"
+

Recieve data

+

Evertime a Message is recieved, you can read incoming data using the following variables:

+
    +
  • ${MESSAGE}: Current message
  • +
  • ${MESSAGE[ID]}: ID of current message
  • +
  • $CAPTION: Captions
  • +
  • $REPLYTO: Original message wich was replied to
  • +
  • $USER: This array contains the First name, last name, username and user id of the sender of the current message. +
      +
    • ${USER[ID]}: User id
    • +
    • ${USER[FIRST_NAME]}: User’s first name
    • +
    • ${USER[LAST_NAME]}: User’s last name
    • +
    • ${USER[USERNAME]}: Username
    • +
  • +
  • $CHAT: This array contains the First name, last name, username, title and user id of the chat of the current message. +
      +
    • ${CHAT[ID]}: Chat id
    • +
    • ${CHAT[FIRST_NAME]}: Chat’s first name
    • +
    • ${CHAT[LAST_NAME]}: Chat’s last name
    • +
    • ${CHAT[USERNAME]}: Username
    • +
    • ${CHAT[TITLE]}: Title
    • +
    • ${CHAT[TYPE]}: Type
    • +
    • ${CHAT[ALL_MEMBERS_ARE_ADMINISTRATORS]}: All members are administrators (true if true)
    • +
  • +
  • $REPLYTO: This array contains the First name, last name, username and user id of the ORIGINAL sender of the message REPLIED to. +
      +
    • ${REPLYTO[ID]}: ID of message wich was replied to
    • +
    • ${REPLYTO[UID]}: Original user’s id
    • +
    • ${REPLYTO[FIRST_NAME]}: Original user’s first name
    • +
    • ${REPLYTO[LAST_NAME]}: Original user’s’ last name
    • +
    • ${REPLYTO[USERNAME]}: Original user’s username
    • +
  • +
  • $FORWARD: This array contains the First name, last name, username and user id of the ORIGINAL sender of the FORWARDED message. +
      +
    • ${FORWARD[ID]}: Same as MESSAGE[ID] if message is forwarded
    • +
    • ${FORWARD[UID]}: Original user’s id
    • +
    • ${FORWARD[FIRST_NAME]}: Original user’s first name
    • +
    • ${FORWARD[LAST_NAME]}: Original user’s’ last name
    • +
    • ${FORWARD[USERNAME]}: Original user’s username
    • +
  • +
  • $URLS: This array contains documents, audio files, voice recordings and stickers as URL. +
      +
    • ${URLS[AUDIO]}: Audio files
    • +
    • ${URLS[VIDEO]}: Videos
    • +
    • ${URLS[PHOTO]}: Photos (maximum quality)
    • +
    • ${URLS[VOICE]}: Voice recordings
    • +
    • ${URLS[STICKER]}: Stickers
    • +
    • ${URLS[DOCUMENT]}: Any other file
    • +
  • +
  • $CONTACT: This array contains info about contacts sent in a chat. +
      +
    • ${CONTACT[ID]}: User id
    • +
    • ${CONTACT[NUMBER]}: Phone number
    • +
    • ${CONTACT[FIRST_NAME]}: First name
    • +
    • ${CONTACT[LAST_NAME]}: Last name
    • +
    • ${CONTACT[VCARD]}: User’s complete Vcard
    • +
  • +
  • $LOCATION: This array contains info about locations sent in a chat. +
      +
    • ${LOCATION[LONGITUDE]}: Longitude
    • +
    • ${LOCATION[LATITUDE]}: Latitude
    • +
  • +
  • $VENUE: This array contains info about venue (a place) sent in a chat. +
      +
    • ${VENUE[TITLE]}: Name of the place
    • +
    • ${VENUE[ADDRESS]}: Address of the place
    • +
    • ${VENUE[LONGITUDE]}: Longitude
    • +
    • ${VENUE[LATITUDE]}: Latitude
    • +
    • ${VENUE[FOURSQUARE]}: Fouresquare ID
    • +
  • +
+

Usage of bashbot functions

+

sending messages

+

To send messages use the send_xxx_message functions.

+

To send regular text without any markdown use:

+
send_text_message "${CHAT[ID]}" "lol"
+

To send text with markdown:

+
send_markdown_message "${CHAT[ID]}" "lol *bold*"
+

To send text with html:

+
send_html_message "${CHAT[ID]}" "lol <b>bold</b>"
+

To forward messages use the forward function:

+
forward "${CHAT[ID]}" "from_chat_id" "message_id"
+

If your Bot is Admin in a Chat you can delete every message, if not you can delete only your messages. To delete a message with a known ${MESSAGE[ID]} you can simple use: ```bash delete_message "${CHAT[ID]}" “${MESSAGE[ID]}” ```

+

send_message

+

In addition there is a universal send_massage function which can output any type of message. This function is used to process output from external scrips like interactive chats or background jobs.
+For safety and performance reasons I recommend to use send_xxxx_message functions above for sending messages

+
send_message "${CHAT[ID]}" "lol"
+

To send html or markdown put the following strings before the text, depending on the parsing mode you want to enable:

+
send_message "${CHAT[ID]}" "markdown_parse_mode lol *bold*"
+
send_message "${CHAT[ID]}" "html_parse_mode lol <b>bold</b>"
+

This function also allows a third parameter that disables additional function parsing (for safety use this when reprinting user input):

+
send_message "${CHAT[ID]}" "lol" "safe"
+

See also Interactive chats

+

Send files, locations, keyboards.

+

To send images, videos, voice files, photos etc. use the send_photo function (remember to change the safety Regex @ line 14 of command.sh to allow sending files only from certain directories):

+
send_file "${CHAT[ID]}" "/home/user/doge.jpg" "Lool"
+

To send custom keyboards use the send_keyboard function:

+
send_keyboard "${CHAT[ID]}" "Text that will appear in chat?" '[ "Yep" , "No" ]' # note the simgle quotes!
+send_keyboard "${CHAT[ID]}" "Text that will appear in chat?" "[ \\"Yep\\" , \\"No\\" ]" # within double quotes you must excape the inside double quots
+

To send locations use the send_location function:

+
send_location "${CHAT[ID]}" "Latitude" "Longitude"
+

To send venues use the send_venue function:

+
send_venue "${CHAT[ID]}" "Latitude" "Longitude" "Title" "Address" "optional foursquare id"
+

To send a chat action use the send_action function. Allowed values: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for locations.

+
send_action "${CHAT[ID]}" "action"
+

See also Bashbot function reference

+

Prev Create Bot

+

Next Advanced Usage

+


VERSION
v0.70-pre1-2-g293ad08

+ + diff --git a/html/3_advanced.html b/html/3_advanced.html new file mode 100644 index 0000000..3a00cee --- /dev/null +++ b/html/3_advanced.html @@ -0,0 +1,161 @@ + + + + + + + Bashobot Documentation - 3_advanced.html + + + + + +

Home

+

Advanced Features

+

Access control

+

Bashbot offers functions to check what Telegram capabilities like ‘chat admin’ or ‘chat creator’ the given user has:

+
# return true if user is admin/owner of the bot
+# -> botadmin is stored in file './botadmin'
+user_is_botadmin "user"  
+
+# return true if user is creator or admin of a chat
+user_is_admin "chat" "user"
+
+# return true if user is creator of a chat or it's a one to one chat
+user_is_creator "chat" "user"
+
+# examples:
+user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
+
+user_is_admin "${CHAT[ID]}" "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *CHATADMIN*."
+

In addition you can check individual capabilities of users as you must define in the file ./botacl:

+
# file: botacl
+# a user not listed here, will return false from 'user_is_allowed'
+#
+# Format:
+# user:ressource:chat
+
+# allow user 123456789 access to all resources in all chats
+123456789:*:*
+
+# allow user 12131415 to start bot in all chats
+12131415:start:*
+
+# allow user 987654321 only to start bot in chat 98979695
+987654321:start:98979695
+
+# * are only allowed on the right hand side and not for user!
+# the following exaples are NOT valid!
+*:*:*
+*:start:*
+*:*:98979695
+

You must use the function user_is_allowed to check if a user has the capability to do something. Example: Check if user has capability to start bot.

+
    case "$MESSAGE" in
+        ################################################
+        # GLOBAL commands start here, only edit messages
+        '/start'*)
+            user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
+            if user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then
+                bot_help "${CHAT[ID]}"
+            else
+                send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
+            ;;
+    esac
+

See also Bashbot User Access Control functions

+

Interactive Chats

+

To create interactive chats, write (or edit the ‘exmaples/question.sh’ script) a bash (or C or python) script, make it executable and then use the ‘startproc’ function to start the script. The output of the script will be sent to the user and user input will be sent to the script. To stop the script use the function ‘killprog’

+

The output of the script will be processed by ‘send_messages’ to enable you to not only send text, but also keyboards, files, locations and more. Each newline in the output will start an new message to the user, to have line breaks in your message you can use ‘mynewlinestartshere’.

+

To open up a keyboard in an interactive script, print out the keyboard layout in the following way:

+
echo "Text that will appear in chat? mykeyboardstartshere [ \"Yep, sure\" , \"No, highly unlikely\" ]"
+

Same goes for files:

+
echo "Text that will appear in chat? myfilelocationstartshere /home/user/doge.jpg"
+

And buttons:

+
echo "Text that will appear in chat. mybtextstartshere Klick me myburlstartshere https://dealz.rrr.de"
+

And locations:

+
echo "Text that will appear in chat. mylatstartshere 45 mylongstartshere 45"
+

And venues:

+
echo "Text that will appear in chat. mylatstartshere 45 mylongstartshere 45 mytitlestartshere my home myaddressstartshere Diagon Alley N. 37"
+

You can combine them:

+
echo "Text that will appear in chat? mykeyboardstartshere [ \"Yep, sure\" , \"No, highly unlikely\" ] myfilelocationstartshere /home/user/doge.jpg mylatstartshere 45 mylongstartshere 45"
+

Please note that you can either send a location or a venue, not both. To send a venue add the mytitlestartshere and the myaddressstartshere keywords.

+

New in v0.6: To insert a linebreak in your message you can insert mynewlinestartshere in your echo command:

+
echo "Text that will appear in one message  mynewlinestartshere  with this text on a new line"
+

New in v0.7: In case you must extend a message already containing a location, a file, a keyboard etc., with additionial text simply add mytextstartshere additional text at the end of the string:

+
out="Text that will appear mylatstartshere 45 mylongstartshere 45"
+[[ "$out" != *'in chat'* ]] &&  out="$out mytextstartshere in chat."
+echo "$out"
+

Note: Interactive Chats run independent from main bot and continue running until your script exits or you /cancel if from your Bot.

+

Background Jobs

+

A background job is similar to an interactive chat, but runs in the background and does only output massages and does not get user input. In contrast to interactive chats it’s possible to run multiple background jobs. To create a background job write a script or edit ‘examples/notify.sh’ script and use the funtion background to start it:

+
background "examples/notify.sh" "jobname"
+

All output of the script will be sent to the user, to stop a background job use:

+
killback "jobname"
+

You can also suspend and resume the last running background jobs from outside bashbot, e.g. in your startup schripts:

+
./bashbot.sh suspendback
+./bashbot.sh resumeback
+

If you want to kill all background jobs permantly run:

+
./bashbot.sh killback
+

Note: Background Jobs run independent from main bot and continue running until your script exits or you stop if from your Bot. Backgound Jobs will continue running if your Bot is stopeda and must be terminated, e.g. by bashbot.sh killback

+

Inline queries

+

The following commands allows users to interact with your bot via inline queries. In order to enable inline mode, send /setinline command to [@BotFather](https://telegram.me/botfather) and provide the placeholder text that the user will see in the input field after typing your bot’s name. Also, edit line 12 from commands.sh putting a “1”. Note that you can’t modify the first two parameters of the function answer_inline_query, only the ones after them.

+

To send messsages or links through an inline query:

+
answer_inline_query "$iQUERY_ID" "article" "Title of the result" "Content of the message to be sent"
+

To send photos in jpeg format and less than 5MB, from a website through an inline query:

+
answer_inline_query "$iQUERY_ID" "photo" "A valid URL of the photo" "URL of the thumbnail"
+

To send standard gifs from a website (less than 1MB) through an inline query:

+
answer_inline_query "$iQUERY_ID" "gif" "gif url"
+

To send mpeg4 gifs from a website (less than 1MB) through an inline query:

+
answer_inline_query "$iQUERY_ID" "mpeg4_gif" "mpeg4 gif url"
+

To send videos from a website through an inline query:

+
answer_inline_query "$iQUERY_ID" "video" "valid video url" "Select one mime type: text/html or video/mp4" "URL of the thumbnail" "Title for the result"
+

To send photos stored in Telegram servers through an inline query:

+
answer_inline_query "$iQUERY_ID" "cached_photo" "identifier for the photo"
+

To send gifs stored in Telegram servers through an inline query:

+
answer_inline_query "$iQUERY_ID" "cached_gif" "identifier for the gif"
+

To send mpeg4 gifs stored in Telegram servers through an inline query:

+
answer_inline_query "$iQUERY_ID" "cached_mpeg4_gif" "identifier for the gif"
+

To send stickers through an inline query:

+
answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker"
+

Prev Getting started

+

Next Expert Use

+


VERSION
v0.70-pre1-8-gfcca139

+ + diff --git a/html/4_expert.html b/html/4_expert.html new file mode 100644 index 0000000..734ec37 --- /dev/null +++ b/html/4_expert.html @@ -0,0 +1,124 @@ + + + + + + + Bashobot Documentation - 4_expert.html + + + + + +

Home

+

Expert Use

+

Handling UTF-8 character sets

+

UTF-8 is a variable length encoding of Unicode. UTF-8 is recommended as the default encoding in JSON, XML and HTML, also Telegram make use of it.

+

The first 128 characters are regular ASCII, so it’s a superset of and compatible with ASCII environments. The next 1,920 characters need two bytes for encoding and covers almost all Latin alphabets, also Greek, Cyrillic, Hebrew, Arabic and more. See Wikipedia for more details.

+

Setting up your Environment

+

In general bash and GNU utitities are UTF-8 aware if you to setup your environment and your scripts accordingly:

+
    +
  1. Your Terminal and Editor must support UTF-8: Set Terminal and Editor locale to UTF-8, eg. in Settings/Configuration select UTF-8 (Unicode) as Charset.

  2. +
  3. Set Shell environment to UTF-8 in your .profile and your scripts. The usual settings are:

  4. +
+
export 'LC_ALL=C.UTF-8'
+export 'LANG=C.UTF-8'
+export 'LANGUAGE=C.UTF-8'
+

If you use other languages, eg. german or US english, change the shell settings to:

+
export 'LC_ALL=de_DE.UTF-8'
+export 'LANG=de_DE.UTF-8'
+export 'LANGUAGE=de_DE.UTF-8'
+
export 'LC_ALL=en_US.UTF-8'
+export 'LANG=de_en_US.UTF-8'
+export 'LANGUAGE=den_US.UTF-8'
+
    +
  1. make shure your bot scripts use the correct settings, eg. include the lines above at the beginning of your scripts
  2. +
+

To display all availible locales on your system run locale -a | more. Gentoo Wiki

+

Bashbot UTF-8 Support

+

Bashbot handles all messages transparently, regardless of the charset in use. The only exception is when converting from JSON data to strings.

+

Telegram use JSON to send / recieve data. JSON encodes strings as follow: Characters not ASCII (>127) are escaped as sequences of \uxxxx to be regular ASCII. In addition multibyte characters, e.g. Emoticons or Arabic characters, are send in double byte UTF-16 notation. The Emoticons 😁 😘 ❤️ 😊 👍 are encoded as: \uD83D\uDE01 \uD83D\uDE18 \u2764\uFE0F \uD83D\uDE0A \uD83D\uDC4D

+

This “mixed” JSON encoding needs special handling and can not decoded from echo -e or printf '%s\\n'

+

Most complete support for decoding of multibyte characters can only be provided if python is installed on your system. Without phyton bashbot falls back to an internal, pure bash implementation which may not work for some corner cases.

+

Run as other user or system service

+

Bashbot is desingned to run manually by the user who installed it. Nevertheless it’s possible to run it by an other user-ID, as a system service or sceduled from cron. This is onyl recommended for experiend linux users.

+

Setup the environment for the user you want to run bashbot and enter desired username, e.g. nobody :

+
sudo ./bashbot.sh init
+

Edit the file bashbot.rc and edit the following lines to fit your configuration:

+
#######################
+# Configuration Section
+
+# edit the next line to fit the user you want to run bashbot, e.g. nobody:
+runas="nobody" 
+
+# uncomment one of the following lines 
+# runcmd="su $runas -s /bin/bash -c "      # runasuser with su
+# runcmd="runuser $runas -s /bin/bash -c " # runasuser with runuser
+
+# edit the values of the following lines to fit your config:
+start="/usr/local/telegram-bot-bash/bashbot.sh" # location of your bashbot.sh script
+name=''   # your bot name as given to botfather, e.g. mysomething_bot
+
+# END Configuration
+#######################
+

From now on use ‘bashbot.rc’ to manage your bot:

+
sudo ./bashbot.rc start
+

Type ps -ef | grep bashbot to verify your Bot is running as the desired user.

+

If your Bot is started by ‘bashbot.rc’, you must use ‘bashbot.rc’ also to manage your Bot! The following commands are availible:

+
sudo ./bashbot.rc start
+sudo ./bashbot.rc stop
+sudo ./bashbot.rc status
+sudo ./bashbot.rc suspendback
+sudo ./bashbot.rc resumeback
+sudo ./bashbot.rc killback
+

To change back the environment to your user-ID run sudo ./bashbot.sh init again and enter your user name.

+

To use bashbot as a system servive include a working bashbot.rc in your init system (systemd, /etc/init.d).

+

Scedule bashbot from Cron

+

An example crontab is provided in examples/bashbot.cron.

+
    +
  • If you are running bashbot with your user-ID, copy the examples lines to your crontab and remove username nobody.
  • +
  • if you run bashbot as an other user or a system service edit examples/bashbot.cron to fit your needs and replace usernamenobody with the username you want to run bashbot. copy the modified file to /etc/cron.d/bashbot
  • +
+

Prev Expert Use

+

Next Best Practice

+


VERSION
v0.70-pre1-0-g490c472

+ + diff --git a/html/5_practice.html b/html/5_practice.html new file mode 100644 index 0000000..077c480 --- /dev/null +++ b/html/5_practice.html @@ -0,0 +1,178 @@ + + + + + + + Bashobot Documentation - 5_practice.html + + + + + +

Home

+

Best Practices

+

New to bot development?

+

If you are new to Bot development read Bots: An introduction for developers and consult Telegram Bot API Documentation.

+

In addition you should know about BotFather, the one bot to rule them all. It will help you create new bots and change settings for existing ones. Commands known by Botfather

+

If you dont’t have a github account, it may time to sepup a free account now

+

Add commands to mycommands.sh only

+

To ease updates never change bashbot.sh, instead your commands and functions must go to mycommands.sh . Insert your Bot commands in the case ... esac block of the ‘mycommands()’ function:

+
# file: mycommands.sh
+# your additional bahsbot commands
+
+# uncomment the following lines to overwrite info and help messages
+ bashbot_info='This is *MY* variant of _bashbot_, the Telegram bot written entirely in bash.
+'
+
+ bashbot_help='*Available commands*:
+/echo message - _echo the given messsage_
+'
+
+# NOTE: command can have @botname attached, you must add * in case tests... 
+mycommands() {
+
+    case "$MESSAGE" in
+        '/echo'*) # example echo command
+            send_normal_message "${CHAT[ID]}" "$MESSAGE"
+            ;;
+        # .....
+    esac
+}
+

Reuse or disable global commands

+

If you want to disable or reuse a global bashbot command comment it out in ‘commands.sh’ by placing a ‘#’ in front of every line from '/command') to ;;.

+

Learn more about Bot commands.

+

Note: Never disable the catchall command *) in ‘commands.sh’!!

+
# file: commands.sh
+
+    case "$MESSAGE" in
+        ################################################
+        # GLOBAL commands start here, edit messages only
+
+        #'/start'*)
+        #   send_action "${CHAT[ID]}" "typing"
+        #   _is_botadmin && _markdown_message "You are *BOTADMIN*."
+        #   if _is_allowed "start" ; then
+        #       _markdown_message "${bot_help}"
+        #   else
+        #       _message "You are not allowed to start Bot."
+        #   fi
+        #   ;;
+
+        *)  # forward other messages to optional dispatcher
+            _is_function startproc && if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi # interactive running
+            _is_function mycommands && mycommands
+            ;;
+    esac
+

Seperate logic from commands

+

If a command need more than 2-3 lines of code, you should use a function to seperate logic from command. Place your functions in mycommands.sh and call the from your command. Example:

+
# file: mycommands.sh
+# your additional bahsbot commands
+
+mycommands() {
+
+    case "$MESSAGE" in
+        '/process'*) # logic for /process is done in process_message 
+            result="$(process_message "$MESSAGE")"
+            send_normal_message "${CHAT[ID]}" "$result" 
+            ;;
+    esac
+
+}
+
+# place your functions here
+
+process_message() {
+   local ARGS="${1#/* }"    # remove command 
+   local TEXT OUTPUT=""
+
+   # process every word in MESSAGE, avoid globbing
+   set -f
+   for WORD in $ARGS
+   do
+    # process links 
+    if [[ "$WORD" == "https://"* ]]; then
+        REPORT="$(dosomething_with_link "$WORD")"
+    # no link, add as text
+    else
+        TEXT="$(echo "${TEXT} $WORD")"
+        continue
+    fi
+    # compose result
+    OUTPUT="* ${REPORT} ${WORD} ${TEXT}"
+    TEXT=""
+   done
+
+   # return result, reset globbing in case we had no ARGS
+   echo "${OUTPUT}${TEXT}"
+}
+

Test your Bot with shellcheck

+

Shellcheck is a static linter for shell scripts providing excellent tips and hints for shell coding pittfalls. You can use it online or install it on your system. All bashbot scripts are linted by shellcheck.

+

Shellcheck examples:

+
$ shellcheck -x mybotcommands.inc.sh
+ 
+Line 17:
+                TEXT="$(echo "${TEXT} $WORD")"
+                      ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
+ 
+

As you can see my mybotcommands.inc.sh contains an useless echo command in ‘TEXT=’ assigment and can be replaced by TEXT="${TEXT}${WORD}"

+
$ shellcheck -x examples/notify
+OK
+$ shellcheck -x examples/question
+OK
+$ shellcheck -x commands.sh
+OK
+$ shellcheck -x bashbot.sh
+
+In bashbot.sh line 123:
+                text="$(echo "$text" | sed 's/ mynewlinestartshere /\r\n/g')" # hack for linebreaks in startproc scripts
+                        ^-- SC2001: See if you can use ${variable//search/replace} instead.
+
+
+In bashbot.sh line 490:
+        CONTACT[USER_ID]="$(sed -n -e '/\["result",'$PROCESS_NUMBER',"message","contact","user_id"\]/  s/.*\][ \t]"\(.*\)"$/\1/p' <"$TMP")"
+        ^-- SC2034: CONTACT appears unused. Verify it or export it.
+

The example show two warnings in bashbots scripts. The first is a hint you may use shell substitions instead of sed, this is fixed and much faster as the “echo | sed” solution. The second warning is about an unused variable, this is true because in our examples CONTACT is not used but assigned in case you want to use it :-)

+

Prev Best Practice

+

Next Functions Reference

+


VERSION
v0.70-pre1-7-g02d9afb

+ + diff --git a/html/6_reference.html b/html/6_reference.html new file mode 100644 index 0000000..47af71f --- /dev/null +++ b/html/6_reference.html @@ -0,0 +1,334 @@ + + + + + + + Bashobot Documentation - 6_reference.html + + + + + +

Home

+

Bashbot function reference

+

Send, forward, delete messages

+
send_action
+

send_action shows users what your bot is currently doing.

+

usage: send_action “${CHAT[ID]}” “action”

+

“action”: typing, upload_photo, record_video, upload_video, record_audio, upload_audio, upload_document, find_location.

+

example:

+
send_action "${CHAT[ID]}" "typing"
+send_action "${CHAT[ID]}" "record_audio"
+
send_normal_message
+

send_normal_message sends text only messages to the given chat.

+

usage: send_normal_message “${CHAT[ID]}” “message”

+

example:

+
send_normal_message "${CHAT[ID]}" "this is a text message"
+
send_markdown_message
+

send_markdown_message sends markdown style messages to the given chat. Telegram supports a reduced set of Markdown only

+

usage: send_markdown_message “${CHAT[ID]}” “markdown message”

+

example:

+
send_markdown_message "${CHAT[ID]}" "this is a markdown  message, next word is *bold*"
+send_markdown_message "${CHAT[ID]}" "*bold* _italic_ [text](link)"
+
send_html_message
+

send_html_message sends HTML style messages to the given chat. Telegram supports a reduced set of HTML only

+

usage: send_html_message “${CHAT[ID]}” “html message”

+

example:

+
send_normal_message "${CHAT[ID]}" "this is a markdown  message, next word is <b>bold</b>"
+send_normal_message "${CHAT[ID]}" "<b>bold</b> <i>italic><i> <em>italic>/em> <a href="link">Text</a>"
+
forward_message
+

forward_mesage forwards a messsage to the given chat.

+

usage: forward_message “chat_to” “chat_from” “${MESSAGE[ID]}”

+

old call: forward “${CHAT[ID]}" "$FROMCHAT” “${MESSAGE[ID]}”

+

See also Text formating options

+
+
delete_message
+

If your Bot is admin of a Chat he can delete every message, if not he can delete only his messages.

+

usage: delete_message “${CHAT[ID]}" "${MESSAGE[ID]}”

+

See also deleteMessage limitations

+
+
answer_inline_query
+

Inline Queries allows users to interact with your bot directly without sending extra commands. answer_inline_query provide the result to a users Inline Query

+

usage: answer_inline_query “$iQUERY_ID” “type” “type arg 1” … “type arg n”

+

example: - see Advanced Usage

+
+

File, Location, Venue, Keyboard

+
send_file
+

send_file allows you to send different type’s of files, e.g. photos, stickers, audio, media, etc. see more

+

usage: send_file “${CHAT[ID]}” “file” “caption”

+

example:

+
send_file "${CHAT[ID]}" "/home/user/doge.jpg" "Lool"
+send_file "${CHAT[ID]}" "https://www.domain,com/something.gif" "Something"
+
send_location
+

usage: send_location “${CHAT[ID]}” “Latitude” “Longitude”

+
send_venue
+

usage: send_venue “${CHAT[ID]}” “Latitude” “Longitude” “Title” “Address” “foursquare id (optional)”

+
+
send_keyboard
+

Note: since version 0.6 send_keyboard was changed to use native “JSON Array” notation as used from Telegram. Example Keybord Array definitions:

+
    +
  • yes no in two rows: +
      +
    • OLD format: ‘yes’ ‘no’ (two strings)
    • +
    • NEW format: ‘[ “yes” ] , [ “no” ]’ (two arrays with a string)
    • +
  • +
  • new layouts made easy with NEW format: +
      +
    • Yes No in one row: ‘[ “yes” , “no” ]’
    • +
    • Yes No plus Maybe in 2.row: ‘[ “yes” , “no” ] , [ “maybe” ]’
    • +
    • numpad style keyboard: ‘[ “1” , “2” , “3” ] , [ “4” , “5” , “6” ] , [ “7” , “8” , “9” ] , [ “0” ]’
    • +
  • +
+

usage: send_keyboard “chat-id” “message” “keyboard”

+

example:

+
send_keyboard "${CHAT[ID]}" "Say yes or no" "[ \\"yes\" , \\"no\" ]""
+send_keyboard "${CHAT[ID]}" "Say yes or no" "[ \\"yes\\" ] , [ \\"no\\" ]"
+send_keyboard "${CHAT[ID]}" "Enter digit" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \\"4\\" , \\"5\\" , \\"6\\" ] , [ \\"7\\" , \\"8\\" , \\"9\\" ] , [ \\"0\\" ]"
+
remove_keyboard
+

usage: remove_keybord “$CHAT[ID]” “message”

+

See also: Keyboard Markup

+
+
send_button
+

usage: send_button “chat-id” “message” “text” “URL”

+

alias: _button “text” “URL”

+

example:

+
send_button "${CHAT[ID]}" "MAKE MONEY FAST!!!" "Visit my Shop" "https://dealz.rrr.de"
+
send_inline_keyboard
+

This allows to place multiple inline buttons in a row. The inline buttons must specified as a JSON array in the following format:

+

[ {"text":"text1", "url":"url1"}, ... {"text":"textN", "url":"urlN"} ]

+

Each button consists of a pair of text and URL values, sourrounded by ‘{ }’, multiple buttons are seperated by ‘,’ and everthing is wrapped in ‘[ ]’.

+

usage: send_inline_keyboard “chat-id” “message” “[ {“text”:“text”, “url”:“url”} …]”

+

alias: _inline_keyboard “[{“text”:“text”, “url”:“url”} …]”

+

example:

+
send_inline_keyboard "${CHAT[ID]}" "MAKE MONEY FAST!!!" '[{"text":"Visit my Shop", url"":"https://dealz.rrr.de"}]'
+send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"button 1", url"":"url 1"}, {"text":"button 2", url"":"url 2"} ]'
+send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"b 1", url"":"u 1"}, {"text":"b 2", url"":"u 2"}, {"text":"b 2", url"":"u 2"} ]'
+

See also Inline keyboard markup

+
+

Manage users

+
kick_chat_member
+

If your Bot is a chat admin he can kick and ban a user.

+

usage: kick_chat_member “${CHAT[ID]}" "${USER[ID]}”

+

alias: _kick_user “${USER[ID]}”

+
unban_chat_member
+

If your Bot is a chat admine can unban a kicked user.

+

usage: unban_chat_member “${CHAT[ID]}" "${USER[ID]}”

+

alias: _unban “${USER[ID]}”

+
leave_chat
+

Your Bot will leave the chat.

+

usage: leave_chat “${CHAT[ID]}”

+

alias: _leave

+
if _is_admin ; then 
+ send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
+ leave_chat "${CHAT[ID]}"
+fi
+

’See also kick Chat Member*

+
+

User Access Control

+
user_is_botadmin
+

Return true (0) if user is admin of bot, user id if botadmin is read from file ‘./botadmin’.

+

usage: user_is_botadmin “${USER[ID]}”

+

modules/alias: _is_botadmin

+

example:

+
 _is_botadmin && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
+
user_is_creator
+

Return true (0) if user is creator of given chat or chat is a private chat.

+

usage: user_is_creator “${CHAT[ID]}" "${USER[ID]}”

+

modules/alias: _is_creator

+
user_is_admin
+

Return true (0) if user is admin or creator of given chat.

+

usage: user_is_admin “${CHAT[ID]}" "${USER[ID]}”

+

modules/alias: _is_admin

+

example:

+
if _is_admin ; then 
+  send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
+  leave_chat "${CHAT[ID]}"
+fi
+

See also Chat Member

+
user_is_allowed
+

Bahsbot supports User Access Control, see Advanced Usage

+

usage: user_is_allowed “${USER[ID]}" "what" "${CHAT[ID]}”

+

example:

+
if ! user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then
+  send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
+fi
+
+

Aliases - shortcuts for often used funtions

+

You must not disable source modules/aliases.sh in ‘commands.sh’ to have the following functions availible.

+
_is_botadmin
+

usage: _is_botadmin

+

alias for: user_is_botadmin “${USER[ID]}”

+
_is_admin
+

usage: _is_admin

+

alias for: user_is_admin “${CHAT[ID]}" "${USER[ID]}”

+
_is_allowed
+

usage: _is_allowed “what”

+

alias for: user_is_allowed “${USER[ID]}" "what" "${CHAT[ID]}”

+
+
_kick_user
+

usage: _kick_user “${USER[ID]}”

+

alias for: kick_chat_member “${CHAT[ID]}" "${USER[ID]}”

+
_unban
+

usage: _unban “${USER[ID]}”

+

alias for: unban_chat_member “${CHAT[ID]}" "${USER[ID]}”

+
_leave
+

usage: _leave

+

alias for: leave_chat “${CHAT[ID]}”

+
+
_message
+

usage: _message “message”

+

alias for: send_normal_message “${CHAT[ID]}” “message”

+
_normal_message
+

usage: _normal_message “message”

+

alias for: send_normal_message “${CHAT[ID]}” “message”

+
_html_message
+

usage: _html_message “message”

+

alias for: send_html_message “${CHAT[ID]}” “message”

+
_markdown_message
+

usage: _markdown_message “message”

+

alias for: send_markdown_message “${CHAT[ID]}” “message”

+
+

Interactive and backgound jobs

+

You must not disable source modules/background.sh in ‘commands.sh’ to have the following functions availible.

+
startproc
+

startproc starts a script, the output of the script is sent to the user or chat, user input will be sent back to the script. see Advanced Usage

+

usage: startproc “script”

+

example:

+
startproc 'examples/calc.sh'
+
checkproc
+

Return true (0) if an interactive script is running in the chat.

+

usage: checkprog

+

example:

+
checkproc 
+if [ "$res" -gt 0 ] ; then
+  startproc "examples/calc.sh"
+else
+   send_normal_message "${CHAT[ID]}" "Calc already running ..."
+fi
+
killproc
+

Kill the interactive script running in the chat

+

usage: killproc

+

example:

+
checkprog
+if [ "$res" -eq 0 ]; then
+  killproc && send_message "${CHAT[ID]}" "Command canceled."
+else
+  send_message "${CHAT[ID]}" "Command is not running."
+fi
+
+
background
+

Starts a script as a background job and attaches a jobname to it. All output from a background job is sent to the associated chat.

+

In contrast to interactive chats, background jobs do not recieve user input and can run forever. In addition you can suspend and restart running jobs, e.g. after reboot.

+

usage: background “script” “jobname”

+

example:

+
background "examples/notify.sh" "notify"
+
checkback
+

Return true (0) if an background job is active in the given chat.

+

usage: checkback “jobname”

+

example:

+
checkback "notify"
+if [ "$res" -gt 0 ] ; then
+  send_normal_message "${CHAT[ID]}" "Start notify"
+  background "examples/notify.sh" "notify"
+else
+ send_normal_message "${CHAT[ID]}" "Process notify already running."
+fi
+
killback
+

usage: killback “jobname”

+

example:

+
checkback "notify"
+if [ "$res" -eq 0 ] ; then
+  send_normal_message "${CHAT[ID]}" "Kill notify"
+  killback "notify"
+else
+  send_normal_message "${CHAT[ID]}" "Process notify not run."
+fi
+
+
send_message
+

send_message sends any type of message to the given chat. Type of output is steered by keywords within the message.

+

The main use case for send_message is to process the output of interactive chats and background jobs. For regular Bot commands I recommend using of the dedicated send_xxx_message() functions from above.

+

usage: send_message “${CHAT[ID]}” “message”

+

example: - see Usage and Advanced Usage

+
+

Helper functions

+
_is_function Returns true if the given function exist, can be used to check if a module is loaded.
+

usage _is_function function

+

example:

+
_is_function "background" && _message "you can run background jobs!"
+
+

Bashbot internal functions

+

These functions are for internal use only and must not used in your bot commands.

+
get_file
+

usage: url=“$(get_file "${CHAT[ID]}” “message”)"

+
+
send_text
+

usage: send_text “${CHAT[ID]}” “message”

+
+
JsonDecode
+

Outputs decoded string to STDOUT

+

usage: JsonDecode “string”

+
JsonGetString
+

Reads JSON fro STDIN and Outputs found String to STDOUT

+

usage: JsonGetString "path","to","string"

+
JsonGetValue
+

Reads JSON fro STDIN and Outputs found Value to STDOUT

+

usage: JsonGetValue "path","to","value"

+
+
get_chat_member_status
+

usage: get_chat_member_status “${CHAT[ID]}" "${USER[ID]}”

+

this may get an official function …

+
+
process_client
+

Every Message sent to your Bot is processd by this function. It parse the send JSON and assign the found Values to bash variables.

+
process_updates
+

If new updates are availible, this functions gets the JSON from Telegram and dispatch it.

+
+
getBotName
+

The name of your bot is availible as bash variable “$ME”, there is no need to call this function if Bot is running.

+

usage: ME=“$(getBotNiname)”

+
inproc
+

Send Input from Telegram to waiting Interactive Chat.

+

Prev Best Practice

+

Next Notes for Developers

+


VERSION
v0.70-pre1-7-g02d9afb

+ + diff --git a/html/7_develop.html b/html/7_develop.html new file mode 100644 index 0000000..e818afe --- /dev/null +++ b/html/7_develop.html @@ -0,0 +1,113 @@ + + + + + + + Bashobot Documentation - 7_develop.html + + + + + +

Home

+

Notes for bashbot developers

+

This section is about help and best practices for new bashbot developers. The main focus on is creating new versions of bashbot, not on develop your individual bot. Nevertheless the rules and tools described here can also help you with your bot development.

+

bashbot development is done on github. If you want to provide fixes or new features fork bashbot on githup and provide changes as pull request on github.

+

Setup your develop environment

+
    +
  1. install git, install shellcheck
  2. +
  3. setup your environment for UTF-8
  4. +
  5. clone your bashbot fork to a new directory git clone https://github.com/<YOURNAME>/telegram-bot-bash.git, replace <YOURNAME> with your username on github
  6. +
  7. create and change to your develop branch git checkout -b <YOURBRANCH>, replace <YOURBRANCH> with the name you want to name it, e.g. ‘develop’
  8. +
  9. give your (dev) fork a new version tag: git tag vx.xx, version must be higher than current version
  10. +
  11. setup github hooks by running dev/install-hooks.sh (optional)
  12. +
+

Test, Add, Push changes

+

A typical bashbot develop loop looks as follow:

+
    +
  1. start developing - change, copy, edit bashbot files …
  2. +
  3. after changing a bash sript: shellcheck -x scipt.sh
  4. +
  5. dev/all-tests.sh - in case if errors back to 2.
  6. +
  7. dev/git-add.sh - check for changed files, update version string, run git add
  8. +
  9. git commit' -m "COMMIT MESSAGE"; git push
  10. +
+

If you setup iyou dev environment with hooks and use the scripts above, versioning, addding and testing is done automatically.

+

Prepare a new version

+

After some development it may time to create a new version for the users. a new version can be in sub version upgrade, e.g. for fixes and smaller additions or a new release version for new features. To mark a new version use git tag NEWVERSION and run dev/version.sh to update all version strings.

+

Usually I start with pre versions and when everything looks good I push out a release candidate (rc) and finally the new version.

+
 v0.x-devx -> v0.x-prex -> v0.x-rc -> v0.x  ... 0.x+1-dev ...
+

Versioning

+

Bashbot is tagged with version numbers. If you start a new development cycle you must tag your fork with a version higher than the current version. E.g. if you fork ‘v0.60’ the next develop version should tagged as git tag "v0.61-dev" for fixes or git tag "v0.70-dev" for new features.

+

To get the current version name of your develepment fork run git describe --tags. The output looks like v0.70-dev-6-g3fb7796 where your version tag is followed by the number of commits since you tag your branch and followed by the latest commit hash. see also comments in version.sh

+

To update the Version Number in your scripts run dev/version.sh, it will update the line ‘####
VERSION
###’ in all files to the current version name.

+

Shellchecking

+

For a shell script running as a service it’s important to be paranoid about quoting, globbing and other common problems. So it’s a must to run shellchek on all shell scripts before you commit a change. this is automated by a git hook activated in Setup step 6.

+

In addition you can run dev/hooks/pre-commit.sh every time you want to shellcheck all files given in ‘dev/shellcheck.files’.

+

bashbot tests

+

Starting with version 0.70 bashbot has a test suite. To start testsuite run dev/all-tests.sh. all-tests.sh will return ‘SUCCESS’ only if all tests pass.

+

enabling / disabling tests

+

All tests are placed in the directory test. To disable a test remove the x flag from the ’*-test.sh’ test script, to (re)enable a test make the script executable again.

+

creating new tests

+

To create a new test run test/ADD-test-new.sh and answer the questions, afterwards you have the following described files and dirs:

+

Each test consists of a script script named like p-name-test.sh (where p is test pass ‘a-z’ and name the name of your test) and an optional dir p-name-test/ (script name minus ‘.sh’) for additional files.

+

The file ALL-tests.inc.sh must be included from all tests, do not forget the shellcheck source directive to statisfy shellcheck.

+

Tests with no dependency to other tests will run in pass ‘a’, tests which need an initialized bahsbot environment must run in pass ‘d’ or later. If ‘$1’ is present the script is started from ‘ALL-tests.sh’ and a temporary test environment is setup in directory ‘$1’. The temporary test environment is created when ‘ALL-tests.sh’ starts and deleted after all tests are finished.

+

Example test

+
#!/usr/bin/env bash
+# file: b-example-test.sh
+
+# include common functions and definitions
+# shellcheck source=test/ALL-tests.inc.sh
+source "./ALL-tests.inc.sh"
+
+if [ -f "bashbot.sh" ]; then
+    echo "${SUCCESS} bashbot.sh exist!"
+    exit 0
+else
+    echo "${NOSUCCESS} bashbot.sh missing!"
+    exit 1
+fi
+

Prev Function Reference

+

Next Bashbot Environment

+


VERSION
v0.70-pre1-7-g02d9afb

+ + diff --git a/html/8_custom.html b/html/8_custom.html new file mode 100644 index 0000000..9f0824e --- /dev/null +++ b/html/8_custom.html @@ -0,0 +1,130 @@ + + + + + + + Bashobot Documentation - 8_custom.html + + + + + +

Home

+

Customize bashbots environment

+

This section describe how you can customize bashbot to your needs by setting environment variables.

+

Change file locations

+

In standard setup bashbot is self containing, this means you can place ‘telegram-bot-bash’ any location and run it from there. All files - programm, config, data etc - will reside in ‘telegram-bot-bash’.

+

If you want to have other locations for config, data etc, define and export the following environment variables. Note: all specified directories and files must exist or running ‘bashbot.sh’ will fail.

+

BASHBOT_ETC

+

Location of the files commands.sh, mycommands.sh, token, botadmin, botacl

+
  unset  BASHBOT_ETC     # keep in telegram-bot-bash (default)
+  export BASHBOT_ETC ""  # keep in telegram-bot-bash
+
+  export BASHBOT_ETC "/etc/bashbot"  # unix like config location
+
+  export BASHBOT_ETC "/etc/bashbot/bot1"  # multibot configuration bot 1
+  export BASHBOT_ETC "/etc/bashbot/bot2"  # multibot configuration bot 2
+

e.g. /etc/bashbot

+

BASHBOT_VAR

+

Location of runtime data data-bot-bash, count

+
  unset  BASHBOT_VAR     # keep in telegram-bot-bash (default)
+  export BASHBOT_VAR ""  # keep in telegram-bot-bash
+
+  export BASHBOT_VAR "/var/spool/bashbot"  # unix like config location
+
+  export BASHBOT_VAR "/var/spool/bashbot/bot1"  # multibot configuration bot 1
+  export BASHBOT_VAR "/var/spool/bashbot/bot2"  # multibot configuration bot 2
+

BASHBOT_JSONSH

+

Full path to JSON.sh script, default: ‘./JSON.sh/JSON.sh’, must end with ‘/JSON.sh’.

+
  unset  BASHBOT_JSONSH     # telegram-bot-bash/JSON.sh/JSON.sh (default)
+  export BASHBOT_JSONSH ""  # telegram-bot-bash/JSON.sh/JSON.sh
+
+  export BASHBOT_JSONSH "/usr/local/bin/JSON.sh"  # installed in /usr/local/bin
+

Change config values

+

BASHBOT_DECODE

+

Bashbot offers two variants for decoding JSON UTF format to UTF-8. By default bashbot uses ‘json.encode’ if python is installed. If ‘BASHBOT_DECODE’ is set to any value (not undefined or not empty) the bash only implementation will be used.

+
  unset  BASHBOT_DECODE       # autodetect python (default)
+  export BASHBOT_DECODE ""    # autodetect python
+
+  export BASHBOT_DECODE "yes" # force internal
+  export BASHBOT_DECODE "no"  # also force internal!
+

BASHBOT_SLEEP

+

Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling. If messages are recieved bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay for every poll until the maximum of BASHBOT_SLEEP ms.

+
  unset  BASHBOT_SLEEP       # 5000ms (default)
+  export BASHBOT_SLEEP ""    # 5000ms 
+
+  export BASHBOT_SLEEP "1000"     # 1s maximum sleep 
+  export BASHBOT_SLEEP "10000"    # 10s maximum sleep
+  export BASHBOT_SLEEP "1"        # values < 1000 disables sleep (not recommended) 
+  
+

Testet configs as of v.07 release

+

Note: Environment variables are not stored, you must setup them before every call to bashbot.sh, e.g. from a script.

+

simple Unix like config, for one bot. bashbot is installed in ‘/usr/local/telegram-bot-bash’

+
  # Note: all dirs and files must exist!
+  export BASHBOT_ETC "/etc/bashbot"
+  export BASHBOT_VAR "/var/spool/bashbot"
+
+  /usr/local/telegram-bot-bash/bashbot.sh start
+

Unix like config for one bot. bashbot.sh is installed in ‘/usr/bin’

+
  # Note: all dirs and files must exist!
+  export BASHBOT_ETC "/etc/bashbot"
+  export BASHBOT_VAR "/var/spool/bashbot"
+  export BASHBOT_JSONSH "/var/spool/bashbot"
+
+  /usr/local/bin/bashbot.sh start
+

simple multibot config, everything is keept inside ‘telegram-bot-bash’ dir

+
  # config for running Bot 1
+  # Note: all dirs and files must exist!
+  export BASHBOT_ETC "./mybot1"
+  export BASHBOT_VAR "./mybot1"
+
+  /usr/local/telegram-bot-bash/bashbot.sh start
+
  # config for running Bot 2
+  # Note: all dirs and files must exist!
+  export BASHBOT_ETC "./mybot2"
+  export BASHBOT_VAR "./mybot2"
+
+  /usr/local/telegram-bot-bash/bashbot.sh start
+

Prev Notes for Developers

+


VERSION
v0.70-pre1-0-g490c472

+ + From 3dfa5e44be57059741c850efc6a34f5cd0476bc3 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 28 Apr 2019 10:33:24 +0200 Subject: [PATCH 56/63] rm html doc from repo, only for dist --- dev/make-dist.sh | 2 +- html/0_install.html | 76 ---------- html/1_firstbot.html | 53 ------- html/2_usage.html | 179 ---------------------- html/3_advanced.html | 161 -------------------- html/4_expert.html | 124 ---------------- html/5_practice.html | 178 ---------------------- html/6_reference.html | 334 ------------------------------------------ html/7_develop.html | 113 -------------- html/8_custom.html | 130 ---------------- 10 files changed, 1 insertion(+), 1349 deletions(-) delete mode 100644 html/0_install.html delete mode 100644 html/1_firstbot.html delete mode 100644 html/2_usage.html delete mode 100644 html/3_advanced.html delete mode 100644 html/4_expert.html delete mode 100644 html/5_practice.html delete mode 100644 html/6_reference.html delete mode 100644 html/7_develop.html delete mode 100644 html/8_custom.html diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 0481060..f35b91c 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-pre1-9-gb831e60 +#### $$VERSION$$ v0.70-pre1-10-g5269b54 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/html/0_install.html b/html/0_install.html deleted file mode 100644 index 3d34bc6..0000000 --- a/html/0_install.html +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - Bashobot Documentation - 0_install.html - - - - -

Home

-

Install bashbot

-
    -
  1. Go to the directory you want to install bashbot, e.g. -
      -
    • your $HOME directory (install and run with your user-ID)
    • -
    • /usr/local if you want to run as service
    • -
  2. -
  3. Download latest release zip from github and extract all files.
  4. -
  5. Change into the directory telegram-bot-bash
  6. -
  7. Create default commands with cp commands.sh.dist commands.sh; cp mycommands.sh.dist mycommands.sh
  8. -
  9. Run ./bashbot.sh init to setup the environment and enter your Bots token given by botfather.
  10. -
-

Now your Bot is ready to start …

-

If you are new to Bot development read Bots: An introduction for developers

-

Install from Github

-

As an alternative to download the zip files, you can clone the github repository to get the latest improvements/fixes.

-
    -
  1. Go to the directory you want to install bashbot, e.g. -
      -
    • your $HOME directory (install and run with your user-ID)
    • -
    • /usr/local if you want to run as service
    • -
  2. -
  3. Run git clone https://github.com/topkecleon/telegram-bot-bash.git
  4. -
  5. Change into the directory telegram-bot-bash
  6. -
  7. Run test/ALL-tests.sh and if everthing finish OK …
  8. -
  9. Run sudo ./bashbot.sh init to setup the environment and enter your Bots token given by botfather.
  10. -
-

Update bashbot

-
    -
  1. Go to the directory where you had installed bashbot, e.g. -
      -
    • your $HOME directory
    • -
    • /usr/local
    • -
  2. -
  3. Download latest release zip from github
  4. -
  5. Extract all files to your existing bashbot dir Note: all files execpt ‘mycommands.sh’ and ‘commands.sh’ may overwritten!
  6. -
  7. Run sudo ./bashbot.sh init to setup your environment after the update
  8. -
-

Notes on Updates

-

Location of tmp / data dir

-

From version 0.70 on the tmp dir is renamed to ‘data-bot-bash’ to reflect the fact that not only temporary files are stored. an existing ‘tmp-bot-bash’ will be automatically renamed after update.

-

From version 0.50 on the temporary files are no more placed in ‘/tmp’. instead a dedicated tmp dir is used.

-

Changes to send_keyboard in v0.6

-

From Version 0.60 on keybord format for send_keyboard and send_message "mykeyboardstartshere ..." was changed. Keybords are now defined in JSON Array notation e.g. “[ \“yes\” , \“no\” ]”. This has the advantage that you can create any type of keyboard supported by Telegram. The old format is supported for backward compatibility, but may fail for corner cases.

-

Example Keyboards:

-
    -
  • yes no in two rows: -
      -
    • OLD format: ‘yes’ ‘no’ (two strings)
    • -
    • NEW format: ‘[ “yes” ] , [ “no” ]’ (two arrays with a string)
    • -
  • -
  • new layouts made easy with NEW format: -
      -
    • Yes No in one row: ‘[ “yes” , “no” ]’
    • -
    • Yes No plus Maybe in 2.row: ‘[ “yes” , “no” ] , [ “maybe” ]’
    • -
    • numpad style keyboard: ‘[ “1” , “2” , “3” ] , [ “4” , “5” , “6” ] , [ “7” , “8” , “9” ] , [ “0” ]’
    • -
  • -
-

Next Create Bot

-


VERSION
v0.70-pre1-2-g293ad08

- - diff --git a/html/1_firstbot.html b/html/1_firstbot.html deleted file mode 100644 index 8ddab68..0000000 --- a/html/1_firstbot.html +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - Bashobot Documentation - 1_firstbot.html - - - - -

Home

-

Create a Telegram Bot with botfather

-

BotFather is the one bot to rule them all. It will help you create new bots and change settings for existing ones. Commands known by Botfather

-

Creating a new Bot

-
    -
  1. Message @botfather https://telegram.me/botfather with the following text: /newbot If you don’t know how to message by username, click the search field on your Telegram app and type @botfather, you should be able to initiate a conversation. Be careful not to send it to the wrong contact, because some users has similar usernames to botfather.
  2. -
-
-botfather initial conversation -

botfather initial conversation

-
-
    -
  1. @botfather replies with Alright, a new bot. How are we going to call it? Please choose a name for your bot.

  2. -
  3. Type whatever name you want for your bot.

  4. -
  5. @botfather replies with Good. Now let's choose a username for your bot. It must end in bot. Like this, for example: TetrisBot or tetris_bot.

  6. -
  7. Type whatever username you want for your bot, minimum 5 characters, and must end with bot. For example: telesample_bot

  8. -
  9. @botfather replies with:

    -

    Done! Congratulations on your new bot. You will find it at telegram.me/telesample_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands.

    -

    Use this token to access the HTTP API: 123456789:AAG90e14-0f8-40183D-18491dDE

    -

    For a description of the Bot API, see this page: https://core.telegram.org/bots/api

  10. -
  11. Note down the ‘token’ mentioned above.

  12. -
  13. Type /setprivacy to @botfather.

  14. -
-
-botfather later conversation -

botfather later conversation

-
-
    -
  1. @botfather replies with Choose a bot to change group messages settings.

  2. -
  3. Type @telesample_bot (change to the username you set at step 5 above, but start it with @)

  4. -
  5. @botfather replies with

    -

    ‘Enable’ - your bot will only receive messages that either start with the ‘/’ symbol or mention the bot by username. ‘Disable’ - your bot will receive all messages that people send to groups. Current status is: ENABLED

  6. -
  7. Type Disable to let your bot receive all messages sent to a group. This step is up to you actually.

  8. -
  9. @botfather replies with Success! The new status is: DISABLED. /help

  10. -
-

Prev Installation

-

Next Getting started

-


VERSION
v0.70-pre1-2-g293ad08

- - diff --git a/html/2_usage.html b/html/2_usage.html deleted file mode 100644 index 3f3579e..0000000 --- a/html/2_usage.html +++ /dev/null @@ -1,179 +0,0 @@ - - - - - - - Bashobot Documentation - 2_usage.html - - - - - -

Home

-

Gettting Started

-

The Bots standard commands are in commands.sh file. You must not add your commands to ‘commands.sh’, instead place them in mycommands.sh, there you also find examples how to process messages and send out text. See Best practices for more information.

-

Once you’re done with editing ‘mycommands.sh’ start the Bot with ./bashbot.sh start. If some thing doesn’t work as it should, debug with bash -x bashbot.sh. To stop the Bot run ./bashbot.sh kill

-

To use the functions provided in this script in other scripts simply source bashbot: source bashbot.sh

-

Have FUN!

-

Managing your own Bot

-

Note: running bashbot as root is highly danger and not recommended. See Expert use.

-

Start / Stop

-

Start or Stop your Bot use the following commands:

-
./bashbot.sh start
-
./bashbot.sh kill
-

User count

-

To count the total number of users that ever used the bot run the following command:

-
./bashbot.sh count
-

Sending broadcasts to all users

-

To send a broadcast to all of users that ever used the bot run the following command:

-
./bashbot.sh broadcast "Hey! I just wanted to let you know that the bot's been updated!"
-

Recieve data

-

Evertime a Message is recieved, you can read incoming data using the following variables:

-
    -
  • ${MESSAGE}: Current message
  • -
  • ${MESSAGE[ID]}: ID of current message
  • -
  • $CAPTION: Captions
  • -
  • $REPLYTO: Original message wich was replied to
  • -
  • $USER: This array contains the First name, last name, username and user id of the sender of the current message. -
      -
    • ${USER[ID]}: User id
    • -
    • ${USER[FIRST_NAME]}: User’s first name
    • -
    • ${USER[LAST_NAME]}: User’s last name
    • -
    • ${USER[USERNAME]}: Username
    • -
  • -
  • $CHAT: This array contains the First name, last name, username, title and user id of the chat of the current message. -
      -
    • ${CHAT[ID]}: Chat id
    • -
    • ${CHAT[FIRST_NAME]}: Chat’s first name
    • -
    • ${CHAT[LAST_NAME]}: Chat’s last name
    • -
    • ${CHAT[USERNAME]}: Username
    • -
    • ${CHAT[TITLE]}: Title
    • -
    • ${CHAT[TYPE]}: Type
    • -
    • ${CHAT[ALL_MEMBERS_ARE_ADMINISTRATORS]}: All members are administrators (true if true)
    • -
  • -
  • $REPLYTO: This array contains the First name, last name, username and user id of the ORIGINAL sender of the message REPLIED to. -
      -
    • ${REPLYTO[ID]}: ID of message wich was replied to
    • -
    • ${REPLYTO[UID]}: Original user’s id
    • -
    • ${REPLYTO[FIRST_NAME]}: Original user’s first name
    • -
    • ${REPLYTO[LAST_NAME]}: Original user’s’ last name
    • -
    • ${REPLYTO[USERNAME]}: Original user’s username
    • -
  • -
  • $FORWARD: This array contains the First name, last name, username and user id of the ORIGINAL sender of the FORWARDED message. -
      -
    • ${FORWARD[ID]}: Same as MESSAGE[ID] if message is forwarded
    • -
    • ${FORWARD[UID]}: Original user’s id
    • -
    • ${FORWARD[FIRST_NAME]}: Original user’s first name
    • -
    • ${FORWARD[LAST_NAME]}: Original user’s’ last name
    • -
    • ${FORWARD[USERNAME]}: Original user’s username
    • -
  • -
  • $URLS: This array contains documents, audio files, voice recordings and stickers as URL. -
      -
    • ${URLS[AUDIO]}: Audio files
    • -
    • ${URLS[VIDEO]}: Videos
    • -
    • ${URLS[PHOTO]}: Photos (maximum quality)
    • -
    • ${URLS[VOICE]}: Voice recordings
    • -
    • ${URLS[STICKER]}: Stickers
    • -
    • ${URLS[DOCUMENT]}: Any other file
    • -
  • -
  • $CONTACT: This array contains info about contacts sent in a chat. -
      -
    • ${CONTACT[ID]}: User id
    • -
    • ${CONTACT[NUMBER]}: Phone number
    • -
    • ${CONTACT[FIRST_NAME]}: First name
    • -
    • ${CONTACT[LAST_NAME]}: Last name
    • -
    • ${CONTACT[VCARD]}: User’s complete Vcard
    • -
  • -
  • $LOCATION: This array contains info about locations sent in a chat. -
      -
    • ${LOCATION[LONGITUDE]}: Longitude
    • -
    • ${LOCATION[LATITUDE]}: Latitude
    • -
  • -
  • $VENUE: This array contains info about venue (a place) sent in a chat. -
      -
    • ${VENUE[TITLE]}: Name of the place
    • -
    • ${VENUE[ADDRESS]}: Address of the place
    • -
    • ${VENUE[LONGITUDE]}: Longitude
    • -
    • ${VENUE[LATITUDE]}: Latitude
    • -
    • ${VENUE[FOURSQUARE]}: Fouresquare ID
    • -
  • -
-

Usage of bashbot functions

-

sending messages

-

To send messages use the send_xxx_message functions.

-

To send regular text without any markdown use:

-
send_text_message "${CHAT[ID]}" "lol"
-

To send text with markdown:

-
send_markdown_message "${CHAT[ID]}" "lol *bold*"
-

To send text with html:

-
send_html_message "${CHAT[ID]}" "lol <b>bold</b>"
-

To forward messages use the forward function:

-
forward "${CHAT[ID]}" "from_chat_id" "message_id"
-

If your Bot is Admin in a Chat you can delete every message, if not you can delete only your messages. To delete a message with a known ${MESSAGE[ID]} you can simple use: ```bash delete_message "${CHAT[ID]}" “${MESSAGE[ID]}” ```

-

send_message

-

In addition there is a universal send_massage function which can output any type of message. This function is used to process output from external scrips like interactive chats or background jobs.
-For safety and performance reasons I recommend to use send_xxxx_message functions above for sending messages

-
send_message "${CHAT[ID]}" "lol"
-

To send html or markdown put the following strings before the text, depending on the parsing mode you want to enable:

-
send_message "${CHAT[ID]}" "markdown_parse_mode lol *bold*"
-
send_message "${CHAT[ID]}" "html_parse_mode lol <b>bold</b>"
-

This function also allows a third parameter that disables additional function parsing (for safety use this when reprinting user input):

-
send_message "${CHAT[ID]}" "lol" "safe"
-

See also Interactive chats

-

Send files, locations, keyboards.

-

To send images, videos, voice files, photos etc. use the send_photo function (remember to change the safety Regex @ line 14 of command.sh to allow sending files only from certain directories):

-
send_file "${CHAT[ID]}" "/home/user/doge.jpg" "Lool"
-

To send custom keyboards use the send_keyboard function:

-
send_keyboard "${CHAT[ID]}" "Text that will appear in chat?" '[ "Yep" , "No" ]' # note the simgle quotes!
-send_keyboard "${CHAT[ID]}" "Text that will appear in chat?" "[ \\"Yep\\" , \\"No\\" ]" # within double quotes you must excape the inside double quots
-

To send locations use the send_location function:

-
send_location "${CHAT[ID]}" "Latitude" "Longitude"
-

To send venues use the send_venue function:

-
send_venue "${CHAT[ID]}" "Latitude" "Longitude" "Title" "Address" "optional foursquare id"
-

To send a chat action use the send_action function. Allowed values: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for locations.

-
send_action "${CHAT[ID]}" "action"
-

See also Bashbot function reference

-

Prev Create Bot

-

Next Advanced Usage

-


VERSION
v0.70-pre1-2-g293ad08

- - diff --git a/html/3_advanced.html b/html/3_advanced.html deleted file mode 100644 index 3a00cee..0000000 --- a/html/3_advanced.html +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - - Bashobot Documentation - 3_advanced.html - - - - - -

Home

-

Advanced Features

-

Access control

-

Bashbot offers functions to check what Telegram capabilities like ‘chat admin’ or ‘chat creator’ the given user has:

-
# return true if user is admin/owner of the bot
-# -> botadmin is stored in file './botadmin'
-user_is_botadmin "user"  
-
-# return true if user is creator or admin of a chat
-user_is_admin "chat" "user"
-
-# return true if user is creator of a chat or it's a one to one chat
-user_is_creator "chat" "user"
-
-# examples:
-user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
-
-user_is_admin "${CHAT[ID]}" "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *CHATADMIN*."
-

In addition you can check individual capabilities of users as you must define in the file ./botacl:

-
# file: botacl
-# a user not listed here, will return false from 'user_is_allowed'
-#
-# Format:
-# user:ressource:chat
-
-# allow user 123456789 access to all resources in all chats
-123456789:*:*
-
-# allow user 12131415 to start bot in all chats
-12131415:start:*
-
-# allow user 987654321 only to start bot in chat 98979695
-987654321:start:98979695
-
-# * are only allowed on the right hand side and not for user!
-# the following exaples are NOT valid!
-*:*:*
-*:start:*
-*:*:98979695
-

You must use the function user_is_allowed to check if a user has the capability to do something. Example: Check if user has capability to start bot.

-
    case "$MESSAGE" in
-        ################################################
-        # GLOBAL commands start here, only edit messages
-        '/start'*)
-            user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
-            if user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then
-                bot_help "${CHAT[ID]}"
-            else
-                send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
-            ;;
-    esac
-

See also Bashbot User Access Control functions

-

Interactive Chats

-

To create interactive chats, write (or edit the ‘exmaples/question.sh’ script) a bash (or C or python) script, make it executable and then use the ‘startproc’ function to start the script. The output of the script will be sent to the user and user input will be sent to the script. To stop the script use the function ‘killprog’

-

The output of the script will be processed by ‘send_messages’ to enable you to not only send text, but also keyboards, files, locations and more. Each newline in the output will start an new message to the user, to have line breaks in your message you can use ‘mynewlinestartshere’.

-

To open up a keyboard in an interactive script, print out the keyboard layout in the following way:

-
echo "Text that will appear in chat? mykeyboardstartshere [ \"Yep, sure\" , \"No, highly unlikely\" ]"
-

Same goes for files:

-
echo "Text that will appear in chat? myfilelocationstartshere /home/user/doge.jpg"
-

And buttons:

-
echo "Text that will appear in chat. mybtextstartshere Klick me myburlstartshere https://dealz.rrr.de"
-

And locations:

-
echo "Text that will appear in chat. mylatstartshere 45 mylongstartshere 45"
-

And venues:

-
echo "Text that will appear in chat. mylatstartshere 45 mylongstartshere 45 mytitlestartshere my home myaddressstartshere Diagon Alley N. 37"
-

You can combine them:

-
echo "Text that will appear in chat? mykeyboardstartshere [ \"Yep, sure\" , \"No, highly unlikely\" ] myfilelocationstartshere /home/user/doge.jpg mylatstartshere 45 mylongstartshere 45"
-

Please note that you can either send a location or a venue, not both. To send a venue add the mytitlestartshere and the myaddressstartshere keywords.

-

New in v0.6: To insert a linebreak in your message you can insert mynewlinestartshere in your echo command:

-
echo "Text that will appear in one message  mynewlinestartshere  with this text on a new line"
-

New in v0.7: In case you must extend a message already containing a location, a file, a keyboard etc., with additionial text simply add mytextstartshere additional text at the end of the string:

-
out="Text that will appear mylatstartshere 45 mylongstartshere 45"
-[[ "$out" != *'in chat'* ]] &&  out="$out mytextstartshere in chat."
-echo "$out"
-

Note: Interactive Chats run independent from main bot and continue running until your script exits or you /cancel if from your Bot.

-

Background Jobs

-

A background job is similar to an interactive chat, but runs in the background and does only output massages and does not get user input. In contrast to interactive chats it’s possible to run multiple background jobs. To create a background job write a script or edit ‘examples/notify.sh’ script and use the funtion background to start it:

-
background "examples/notify.sh" "jobname"
-

All output of the script will be sent to the user, to stop a background job use:

-
killback "jobname"
-

You can also suspend and resume the last running background jobs from outside bashbot, e.g. in your startup schripts:

-
./bashbot.sh suspendback
-./bashbot.sh resumeback
-

If you want to kill all background jobs permantly run:

-
./bashbot.sh killback
-

Note: Background Jobs run independent from main bot and continue running until your script exits or you stop if from your Bot. Backgound Jobs will continue running if your Bot is stopeda and must be terminated, e.g. by bashbot.sh killback

-

Inline queries

-

The following commands allows users to interact with your bot via inline queries. In order to enable inline mode, send /setinline command to [@BotFather](https://telegram.me/botfather) and provide the placeholder text that the user will see in the input field after typing your bot’s name. Also, edit line 12 from commands.sh putting a “1”. Note that you can’t modify the first two parameters of the function answer_inline_query, only the ones after them.

-

To send messsages or links through an inline query:

-
answer_inline_query "$iQUERY_ID" "article" "Title of the result" "Content of the message to be sent"
-

To send photos in jpeg format and less than 5MB, from a website through an inline query:

-
answer_inline_query "$iQUERY_ID" "photo" "A valid URL of the photo" "URL of the thumbnail"
-

To send standard gifs from a website (less than 1MB) through an inline query:

-
answer_inline_query "$iQUERY_ID" "gif" "gif url"
-

To send mpeg4 gifs from a website (less than 1MB) through an inline query:

-
answer_inline_query "$iQUERY_ID" "mpeg4_gif" "mpeg4 gif url"
-

To send videos from a website through an inline query:

-
answer_inline_query "$iQUERY_ID" "video" "valid video url" "Select one mime type: text/html or video/mp4" "URL of the thumbnail" "Title for the result"
-

To send photos stored in Telegram servers through an inline query:

-
answer_inline_query "$iQUERY_ID" "cached_photo" "identifier for the photo"
-

To send gifs stored in Telegram servers through an inline query:

-
answer_inline_query "$iQUERY_ID" "cached_gif" "identifier for the gif"
-

To send mpeg4 gifs stored in Telegram servers through an inline query:

-
answer_inline_query "$iQUERY_ID" "cached_mpeg4_gif" "identifier for the gif"
-

To send stickers through an inline query:

-
answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker"
-

Prev Getting started

-

Next Expert Use

-


VERSION
v0.70-pre1-8-gfcca139

- - diff --git a/html/4_expert.html b/html/4_expert.html deleted file mode 100644 index 734ec37..0000000 --- a/html/4_expert.html +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - Bashobot Documentation - 4_expert.html - - - - - -

Home

-

Expert Use

-

Handling UTF-8 character sets

-

UTF-8 is a variable length encoding of Unicode. UTF-8 is recommended as the default encoding in JSON, XML and HTML, also Telegram make use of it.

-

The first 128 characters are regular ASCII, so it’s a superset of and compatible with ASCII environments. The next 1,920 characters need two bytes for encoding and covers almost all Latin alphabets, also Greek, Cyrillic, Hebrew, Arabic and more. See Wikipedia for more details.

-

Setting up your Environment

-

In general bash and GNU utitities are UTF-8 aware if you to setup your environment and your scripts accordingly:

-
    -
  1. Your Terminal and Editor must support UTF-8: Set Terminal and Editor locale to UTF-8, eg. in Settings/Configuration select UTF-8 (Unicode) as Charset.

  2. -
  3. Set Shell environment to UTF-8 in your .profile and your scripts. The usual settings are:

  4. -
-
export 'LC_ALL=C.UTF-8'
-export 'LANG=C.UTF-8'
-export 'LANGUAGE=C.UTF-8'
-

If you use other languages, eg. german or US english, change the shell settings to:

-
export 'LC_ALL=de_DE.UTF-8'
-export 'LANG=de_DE.UTF-8'
-export 'LANGUAGE=de_DE.UTF-8'
-
export 'LC_ALL=en_US.UTF-8'
-export 'LANG=de_en_US.UTF-8'
-export 'LANGUAGE=den_US.UTF-8'
-
    -
  1. make shure your bot scripts use the correct settings, eg. include the lines above at the beginning of your scripts
  2. -
-

To display all availible locales on your system run locale -a | more. Gentoo Wiki

-

Bashbot UTF-8 Support

-

Bashbot handles all messages transparently, regardless of the charset in use. The only exception is when converting from JSON data to strings.

-

Telegram use JSON to send / recieve data. JSON encodes strings as follow: Characters not ASCII (>127) are escaped as sequences of \uxxxx to be regular ASCII. In addition multibyte characters, e.g. Emoticons or Arabic characters, are send in double byte UTF-16 notation. The Emoticons 😁 😘 ❤️ 😊 👍 are encoded as: \uD83D\uDE01 \uD83D\uDE18 \u2764\uFE0F \uD83D\uDE0A \uD83D\uDC4D

-

This “mixed” JSON encoding needs special handling and can not decoded from echo -e or printf '%s\\n'

-

Most complete support for decoding of multibyte characters can only be provided if python is installed on your system. Without phyton bashbot falls back to an internal, pure bash implementation which may not work for some corner cases.

-

Run as other user or system service

-

Bashbot is desingned to run manually by the user who installed it. Nevertheless it’s possible to run it by an other user-ID, as a system service or sceduled from cron. This is onyl recommended for experiend linux users.

-

Setup the environment for the user you want to run bashbot and enter desired username, e.g. nobody :

-
sudo ./bashbot.sh init
-

Edit the file bashbot.rc and edit the following lines to fit your configuration:

-
#######################
-# Configuration Section
-
-# edit the next line to fit the user you want to run bashbot, e.g. nobody:
-runas="nobody" 
-
-# uncomment one of the following lines 
-# runcmd="su $runas -s /bin/bash -c "      # runasuser with su
-# runcmd="runuser $runas -s /bin/bash -c " # runasuser with runuser
-
-# edit the values of the following lines to fit your config:
-start="/usr/local/telegram-bot-bash/bashbot.sh" # location of your bashbot.sh script
-name=''   # your bot name as given to botfather, e.g. mysomething_bot
-
-# END Configuration
-#######################
-

From now on use ‘bashbot.rc’ to manage your bot:

-
sudo ./bashbot.rc start
-

Type ps -ef | grep bashbot to verify your Bot is running as the desired user.

-

If your Bot is started by ‘bashbot.rc’, you must use ‘bashbot.rc’ also to manage your Bot! The following commands are availible:

-
sudo ./bashbot.rc start
-sudo ./bashbot.rc stop
-sudo ./bashbot.rc status
-sudo ./bashbot.rc suspendback
-sudo ./bashbot.rc resumeback
-sudo ./bashbot.rc killback
-

To change back the environment to your user-ID run sudo ./bashbot.sh init again and enter your user name.

-

To use bashbot as a system servive include a working bashbot.rc in your init system (systemd, /etc/init.d).

-

Scedule bashbot from Cron

-

An example crontab is provided in examples/bashbot.cron.

-
    -
  • If you are running bashbot with your user-ID, copy the examples lines to your crontab and remove username nobody.
  • -
  • if you run bashbot as an other user or a system service edit examples/bashbot.cron to fit your needs and replace usernamenobody with the username you want to run bashbot. copy the modified file to /etc/cron.d/bashbot
  • -
-

Prev Expert Use

-

Next Best Practice

-


VERSION
v0.70-pre1-0-g490c472

- - diff --git a/html/5_practice.html b/html/5_practice.html deleted file mode 100644 index 077c480..0000000 --- a/html/5_practice.html +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - - Bashobot Documentation - 5_practice.html - - - - - -

Home

-

Best Practices

-

New to bot development?

-

If you are new to Bot development read Bots: An introduction for developers and consult Telegram Bot API Documentation.

-

In addition you should know about BotFather, the one bot to rule them all. It will help you create new bots and change settings for existing ones. Commands known by Botfather

-

If you dont’t have a github account, it may time to sepup a free account now

-

Add commands to mycommands.sh only

-

To ease updates never change bashbot.sh, instead your commands and functions must go to mycommands.sh . Insert your Bot commands in the case ... esac block of the ‘mycommands()’ function:

-
# file: mycommands.sh
-# your additional bahsbot commands
-
-# uncomment the following lines to overwrite info and help messages
- bashbot_info='This is *MY* variant of _bashbot_, the Telegram bot written entirely in bash.
-'
-
- bashbot_help='*Available commands*:
-/echo message - _echo the given messsage_
-'
-
-# NOTE: command can have @botname attached, you must add * in case tests... 
-mycommands() {
-
-    case "$MESSAGE" in
-        '/echo'*) # example echo command
-            send_normal_message "${CHAT[ID]}" "$MESSAGE"
-            ;;
-        # .....
-    esac
-}
-

Reuse or disable global commands

-

If you want to disable or reuse a global bashbot command comment it out in ‘commands.sh’ by placing a ‘#’ in front of every line from '/command') to ;;.

-

Learn more about Bot commands.

-

Note: Never disable the catchall command *) in ‘commands.sh’!!

-
# file: commands.sh
-
-    case "$MESSAGE" in
-        ################################################
-        # GLOBAL commands start here, edit messages only
-
-        #'/start'*)
-        #   send_action "${CHAT[ID]}" "typing"
-        #   _is_botadmin && _markdown_message "You are *BOTADMIN*."
-        #   if _is_allowed "start" ; then
-        #       _markdown_message "${bot_help}"
-        #   else
-        #       _message "You are not allowed to start Bot."
-        #   fi
-        #   ;;
-
-        *)  # forward other messages to optional dispatcher
-            _is_function startproc && if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi # interactive running
-            _is_function mycommands && mycommands
-            ;;
-    esac
-

Seperate logic from commands

-

If a command need more than 2-3 lines of code, you should use a function to seperate logic from command. Place your functions in mycommands.sh and call the from your command. Example:

-
# file: mycommands.sh
-# your additional bahsbot commands
-
-mycommands() {
-
-    case "$MESSAGE" in
-        '/process'*) # logic for /process is done in process_message 
-            result="$(process_message "$MESSAGE")"
-            send_normal_message "${CHAT[ID]}" "$result" 
-            ;;
-    esac
-
-}
-
-# place your functions here
-
-process_message() {
-   local ARGS="${1#/* }"    # remove command 
-   local TEXT OUTPUT=""
-
-   # process every word in MESSAGE, avoid globbing
-   set -f
-   for WORD in $ARGS
-   do
-    # process links 
-    if [[ "$WORD" == "https://"* ]]; then
-        REPORT="$(dosomething_with_link "$WORD")"
-    # no link, add as text
-    else
-        TEXT="$(echo "${TEXT} $WORD")"
-        continue
-    fi
-    # compose result
-    OUTPUT="* ${REPORT} ${WORD} ${TEXT}"
-    TEXT=""
-   done
-
-   # return result, reset globbing in case we had no ARGS
-   echo "${OUTPUT}${TEXT}"
-}
-

Test your Bot with shellcheck

-

Shellcheck is a static linter for shell scripts providing excellent tips and hints for shell coding pittfalls. You can use it online or install it on your system. All bashbot scripts are linted by shellcheck.

-

Shellcheck examples:

-
$ shellcheck -x mybotcommands.inc.sh
- 
-Line 17:
-                TEXT="$(echo "${TEXT} $WORD")"
-                      ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
- 
-

As you can see my mybotcommands.inc.sh contains an useless echo command in ‘TEXT=’ assigment and can be replaced by TEXT="${TEXT}${WORD}"

-
$ shellcheck -x examples/notify
-OK
-$ shellcheck -x examples/question
-OK
-$ shellcheck -x commands.sh
-OK
-$ shellcheck -x bashbot.sh
-
-In bashbot.sh line 123:
-                text="$(echo "$text" | sed 's/ mynewlinestartshere /\r\n/g')" # hack for linebreaks in startproc scripts
-                        ^-- SC2001: See if you can use ${variable//search/replace} instead.
-
-
-In bashbot.sh line 490:
-        CONTACT[USER_ID]="$(sed -n -e '/\["result",'$PROCESS_NUMBER',"message","contact","user_id"\]/  s/.*\][ \t]"\(.*\)"$/\1/p' <"$TMP")"
-        ^-- SC2034: CONTACT appears unused. Verify it or export it.
-

The example show two warnings in bashbots scripts. The first is a hint you may use shell substitions instead of sed, this is fixed and much faster as the “echo | sed” solution. The second warning is about an unused variable, this is true because in our examples CONTACT is not used but assigned in case you want to use it :-)

-

Prev Best Practice

-

Next Functions Reference

-


VERSION
v0.70-pre1-7-g02d9afb

- - diff --git a/html/6_reference.html b/html/6_reference.html deleted file mode 100644 index 47af71f..0000000 --- a/html/6_reference.html +++ /dev/null @@ -1,334 +0,0 @@ - - - - - - - Bashobot Documentation - 6_reference.html - - - - - -

Home

-

Bashbot function reference

-

Send, forward, delete messages

-
send_action
-

send_action shows users what your bot is currently doing.

-

usage: send_action “${CHAT[ID]}” “action”

-

“action”: typing, upload_photo, record_video, upload_video, record_audio, upload_audio, upload_document, find_location.

-

example:

-
send_action "${CHAT[ID]}" "typing"
-send_action "${CHAT[ID]}" "record_audio"
-
send_normal_message
-

send_normal_message sends text only messages to the given chat.

-

usage: send_normal_message “${CHAT[ID]}” “message”

-

example:

-
send_normal_message "${CHAT[ID]}" "this is a text message"
-
send_markdown_message
-

send_markdown_message sends markdown style messages to the given chat. Telegram supports a reduced set of Markdown only

-

usage: send_markdown_message “${CHAT[ID]}” “markdown message”

-

example:

-
send_markdown_message "${CHAT[ID]}" "this is a markdown  message, next word is *bold*"
-send_markdown_message "${CHAT[ID]}" "*bold* _italic_ [text](link)"
-
send_html_message
-

send_html_message sends HTML style messages to the given chat. Telegram supports a reduced set of HTML only

-

usage: send_html_message “${CHAT[ID]}” “html message”

-

example:

-
send_normal_message "${CHAT[ID]}" "this is a markdown  message, next word is <b>bold</b>"
-send_normal_message "${CHAT[ID]}" "<b>bold</b> <i>italic><i> <em>italic>/em> <a href="link">Text</a>"
-
forward_message
-

forward_mesage forwards a messsage to the given chat.

-

usage: forward_message “chat_to” “chat_from” “${MESSAGE[ID]}”

-

old call: forward “${CHAT[ID]}" "$FROMCHAT” “${MESSAGE[ID]}”

-

See also Text formating options

-
-
delete_message
-

If your Bot is admin of a Chat he can delete every message, if not he can delete only his messages.

-

usage: delete_message “${CHAT[ID]}" "${MESSAGE[ID]}”

-

See also deleteMessage limitations

-
-
answer_inline_query
-

Inline Queries allows users to interact with your bot directly without sending extra commands. answer_inline_query provide the result to a users Inline Query

-

usage: answer_inline_query “$iQUERY_ID” “type” “type arg 1” … “type arg n”

-

example: - see Advanced Usage

-
-

File, Location, Venue, Keyboard

-
send_file
-

send_file allows you to send different type’s of files, e.g. photos, stickers, audio, media, etc. see more

-

usage: send_file “${CHAT[ID]}” “file” “caption”

-

example:

-
send_file "${CHAT[ID]}" "/home/user/doge.jpg" "Lool"
-send_file "${CHAT[ID]}" "https://www.domain,com/something.gif" "Something"
-
send_location
-

usage: send_location “${CHAT[ID]}” “Latitude” “Longitude”

-
send_venue
-

usage: send_venue “${CHAT[ID]}” “Latitude” “Longitude” “Title” “Address” “foursquare id (optional)”

-
-
send_keyboard
-

Note: since version 0.6 send_keyboard was changed to use native “JSON Array” notation as used from Telegram. Example Keybord Array definitions:

-
    -
  • yes no in two rows: -
      -
    • OLD format: ‘yes’ ‘no’ (two strings)
    • -
    • NEW format: ‘[ “yes” ] , [ “no” ]’ (two arrays with a string)
    • -
  • -
  • new layouts made easy with NEW format: -
      -
    • Yes No in one row: ‘[ “yes” , “no” ]’
    • -
    • Yes No plus Maybe in 2.row: ‘[ “yes” , “no” ] , [ “maybe” ]’
    • -
    • numpad style keyboard: ‘[ “1” , “2” , “3” ] , [ “4” , “5” , “6” ] , [ “7” , “8” , “9” ] , [ “0” ]’
    • -
  • -
-

usage: send_keyboard “chat-id” “message” “keyboard”

-

example:

-
send_keyboard "${CHAT[ID]}" "Say yes or no" "[ \\"yes\" , \\"no\" ]""
-send_keyboard "${CHAT[ID]}" "Say yes or no" "[ \\"yes\\" ] , [ \\"no\\" ]"
-send_keyboard "${CHAT[ID]}" "Enter digit" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \\"4\\" , \\"5\\" , \\"6\\" ] , [ \\"7\\" , \\"8\\" , \\"9\\" ] , [ \\"0\\" ]"
-
remove_keyboard
-

usage: remove_keybord “$CHAT[ID]” “message”

-

See also: Keyboard Markup

-
-
send_button
-

usage: send_button “chat-id” “message” “text” “URL”

-

alias: _button “text” “URL”

-

example:

-
send_button "${CHAT[ID]}" "MAKE MONEY FAST!!!" "Visit my Shop" "https://dealz.rrr.de"
-
send_inline_keyboard
-

This allows to place multiple inline buttons in a row. The inline buttons must specified as a JSON array in the following format:

-

[ {"text":"text1", "url":"url1"}, ... {"text":"textN", "url":"urlN"} ]

-

Each button consists of a pair of text and URL values, sourrounded by ‘{ }’, multiple buttons are seperated by ‘,’ and everthing is wrapped in ‘[ ]’.

-

usage: send_inline_keyboard “chat-id” “message” “[ {“text”:“text”, “url”:“url”} …]”

-

alias: _inline_keyboard “[{“text”:“text”, “url”:“url”} …]”

-

example:

-
send_inline_keyboard "${CHAT[ID]}" "MAKE MONEY FAST!!!" '[{"text":"Visit my Shop", url"":"https://dealz.rrr.de"}]'
-send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"button 1", url"":"url 1"}, {"text":"button 2", url"":"url 2"} ]'
-send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"b 1", url"":"u 1"}, {"text":"b 2", url"":"u 2"}, {"text":"b 2", url"":"u 2"} ]'
-

See also Inline keyboard markup

-
-

Manage users

-
kick_chat_member
-

If your Bot is a chat admin he can kick and ban a user.

-

usage: kick_chat_member “${CHAT[ID]}" "${USER[ID]}”

-

alias: _kick_user “${USER[ID]}”

-
unban_chat_member
-

If your Bot is a chat admine can unban a kicked user.

-

usage: unban_chat_member “${CHAT[ID]}" "${USER[ID]}”

-

alias: _unban “${USER[ID]}”

-
leave_chat
-

Your Bot will leave the chat.

-

usage: leave_chat “${CHAT[ID]}”

-

alias: _leave

-
if _is_admin ; then 
- send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
- leave_chat "${CHAT[ID]}"
-fi
-

’See also kick Chat Member*

-
-

User Access Control

-
user_is_botadmin
-

Return true (0) if user is admin of bot, user id if botadmin is read from file ‘./botadmin’.

-

usage: user_is_botadmin “${USER[ID]}”

-

modules/alias: _is_botadmin

-

example:

-
 _is_botadmin && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
-
user_is_creator
-

Return true (0) if user is creator of given chat or chat is a private chat.

-

usage: user_is_creator “${CHAT[ID]}" "${USER[ID]}”

-

modules/alias: _is_creator

-
user_is_admin
-

Return true (0) if user is admin or creator of given chat.

-

usage: user_is_admin “${CHAT[ID]}" "${USER[ID]}”

-

modules/alias: _is_admin

-

example:

-
if _is_admin ; then 
-  send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
-  leave_chat "${CHAT[ID]}"
-fi
-

See also Chat Member

-
user_is_allowed
-

Bahsbot supports User Access Control, see Advanced Usage

-

usage: user_is_allowed “${USER[ID]}" "what" "${CHAT[ID]}”

-

example:

-
if ! user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then
-  send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
-fi
-
-

Aliases - shortcuts for often used funtions

-

You must not disable source modules/aliases.sh in ‘commands.sh’ to have the following functions availible.

-
_is_botadmin
-

usage: _is_botadmin

-

alias for: user_is_botadmin “${USER[ID]}”

-
_is_admin
-

usage: _is_admin

-

alias for: user_is_admin “${CHAT[ID]}" "${USER[ID]}”

-
_is_allowed
-

usage: _is_allowed “what”

-

alias for: user_is_allowed “${USER[ID]}" "what" "${CHAT[ID]}”

-
-
_kick_user
-

usage: _kick_user “${USER[ID]}”

-

alias for: kick_chat_member “${CHAT[ID]}" "${USER[ID]}”

-
_unban
-

usage: _unban “${USER[ID]}”

-

alias for: unban_chat_member “${CHAT[ID]}" "${USER[ID]}”

-
_leave
-

usage: _leave

-

alias for: leave_chat “${CHAT[ID]}”

-
-
_message
-

usage: _message “message”

-

alias for: send_normal_message “${CHAT[ID]}” “message”

-
_normal_message
-

usage: _normal_message “message”

-

alias for: send_normal_message “${CHAT[ID]}” “message”

-
_html_message
-

usage: _html_message “message”

-

alias for: send_html_message “${CHAT[ID]}” “message”

-
_markdown_message
-

usage: _markdown_message “message”

-

alias for: send_markdown_message “${CHAT[ID]}” “message”

-
-

Interactive and backgound jobs

-

You must not disable source modules/background.sh in ‘commands.sh’ to have the following functions availible.

-
startproc
-

startproc starts a script, the output of the script is sent to the user or chat, user input will be sent back to the script. see Advanced Usage

-

usage: startproc “script”

-

example:

-
startproc 'examples/calc.sh'
-
checkproc
-

Return true (0) if an interactive script is running in the chat.

-

usage: checkprog

-

example:

-
checkproc 
-if [ "$res" -gt 0 ] ; then
-  startproc "examples/calc.sh"
-else
-   send_normal_message "${CHAT[ID]}" "Calc already running ..."
-fi
-
killproc
-

Kill the interactive script running in the chat

-

usage: killproc

-

example:

-
checkprog
-if [ "$res" -eq 0 ]; then
-  killproc && send_message "${CHAT[ID]}" "Command canceled."
-else
-  send_message "${CHAT[ID]}" "Command is not running."
-fi
-
-
background
-

Starts a script as a background job and attaches a jobname to it. All output from a background job is sent to the associated chat.

-

In contrast to interactive chats, background jobs do not recieve user input and can run forever. In addition you can suspend and restart running jobs, e.g. after reboot.

-

usage: background “script” “jobname”

-

example:

-
background "examples/notify.sh" "notify"
-
checkback
-

Return true (0) if an background job is active in the given chat.

-

usage: checkback “jobname”

-

example:

-
checkback "notify"
-if [ "$res" -gt 0 ] ; then
-  send_normal_message "${CHAT[ID]}" "Start notify"
-  background "examples/notify.sh" "notify"
-else
- send_normal_message "${CHAT[ID]}" "Process notify already running."
-fi
-
killback
-

usage: killback “jobname”

-

example:

-
checkback "notify"
-if [ "$res" -eq 0 ] ; then
-  send_normal_message "${CHAT[ID]}" "Kill notify"
-  killback "notify"
-else
-  send_normal_message "${CHAT[ID]}" "Process notify not run."
-fi
-
-
send_message
-

send_message sends any type of message to the given chat. Type of output is steered by keywords within the message.

-

The main use case for send_message is to process the output of interactive chats and background jobs. For regular Bot commands I recommend using of the dedicated send_xxx_message() functions from above.

-

usage: send_message “${CHAT[ID]}” “message”

-

example: - see Usage and Advanced Usage

-
-

Helper functions

-
_is_function Returns true if the given function exist, can be used to check if a module is loaded.
-

usage _is_function function

-

example:

-
_is_function "background" && _message "you can run background jobs!"
-
-

Bashbot internal functions

-

These functions are for internal use only and must not used in your bot commands.

-
get_file
-

usage: url=“$(get_file "${CHAT[ID]}” “message”)"

-
-
send_text
-

usage: send_text “${CHAT[ID]}” “message”

-
-
JsonDecode
-

Outputs decoded string to STDOUT

-

usage: JsonDecode “string”

-
JsonGetString
-

Reads JSON fro STDIN and Outputs found String to STDOUT

-

usage: JsonGetString "path","to","string"

-
JsonGetValue
-

Reads JSON fro STDIN and Outputs found Value to STDOUT

-

usage: JsonGetValue "path","to","value"

-
-
get_chat_member_status
-

usage: get_chat_member_status “${CHAT[ID]}" "${USER[ID]}”

-

this may get an official function …

-
-
process_client
-

Every Message sent to your Bot is processd by this function. It parse the send JSON and assign the found Values to bash variables.

-
process_updates
-

If new updates are availible, this functions gets the JSON from Telegram and dispatch it.

-
-
getBotName
-

The name of your bot is availible as bash variable “$ME”, there is no need to call this function if Bot is running.

-

usage: ME=“$(getBotNiname)”

-
inproc
-

Send Input from Telegram to waiting Interactive Chat.

-

Prev Best Practice

-

Next Notes for Developers

-


VERSION
v0.70-pre1-7-g02d9afb

- - diff --git a/html/7_develop.html b/html/7_develop.html deleted file mode 100644 index e818afe..0000000 --- a/html/7_develop.html +++ /dev/null @@ -1,113 +0,0 @@ - - - - - - - Bashobot Documentation - 7_develop.html - - - - - -

Home

-

Notes for bashbot developers

-

This section is about help and best practices for new bashbot developers. The main focus on is creating new versions of bashbot, not on develop your individual bot. Nevertheless the rules and tools described here can also help you with your bot development.

-

bashbot development is done on github. If you want to provide fixes or new features fork bashbot on githup and provide changes as pull request on github.

-

Setup your develop environment

-
    -
  1. install git, install shellcheck
  2. -
  3. setup your environment for UTF-8
  4. -
  5. clone your bashbot fork to a new directory git clone https://github.com/<YOURNAME>/telegram-bot-bash.git, replace <YOURNAME> with your username on github
  6. -
  7. create and change to your develop branch git checkout -b <YOURBRANCH>, replace <YOURBRANCH> with the name you want to name it, e.g. ‘develop’
  8. -
  9. give your (dev) fork a new version tag: git tag vx.xx, version must be higher than current version
  10. -
  11. setup github hooks by running dev/install-hooks.sh (optional)
  12. -
-

Test, Add, Push changes

-

A typical bashbot develop loop looks as follow:

-
    -
  1. start developing - change, copy, edit bashbot files …
  2. -
  3. after changing a bash sript: shellcheck -x scipt.sh
  4. -
  5. dev/all-tests.sh - in case if errors back to 2.
  6. -
  7. dev/git-add.sh - check for changed files, update version string, run git add
  8. -
  9. git commit' -m "COMMIT MESSAGE"; git push
  10. -
-

If you setup iyou dev environment with hooks and use the scripts above, versioning, addding and testing is done automatically.

-

Prepare a new version

-

After some development it may time to create a new version for the users. a new version can be in sub version upgrade, e.g. for fixes and smaller additions or a new release version for new features. To mark a new version use git tag NEWVERSION and run dev/version.sh to update all version strings.

-

Usually I start with pre versions and when everything looks good I push out a release candidate (rc) and finally the new version.

-
 v0.x-devx -> v0.x-prex -> v0.x-rc -> v0.x  ... 0.x+1-dev ...
-

Versioning

-

Bashbot is tagged with version numbers. If you start a new development cycle you must tag your fork with a version higher than the current version. E.g. if you fork ‘v0.60’ the next develop version should tagged as git tag "v0.61-dev" for fixes or git tag "v0.70-dev" for new features.

-

To get the current version name of your develepment fork run git describe --tags. The output looks like v0.70-dev-6-g3fb7796 where your version tag is followed by the number of commits since you tag your branch and followed by the latest commit hash. see also comments in version.sh

-

To update the Version Number in your scripts run dev/version.sh, it will update the line ‘####
VERSION
###’ in all files to the current version name.

-

Shellchecking

-

For a shell script running as a service it’s important to be paranoid about quoting, globbing and other common problems. So it’s a must to run shellchek on all shell scripts before you commit a change. this is automated by a git hook activated in Setup step 6.

-

In addition you can run dev/hooks/pre-commit.sh every time you want to shellcheck all files given in ‘dev/shellcheck.files’.

-

bashbot tests

-

Starting with version 0.70 bashbot has a test suite. To start testsuite run dev/all-tests.sh. all-tests.sh will return ‘SUCCESS’ only if all tests pass.

-

enabling / disabling tests

-

All tests are placed in the directory test. To disable a test remove the x flag from the ’*-test.sh’ test script, to (re)enable a test make the script executable again.

-

creating new tests

-

To create a new test run test/ADD-test-new.sh and answer the questions, afterwards you have the following described files and dirs:

-

Each test consists of a script script named like p-name-test.sh (where p is test pass ‘a-z’ and name the name of your test) and an optional dir p-name-test/ (script name minus ‘.sh’) for additional files.

-

The file ALL-tests.inc.sh must be included from all tests, do not forget the shellcheck source directive to statisfy shellcheck.

-

Tests with no dependency to other tests will run in pass ‘a’, tests which need an initialized bahsbot environment must run in pass ‘d’ or later. If ‘$1’ is present the script is started from ‘ALL-tests.sh’ and a temporary test environment is setup in directory ‘$1’. The temporary test environment is created when ‘ALL-tests.sh’ starts and deleted after all tests are finished.

-

Example test

-
#!/usr/bin/env bash
-# file: b-example-test.sh
-
-# include common functions and definitions
-# shellcheck source=test/ALL-tests.inc.sh
-source "./ALL-tests.inc.sh"
-
-if [ -f "bashbot.sh" ]; then
-    echo "${SUCCESS} bashbot.sh exist!"
-    exit 0
-else
-    echo "${NOSUCCESS} bashbot.sh missing!"
-    exit 1
-fi
-

Prev Function Reference

-

Next Bashbot Environment

-


VERSION
v0.70-pre1-7-g02d9afb

- - diff --git a/html/8_custom.html b/html/8_custom.html deleted file mode 100644 index 9f0824e..0000000 --- a/html/8_custom.html +++ /dev/null @@ -1,130 +0,0 @@ - - - - - - - Bashobot Documentation - 8_custom.html - - - - - -

Home

-

Customize bashbots environment

-

This section describe how you can customize bashbot to your needs by setting environment variables.

-

Change file locations

-

In standard setup bashbot is self containing, this means you can place ‘telegram-bot-bash’ any location and run it from there. All files - programm, config, data etc - will reside in ‘telegram-bot-bash’.

-

If you want to have other locations for config, data etc, define and export the following environment variables. Note: all specified directories and files must exist or running ‘bashbot.sh’ will fail.

-

BASHBOT_ETC

-

Location of the files commands.sh, mycommands.sh, token, botadmin, botacl

-
  unset  BASHBOT_ETC     # keep in telegram-bot-bash (default)
-  export BASHBOT_ETC ""  # keep in telegram-bot-bash
-
-  export BASHBOT_ETC "/etc/bashbot"  # unix like config location
-
-  export BASHBOT_ETC "/etc/bashbot/bot1"  # multibot configuration bot 1
-  export BASHBOT_ETC "/etc/bashbot/bot2"  # multibot configuration bot 2
-

e.g. /etc/bashbot

-

BASHBOT_VAR

-

Location of runtime data data-bot-bash, count

-
  unset  BASHBOT_VAR     # keep in telegram-bot-bash (default)
-  export BASHBOT_VAR ""  # keep in telegram-bot-bash
-
-  export BASHBOT_VAR "/var/spool/bashbot"  # unix like config location
-
-  export BASHBOT_VAR "/var/spool/bashbot/bot1"  # multibot configuration bot 1
-  export BASHBOT_VAR "/var/spool/bashbot/bot2"  # multibot configuration bot 2
-

BASHBOT_JSONSH

-

Full path to JSON.sh script, default: ‘./JSON.sh/JSON.sh’, must end with ‘/JSON.sh’.

-
  unset  BASHBOT_JSONSH     # telegram-bot-bash/JSON.sh/JSON.sh (default)
-  export BASHBOT_JSONSH ""  # telegram-bot-bash/JSON.sh/JSON.sh
-
-  export BASHBOT_JSONSH "/usr/local/bin/JSON.sh"  # installed in /usr/local/bin
-

Change config values

-

BASHBOT_DECODE

-

Bashbot offers two variants for decoding JSON UTF format to UTF-8. By default bashbot uses ‘json.encode’ if python is installed. If ‘BASHBOT_DECODE’ is set to any value (not undefined or not empty) the bash only implementation will be used.

-
  unset  BASHBOT_DECODE       # autodetect python (default)
-  export BASHBOT_DECODE ""    # autodetect python
-
-  export BASHBOT_DECODE "yes" # force internal
-  export BASHBOT_DECODE "no"  # also force internal!
-

BASHBOT_SLEEP

-

Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling. If messages are recieved bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay for every poll until the maximum of BASHBOT_SLEEP ms.

-
  unset  BASHBOT_SLEEP       # 5000ms (default)
-  export BASHBOT_SLEEP ""    # 5000ms 
-
-  export BASHBOT_SLEEP "1000"     # 1s maximum sleep 
-  export BASHBOT_SLEEP "10000"    # 10s maximum sleep
-  export BASHBOT_SLEEP "1"        # values < 1000 disables sleep (not recommended) 
-  
-

Testet configs as of v.07 release

-

Note: Environment variables are not stored, you must setup them before every call to bashbot.sh, e.g. from a script.

-

simple Unix like config, for one bot. bashbot is installed in ‘/usr/local/telegram-bot-bash’

-
  # Note: all dirs and files must exist!
-  export BASHBOT_ETC "/etc/bashbot"
-  export BASHBOT_VAR "/var/spool/bashbot"
-
-  /usr/local/telegram-bot-bash/bashbot.sh start
-

Unix like config for one bot. bashbot.sh is installed in ‘/usr/bin’

-
  # Note: all dirs and files must exist!
-  export BASHBOT_ETC "/etc/bashbot"
-  export BASHBOT_VAR "/var/spool/bashbot"
-  export BASHBOT_JSONSH "/var/spool/bashbot"
-
-  /usr/local/bin/bashbot.sh start
-

simple multibot config, everything is keept inside ‘telegram-bot-bash’ dir

-
  # config for running Bot 1
-  # Note: all dirs and files must exist!
-  export BASHBOT_ETC "./mybot1"
-  export BASHBOT_VAR "./mybot1"
-
-  /usr/local/telegram-bot-bash/bashbot.sh start
-
  # config for running Bot 2
-  # Note: all dirs and files must exist!
-  export BASHBOT_ETC "./mybot2"
-  export BASHBOT_VAR "./mybot2"
-
-  /usr/local/telegram-bot-bash/bashbot.sh start
-

Prev Notes for Developers

-


VERSION
v0.70-pre1-0-g490c472

- - From 7ce2c5be2cc81b36e56fe1badbe7135ddb013968 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 29 Apr 2019 18:50:36 +0200 Subject: [PATCH 57/63] add some more useful background examples --- examples/background-scripts/mycommands.sh | 105 ++++++++++++++++++ examples/background-scripts/run_diskusage.sh | 42 +++++++ .../background-scripts/run_filecontent.sh | 32 ++++++ examples/background-scripts/run_filename.sh | 32 ++++++ examples/background-scripts/run_notify.sh | 34 ++++++ examples/calc.sh | 4 +- examples/notify.sh | 4 +- examples/question,sh | 30 ----- examples/question.sh | 4 +- 9 files changed, 254 insertions(+), 33 deletions(-) create mode 100644 examples/background-scripts/mycommands.sh create mode 100755 examples/background-scripts/run_diskusage.sh create mode 100755 examples/background-scripts/run_filecontent.sh create mode 100755 examples/background-scripts/run_filename.sh create mode 100755 examples/background-scripts/run_notify.sh delete mode 100755 examples/question,sh diff --git a/examples/background-scripts/mycommands.sh b/examples/background-scripts/mycommands.sh new file mode 100644 index 0000000..311f061 --- /dev/null +++ b/examples/background-scripts/mycommands.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# files: mycommands.sh.dist +# copy to mycommands.sh and add all your commands an functions here ... +export res + +# your additional bahsbot commands ... +mycommands() { + + case "$MESSAGE" in + '/run_'*) + myback="run_${MESSAGE#*_}" + if [ -x "./$myback.sh" ]; then + checkback "$myback" + if [ "$res" -gt 0 ] ; then + send_normal_message "${CHAT[ID]}" "Starte $myback" + background "./$myback.sh" "$myback" + else + send_normal_message "${CHAT[ID]}" "Prozess $myback laeuft bereits." + fi + fi + ;; + '/kill_'*) + myback="run_${MESSAGE#*_}" + if [ -x "./$myback.sh" ]; then + checkback "$myback" + if [ "$res" -eq 0 ] ; then + killback "$myback" + send_normal_message "${CHAT[ID]}" "Beende $myback." + else + send_normal_message "${CHAT[ID]}" "Prozess $myback laeuft nicht." + fi + fi + ;; + esac +} + +# place your additional processing functions here ... + +# returns true if function exist +_is_function() +{ + [ "$(LC_ALL=C type -t "$1")" = "function" ] +} + +# inifnite loop for waching a given dir for new files +# $1 dir to wtach for new files +watch_dir_loop() { + local newfile old + # wait for new files in WATCHDIR + inotifywait -q -m "$1" -e create --format "%f" \ + | while true + do + # read in newfile + read -r newfile + + #skip if not match or same name as last time + [ "${newfile}" = "${old}" ] && continue + sleep 0.2 + + # process content and output message + echo "$(date) found ${newfile}" >&2 + # note: loop callback must a function in the calling script! + if _is_function loop_callback ; then + loop_callback "$1/$newfile" + else + echo "ERROR: loop_callback not found!" >&2 + fi + done +} # 2>>"$0.log" + + +output_telegram() { + # output to telegram + sed <<< "${1}" -e ':a;N;$!ba;s/\n/ mynewlinestartshere /g' +} # 2>>"$0.log" + +# name and localtion of the tml file + +# $1 string to output +# $2 file to add file to +output_html_file() { + local date + date="$(date)" + output_file "$(sed <<< "
$1
${date}
" ' + s/ my[a-z]\{3,15}\(start\|ends\)here.*
/
/g + s/ *mynewlinestartshere */
/ + s/\n/
/ + ')" +} # >>"$0.log" 2>&1 + +# $1 string to output +# $2 file to add file to +output_file() { + local publish="${2}" + [ ! -w "${publish}" ] && echo "ERROR: file ${publish} is not writeable or does not exist!" && exit + + # output at beginnung of file, add date to message + sed <<< "${1}" ' + s/ *mynewlinestartshere */\n/ + s/ my[a-z]\{3,15}\(start\|ends\)here.*//g + ' >"$publish$$" + cat "$publish" >>"$publish$$" + mv "${publish}$$" "${publish}" +} # >>"$0.log" 2>&1 + diff --git a/examples/background-scripts/run_diskusage.sh b/examples/background-scripts/run_diskusage.sh new file mode 100755 index 0000000..cc66ecb --- /dev/null +++ b/examples/background-scripts/run_diskusage.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# file: run_diskcusage.sh +# example for an background job display a system value + +# 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-11-g3dfa5e4 + +# 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 + +# discard STDIN for background jobs! +cat >/dev/null & + +source "./mycommands.sh" + +# check if $1 is a number +re='^[0-9]+$' +if [[ $1 =~ $re ]] ; then + SLEEP="$1" +else + SLEEP=100 # time between time notifications +fi + +NEWLINE=$'\n' + +# output disk usgae every $1 seconds +WAIT=0 +while sleep $WAIT +do + output_telegram "Current Disk usage ${NEWLINE} $(df -h / /tmp /usr /var /home)" + # only for testing, delete echo line for production ... + echo "Current Disk usage ${NEWLINE} $(df -h / /tmp /usr /var /home)" + WAIT="$SLEEP" +done + diff --git a/examples/background-scripts/run_filecontent.sh b/examples/background-scripts/run_filecontent.sh new file mode 100755 index 0000000..fd9215d --- /dev/null +++ b/examples/background-scripts/run_filecontent.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# file: run_filename +# background job to display content of all new files in WATCHDIR +# + +# 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 + +# discard STDIN for background jobs! +cat >/dev/null & + +# watch for new logfiles +WATCHDIR="/my_special/dir_to_watch" +source "./mycommands.sh" + +# test your script and the remove ... +WATCHDIR="/tmp" + +# this is calles by watch loop +# $1 is name of the new file +loop_callback() { + # output content of file, you MUST trust creator of the file because it contest are sent as message to you! + output_telegram "Contents of ${1}: mynewlinestartshere $(cat "${1}")" +} + +watch_dir_loop "$WATCHDIR" diff --git a/examples/background-scripts/run_filename.sh b/examples/background-scripts/run_filename.sh new file mode 100755 index 0000000..53bd926 --- /dev/null +++ b/examples/background-scripts/run_filename.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# file: run_filename +# background job to display all new files in WATCHDIR +# + +# 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 + +# discard STDIN for background jobs! +cat >/dev/null & + +# watch for new logfiles +WATCHDIR="/var/log" +source "./mycommands.sh" + +# test your script and the remove ... +WATCHDIR="/tmp" + +# this is calles by watch loop +# $1 is name of the new file +loop_callback() { + # output one simple line ... + echo "New file ${1} created in ${WATCHDIR}!" +} + +watch_dir_loop "$WATCHDIR" diff --git a/examples/background-scripts/run_notify.sh b/examples/background-scripts/run_notify.sh new file mode 100755 index 0000000..c336728 --- /dev/null +++ b/examples/background-scripts/run_notify.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# file: notify.sh +# example for an background job, run with startback notify.sh + +# 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-11-g3dfa5e4 + +# 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 + +# discard STDIN for background jobs! +cat >/dev/null & + +# check if $1 is a number +re='^[0-9]+$' +if [[ $1 =~ $re ]] ; then + SLEEP="$1" +else + SLEEP=10 # time between time notifications +fi + +# output current time every $1 seconds +while sleep $SLEEP +do + date "+* It's %k:%M:%S o' clock ..." +done + diff --git a/examples/calc.sh b/examples/calc.sh index a5df907..0c8cca4 100755 --- a/examples/calc.sh +++ b/examples/calc.sh @@ -1,9 +1,11 @@ #!/bin/bash +# file: calc.sh +# example for an interactive chat, run with startprog calc.sh # 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-0-g490c472 +#### $$VERSION$$ v0.70-pre1-11-g3dfa5e4 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index 13c8979..c336728 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -1,8 +1,10 @@ #!/bin/bash +# file: notify.sh +# example for an background job, run with startback notify.sh # 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-0-g490c472 +#### $$VERSION$$ v0.70-pre1-11-g3dfa5e4 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question,sh b/examples/question,sh deleted file mode 100755 index 42c634a..0000000 --- a/examples/question,sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -# 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-0-g490c472 - -# 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 - -echo "Why hello there. -Would you like some tea (y/n)?" -read -r 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 - echo 'Do you like Music? mykeyboardstartshere "Yass!" , "No"' - read -r answer - case $answer in - 'Yass!') echo "Goody! mykeyboardendshere";SUCCESS=y;; - 'No') echo "Well that's weird. mykeyboardendshere";SUCCESS=y;; - *) SUCCESS=n;; - esac -done -exit diff --git a/examples/question.sh b/examples/question.sh index 42c634a..86807bc 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -1,9 +1,11 @@ #!/bin/bash +# file: question.sh +# example for an interactive chat, run with startprog question.sh # 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-0-g490c472 +#### $$VERSION$$ v0.70-pre1-11-g3dfa5e4 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment From 4b83377905597eeaaadc478c9a05a2d0111dc357 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 29 Apr 2019 19:34:47 +0200 Subject: [PATCH 58/63] v0.70-pre2, doc for examples --- README.html | 3 +- README.md | 4 +-- README.txt | 4 +-- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/all-tests.sh | 2 +- dev/git-add.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- examples/README.md | 35 ++++++++++++++++++++ examples/background-scripts/mycommands.sh | 20 +++++------ examples/background-scripts/run_diskusage.sh | 2 +- examples/background-scripts/run_notify.sh | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question.sh | 2 +- modules/aliases.sh | 2 +- modules/background.sh | 2 +- modules/inline.sh | 2 +- mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/a-commit-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 43 files changed, 89 insertions(+), 53 deletions(-) create mode 100644 examples/README.md diff --git a/README.html b/README.html index 9be0a30..a4d6e0f 100644 --- a/README.html +++ b/README.html @@ -70,6 +70,7 @@
  • Bashbot testsuite
  • Customize bashbot environment
  • +
  • Exmaples
  • Security Considerations

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

    @@ -96,6 +97,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.70-pre1-6-g3cd6eeb

    +


    VERSION
    v0.7-pre2-0-g7ce2c5b

    diff --git a/README.md b/README.md index 4cb1735..43a3686 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do * Prepare a new version * Bashbot testsuite * [Customize bashbot environment](doc/8_customize.md) - +* [Exmaples](examples/README.MD) ## Security Considerations Running a Telegram Bot means it is connected to the public and you never know whats send to your Bot. @@ -93,4 +93,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.70-pre1-6-g3cd6eeb +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b diff --git a/README.txt b/README.txt index ff9cd1f..608e51c 100644 --- a/README.txt +++ b/README.txt @@ -58,7 +58,7 @@ all](https://core.telegram.org/bots#3-how-do-i-create-a-bot) * Prepare a new version * Bashbot testsuite * [Customize bashbot environment](doc/8_customize.md) - +* [Exmaples](examples/README.MD) ## Security Considerations Running a Telegram Bot means it is connected to the public and you never know @@ -130,4 +130,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.70-pre1-6-g3cd6eeb +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b diff --git a/bashbot.rc b/bashbot.rc index a8034b3..77e8a5c 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-pre1-4-g0d38a67 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 90a4014..b6b6879 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.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index c4d9000..ad3c137 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.70-pre1-2-g293ad08 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/all-tests.sh b/dev/all-tests.sh index ca15bbd..c2fb711 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/git-add.sh b/dev/git-add.sh index 12cc338..7cf8979 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 3dd31dc..92c1591 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index 66d3712..cd92f63 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 84229a3..8be89f0 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index f35b91c..03ae356 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-pre1-10-g5269b54 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index cfedc86..b246f19 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index d465a6c..8f76456 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-pre1-8-gfcca139 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index fd14b20..f83c55f 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -63,5 +63,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.70-pre1-2-g293ad08 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 819be0a..6d518ae 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -65,5 +65,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-pre1-2-g293ad08 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b diff --git a/doc/2_usage.md b/doc/2_usage.md index b4706cc..ba089a5 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -167,5 +167,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-pre1-2-g293ad08 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b diff --git a/doc/3_advanced.md b/doc/3_advanced.md index aa99445..6684b65 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -177,5 +177,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-pre1-8-gfcca139 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b diff --git a/doc/4_expert.md b/doc/4_expert.md index fa50955..7f08530 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b diff --git a/doc/5_practice.md b/doc/5_practice.md index a677596..a7f4625 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -153,5 +153,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-pre1-7-g02d9afb +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b diff --git a/doc/6_reference.md b/doc/6_reference.md index 3dcf124..5bbb880 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -489,5 +489,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-pre1-7-g02d9afb +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b diff --git a/doc/7_develop.md b/doc/7_develop.md index 1ee20e3..0b4b1a0 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -92,5 +92,5 @@ fi #### [Prev Function Reference](6_function.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.70-pre1-7-g02d9afb +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b diff --git a/doc/8_custom.md b/doc/8_custom.md index 5c57725..acfca7e 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -117,5 +117,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..9c51671 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,35 @@ +#### [Home](../README.md) + +## Bashbot examples + +### bashbot.cron +An example crontab is provided in ```examples/bashbot.cron```, see [Expert use](../doc/4_expert.md#Scedule-bashbot-from-Cron) + + +### Interactive chat examples +Two examples for interactive scripts are provided as 'calc.sh' and 'question.sh', see [Advanced use](../doc/3_advanced.md#Interactive-Chats) + +### Background jobs + +Background jobs are an easy way to provide sceduled messages or alerts if something happens. + +'notify.sh' shows you a simple exmaple to send a message ervery x seonds, e.g. actual time. + +'background-scripts' contains a more complex example on how to start and kill many scripts sending messages to a chat. + +``` + mycommands.sh - /run_xxx and /kill-xxx wil start any script named run_xxx.sh + + run_diskusage.sh - shows disk usage every 100 seconds + run_filename.sh - shown the namei of new files in a named dir + run_filecontent.sh - shown the content of new files in a named dir + run_notify.sh - same as notify.sh +``` + +### Use bashbot from external scripts + +In 'external-use' you will find some examples on how to send messages from external scripts to send messages to Telegram chats or users. + +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b + + diff --git a/examples/background-scripts/mycommands.sh b/examples/background-scripts/mycommands.sh index 311f061..307c9c9 100644 --- a/examples/background-scripts/mycommands.sh +++ b/examples/background-scripts/mycommands.sh @@ -9,25 +9,25 @@ mycommands() { case "$MESSAGE" in '/run_'*) myback="run_${MESSAGE#*_}" - if [ -x "./$myback.sh" ]; then - checkback "$myback" + if [ -x "./${myback}.sh" ]; then + checkback "${myback}" if [ "$res" -gt 0 ] ; then - send_normal_message "${CHAT[ID]}" "Starte $myback" - background "./$myback.sh" "$myback" + send_normal_message "${CHAT[ID]}" "Start ${myback}, use /kill${myback} to stop it." + background "./${myback}.sh" "${myback}" else - send_normal_message "${CHAT[ID]}" "Prozess $myback laeuft bereits." + send_normal_message "${CHAT[ID]}" "Background job ${myback} already running." fi fi ;; '/kill_'*) myback="run_${MESSAGE#*_}" - if [ -x "./$myback.sh" ]; then - checkback "$myback" + if [ -x "./${myback}.sh" ]; then + checkback "${myback}" if [ "$res" -eq 0 ] ; then - killback "$myback" - send_normal_message "${CHAT[ID]}" "Beende $myback." + killback "${myback}" + send_normal_message "${CHAT[ID]}" "Stopping ${myback}, use /run_${myback} to start again." else - send_normal_message "${CHAT[ID]}" "Prozess $myback laeuft nicht." + send_normal_message "${CHAT[ID]}" "No background job ${myback}." fi fi ;; diff --git a/examples/background-scripts/run_diskusage.sh b/examples/background-scripts/run_diskusage.sh index cc66ecb..05fe882 100755 --- a/examples/background-scripts/run_diskusage.sh +++ b/examples/background-scripts/run_diskusage.sh @@ -4,7 +4,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-11-g3dfa5e4 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/background-scripts/run_notify.sh b/examples/background-scripts/run_notify.sh index c336728..ef6275c 100755 --- a/examples/background-scripts/run_notify.sh +++ b/examples/background-scripts/run_notify.sh @@ -4,7 +4,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-11-g3dfa5e4 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/bashbot.cron b/examples/bashbot.cron index f8ed2ea..953a593 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 0c8cca4..f1382f1 100755 --- a/examples/calc.sh +++ b/examples/calc.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-11-g3dfa5e4 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index c336728..ef6275c 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -4,7 +4,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-11-g3dfa5e4 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index 86807bc..4cf09c5 100755 --- a/examples/question.sh +++ b/examples/question.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-11-g3dfa5e4 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/modules/aliases.sh b/modules/aliases.sh index 543eab8..c0bb68b 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # # source from commands.sh to use the aliases diff --git a/modules/background.sh b/modules/background.sh index 84b5091..e4c3832 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-6-g3cd6eeb +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/inline.sh b/modules/inline.sh index 6fb26dc..f8e7108 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -5,6 +5,6 @@ # 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-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # source from commands.sh to use the inline functions diff --git a/mycommands.sh b/mycommands.sh index 3bfe217..0f88be6 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-pre1-2-g293ad08 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index c5742e3..f1648e5 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 500ab66..2b6ae73 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 6f5a472..fa5ad5b 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b ../dev/hooks/pre-commit.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index b6d5e91..1b6736f 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 7d54782..eb7a993 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 386a834..bc4f074 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index c520690..f3081ff 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-6-g3cd6eeb +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 8df6fb0..fe5d79b 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-pre1-0-g490c472 +#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 68afdbf3fc9d8f4220cd6d11ef602582bb717ee0 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 29 Apr 2019 19:38:54 +0200 Subject: [PATCH 59/63] fix exmaples spelling --- README.html | 4 ++-- README.md | 4 ++-- README.txt | 4 ++-- examples/README.md | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.html b/README.html index a4d6e0f..ea61c68 100644 --- a/README.html +++ b/README.html @@ -70,7 +70,7 @@
  • Bashbot testsuite
  • Customize bashbot environment
  • -
  • Exmaples
  • +
  • Examples
  • Security Considerations

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

    @@ -97,6 +97,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.7-pre2-0-g7ce2c5b

    +


    VERSION
    v0.7-pre2-1-g4b83377

    diff --git a/README.md b/README.md index 43a3686..8003e09 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do * Prepare a new version * Bashbot testsuite * [Customize bashbot environment](doc/8_customize.md) -* [Exmaples](examples/README.MD) +* [Examples](examples/README.md) ## Security Considerations Running a Telegram Bot means it is connected to the public and you never know whats send to your Bot. @@ -93,4 +93,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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-pre2-1-g4b83377 diff --git a/README.txt b/README.txt index 608e51c..89eec0f 100644 --- a/README.txt +++ b/README.txt @@ -58,7 +58,7 @@ all](https://core.telegram.org/bots#3-how-do-i-create-a-bot) * Prepare a new version * Bashbot testsuite * [Customize bashbot environment](doc/8_customize.md) -* [Exmaples](examples/README.MD) +* [Examples](examples/README.md) ## Security Considerations Running a Telegram Bot means it is connected to the public and you never know @@ -130,4 +130,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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-pre2-1-g4b83377 diff --git a/examples/README.md b/examples/README.md index 9c51671..317858c 100644 --- a/examples/README.md +++ b/examples/README.md @@ -13,7 +13,7 @@ Two examples for interactive scripts are provided as 'calc.sh' and 'question.sh' Background jobs are an easy way to provide sceduled messages or alerts if something happens. -'notify.sh' shows you a simple exmaple to send a message ervery x seonds, e.g. actual time. +'notify.sh' shows you a simple examples to send a message ervery x seonds, e.g. actual time. 'background-scripts' contains a more complex example on how to start and kill many scripts sending messages to a chat. @@ -30,6 +30,6 @@ Background jobs are an easy way to provide sceduled messages or alerts if someth In 'external-use' you will find some examples on how to send messages from external scripts to send messages to Telegram chats or users. -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-pre2-1-g4b83377 From e0a6d388843f23a9ddf6f164722770144c17a5f4 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 30 Apr 2019 10:40:07 +0200 Subject: [PATCH 60/63] fix newlines in added text, add version to all examples --- examples/README.md | 16 +++++++++------- examples/background-scripts/mycommands.sh | 4 +++- examples/background-scripts/run_filecontent.sh | 15 +++++++++------ examples/background-scripts/run_filename.sh | 5 +++-- modules/background.sh | 5 +++-- .../d-send_message-test.input | 2 +- .../d-send_message-test.result | 4 +++- 7 files changed, 31 insertions(+), 20 deletions(-) diff --git a/examples/README.md b/examples/README.md index 317858c..dbd9cc3 100644 --- a/examples/README.md +++ b/examples/README.md @@ -6,30 +6,32 @@ An example crontab is provided in ```examples/bashbot.cron```, see [Expert use](../doc/4_expert.md#Scedule-bashbot-from-Cron) -### Interactive chat examples -Two examples for interactive scripts are provided as 'calc.sh' and 'question.sh', see [Advanced use](../doc/3_advanced.md#Interactive-Chats) +### Interactive chats +Two examples for interactive scripts are provided as **calc.sh** and **question.sh**, see [Advanced use](../doc/3_advanced.md#Interactive-Chats) ### Background jobs Background jobs are an easy way to provide sceduled messages or alerts if something happens. -'notify.sh' shows you a simple examples to send a message ervery x seonds, e.g. actual time. +**notify.sh** is a simple example how to send a message ervery x seonds, e.g. actual time. -'background-scripts' contains a more complex example on how to start and kill many scripts sending messages to a chat. +**background-scripts** contains a more concrete example on how to start and kill diffrent background scripts plus some example backgound scripts. ``` mycommands.sh - /run_xxx and /kill-xxx wil start any script named run_xxx.sh run_diskusage.sh - shows disk usage every 100 seconds - run_filename.sh - shown the namei of new files in a named dir + run_filename.sh - shown the name of new files in a named dir run_filecontent.sh - shown the content of new files in a named dir run_notify.sh - same as notify.sh ``` +**Note:** Output of system commands often contains newlines, each newline results in a a sepperate telegram message, see function send_telegram in +mycommands.sh on how to avoid this. ### Use bashbot from external scripts -In 'external-use' you will find some examples on how to send messages from external scripts to send messages to Telegram chats or users. +**external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users. -#### $$VERSION$$ v0.7-pre2-1-g4b83377 +#### $$VERSION$$ v0.7-pre2-2-g68afdbf diff --git a/examples/background-scripts/mycommands.sh b/examples/background-scripts/mycommands.sh index 307c9c9..c9f62ae 100644 --- a/examples/background-scripts/mycommands.sh +++ b/examples/background-scripts/mycommands.sh @@ -46,6 +46,7 @@ _is_function() # $1 dir to wtach for new files watch_dir_loop() { local newfile old + [ ! -d "$1" ] && echo "ERROR: no directory $1 found!" >&2 && exit 1 # wait for new files in WATCHDIR inotifywait -q -m "$1" -e create --format "%f" \ | while true @@ -58,12 +59,13 @@ watch_dir_loop() { sleep 0.2 # process content and output message - echo "$(date) found ${newfile}" >&2 + echo "$(date): new file: ${newfile}" >>"$0.log" # note: loop callback must a function in the calling script! if _is_function loop_callback ; then loop_callback "$1/$newfile" else echo "ERROR: loop_callback not found!" >&2 + exit 1 fi done } # 2>>"$0.log" diff --git a/examples/background-scripts/run_filecontent.sh b/examples/background-scripts/run_filecontent.sh index fd9215d..c9d9551 100755 --- a/examples/background-scripts/run_filecontent.sh +++ b/examples/background-scripts/run_filecontent.sh @@ -2,6 +2,7 @@ # file: run_filename # background job to display content of all new files in WATCHDIR # +#### $$VERSION$$ v0.7-pre2-2-g68afdbf # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment @@ -15,18 +16,20 @@ unset IFS # discard STDIN for background jobs! cat >/dev/null & -# watch for new logfiles -WATCHDIR="/my_special/dir_to_watch" +# watch for new files created by a trusted programm +WATCHDIR="/my_trusted/dir_to_watch" source "./mycommands.sh" # test your script and the remove ... -WATCHDIR="/tmp" +WATCHDIR="/tmp/bottest" -# this is calles by watch loop +NEWLINE='mynewlinestartshere' + +# this is called by watch dir loop # $1 is name of the new file loop_callback() { - # output content of file, you MUST trust creator of the file because it contest are sent as message to you! - output_telegram "Contents of ${1}: mynewlinestartshere $(cat "${1}")" + # output content of file, you must trust creator because content is sent as message! + output_telegram "Contents of ${1}: ${NEWLINE} $(cat "${1}")" } watch_dir_loop "$WATCHDIR" diff --git a/examples/background-scripts/run_filename.sh b/examples/background-scripts/run_filename.sh index 53bd926..18a7356 100755 --- a/examples/background-scripts/run_filename.sh +++ b/examples/background-scripts/run_filename.sh @@ -2,6 +2,7 @@ # file: run_filename # background job to display all new files in WATCHDIR # +#### $$VERSION$$ v0.7-pre2-2-g68afdbf # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment @@ -20,9 +21,9 @@ WATCHDIR="/var/log" source "./mycommands.sh" # test your script and the remove ... -WATCHDIR="/tmp" +WATCHDIR="/tmp/bottest" -# this is calles by watch loop +# this is called by watch dir loop # $1 is name of the new file loop_callback() { # output one simple line ... diff --git a/modules/background.sh b/modules/background.sh index e4c3832..e571094 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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-pre2-2-g68afdbf # source from commands.sh if you want ro use interactive or background jobs @@ -17,7 +17,8 @@ export res send_message() { [ "$2" = "" ] && return 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')" + text="$(sed <<< "${2}" 's/ mykeyboardend.*//;s/ *my[kfltab][a-z]\{2,13\}startshere.*//')$(sed <<< "${2}" -n '/mytextstartshere/ s/.*mytextstartshere//p')" + text="$(sed <<< "${text}" 's/ *mynewlinestartshere */\r\n/g')" [ "$3" != "safe" ] && { no_keyboard="$(sed <<< "${2}" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere *//;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')" 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 f00eb65..0a1c6b2 100644 --- a/test/d-send_message-test/d-send_message-test.input +++ b/test/d-send_message-test/d-send_message-test.input @@ -15,4 +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 +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 mynewlinestartshere plus newline. 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 5ddf545..575d856 100644 --- a/test/d-send_message-test/d-send_message-test.result +++ b/test/d-send_message-test/d-send_message-test.result @@ -54,6 +54,8 @@ 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"}] ]} +[https://images-na.ssl-images-amazon.com/images/I/41oypA3kmHL.l_SX300.jpg] +second part of text +plus newline.", "reply_markup": {"inline_keyboard": [ [ {"text":"Bei Amazon ansehen ...", "url":"https://www.amazon.de/dp/B014TN3JYW"}] ]} URL:https://api.telegram.org/botbashbottestscript/sendMessage From 8dcbc292a2c1a3b066df798c1b8cd0a5657289ca Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 30 Apr 2019 14:21:24 +0200 Subject: [PATCH 61/63] fix make-dist, fix doc links --- README.html | 4 ++-- README.md | 4 ++-- README.txt | 4 ++-- dev/make-dist.sh | 15 ++++++++------- doc/6_reference.md | 4 ++-- doc/7_develop.md | 4 ++-- examples/README.md | 10 +++++----- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/README.html b/README.html index ea61c68..3af1370 100644 --- a/README.html +++ b/README.html @@ -69,7 +69,7 @@
  • Prepare a new version
  • Bashbot testsuite
  • -
  • Customize bashbot environment
  • +
  • Customize bashbot environment
  • Examples
  • Security Considerations

    @@ -97,6 +97,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.7-pre2-1-g4b83377

    +


    VERSION
    v0.7-pre2-3-ge0a6d38

    diff --git a/README.md b/README.md index 8003e09..868b9a1 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do * Test, Add, Push changes * Prepare a new version * Bashbot testsuite -* [Customize bashbot environment](doc/8_customize.md) +* [Customize bashbot environment](doc/8_custom.md) * [Examples](examples/README.md) ## Security Considerations @@ -93,4 +93,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.7-pre2-1-g4b83377 +#### $$VERSION$$ v0.7-pre2-3-ge0a6d38 diff --git a/README.txt b/README.txt index 89eec0f..63f0133 100644 --- a/README.txt +++ b/README.txt @@ -57,7 +57,7 @@ all](https://core.telegram.org/bots#3-how-do-i-create-a-bot) * Test, Add, Push changes * Prepare a new version * Bashbot testsuite -* [Customize bashbot environment](doc/8_customize.md) +* [Customize bashbot environment](doc/8_custom.md) * [Examples](examples/README.md) ## Security Considerations @@ -130,4 +130,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.7-pre2-1-g4b83377 +#### $$VERSION$$ v0.7-pre2-3-ge0a6d38 diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 03ae356..28fef22 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,18 +1,18 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-pre2-3-ge0a6d38 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script GIT_DIR=$(git rev-parse --git-dir) cd "$GIT_DIR/.." || exit 1 -VERSION="$(git describe --tags | sed -e 's/-.*//' -e 's/v//')" +VERSION="$(git describe --tags | sed -e 's/-[0-9].*//' -e 's/v//')" DISTNAME="telegram-bot-bash" DISTDIR="./dist/${DISTNAME}" -DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh doc examples modules LICENSE README.md README.txt" +DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh doc examples modules LICENSE README.md README.txt README.html" # run tests first! @@ -36,16 +36,17 @@ mv "mycommands.sh" "mycommands.sh.dist" JSONSHFILE="JSON.sh/JSON.sh" if [ ! -f "${JSONSHFILE}" ]; then - mkdir "JSON.sh" 2>/dev/null; + mkdir "JSON.sh" 2>/dev/null curl -sL -o "${JSONSHFILE}" "https://cdn.jsdelivr.net/gh/dominictarr/JSON.sh/JSON.sh" chmod +x "${JSONSHFILE}" fi # make html doc -mkdir html +mkdir html 2>/dev/null cp README.html html/index.html -find ./doc -iname "*.md" -type f -exec sh -c 'pandoc -s -S -M "title=Bashobot Documentation - ${0%.md}.html" "${0}" -o "./html/$(basename ${0%.md}.html)"' {} \; -find README.html html -iname "*.html" -type f -exec sh -c 'sed -i -E "s/href=\"(.*).md\"/href=\"\1.html\"/g" ${0}' {} \; +find doc -iname "*.md" -type f -exec sh -c 'pandoc -s -S -M "title=Bashobot Documentation - ${0%.md}.html" "${0}" -o "./html/$(basename ${0%.md}.html)"' {} \; +find examples -iname "*.md" -type f -exec sh -c 'pandoc -s -S -M "title=Bashobot Documentation - ${0%.md}.html" "${0}" -o "${0%.md}.html"' {} \; +find README.html html examples -iname "*.html" -type f -exec sh -c 'sed -i -E "s/href=\"(\.\.\/)*doc\//href=\"\1html\//g;s/href=\"(.*).md(#.*)*\"/href=\"\1.html\"/g" ${0}' {} \; # create archive cd .. || exit 1 diff --git a/doc/6_reference.md b/doc/6_reference.md index 5bbb880..3fe0605 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -238,7 +238,7 @@ fi *See also [Chat Member](https://core.telegram.org/bots/api/#chatmember)* ##### user_is_allowed -Bahsbot supports User Access Control, see [Advanced Usage](4_advanced.md) +Bahsbot supports User Access Control, see [Advanced Usage](3_advanced.md) *usage:* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}" @@ -489,5 +489,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-pre2-3-ge0a6d38 diff --git a/doc/7_develop.md b/doc/7_develop.md index 0b4b1a0..7e17777 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -89,8 +89,8 @@ else fi ``` -#### [Prev Function Reference](6_function.md) +#### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-pre2-3-ge0a6d38 diff --git a/examples/README.md b/examples/README.md index dbd9cc3..24535a1 100644 --- a/examples/README.md +++ b/examples/README.md @@ -13,9 +13,9 @@ Two examples for interactive scripts are provided as **calc.sh** and **question. Background jobs are an easy way to provide sceduled messages or alerts if something happens. -**notify.sh** is a simple example how to send a message ervery x seonds, e.g. actual time. +**notify.sh** is a simple example on how to send a message every x seonds, e.g. current time. -**background-scripts** contains a more concrete example on how to start and kill diffrent background scripts plus some example backgound scripts. +**background-scripts** contains a more concrete example on how to start and stop different scripts plus some example backgound scripts. ``` mycommands.sh - /run_xxx and /kill-xxx wil start any script named run_xxx.sh @@ -25,13 +25,13 @@ Background jobs are an easy way to provide sceduled messages or alerts if someth run_filecontent.sh - shown the content of new files in a named dir run_notify.sh - same as notify.sh ``` -**Note:** Output of system commands often contains newlines, each newline results in a a sepperate telegram message, see function send_telegram in -mycommands.sh on how to avoid this. +**Note:** Output of system commands often contains newlines, each newline results in a telegram message, the function 'send_telegram' in +mycommands.sh avoids this by converting each newline to ' mynewlinestartshere ' before output the string. ### Use bashbot from external scripts **external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users. -#### $$VERSION$$ v0.7-pre2-2-g68afdbf +#### $$VERSION$$ v0.7-pre2-3-ge0a6d38 From 8279bdb2ea3196cc068ab607f40d1954cf395cf1 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 30 Apr 2019 15:48:55 +0200 Subject: [PATCH 62/63] add example to show system status --- examples/README.md | 8 ++- examples/send-system-status/botacl | 17 +++++ examples/send-system-status/mycommands.sh | 84 +++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 examples/send-system-status/botacl create mode 100644 examples/send-system-status/mycommands.sh diff --git a/examples/README.md b/examples/README.md index 24535a1..d1189f6 100644 --- a/examples/README.md +++ b/examples/README.md @@ -28,10 +28,16 @@ Background jobs are an easy way to provide sceduled messages or alerts if someth **Note:** Output of system commands often contains newlines, each newline results in a telegram message, the function 'send_telegram' in mycommands.sh avoids this by converting each newline to ' mynewlinestartshere ' before output the string. +**system-status** contains an example with commands showing system status. This example is adapted from https://github.com/RG72/telegram-bot-bash + +``` + mycommands.sh - sommands to show system status + botacl - controls who can show system status +``` ### Use bashbot from external scripts **external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users. -#### $$VERSION$$ v0.7-pre2-3-ge0a6d38 +#### $$VERSION$$ v0.7-pre2-4-g8dcbc29 diff --git a/examples/send-system-status/botacl b/examples/send-system-status/botacl new file mode 100644 index 0000000..40a251d --- /dev/null +++ b/examples/send-system-status/botacl @@ -0,0 +1,17 @@ +# file: botacl +# a user not listed here, will return false from 'user_is_allowed' +# +# Format: +# user:ressource:chat + +# allow user 123456789 access to all resources in all chats +123456789:*:* + +# allow user 12131415 to request systemstatus in all chats +12131415:systemstatus:* + +# * are only allowed on the right hand side and not for user! +# the following exaples are NOT valid! +*:*:* +*:start:* +*:*:98979695 diff --git a/examples/send-system-status/mycommands.sh b/examples/send-system-status/mycommands.sh new file mode 100644 index 0000000..de64d56 --- /dev/null +++ b/examples/send-system-status/mycommands.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# files: mycommands.sh +# +# this example is rendered after https://github.com/RG72/telegram-bot-bash +# to show how you can customize bashbot by only editing mycommands.sh +# NOTE: this is not tested, simply copied from original source and reworked! +# +#### $$VERSION$$ v0.7-pre2-4-g8dcbc29 +# +# shellcheck disable=SC2154 +# shellcheck disable=SC2034 + + +# uncomment the following lines to overwrite info and help messages +#' + +# returned messages + +bashbot_info='This bot allows you to request status of your system. +To begin using the bot, try with the /help command. +' +bashbot_help='*Availiable commands*: +/s *sensors* +/ss *smbstatus* +/free *memory status* +/md *raid status* +/lvs *lvm status* +/lvsd *Datailed lvm status* +/df *disk space* +/ifconfig *ifconfig output* +/smart *-d sda* _smart status for sda drive_ +' +IDMESSAGEPRE="Your chat identifier is" + + +# your additional bahsbot commands +# NOTE: command can have @botname attached, you must add * in case tests... +mycommands() { + if user_is_allowed "${USER[ID]}" "systemstatus"; then + case "$MESSAGE" in + '/md'|'raid_status') msg="$(cat /proc/mdstat)";; + '/ss'|'smbstatus') + msg="" + smbstatus >/tmp/smbstatus + send_doc "$TARGET" "/tmp/smbstatus" + prevActiveTime=$curTime + ;; + '/s'|'sensors'|'/sensors') msg="$(sensors | sed -r 's/\s|\)+//g' | sed -r 's/\(high=|\(min=/\//' | sed -r 's/\,crit=|\,max=/\//')";; + '/free') msg="$(free -h)";; + '/pvs') msg="$(pvs)";; + '/ifconfig') msg="$(ifconfig)";; + '/vgs') msg="$(vgs)";; + '/lvs') msg="$(lvs | sed -r 's/\s+/\n/g')";; + '/lvsd') msg="$(lvs -a -o +devices | sed -r 's/\s+/\n/g')";; + '/smart'|'/smartctl') + if [ "$OPTARG" == "" ]; then + msg="example \`/smart sda\`" + else + drive="$(echo "$OPTARG" | cut -c 1-3)" + echo "smartctl -a /dev/$drive" + msg="$(smartctl -a "/dev/$drive")" + fi + ;; + '/df') msg="$(df -h | sed -r 's/^/\n/' | sed -r 's/\s+/\n/g')";; + esac + + if [ "$msg" != "" ]; then + send_telegram "${CHAT[ID]}" "$msg" + fi + else + send_normal_message "Sorry, you are not allowed to use this bot!" + fi +} + +# place your processing functions here + +# converts newlines for telegram and send as one message +# $1 chat +# $2 message +send_telegram() { + # output to telegram + send_message "${1}" "$(sed <<< "${2}" -e ':a;N;$!ba;s/\n/ mynewlinestartshere /g')" +} # 2>>"$0.log" + From 4b69c4eaad4862baeabc283d7dc14571087d93ff Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 30 Apr 2019 15:50:23 +0200 Subject: [PATCH 63/63] Version v0.7 RC1 --- README.html | 2 +- README.md | 2 +- README.txt | 2 +- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/all-tests.sh | 2 +- dev/git-add.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-dist.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- examples/README.md | 2 +- examples/background-scripts/run_diskusage.sh | 2 +- examples/background-scripts/run_filecontent.sh | 2 +- examples/background-scripts/run_filename.sh | 2 +- examples/background-scripts/run_notify.sh | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question.sh | 2 +- examples/send-system-status/mycommands.sh | 2 +- modules/aliases.sh | 2 +- modules/background.sh | 2 +- modules/inline.sh | 2 +- mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/a-commit-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- 45 files changed, 45 insertions(+), 45 deletions(-) diff --git a/README.html b/README.html index 3af1370..dcdd24f 100644 --- a/README.html +++ b/README.html @@ -97,6 +97,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.7-pre2-3-ge0a6d38

    +


    VERSION
    v0.7-rc1-0-g8279bdb

    diff --git a/README.md b/README.md index 868b9a1..d4a5fac 100644 --- a/README.md +++ b/README.md @@ -93,4 +93,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.7-pre2-3-ge0a6d38 +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/README.txt b/README.txt index 63f0133..d354c82 100644 --- a/README.txt +++ b/README.txt @@ -130,4 +130,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.7-pre2-3-ge0a6d38 +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/bashbot.rc b/bashbot.rc index 77e8a5c..1cf26be 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index b6b6879..4a090ff 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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index ad3c137..fff8090 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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/all-tests.sh b/dev/all-tests.sh index c2fb711..3a5d570 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/git-add.sh b/dev/git-add.sh index 7cf8979..3339fbc 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 92c1591..cc4ccd4 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index cd92f63..da5e5bc 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 8be89f0..45f7467 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 28fef22..4112b4d 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.7-pre2-3-ge0a6d38 +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index b246f19..faa64f8 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 8f76456..a1b4dd6 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index f83c55f..437f3fd 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -63,5 +63,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 6d518ae..d891e68 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -65,5 +65,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/doc/2_usage.md b/doc/2_usage.md index ba089a5..011d224 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -167,5 +167,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 6684b65..4480f4c 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -177,5 +177,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/doc/4_expert.md b/doc/4_expert.md index 7f08530..abc9c95 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/doc/5_practice.md b/doc/5_practice.md index a7f4625..9e8a868 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -153,5 +153,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/doc/6_reference.md b/doc/6_reference.md index 3fe0605..8ce949b 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -489,5 +489,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.7-pre2-3-ge0a6d38 +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/doc/7_develop.md b/doc/7_develop.md index 7e17777..57723d8 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -92,5 +92,5 @@ fi #### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.7-pre2-3-ge0a6d38 +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/doc/8_custom.md b/doc/8_custom.md index acfca7e..da4611a 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -117,5 +117,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/examples/README.md b/examples/README.md index d1189f6..1917f03 100644 --- a/examples/README.md +++ b/examples/README.md @@ -38,6 +38,6 @@ mycommands.sh avoids this by converting each newline to ' mynewlinestartshere ' **external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users. -#### $$VERSION$$ v0.7-pre2-4-g8dcbc29 +#### $$VERSION$$ v0.7-rc1-0-g8279bdb diff --git a/examples/background-scripts/run_diskusage.sh b/examples/background-scripts/run_diskusage.sh index 05fe882..b4217a0 100755 --- a/examples/background-scripts/run_diskusage.sh +++ b/examples/background-scripts/run_diskusage.sh @@ -4,7 +4,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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/background-scripts/run_filecontent.sh b/examples/background-scripts/run_filecontent.sh index c9d9551..467ede3 100755 --- a/examples/background-scripts/run_filecontent.sh +++ b/examples/background-scripts/run_filecontent.sh @@ -2,7 +2,7 @@ # file: run_filename # background job to display content of all new files in WATCHDIR # -#### $$VERSION$$ v0.7-pre2-2-g68afdbf +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/background-scripts/run_filename.sh b/examples/background-scripts/run_filename.sh index 18a7356..08de54b 100755 --- a/examples/background-scripts/run_filename.sh +++ b/examples/background-scripts/run_filename.sh @@ -2,7 +2,7 @@ # file: run_filename # background job to display all new files in WATCHDIR # -#### $$VERSION$$ v0.7-pre2-2-g68afdbf +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/background-scripts/run_notify.sh b/examples/background-scripts/run_notify.sh index ef6275c..9f563ae 100755 --- a/examples/background-scripts/run_notify.sh +++ b/examples/background-scripts/run_notify.sh @@ -4,7 +4,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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 953a593..dc89324 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index f1382f1..6826000 100755 --- a/examples/calc.sh +++ b/examples/calc.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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index ef6275c..9f563ae 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -4,7 +4,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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index 4cf09c5..faa0e72 100755 --- a/examples/question.sh +++ b/examples/question.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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/send-system-status/mycommands.sh b/examples/send-system-status/mycommands.sh index de64d56..2444f7d 100644 --- a/examples/send-system-status/mycommands.sh +++ b/examples/send-system-status/mycommands.sh @@ -5,7 +5,7 @@ # to show how you can customize bashbot by only editing mycommands.sh # NOTE: this is not tested, simply copied from original source and reworked! # -#### $$VERSION$$ v0.7-pre2-4-g8dcbc29 +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/modules/aliases.sh b/modules/aliases.sh index c0bb68b..473db4c 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # # source from commands.sh to use the aliases diff --git a/modules/background.sh b/modules/background.sh index e571094..fba9649 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.7-pre2-2-g68afdbf +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/inline.sh b/modules/inline.sh index f8e7108..f994b35 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -5,6 +5,6 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # source from commands.sh to use the inline functions diff --git a/mycommands.sh b/mycommands.sh index 0f88be6..148bb60 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index f1648e5..9f9305d 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 2b6ae73..63b6cca 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index fa5ad5b..3f20fb1 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb ../dev/hooks/pre-commit.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 1b6736f..be914f2 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index eb7a993..a3b35fa 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index bc4f074..0a89905 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index f3081ff..7eda80d 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.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index fe5d79b..dafd32b 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.7-pre2-0-g7ce2c5b +#### $$VERSION$$ v0.7-rc1-0-g8279bdb # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh