From b8414b3d05ac6f26db7dd8eb97d43e850c0afba8 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 10 May 2019 21:38:25 +0200 Subject: [PATCH 01/27] fix make-dist.sh --- dev/make-dist.sh | 3 ++- mycommands.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dev/make-dist.sh b/dev/make-dist.sh index 65a3812..af625cf 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.72-1-g67c47ac +#### $$VERSION$$ v0.72-3-gdb14eb9 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -31,6 +31,7 @@ cp -r ${DISTFILES} "${DISTDIR}" cd "${DISTDIR}" || exit 1 # additional stuff +mv "bashbot.rc" "bashbot.rc.dist" mv "commands.sh" "commands.sh.dist" mv "mycommands.sh" "mycommands.sh.dist" diff --git a/mycommands.sh b/mycommands.sh index 6584e8f..5fde541 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.72-1-g67c47ac +#### $$VERSION$$ v0.72-3-gdb14eb9 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -64,6 +64,7 @@ else ####################### # Inline query examples, do not use them in production (exept image search ;-) # shellcheck disable=SC2128 + iQUERY="${iQUERY,,}" # all lowercase case "${iQUERY}" in "image "*) # search images with yahoo local search="${iQUERY#* }" From 0b36bc517b9b2c5df8e34a18faa10937014ad2da Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 10 May 2019 21:41:59 +0200 Subject: [PATCH 02/27] develop v0.80-dev2 --- 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 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dev/all-tests.sh b/dev/all-tests.sh index c0c1199..edf079a 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-0-gdbba89c # 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 5127114..275152c 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-0-gdbba89c # 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 17d42e6..f379596 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-0-gdbba89c ############ # 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 49a2982..2879aa5 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-0-gdbba89c ############ # 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 0abb9d0..4354a98 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-0-gdbba89c # 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 af625cf..c3228f0 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.72-3-gdb14eb9 +#### $$VERSION$$ v0.80-dev2-0-gdbba89c # 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 4cc2c8b..25806fb 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-0-gdbba89c bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 8c04f1d..c9b9171 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-0-gdbba89c # shellcheck disable=SC2016 # # Easy Versioning in git: From 0c5e3dd5975de6c3746033afcaa2029a1d540078 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 10 May 2019 21:44:13 +0200 Subject: [PATCH 03/27] develop v0.80-dev2 --- 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-multi.sh | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question.sh | 2 +- examples/send-system-status/botacl | 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/b-example-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_inline-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- test/e-env-test.sh | 2 +- 50 files changed, 50 insertions(+), 50 deletions(-) diff --git a/README.html b/README.html index b89a8c7..8395305 100644 --- a/README.html +++ b/README.html @@ -103,6 +103,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.72-1-g67c47ac

+


VERSION
v0.80-dev2-1-g0b36bc5

diff --git a/README.md b/README.md index 933f838..2d09455 100644 --- a/README.md +++ b/README.md @@ -98,4 +98,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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/README.txt b/README.txt index 288c2d4..bcf85c4 100644 --- a/README.txt +++ b/README.txt @@ -137,4 +137,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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/bashbot.rc b/bashbot.rc index 309696a..d68262f 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index c86f652..7251d91 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index c3d3e9f..89c600d 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/dev/all-tests.sh b/dev/all-tests.sh index edf079a..e649aff 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.80-dev2-0-gdbba89c +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 275152c..e868495 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.80-dev2-0-gdbba89c +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 f379596..3f0e08a 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-0-gdbba89c +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 ############ # 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 2879aa5..e38c9d2 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-0-gdbba89c +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 ############ # 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 4354a98..87c9c00 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.80-dev2-0-gdbba89c +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 c3228f0..f7e8188 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.80-dev2-0-gdbba89c +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 25806fb..34a9b95 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.80-dev2-0-gdbba89c +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index c9b9171..3d75f88 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.80-dev2-0-gdbba89c +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index eeb8762..eb65418 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 1743943..3329a7e 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/doc/2_usage.md b/doc/2_usage.md index fda5b85..c88a85c 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -182,5 +182,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index a383c1d..c4af452 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -180,5 +180,5 @@ See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inli #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/doc/4_expert.md b/doc/4_expert.md index a41dcf0..b7f40af 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/doc/5_practice.md b/doc/5_practice.md index 864620f..f11d950 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/doc/6_reference.md b/doc/6_reference.md index 7b88700..e94bdff 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -592,5 +592,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/doc/7_develop.md b/doc/7_develop.md index 545ed1a..bb3f7cc 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -131,5 +131,5 @@ fi #### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/doc/8_custom.md b/doc/8_custom.md index 83ff64e..bf3a37f 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/examples/README.md b/examples/README.md index ea1bea1..c0923e4 100644 --- a/examples/README.md +++ b/examples/README.md @@ -55,6 +55,6 @@ convert existing bots. **external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users. -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 diff --git a/examples/background-scripts/run_diskusage.sh b/examples/background-scripts/run_diskusage.sh index dc39707..0a3802c 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 ac9dfb1..9c07200 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 b67d8e8..0b5d2cf 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 a8fe754..dba82cd 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/bashbot-multi.sh b/examples/bashbot-multi.sh index a9d8a31..2f84d15 100755 --- a/examples/bashbot-multi.sh +++ b/examples/bashbot-multi.sh @@ -2,7 +2,7 @@ # file. multibot.sh # description: run multiple telegram bots from one installation # -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then echo "Usage: $0 botname command" diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 9095f6c..8b77918 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 89c9778..06fa895 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 a8fe754..dba82cd 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 ce7dc61..38c83a2 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/send-system-status/botacl b/examples/send-system-status/botacl index 9a75940..019624a 100644 --- a/examples/send-system-status/botacl +++ b/examples/send-system-status/botacl @@ -1,7 +1,7 @@ # file: botacl # a user not listed here, will return false from 'user_is_allowed' # -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # Format: # user:ressource:chat diff --git a/examples/send-system-status/mycommands.sh b/examples/send-system-status/mycommands.sh index 0acb579..23af90e 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/modules/aliases.sh b/modules/aliases.sh index 050c1ac..d700c45 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # # source from commands.sh to use the aliases diff --git a/modules/background.sh b/modules/background.sh index 783cf3d..94109ce 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/inline.sh b/modules/inline.sh index 2af5718..1d2d4fa 100644 --- a/modules/inline.sh +++ b/modules/inline.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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # source from commands.sh to use the inline functions diff --git a/mycommands.sh b/mycommands.sh index 5fde541..54ca77b 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.72-3-gdb14eb9 +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 89667fa..d115ed3 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 7f64d48..e652a76 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 5d0db81..c1c8818 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 ../dev/hooks/pre-commit.sh diff --git a/test/b-example-test.sh b/test/b-example-test.sh index 9ff2459..fbf2f84 100644 --- a/test/b-example-test.sh +++ b/test/b-example-test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # file: b-example-test.sh -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index c200f5b..87fc2d1 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 b03d601..7af81c3 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh index ef5091c..d642883 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 0877c4b..7840a07 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 856d999..0ba4462 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # 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 cc1472b..6c5b758 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.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/e-env-test.sh b/test/e-env-test.sh index a079317..eebfd96 100755 --- a/test/e-env-test.sh +++ b/test/e-env-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.72-1-g67c47ac +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From e492da05f7b0d79994163ccabcbf620befa3d238 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 11 May 2019 12:07:06 +0200 Subject: [PATCH 04/27] add make-standalone.sh, creates old style minimal bashbot files --- bashbot.sh | 3 +- dev/all-tests.sh | 10 ++- dev/git-add.sh | 10 ++- dev/install-hooks.sh | 10 ++- dev/{make-dist.sh => make-distribution.sh} | 11 ++- dev/make-standalone.sh | 87 ++++++++++++++++++++++ dev/version.sh | 10 ++- mycommands.sh | 4 +- 8 files changed, 127 insertions(+), 18 deletions(-) rename dev/{make-dist.sh => make-distribution.sh} (88%) create mode 100755 dev/make-standalone.sh diff --git a/bashbot.sh b/bashbot.sh index 7251d91..a5bf31e 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd # # Exit Codes: # - 0 sucess (hopefully) @@ -32,6 +32,7 @@ if [ -t 1 ] && [ "$TERM" != "" ]; then fi # get location and name of bashbot.sh +export SCRIPT SCRIPTDIR MODULEDIR RUNDIR RUNUSER SCRIPT="$0" SCRIPTDIR="$(dirname "$0")" MODULEDIR="${SCRIPTDIR}/modules" diff --git a/dev/all-tests.sh b/dev/all-tests.sh index e649aff..5af55fa 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -1,12 +1,16 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd # 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 +GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) +if [ "$GIT_DIR" != "" ] ; then + cd "$GIT_DIR/.." || exit 1 +else + echo "Sorry, no git repository $(pwd)" && exit 1 +fi # create test environment TESTENV="/tmp/bashbot.test$$" diff --git a/dev/git-add.sh b/dev/git-add.sh index e868495..250b6d0 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,12 +3,16 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd # 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 +GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) +if [ "$GIT_DIR" != "" ] ; then + cd "$GIT_DIR/.." || exit 1 +else + echo "Sorry, no git repository $(pwd)" && exit 1 +fi [ ! -f .git/.lastpush ] && echo "No push or hooks not installed, use \"git add\" instead ... Abort" && exit diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 87c9c00..b432650 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,12 +1,16 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd # 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 +GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) +if [ "$GIT_DIR" != "" ] ; then + cd "$GIT_DIR/.." || exit 1 +else + echo "Sorry, no git repository $(pwd)" && exit 1 +fi HOOKDIR="dev/hooks" diff --git a/dev/make-dist.sh b/dev/make-distribution.sh similarity index 88% rename from dev/make-dist.sh rename to dev/make-distribution.sh index f7e8188..5fe29d7 100755 --- a/dev/make-dist.sh +++ b/dev/make-distribution.sh @@ -1,12 +1,16 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd # 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 +GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) +if [ "$GIT_DIR" != "" ] ; then + cd "$GIT_DIR/.." || exit 1 +else + echo "Sorry, no git repository $(pwd)" && exit 1 +fi VERSION="$(git describe --tags | sed -e 's/-[0-9].*//' -e 's/v//')" @@ -18,6 +22,7 @@ DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh doc examples modu for test in "dev/all-tests.sh" do + [ ! -x ""${test} ] && continue if ! "${test}" ; then echo "Test ${test} failed, can't create dist!" exit 1 diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh new file mode 100755 index 0000000..e450873 --- /dev/null +++ b/dev/make-standalone.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash +# this has to run once atfer git clone +# and every time we create new hooks +#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd + +# 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 2>/dev/null) +if [ "$GIT_DIR" != "" ] ; then + cd "$GIT_DIR/.." || exit 1 +else + [ ! -f "bashbot.sh" ] && echo "bashbot.sh not found in $(pwd)" && exit 1 +fi + +#DISTNAME="telegram-bot-bash" +DISTDIR="./standalone/${DISTNAME}" +DISTFILES="bashbot.sh commands.sh mycommands.sh modules LICENSE README.txt token count botacl botadmin" + +# run tests first! + +for test in "dev/all-tests.sh" +do + [ ! -x "${test}" ] && continue + if ! "${test}" ; then + echo "Test ${test} failed, can't create standalone!" + exit 1 + fi +done + +# create dir for distribution and copy files +mkdir -p "${DISTDIR}" 2>/dev/null +# shellcheck disable=SC2086 +cp -r ${DISTFILES} "${DISTDIR}" 2>/dev/null +cd "${DISTDIR}" || exit 1 + +####################### +# here the magic starts +# create all in one bashbot.sh file + +echo "OK, noe lets do the magic ..." +echo " ... create unified commands.sh" + +{ + # first head of commands.sh + sed -n '0,/^if / p' commands.sh | head -n -2 | grep -v 'mycommands.sh' + + # then mycommands from first non comment line on + printf '\n##############################\n# my commands starts here ...\n' + sed -n '/^$/,$ p' mycommands.sh + + # last tail of commands.sh + printf '\n##############################\n# default commands starts here ...\n' + sed -n '/\/mycommands.sh"/,$ p' commands.sh | tail -n +2 + +} >>$$commands.sh + +mv $$commands.sh commands.sh +rm -f mycommands.sh + +echo " ... create unified bashbot.sh" + +{ + # first head of bashbot.sh + sed -n '0,/\/commands.sh"/ p' bashbot.sh | head -n -2 + + # then mycommands from first non comment line on + printf '\n##############################\n# bashbot modules starts here ...\n' + cat modules/*.sh | sed -e 's/^#\!\/bin\/bash.*//' + + # last tail of commands.sh + printf '\n##############################\n# bashbot functions starts here ...\n\n' + sed -n '/\/commands.sh"/,$ p' bashbot.sh + +} >>$$bashbot.sh + +mv $$bashbot.sh bashbot.sh +chmod +x bashbot.sh + +rm -rf modules + +echo "Done!" + +cd .. || exit 1 + +echo -e "\\nStandalone bashbot files are now availible in \"${DISTDIR}\":\\n" +ls -l "${DISTDIR}"* + diff --git a/dev/version.sh b/dev/version.sh index 3d75f88..7f3e518 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd # shellcheck disable=SC2016 # # Easy Versioning in git: @@ -36,8 +36,12 @@ # 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 +GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) +if [ "$GIT_DIR" != "" ] ; then + cd "$GIT_DIR/.." || exit 1 +else + echo "Sorry, no git repository $(pwd)" && exit 1 +fi unset IFS # set -f # if you are paranoid use set -f to disable globbing diff --git a/mycommands.sh b/mycommands.sh index 54ca77b..cad65c3 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd # # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -117,7 +117,7 @@ else local image result sep="" count="1" result="$(wget --user-agent 'Mozilla/5.0' -qO - "https://images.search.yahoo.com/search/images?p=$1" | sed 's/ Date: Sat, 11 May 2019 12:17:38 +0200 Subject: [PATCH 05/27] fix make-* decriptions --- dev/make-distribution.sh | 7 ++++--- dev/make-standalone.sh | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index 5fe29d7..6798b12 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash -# this has to run once atfer git clone -# and every time we create new hooks -#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd +# file: make-distribution.sh +# creates files and arcchives to dirtribute bashbot +# +#### $$VERSION$$ v0.80-dev2-3-ge492da0 # 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-standalone.sh b/dev/make-standalone.sh index e450873..2438159 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -1,7 +1,11 @@ #!/usr/bin/env bash -# this has to run once atfer git clone -# and every time we create new hooks -#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd +# file: make-standalone.sh +# even after make-distribution.sh bashbot is not self contained as it was in the past. +# +# If you your bot is finished you can use make-standalone.sh to create the +# the old all-in-one bashbot: bashbot.sh and commands.sh only! +# +#### $$VERSION$$ v0.80-dev2-3-ge492da0 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script From d08d91205d9d0c29753c9b5a50fcb4f4e56d86f2 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 11 May 2019 18:36:40 +0200 Subject: [PATCH 06/27] move process_inline to bashbot.sh, documentation make-standalone.sh --- README.html | 4 +++- README.md | 8 +++++++- README.txt | 12 +++++++++++- bashbot.sh | 15 ++++++++++++--- commands.sh | 9 +++------ doc/7_develop.md | 18 ++++++++++++++++-- modules/inline.sh | 14 +------------- 7 files changed, 53 insertions(+), 27 deletions(-) diff --git a/README.html b/README.html index 8395305..06eff05 100644 --- a/README.html +++ b/README.html @@ -78,6 +78,8 @@
  • Customize bashbot environment
  • Examples
  • +

    I don’t like the many bashbot files

    +

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

    Security Considerations

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

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

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

    @Gnadelwartz

    That’s it!

    If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!

    -


    VERSION
    v0.80-dev2-1-g0b36bc5

    +


    VERSION
    v0.80-dev2-4-gb7df57a

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

    I don’t like the many bashbot files

    -

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

    +

    You don’t like the many bashbot files?

    +

    At the beginning bashbot was simply the file bashbot.sh I can copy everywhere and run the bot. Now we have ‘commands.sh’, ‘mycommands.sh’, ’modules/*.sh’ and much more.

    +

    Hey no Problem, if you are finished with your cool bot simply run dev/make-standalone.sh to create a stripped down Version containing only ‘bashbot.sh’ and ‘commands.sh’! For more information see Create a stripped down Version of your Bot

    Security Considerations

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

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

    @@ -105,6 +106,6 @@

    @Gnadelwartz

    That’s it!

    If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!

    -


    VERSION
    v0.80-dev2-4-gb7df57a

    +


    VERSION
    v0.80-dev2-5-gd08d912

    diff --git a/README.md b/README.md index 19d54da..435d17f 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,10 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do * [Examples](examples/README.md) -### I don't like the many bashbot files +#### You don't like the many bashbot files? At the beginning bashbot was simply the file ```bashbot.sh``` I can copy everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh', 'modules/*.sh' and much more. -Hey no Problem, if you are finished with your cool bot simply run ```dev/make-standalone.sh``` to create a a stripped down Version containing only + +Hey no Problem, if you are finished with your cool bot simply run ```dev/make-standalone.sh``` to create a stripped down Version containing only 'bashbot.sh' and 'commands.sh'! For more information see [Create a stripped down Version of your Bot](doc/7_develop.md) ## Security Considerations @@ -104,4 +105,4 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-4-gb7df57a +#### $$VERSION$$ v0.80-dev2-5-gd08d912 diff --git a/README.txt b/README.txt index 3953989..fe5ac9f 100644 --- a/README.txt +++ b/README.txt @@ -65,12 +65,13 @@ all](https://core.telegram.org/bots#3-how-do-i-create-a-bot) * [Examples](examples/README.md) -### I don't like the many bashbot files +#### You don't like the many bashbot files? At the beginning bashbot was simply the file ```bashbot.sh``` I can copy everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh', 'modules/*.sh' and much more. + Hey no Problem, if you are finished with your cool bot simply run -```dev/make-standalone.sh``` to create a a stripped down Version containing only +```dev/make-standalone.sh``` to create a stripped down Version containing only 'bashbot.sh' and 'commands.sh'! For more information see [Create a stripped down Version of your Bot](doc/7_develop.md) @@ -147,4 +148,4 @@ health status If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-4-gb7df57a +#### $$VERSION$$ v0.80-dev2-5-gd08d912 diff --git a/doc/7_develop.md b/doc/7_develop.md index 8dca1a6..0d1c15c 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -24,7 +24,7 @@ Let's create a stripped down version: - delete all modules you do not need from 'modules', e.g. 'modules/inline.sh' if you don't use inline queries - delete not needed standard commands and messages from 'commands.sh' -- delete not neede commands and functions from 'mycommands.sh' +- delete not needed commands and functions from 'mycommands.sh' - run ```dev/make-standalone.sh``` to create a a stripped down version of your bo Now have a look at the directory 'standalone', here you find the files 'bashbot.sh' and 'commands.sh' containing everything to run your bot. @@ -145,5 +145,5 @@ fi #### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.80-dev2-4-gb7df57a +#### $$VERSION$$ v0.80-dev2-5-gd08d912 From 92f022d03843471069738b66fe4d3ea32e79ae0a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 12 May 2019 17:51:52 +0200 Subject: [PATCH 08/27] fix source commands.sh, fix sendJson, sendMEssage module --- bashbot.sh | 208 ++---------------------------------- commands.sh | 39 ++++--- modules/answerInline.sh | 102 ++++++++++++++++++ modules/background.sh | 74 +------------ modules/chatMember.sh | 63 +++++++++++ modules/inline.sh | 102 +----------------- modules/sendMessage.sh | 228 ++++++++++++++++++++++++++++++++++++++++ mycommands.sh | 10 +- 8 files changed, 430 insertions(+), 396 deletions(-) create mode 100644 modules/answerInline.sh create mode 100644 modules/chatMember.sh create mode 100644 modules/sendMessage.sh diff --git a/bashbot.sh b/bashbot.sh index 8c5040d..c6f674e 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-4-gb7df57a +#### $$VERSION$$ v0.80-dev2-6-g5b10e75 # # Exit Codes: # - 0 sucess (hopefully) @@ -122,30 +122,14 @@ fi BOTTOKEN="$(cat "${TOKENFILE}")" URL='https://api.telegram.org/bot'$BOTTOKEN -MSG_URL=$URL'/sendMessage' -LEAVE_URL=$URL'/leaveChat' -KICK_URL=$URL'/kickChatMember' -UNBAN_URL=$URL'/unbanChatMember' -PHO_URL=$URL'/sendPhoto' -AUDIO_URL=$URL'/sendAudio' -DOCUMENT_URL=$URL'/sendDocument' -STICKER_URL=$URL'/sendSticker' -VIDEO_URL=$URL'/sendVideo' -VOICE_URL=$URL'/sendVoice' -LOCATION_URL=$URL'/sendLocation' -VENUE_URL=$URL'/sendVenue' -ACTION_URL=$URL'/sendChatAction' -FORWARD_URL=$URL'/forwardMessage' ME_URL=$URL'/getMe' -DELETE_URL=$URL'/deleteMessage' -GETMEMBER_URL=$URL'/getChatMember' UPD_URL=$URL'/getUpdates?offset=' GETFILE_URL=$URL'/getFile' unset USER declare -A BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY -export BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY +export res BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY COMMANDS="${BASHBOT_ETC:-.}/commands.sh" if [ "$1" != "source" ]; then @@ -160,116 +144,11 @@ if [ "$1" != "source" ]; then fi -send_normal_message() { - local text="${2}" - until [ -z "${text}" ]; do - sendJson "${1}" '"text":"'"${text:0:4096}"'"' "${MSG_URL}" - text="${text:4096}" - done -} - -send_markdown_message() { - 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() { - local text="${2}" - until [ -z "${text}" ]; do - sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"html"' "${MSG_URL}" - text="${text:4096}" - done -} - +DELETE_URL=$URL'/deleteMessage' delete_message() { 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" - JsonGetString '"result","status"' <<< "$res" -} - -kick_chat_member() { - sendJson "$1" 'user_id: '"$2"'' "$KICK_URL" -} - -unban_chat_member() { - sendJson "$1" 'user_id: '"$2"'' "$UNBAN_URL" -} - -leave_chat() { - sendJson "$1" "" "$LEAVE_URL" -} - -user_is_creator() { - if [ "${1:--}" = "${2:-+}" ] || [ "$(get_chat_member_status "$1" "$2")" = "creator" ]; then return 0; fi - return 1 -} - -user_is_admin() { - local me; me="$(get_chat_member_status "$1" "$2")" - if [ "${me}" = "creator" ] || [ "${me}" = "administrator" ]; then return 0; fi - return 1 -} - -user_is_botadmin() { - local admin; admin="$(head -n 1 "${BOTADMIN}")" - [ "${admin}" = "${1}" ] && return 0 - [[ "${admin}" = "@*" ]] && [[ "${admin}" = "${2}" ]] && return 0 - if [ "${admin}" = "?" ]; then echo "${1:-?}" >"${BOTADMIN}"; return 0; fi - return 1 -} - -user_is_allowed() { - local acl="$1" - [ "$1" = "" ] && return 1 - grep -F -xq "${acl}:*:*" <"${BOTACL}" && return 0 - [ "$2" != "" ] && acl="${acl}:$2" - grep -F -xq "${acl}:*" <"${BOTACL}" && return 0 - [ "$3" != "" ] && acl="${acl}:$3" - grep -F -xq "${acl}" <"${BOTACL}" -} - -old_send_keyboard() { - local text='"text":"'"${2}"'"' - shift 2 - local keyboard=init - OLDIFS=$IFS - IFS=$(echo -en "\"") - for f in "$@" ;do [ "$f" != " " ] && keyboard="$keyboard, [\"$f\"]";done - IFS=$OLDIFS - keyboard=${keyboard/init, /} - sendJson "${1}" "${text}"', "reply_markup": {"keyboard": [ '"${keyboard}"' ],"one_time_keyboard": true}' "$MSG_URL" -} - -ISEMPTY="ThisTextIsEmptyAndWillBeDeleted" -send_keyboard() { - if [[ "$3" != *'['* ]]; then old_send_keyboard "$@"; return; fi - local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${ISEMPTY}"'"' - local one_time=', "one_time_keyboard":true' && [ "$4" != "" ] && one_time="" - sendJson "${1}" "${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"'}' "$MSG_URL" - # '"text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true}' -} - -remove_keyboard() { - 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}' -} -send_inline_keyboard() { - 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_button() { - send_inline_keyboard "${1}" "${2}" '[ {"text":"'"${3}"'", "url":"'"${4}"'"}]' -} - # usage: sendJson "chat" "JSON" "URL" sendJson(){ local chat=""; @@ -278,7 +157,6 @@ sendJson(){ -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]}" } # convert common telegram entities to JSON @@ -300,82 +178,6 @@ get_file() { echo "${URL}/$(echo "${res}" | jsonGetString '"result","file_path"')" } -send_file() { - [ "$2" = "" ] && return - local CAPTION - local chat_id=$1 - local file=$2 - echo "$file" | grep -qE "$FILE_REGEX" || return - local ext="${file##*.}" - case $ext in - mp3|flac) - CUR_URL=$AUDIO_URL - WHAT=audio - STATUS=upload_audio - CAPTION="$3" - ;; - png|jpg|jpeg|gif) - CUR_URL=$PHO_URL - WHAT=photo - STATUS=upload_photo - CAPTION="$3" - ;; - webp) - CUR_URL=$STICKER_URL - WHAT=sticker - STATUS= - ;; - mp4) - CUR_URL=$VIDEO_URL - WHAT=video - STATUS=upload_video - CAPTION="$3" - ;; - - ogg) - CUR_URL=$VOICE_URL - WHAT=voice - STATUS= - ;; - *) - CUR_URL=$DOCUMENT_URL - WHAT=document - STATUS=upload_document - CAPTION="$3" - ;; - esac - send_action "$chat_id" "$STATUS" - res="$(curl -s "$CUR_URL" -F "chat_id=$chat_id" -F "$WHAT=@$file" -F "caption=$CAPTION")" -} - -# 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 location - -send_action() { - [ "$2" = "" ] && return - sendJson "${1}" '"action": "'"${2}"'"' "$ACTION_URL" -} - -send_location() { - [ "$3" = "" ] && return - sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"'' "$LOCATION_URL" -} - -send_venue() { - local add="" - [ "$5" = "" ] && return - [ "$6" != "" ] && add=', "foursquare_id": '"$6"'' - sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"', "address": "'"${5}"'", "title": "'"${4}"'"'"${add}" "$VENUE_URL" -} - - -forward_message() { - [ "$3" = "" ] && return - sendJson "${1}" '"from_chat_id": '"${2}"', "message_id": '"${3}"'' "$FORWARD_URL" -} -forward() { # backward compatibility - forward_message "$@" || return -} - # returns true if function exist _is_function() { @@ -398,7 +200,9 @@ process_client() { fi # Tmux copname="$ME"_"${CHAT[ID]}" - source commands.sh + # shellcheck source=./commands.sh + source "${COMMANDS}" "$1" + tmpcount="COUNT${CHAT[ID]}" grep -q "$tmpcount" <"${COUNTFILE}" >/dev/null 2>&1 || echo "$tmpcount">>"${COUNTFILE}" # To get user count execute bash bashbot.sh count diff --git a/commands.sh b/commands.sh index be5fe65..e86ad8f 100644 --- a/commands.sh +++ b/commands.sh @@ -5,10 +5,8 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-4-gb7df57a +#### $$VERSION$$ v0.80-dev2-6-g5b10e75 # -# shellcheck disable=SC2154 -# shellcheck disable=SC2034 # 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 @@ -38,43 +36,50 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili) and KayM(@gnadelwar Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) ' -if [ "${1}" != "source" ]; then - # shellcheck source=./modules/aliases.sh - [ -r "${MODULEDIR:-.}/aliases.sh" ] && source "${MODULEDIR:-.}/aliases.sh" - # shellcheck source=./modules/background.sh - [ -r "${MODULEDIR:-.}/background.sh" ] && source "${MODULEDIR:-.}/background.sh" - # shellcheck source=./modules/background.sh - [ -r "${MODULEDIR:-.}/inline.sh" ] && source "${MODULEDIR:-.}/inline.sh" -else - # defaults to no inline and nonsense home dir - INLINE="0" - FILE_REGEX='/home/user/allowed/.*' +# load modues on startup and always on on debug +if [ "${1}" = "source" ] || [[ "${1}" = *"debug"* ]] ; then + # load all readable modules + for modules in ${MODULEDIR:-.}/*.sh ; do + # shellcheck source=./modules/aliases.sh + [ -r "${modules}" ] && source "${modules}" "${1}" + done fi +# defaults to no inline and nonsense home dir +export INLINE="0" +export FILE_REGEX='/home/user/allowed/.*' + + # load mycommands # shellcheck source=./commands.sh [ -r "${BASHBOT_ETC:-.}/mycommands.sh" ] && source "${BASHBOT_ETC:-.}/mycommands.sh" "${1}" if [ "${1}" != "source" ];then + # this was here from beginning, can some tell me what this is for? + # I GUESS it was used to auto send files and locations?? + # this will be removed!!! if ! tmux ls 2>/dev/null | grep -v send | grep -q "$copname"; then - # interactive running? [ ! -z "${URLS[*]}" ] && { curl -s "${URLS[*]}" -o "$NAME" send_file "${CHAT[ID]}" "$NAME" "$CAPTION" rm -f "$NAME" } [ ! -z "${LOCATION[*]}" ] && send_location "${CHAT[ID]}" "${LOCATION[LATITUDE]}" "${LOCATION[LONGITUDE]}" - fi + # detect inline commands.... + # no default commands, all processing is done in myinlines() if [ "$INLINE" != "0" ] && [ "${iQUERY[ID]}" != "" ]; then if _is_function process_inline; then # forward iinline query to optional dispatcher _is_function myinlines && myinlines fi + + # regular (gobal) commands ... + # your commands are in mycommands() else - + case "${MESSAGE}" in ################################################ # GLOBAL commands start here, edit messages only diff --git a/modules/answerInline.sh b/modules/answerInline.sh new file mode 100644 index 0000000..5ad0edc --- /dev/null +++ b/modules/answerInline.sh @@ -0,0 +1,102 @@ +#!/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.80-dev2-4-gb7df57a + +# source from commands.sh to use the inline functions + +INLINE_QUERY=$URL'/answerInlineQuery' + +answer_inline_query() { + answer_inline_multi "${1}" "$(shift; inline_query_compose "$RANDOM" "$@")" +} +answer_inline_multi() { + sendJson "" '"inline_query_id": '"${1}"', "results": ['"${2}"']' "${INLINE_QUERY}" +} + +# $1 unique ID for answer +# $2 type of answer +# remaining arguments are the "must have" arguments in the order as in telegram doc +# followed by the optional arguments: https://core.telegram.org/bots/api#inlinequeryresult +inline_query_compose(){ + local JSON="{}" + local ID="${1}" + local fours last + # title2Json title caption description markup inlinekeyboard + case "${2}" in + # user provided media + "article"|"message") # article ID title message (markup decription) + JSON='{"type":"article","id":"'$ID'","input_message_content": {"message_text":"'$4'"} '$(title2Json "$3" "" "$5" "$6")'}' + ;; + "photo") # photo ID photoURL (thumbURL title description caption) + [ "$4" = "" ] && tumb="$3" + JSON='{"type":"photo","id":"'$ID'","photo_url":"'$3'","thumb_url":"'$4${tumb}'"'$(title2Json "$5" "$7" "$6")'}' + ;; + "gif") # gif ID photoURL (thumbURL title caption) + [ "$4" = "" ] && tumb="$3" + JSON='{"type":"gif","id":"'$ID'","gif_url":"'$3'", "thumb_url":"'$4${tumb}'"'$(title2Json "$5" "$6")'}' + ;; + "mpeg4_gif") # mpeg4_gif ID mpegURL (thumbURL title caption) + [ "$4" != "" ] && tumb='","thumb_url":"'$4'"' + JSON='{"type":"mpeg4_gif","id":"'$ID'","mpeg4_url":"'$3'"'${tumb}$(title2Json "$5" "$6")'}' + ;; + "video") # video ID videoURL mime thumbURL title (caption) + JSON='{"type":"video","id":"'$ID'","video_url":"'$3'","mime_type":"'$4'","thumb_url":"'$5'"'$(title2Json "$6" "$7")'}' + ;; + "audio") # audio ID audioURL title (caption) + JSON='{"type":"audio","id":"'$ID'","audio_url":"'$3'"'$(title2Json "$4" "$5")'}' + ;; + "voice") # voice ID voiceURL title (caption) + JSON='{"type":"voice","id":"'$ID'","voice_url":"'$3'"'$(title2Json "$4" "$5")'}' + ;; + "document") # document ID title documentURL mimetype (caption description) + JSON='{"type":"document","id":"'$ID'","document_url":"'$4'","mime_type":"'$5'"'$(title2Json "$3" "$6" "$7")'}' + ;; + "location") # location ID lat long title + JSON='{"type":"location","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'"}' + ;; + "venue") # venue ID lat long title (adress forsquare) + [ "$6" = "" ] && addr="$5" + [ "$7" != "" ] && fours=',"foursquare_id":"'$7'"' + JSON='{"type":"venue","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'","address":"'$6${addr}'"'${fours}'}' + ;; + "contact") # contact ID phone first (last thumb) + [ "$5" != "" ] && last=',"last_name":"'$5'"' + [ "$6" != "" ] && tumb='","thumb_url":"'$6'"' + JSON='{"type":"contact","id":"'$ID'","phone_number":"'$3'","first_name":"'$4'"'${last}'"}' + ;; + # title2Json title caption description markup inlinekeyboard + # Cached media stored in Telegram server + "cached_photo") # photo ID file (title description caption) + JSON='{"type":"photo","id":"'$ID'","photo_file_id":"'$3'"'$(title2Json "$4" "$6" "$5")'}' + ;; + "cached_gif") # gif ID file (title caption) + JSON='{"type":"gif","id":"'$ID'","gif_file_id":"'$3'"'$(title2Json "$4" "$5")'}' + ;; + "cached_mpeg4_gif") # mpeg ID file (title caption) + JSON='{"type":"mpeg4_gif","id":"'$ID'","mpeg4_file_id":"'$3'"'$(title2Json "$4" "$5")'}' + ;; + "cached_sticker") # sticker ID file + JSON='{"type":"sticker","id":"'$ID'","sticker_file_id":"'$3'"}' + ;; + "cached_document") # document ID title file (description caption) + JSON='{"type":"document","id":"'$ID'","document_file_id":"'$4'"'$(title2Json "$3" "$6" "$5")'}' + ;; + "cached_video") # video ID file title (description caption) + JSON='{"type":"video","id":"'$ID'","video_file_id":"'$3'"'$(title2Json "$4" "$6" "$5")'}' + ;; + "cached_voice") # voice ID file title (caption) + JSON='{"type":"voice","id":"'$ID'","voice_file_id":"'$3'"'$(title2Json "$4" "$5")'}' + ;; + "cached_audio") # audio ID file title (caption) + JSON='{"type":"audio","id":"'$ID'","audio_file_id":"'$3'"'$(title2Json "$4" "$5")'}' + ;; + esac + + echo "${JSON}" +} + diff --git a/modules/background.sh b/modules/background.sh index 94109ce..946c59b 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -5,78 +5,10 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-6-g5b10e75 # 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() { - [ "$2" = "" ] && return - local text keyboard btext burl no_keyboard file lat long title address sent - 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.*//')" - 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 "$1" "$text" - sent=y - fi - if [ "$keyboard" != "" ]; then - if [[ "$keyboard" != *"["* ]]; then # pre 0.60 style - keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]" - fi - send_keyboard "$1" "$text" "$keyboard" - sent=y - fi - if [ "$btext" != "" ] && [ "$burl" != "" ]; then - send_button "$1" "$text" "$btext" "$burl" - sent=y - fi - if [ "$file" != "" ]; then - send_file "$1" "$file" "$text" - sent=y - fi - if [ "$lat" != "" ] && [ "$long" != "" ]; then - if [ "$address" != "" ] && [ "$title" != "" ]; then - send_venue "$1" "$lat" "$long" "$title" "$address" - else - send_location "$1" "$lat" "$long" - fi - sent=y - fi - if [ "$sent" != "y" ];then - send_text "$1" "$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 @@ -99,7 +31,9 @@ checkback() { } checkproc() { - tmux ls | grep -q "$1${copname}"; res=$?; return $? + tmux ls | grep -q "$1${copname}" + # shellcheck disable=SC2034 + res=$?; return $? } killback() { diff --git a/modules/chatMember.sh b/modules/chatMember.sh new file mode 100644 index 0000000..9f19534 --- /dev/null +++ b/modules/chatMember.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# file: modules/chatMember.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.80-dev2-6-g5b10e75 + +# source from commands.sh to use the member functions + +LEAVE_URL=$URL'/leaveChat' +KICK_URL=$URL'/kickChatMember' +UNBAN_URL=$URL'/unbanChatMember' +GETMEMBER_URL=$URL'/getChatMember' + +# usage: status="$(get_chat_member_status "chat" "user")" +get_chat_member_status() { + sendJson "$1" 'user_id: '"$2"'' "$GETMEMBER_URL" + # shellcheck disable=SC2154 + JsonGetString '"result","status"' <<< "$res" +} + +kick_chat_member() { + sendJson "$1" 'user_id: '"$2"'' "$KICK_URL" +} + +unban_chat_member() { + sendJson "$1" 'user_id: '"$2"'' "$UNBAN_URL" +} + +leave_chat() { + sendJson "$1" "" "$LEAVE_URL" +} + +user_is_creator() { + if [ "${1:--}" = "${2:-+}" ] || [ "$(get_chat_member_status "$1" "$2")" = "creator" ]; then return 0; fi + return 1 +} + +user_is_admin() { + local me; me="$(get_chat_member_status "$1" "$2")" + if [ "${me}" = "creator" ] || [ "${me}" = "administrator" ]; then return 0; fi + return 1 +} + +user_is_botadmin() { + local admin; admin="$(head -n 1 "${BOTADMIN}")" + [ "${admin}" = "${1}" ] && return 0 + [[ "${admin}" = "@*" ]] && [[ "${admin}" = "${2}" ]] && return 0 + if [ "${admin}" = "?" ]; then echo "${1:-?}" >"${BOTADMIN}"; return 0; fi + return 1 +} + +user_is_allowed() { + local acl="$1" + [ "$1" = "" ] && return 1 + grep -F -xq "${acl}:*:*" <"${BOTACL}" && return 0 + [ "$2" != "" ] && acl="${acl}:$2" + grep -F -xq "${acl}:*" <"${BOTACL}" && return 0 + [ "$3" != "" ] && acl="${acl}:$3" + grep -F -xq "${acl}" <"${BOTACL}" +} diff --git a/modules/inline.sh b/modules/inline.sh index 5ad0edc..601d1e5 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -1,102 +1,2 @@ #!/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.80-dev2-4-gb7df57a - -# source from commands.sh to use the inline functions - -INLINE_QUERY=$URL'/answerInlineQuery' - -answer_inline_query() { - answer_inline_multi "${1}" "$(shift; inline_query_compose "$RANDOM" "$@")" -} -answer_inline_multi() { - sendJson "" '"inline_query_id": '"${1}"', "results": ['"${2}"']' "${INLINE_QUERY}" -} - -# $1 unique ID for answer -# $2 type of answer -# remaining arguments are the "must have" arguments in the order as in telegram doc -# followed by the optional arguments: https://core.telegram.org/bots/api#inlinequeryresult -inline_query_compose(){ - local JSON="{}" - local ID="${1}" - local fours last - # title2Json title caption description markup inlinekeyboard - case "${2}" in - # user provided media - "article"|"message") # article ID title message (markup decription) - JSON='{"type":"article","id":"'$ID'","input_message_content": {"message_text":"'$4'"} '$(title2Json "$3" "" "$5" "$6")'}' - ;; - "photo") # photo ID photoURL (thumbURL title description caption) - [ "$4" = "" ] && tumb="$3" - JSON='{"type":"photo","id":"'$ID'","photo_url":"'$3'","thumb_url":"'$4${tumb}'"'$(title2Json "$5" "$7" "$6")'}' - ;; - "gif") # gif ID photoURL (thumbURL title caption) - [ "$4" = "" ] && tumb="$3" - JSON='{"type":"gif","id":"'$ID'","gif_url":"'$3'", "thumb_url":"'$4${tumb}'"'$(title2Json "$5" "$6")'}' - ;; - "mpeg4_gif") # mpeg4_gif ID mpegURL (thumbURL title caption) - [ "$4" != "" ] && tumb='","thumb_url":"'$4'"' - JSON='{"type":"mpeg4_gif","id":"'$ID'","mpeg4_url":"'$3'"'${tumb}$(title2Json "$5" "$6")'}' - ;; - "video") # video ID videoURL mime thumbURL title (caption) - JSON='{"type":"video","id":"'$ID'","video_url":"'$3'","mime_type":"'$4'","thumb_url":"'$5'"'$(title2Json "$6" "$7")'}' - ;; - "audio") # audio ID audioURL title (caption) - JSON='{"type":"audio","id":"'$ID'","audio_url":"'$3'"'$(title2Json "$4" "$5")'}' - ;; - "voice") # voice ID voiceURL title (caption) - JSON='{"type":"voice","id":"'$ID'","voice_url":"'$3'"'$(title2Json "$4" "$5")'}' - ;; - "document") # document ID title documentURL mimetype (caption description) - JSON='{"type":"document","id":"'$ID'","document_url":"'$4'","mime_type":"'$5'"'$(title2Json "$3" "$6" "$7")'}' - ;; - "location") # location ID lat long title - JSON='{"type":"location","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'"}' - ;; - "venue") # venue ID lat long title (adress forsquare) - [ "$6" = "" ] && addr="$5" - [ "$7" != "" ] && fours=',"foursquare_id":"'$7'"' - JSON='{"type":"venue","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'","address":"'$6${addr}'"'${fours}'}' - ;; - "contact") # contact ID phone first (last thumb) - [ "$5" != "" ] && last=',"last_name":"'$5'"' - [ "$6" != "" ] && tumb='","thumb_url":"'$6'"' - JSON='{"type":"contact","id":"'$ID'","phone_number":"'$3'","first_name":"'$4'"'${last}'"}' - ;; - # title2Json title caption description markup inlinekeyboard - # Cached media stored in Telegram server - "cached_photo") # photo ID file (title description caption) - JSON='{"type":"photo","id":"'$ID'","photo_file_id":"'$3'"'$(title2Json "$4" "$6" "$5")'}' - ;; - "cached_gif") # gif ID file (title caption) - JSON='{"type":"gif","id":"'$ID'","gif_file_id":"'$3'"'$(title2Json "$4" "$5")'}' - ;; - "cached_mpeg4_gif") # mpeg ID file (title caption) - JSON='{"type":"mpeg4_gif","id":"'$ID'","mpeg4_file_id":"'$3'"'$(title2Json "$4" "$5")'}' - ;; - "cached_sticker") # sticker ID file - JSON='{"type":"sticker","id":"'$ID'","sticker_file_id":"'$3'"}' - ;; - "cached_document") # document ID title file (description caption) - JSON='{"type":"document","id":"'$ID'","document_file_id":"'$4'"'$(title2Json "$3" "$6" "$5")'}' - ;; - "cached_video") # video ID file title (description caption) - JSON='{"type":"video","id":"'$ID'","video_file_id":"'$3'"'$(title2Json "$4" "$6" "$5")'}' - ;; - "cached_voice") # voice ID file title (caption) - JSON='{"type":"voice","id":"'$ID'","voice_file_id":"'$3'"'$(title2Json "$4" "$5")'}' - ;; - "cached_audio") # audio ID file title (caption) - JSON='{"type":"audio","id":"'$ID'","audio_file_id":"'$3'"'$(title2Json "$4" "$5")'}' - ;; - esac - - echo "${JSON}" -} - +echo "use answerInline.sh" >&2 diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh new file mode 100644 index 0000000..92e1f50 --- /dev/null +++ b/modules/sendMessage.sh @@ -0,0 +1,228 @@ +#!/bin/bash +# file: modules/message.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.80-dev2-6-g5b10e75 + +# source from commands.sh to use the sendMessage functions + +MSG_URL=$URL'/sendMessage' +PHO_URL=$URL'/sendPhoto' +AUDIO_URL=$URL'/sendAudio' +DOCUMENT_URL=$URL'/sendDocument' +STICKER_URL=$URL'/sendSticker' +VIDEO_URL=$URL'/sendVideo' +VOICE_URL=$URL'/sendVoice' +LOCATION_URL=$URL'/sendLocation' +VENUE_URL=$URL'/sendVenue' +ACTION_URL=$URL'/sendChatAction' +FORWARD_URL=$URL'/forwardMessage' + +send_normal_message() { + local text="${2}" + until [ -z "${text}" ]; do + sendJson "${1}" '"text":"'"${text:0:4096}"'"' "${MSG_URL}" + text="${text:4096}" + done +} + +send_markdown_message() { + 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() { + local text="${2}" + until [ -z "${text}" ]; do + sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"html"' "${MSG_URL}" + text="${text:4096}" + done +} + +old_send_keyboard() { + local text='"text":"'"${2}"'"' + shift 2 + local keyboard=init + OLDIFS=$IFS + IFS=$(echo -en "\"") + for f in "$@" ;do [ "$f" != " " ] && keyboard="$keyboard, [\"$f\"]";done + IFS=$OLDIFS + keyboard=${keyboard/init, /} + sendJson "${1}" "${text}"', "reply_markup": {"keyboard": [ '"${keyboard}"' ],"one_time_keyboard": true}' "$MSG_URL" +} + +ISEMPTY="ThisTextIsEmptyAndWillBeDeleted" +sendEmpty() { + sendJson "${@}" + [[ "${2}" = *"${ISEMPTY}"* ]] && delete_message "${1}" "${BOTSENT[ID]}" +} +send_keyboard() { + if [[ "$3" != *'['* ]]; then old_send_keyboard "${@}"; return; fi + local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${ISEMPTY}"'"' + local one_time=', "one_time_keyboard":true' && [ "$4" != "" ] && one_time="" + sendEmpty "${1}" "${text}"', "reply_markup": {"keyboard": [ '"${3}"' ] '"${one_time}"'}' "$MSG_URL" + # '"text":"$2", "reply_markup": {"keyboard": [ ${3} ], "one_time_keyboard": true}' +} + +remove_keyboard() { + local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${ISEMPTY}"'"' + sendEmpty "${1}" "${text}"', "reply_markup": {"remove_keyboard":true}' "$MSG_URL" + #JSON='"text":"$2", "reply_markup": {"remove_keyboard":true}' +} +send_inline_keyboard() { + local text='"text":"'"${2}"'"'; [ "${2}" = "" ] && text='"text":"'"${ISEMPTY}"'"' + sendEmpty "${1}" "${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]}' "$MSG_URL" + # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}' +} +send_button() { + send_inline_keyboard "${1}" "${2}" '[ {"text":"'"${3}"'", "url":"'"${4}"'"}]' +} + + +send_file() { + [ "$2" = "" ] && return + local CAPTION + local chat_id=$1 + local file=$2 + echo "$file" | grep -qE "$FILE_REGEX" || return + local ext="${file##*.}" + case $ext in + mp3|flac) + CUR_URL=$AUDIO_URL + WHAT=audio + STATUS=upload_audio + CAPTION="$3" + ;; + png|jpg|jpeg|gif) + CUR_URL=$PHO_URL + WHAT=photo + STATUS=upload_photo + CAPTION="$3" + ;; + webp) + CUR_URL=$STICKER_URL + WHAT=sticker + STATUS= + ;; + mp4) + CUR_URL=$VIDEO_URL + WHAT=video + STATUS=upload_video + CAPTION="$3" + ;; + + ogg) + CUR_URL=$VOICE_URL + WHAT=voice + STATUS= + ;; + *) + CUR_URL=$DOCUMENT_URL + WHAT=document + STATUS=upload_document + CAPTION="$3" + ;; + esac + send_action "$chat_id" "$STATUS" + # convert over to sendJson!! + # shellcheck disable=SC2034 + res="$(curl -s "$CUR_URL" -F "chat_id=$chat_id" -F "$WHAT=@$file" -F "caption=$CAPTION")" +} + +# 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 location + +send_action() { + [ "$2" = "" ] && return + sendJson "${1}" '"action": "'"${2}"'"' "$ACTION_URL" +} + +send_location() { + [ "$3" = "" ] && return + sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"'' "$LOCATION_URL" +} + +send_venue() { + local add="" + [ "$5" = "" ] && return + [ "$6" != "" ] && add=', "foursquare_id": '"$6"'' + sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"', "address": "'"${5}"'", "title": "'"${4}"'"'"${add}" "$VENUE_URL" +} + + +forward_message() { + [ "$3" = "" ] && return + sendJson "${1}" '"from_chat_id": '"${2}"', "message_id": '"${3}"'' "$FORWARD_URL" +} +forward() { # backward compatibility + forward_message "$@" || return +} + +send_message() { + [ "$2" = "" ] && return + local text keyboard btext burl no_keyboard file lat long title address sent + 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.*//')" + 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 "$1" "$text" + sent=y + fi + if [ "$keyboard" != "" ]; then + if [[ "$keyboard" != *"["* ]]; then # pre 0.60 style + keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]" + fi + send_keyboard "$1" "$text" "$keyboard" + sent=y + fi + if [ "$btext" != "" ] && [ "$burl" != "" ]; then + send_button "$1" "$text" "$btext" "$burl" + sent=y + fi + if [ "$file" != "" ]; then + send_file "$1" "$file" "$text" + sent=y + fi + if [ "$lat" != "" ] && [ "$long" != "" ]; then + if [ "$address" != "" ] && [ "$title" != "" ]; then + send_venue "$1" "$lat" "$long" "$title" "$address" + else + send_location "$1" "$lat" "$long" + fi + sent=y + fi + if [ "$sent" != "y" ];then + send_text "$1" "$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 +} + diff --git a/mycommands.sh b/mycommands.sh index cad65c3..808aee7 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,24 +2,22 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd +#### $$VERSION$$ v0.80-dev2-6-g5b10e75 # -# shellcheck disable=SC2154 -# shellcheck disable=SC2034 - # 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*: #' +res="" if [ "$1" = "source" ];then # Set INLINE to 1 in order to receive inline queries. # To enable this option in your bot, send the /setinline command to @BotFather. - INLINE="0" + export INLINE="0" # Set to .* to allow sending files from all locations - FILE_REGEX='/home/user/allowed/.*' + export FILE_REGEX='/home/user/allowed/.*' else # your additional bahsbot commands From e9cf8d25e5dec8dea3fa04d04fb24dafcf7c7253 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 13 May 2019 11:24:42 +0200 Subject: [PATCH 09/27] fix old errors found while factor out send_message to module --- bashbot.sh | 9 +++++---- commands.sh | 2 +- dev/all-tests.sh | 6 +++--- modules/sendMessage.sh | 4 ++-- test/ADD-test-new.sh | 3 ++- test/c-init-test.sh | 4 +++- test/d-process_inline-test.sh | 4 ++-- test/d-process_message-test.sh | 4 +++- test/d-send_message-test.sh | 18 +++++++++++++----- .../d-send_message-test.input | 2 -- .../d-send_message-test.result | 6 ------ test/d-user_is-test.sh | 5 ++++- 12 files changed, 38 insertions(+), 29 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index c6f674e..d3beacd 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-6-g5b10e75 +#### $$VERSION$$ v0.80-dev2-7-g92f022d # # Exit Codes: # - 0 sucess (hopefully) @@ -385,11 +385,12 @@ else local out="$1" local remain="" local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)' + local W1 W2 U 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 )) - local U=$(( ( W1 | W2 ) + 0x10000 )) + W1=$(( ( 0xd${BASH_REMATCH[2]} & 0x3ff) <<10 )) + W2=$(( 0xd${BASH_REMATCH[3]} & 0x3ff )) + U=$(( ( W1 | W2 ) + 0x10000 )) remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}" out="${BASH_REMATCH[1]}" done diff --git a/commands.sh b/commands.sh index e86ad8f..0de1afe 100644 --- a/commands.sh +++ b/commands.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-6-g5b10e75 +#### $$VERSION$$ v0.80-dev2-7-g92f022d # # adjust your language setting here, e.g.when run from other user or cron. diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 5af55fa..24fd7a1 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.80-dev2-2-g0c5e3dd +#### $$VERSION$$ v0.80-dev2-7-g92f022d # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -49,8 +49,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 -e "${passed} / ${tests}\\n" diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 92e1f50..0f3182a 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-6-g5b10e75 +#### $$VERSION$$ v0.80-dev2-7-g92f022d # source from commands.sh to use the sendMessage functions @@ -90,7 +90,7 @@ send_file() { local CAPTION local chat_id=$1 local file=$2 - echo "$file" | grep -qE "$FILE_REGEX" || return + [[ "$file" =~ $FILE_REGEX ]] || return local ext="${file##*.}" case $ext in mp3|flac) diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index d115ed3..e257706 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-7-g92f022d # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -65,6 +65,7 @@ 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}/commands.sh" source # start writing your tests here ... diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 87fc2d1..ea00861 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-7-g92f022d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -36,6 +36,8 @@ cd "${TESTDIR}" || exit # shellcheck source=./bashbot.sh source "${TESTDIR}/bashbot.sh" source +source "${TESTDIR}/commands.sh" source + trap '' EXIT cd "${DIRME}" || exit 1 echo "${SUCCESS}" diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh index d642883..23f43fc 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-7-g92f022d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -12,7 +12,7 @@ cd "${TESTDIR}" || exit 1 # shellcheck source=./bashbot.sh source "${TESTDIR}/bashbot.sh" source # shellcheck source=./bashbot.sh -source "${TESTDIR}/modules/inline.sh" source +source "${TESTDIR}/modules/answerInline.sh" source # overwrite get_file for test get_file() { diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 7840a07..eb751a4 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-7-g92f022d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -11,6 +11,8 @@ set -e cd "${TESTDIR}" || exit 1 # shellcheck source=./bashbot.sh source "${TESTDIR}/bashbot.sh" source +# shellcheck source=./bashbot.sh +source "${TESTDIR}/commands.sh" source # overwrite get_file for test get_file() { diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index 0ba4462..1d0cc20 100755 --- a/test/d-send_message-test.sh +++ b/test/d-send_message-test.sh @@ -1,34 +1,42 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-7-g92f022d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh source "./ALL-tests.inc.sh" set -e +set +f 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" +# shellcheck source=./bashbot.sh +source "${TESTDIR}/commands.sh" source + +_is_function send_message || echo "Send Message not found!" # start writing your tests here ... # over write sendJson to output parameter only +sendEmpty() { + printf 'chat:%s\tJSON:%s\nURL:%s\n\n' "${1}" "${2}" "${3}" +} + 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 + +while read -r line ; do echo -n "." send_message "123456" "$line" >>"${OUTPUTFILE}" -done < "${INPUTFILE}" 2>>"${LOGFILE}" +done < "${INPUTFILE}" #2>>"${LOGFILE}" echo " done." { diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1; } | cat -v 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 0a1c6b2..1c17d70 100644 --- a/test/d-send_message-test/d-send_message-test.input +++ b/test/d-send_message-test/d-send_message-test.input @@ -8,10 +8,8 @@ markdown_parse_mode This is a *MARKDOWN* text mynewlinestartshere with a line br # 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 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 575d856..9d32aaf 100644 --- a/test/d-send_message-test/d-send_message-test.result +++ b/test/d-send_message-test/d-send_message-test.result @@ -28,9 +28,6 @@ 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 @@ -40,9 +37,6 @@ 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 diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 6c5b758..2c32953 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,17 +1,20 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-7-g92f022d # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh source "./ALL-tests.inc.sh" set -e +set +f cd "${TESTDIR}" || exit 1 # source bashbot.sh function, uncomment if you want to test functions # shellcheck source=./bashbot.sh source "${TESTDIR}/bashbot.sh" source +# shellcheck source=./bashbot.sh +source "${TESTDIR}/commands.sh" source # start writing your tests here ... From a79f97fdd61c2f7017dc1988258e9eb84a7ddd51 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 13 May 2019 11:28:03 +0200 Subject: [PATCH 10/27] enable cleaup after failed test again ... --- dev/all-tests.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 24fd7a1..9ddc936 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.80-dev2-7-g92f022d +#### $$VERSION$$ v0.80-dev2-8-ge9cf8d2 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -49,8 +49,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 -e "${passed} / ${tests}\\n" From 5f945e5e0ae0d526c4d7888b43b3f55f04369928 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 13 May 2019 12:47:03 +0200 Subject: [PATCH 11/27] more strict checks for send_file --- bashbot.sh | 2 +- modules/sendMessage.sh | 15 +++++++++++++-- .../d-send_message-test.result | 6 ------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index d3beacd..3937a3d 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-7-g92f022d +#### $$VERSION$$ v0.80-dev2-9-ga79f97f # # Exit Codes: # - 0 sucess (hopefully) diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 0f3182a..6ae610f 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-7-g92f022d +#### $$VERSION$$ v0.80-dev2-9-ga79f97f # source from commands.sh to use the sendMessage functions @@ -85,12 +85,23 @@ send_button() { } +UPLOADDIR="${BASHBOT_UPLOAD:-${TMPDIR}/upload}" + send_file() { [ "$2" = "" ] && return local CAPTION local chat_id=$1 local file=$2 - [[ "$file" =~ $FILE_REGEX ]] || return + # file access checks ... + [[ "$file" = *'..'* ]] && return # no directory traversal + [[ "$file" = '.'* ]] && return # no hidden or relative files + if [[ "$file" = '/'* ]] ; then + [[ "$file" =~ $FILE_REGEX ]] || return # absulute must match REGEX + else + file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # othiers must be in UPLOADDIR + fi + [ -r "$file" ] || return # and file must exits of course + local ext="${file##*.}" case $ext in mp3|flac) 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 9d32aaf..c0dfa66 100644 --- a/test/d-send_message-test/d-send_message-test.result +++ b/test/d-send_message-test/d-send_message-test.result @@ -34,12 +34,6 @@ 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:"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 From b55c1712333b983b81bfe86f3861ed4892d8398f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 13 May 2019 19:27:28 +0200 Subject: [PATCH 12/27] add bash and busybox command list --- doc/7_develop.md | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/doc/7_develop.md b/doc/7_develop.md index 0d1c15c..7fca705 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -51,6 +51,48 @@ A typical bashbot develop loop looks as follow: **If you setup your dev environment with hooks and use the scripts above, versioning, addding and testing is done automatically.** +### bash only commands +We state bashbot is a bash only bot, but this is not true. bashbot is a bash script using bash features PLUS external commands. +Usually bash is used unix/linux environment where many external (GNU) commands are availible, but if one command is missing, bashbot may not work. + +To avoid this and make bashbot working on as many platforms as psossible - from embedded linux to mainframes - I recommed to restrict +yourself to the commandset and features provided by bash and busybox/toybox. +See [Bash Builtins](https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html) less as you migth expect and +[Busybox Builtins](https://busybox.net/downloads/BusyBox.html) + +example list of mumimum availible commandsi for bash scripts. Do you find curl on the list? +```bash + .\*, [\*, [[\*, basename, break, builtin\*, bzcat, caller\*, cat, cd\*, chattr, + chgrp, chmod, chown, clear, command\*, continue \*, cp, cut, date, declare\*, + dc, dd, df, diff, dirname, du, echo\*, ed, eval\*, exec\*, exit \*, expr\*, find, + fuser, getopt\*, grep, hash\*, head, hexdump, id, kill, killall, last, length, + less, let\*, ln, local\*, logname, ls, lsattr, lsmod, man, mapfile\*, md5sum, mkdir, + mkfifo, mknod, more, mv, nice, nohup, passwd, patch, printf\*, ps, pwd\*, read\*, + readarray\*, readonly\* return\*, rm, rmdir, sed, seq, sha1sum, sha256sum, sha512sum, + shift\*, sleep, source\*, sort, split, stat, strings, su, sync, tail, tar, tee, test, + time, times\*, timeout, touch, tr, trap\*, true, umask\*, unix2dos, usleep, uudecode, + uuencode, vi, wc, wget, which, who, whoami, xargs, yes +``` +commands marked with \* are bash builtins, all others are external programms. Calling an external programm is more expensive then using bulitins +or using an internal replacement. Here are some examples of internal replacement for external commands: +```bash +HOST="$(hostname)" -> HOST="$HOSTNAME" + +seq 1 100 -> {0..100} + +data="$(cat file)" -> data="$(<"file")" + +DIR="$(dirname $0) -> DIR=""${0%/*}/"" + +IAM="($basename $0)" -> IAM="${0##*/}* + +VAR="$(( 1 + 2 ))" -> (( var=1+2 )) + +INDEX="$(( ${INDEX} + 1 ))" -> (( INDEX++ )) + +``` +For more examples see [Pure bash bible](https://github.com/dylanaraps/pure-bash-bible) + ### 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. @@ -145,5 +187,5 @@ fi #### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.80-dev2-5-gd08d912 +#### $$VERSION$$ v0.80-dev2-10-g5f945e5 From df03727e1403b098c604cf894f8841a4d0536adf Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 14 May 2019 13:16:58 +0200 Subject: [PATCH 13/27] some fixes for updates from older versions --- bashbot.sh | 23 +++++++++++++---------- commands.sh | 14 +------------- doc/0_install.md | 11 +++++++++-- doc/7_develop.md | 30 +++++++++++++++--------------- modules/inline.sh | 2 -- modules/sendMessage.sh | 5 ++--- mycommands.sh | 4 ++-- 7 files changed, 42 insertions(+), 47 deletions(-) delete mode 100644 modules/inline.sh diff --git a/bashbot.sh b/bashbot.sh index 3937a3d..18f6c39 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-9-ga79f97f +#### $$VERSION$$ v0.80-dev2-11-gb55c171 # # Exit Codes: # - 0 sucess (hopefully) @@ -119,7 +119,7 @@ elif [ ! -w "${COUNTFILE}" ]; then fi -BOTTOKEN="$(cat "${TOKENFILE}")" +BOTTOKEN="$(< "${TOKENFILE}")" URL='https://api.telegram.org/bot'$BOTTOKEN ME_URL=$URL'/getMe' @@ -129,7 +129,7 @@ GETFILE_URL=$URL'/getFile' unset USER declare -A BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY -export res BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY +export res BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY CAPTION NAME COMMANDS="${BASHBOT_ETC:-.}/commands.sh" if [ "$1" != "source" ]; then @@ -314,13 +314,12 @@ start_bot() { [[ "${DEBUG}" = *"debug" ]] && exec &>>"DEBUG.log" [ "${DEBUG}" != "" ] && date && echo "Start BASHBOT in Mode \"${DEBUG}\"" [[ "${DEBUG}" = "xdebug"* ]] && set -x - while true; do { - + while true; do UPDATE="$(curl -s "$UPD_URL$OFFSET" | "${JSONSHFILE}" -s -b -n)" # Offset OFFSET="$(grep <<< "${UPDATE}" '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)" - OFFSET=$((OFFSET+1)) + ((OFFSET++)) if [ "$OFFSET" != "1" ]; then mysleep="100" @@ -328,16 +327,18 @@ start_bot() { fi # adaptive sleep in ms rounded to next lower second [ "${mysleep}" -gt "999" ] && sleep "${mysleep%???}" - mysleep=$((mysleep+addsleep)); [ "${mysleep}" -gt "${maxsleep}" ] && mysleep="${maxsleep}" - } + # bash aritmetic + ((mysleep+= addsleep , mysleep= mysleep>maxsleep ?maxsleep:mysleep)) done } # initialize bot environment, user and permissions bot_init() { - # move tmpdir to datadir + # upgrade from old version local OLDTMP="${BASHBOT_VAR:-.}/tmp-bot-bash" [ -d "${OLDTMP}" ] && { mv -n "${OLDTMP}/"* "${TMPDIR}"; rmdir "${OLDTMP}"; } + [ -f "modules/inline.sh" ] && rm -f "modules/inline.sh" + #setup bashbot [[ "$(id -u)" -eq "0" ]] && RUNUSER="nobody" echo -n "Enter User to run basbot [$RUNUSER]: " read -r TOUSER @@ -365,7 +366,7 @@ getBotName() { ME="$(getBotName)" if [ "$ME" = "" ]; then - if [ "$(cat "${TOKENFILE}")" = "bashbottestscript" ]; then + if [ "$(< "${TOKENFILE}")" = "bashbottestscript" ]; then ME="bashbottestscript" else echo -e "${RED}ERROR: Can't connect to Telegram Bot! May be your TOKEN is invalid ...${NC}" @@ -407,6 +408,8 @@ if [ "$1" != "source" ]; then # internal options only for use from bashbot and developers case "$1" in "outproc") # forward output from interactive and jobs to chat + [ "$3" = "" ] && echo "No file to read from" && exit 3 + [ "$2" = "" ] && echo "No chat to send to" && exit 3 until [ "$line" = "imprettydarnsuredatdisisdaendofdacmd" ];do line="" read -r -t 10 line diff --git a/commands.sh b/commands.sh index 0de1afe..79469d2 100644 --- a/commands.sh +++ b/commands.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-7-g92f022d +#### $$VERSION$$ v0.80-dev2-11-gb55c171 # # adjust your language setting here, e.g.when run from other user or cron. @@ -56,18 +56,6 @@ export FILE_REGEX='/home/user/allowed/.*' if [ "${1}" != "source" ];then - # this was here from beginning, can some tell me what this is for? - # I GUESS it was used to auto send files and locations?? - # this will be removed!!! - if ! tmux ls 2>/dev/null | grep -v send | grep -q "$copname"; then - [ ! -z "${URLS[*]}" ] && { - curl -s "${URLS[*]}" -o "$NAME" - send_file "${CHAT[ID]}" "$NAME" "$CAPTION" - rm -f "$NAME" - } - [ ! -z "${LOCATION[*]}" ] && send_location "${CHAT[ID]}" "${LOCATION[LATITUDE]}" "${LOCATION[LONGITUDE]}" - fi - # detect inline commands.... # no default commands, all processing is done in myinlines() if [ "$INLINE" != "0" ] && [ "${iQUERY[ID]}" != "" ]; then diff --git a/doc/0_install.md b/doc/0_install.md index eb65418..96c557c 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -34,13 +34,20 @@ As an alternative to download the zip files, you can clone the github repository 2. [Download latest release zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) 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 +4. Save your your current 'commands.sh' and run ```cp commands.sh.dist commands.sh``` +5. Run ```sudo ./bashbot.sh init``` to setup your environment after the update + +If you modified 'commands.sh' re apply all changes to the new 'commands.sh'. To avoid this all your modifications +must be done in 'mycommands.sh' only. ### 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.60 on your commands must be placed in 'mycommands.sh'. If you update from a version with your commands +in 'commands.sh' move all your commands and functions to 'mycommands.sh'. + 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 @@ -63,5 +70,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-11-gb55c171 diff --git a/doc/7_develop.md b/doc/7_develop.md index 7fca705..a68f4e5 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -53,24 +53,24 @@ A typical bashbot develop loop looks as follow: ### bash only commands We state bashbot is a bash only bot, but this is not true. bashbot is a bash script using bash features PLUS external commands. -Usually bash is used unix/linux environment where many external (GNU) commands are availible, but if one command is missing, bashbot may not work. +Usually bash is used in a unix/linux environment where many (GNU) commands are availible, but if commands are missing, bashbot may not work. -To avoid this and make bashbot working on as many platforms as psossible - from embedded linux to mainframes - I recommed to restrict -yourself to the commandset and features provided by bash and busybox/toybox. -See [Bash Builtins](https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html) less as you migth expect and +To avoid this and make bashbot working on as many platforms as possible - from embedded linux to mainframe - I recommed to restrict +ourself to the commands provided by bash and busybox/toybox. +See [Bash Builtins](https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html) and [Busybox Builtins](https://busybox.net/downloads/BusyBox.html) -example list of mumimum availible commandsi for bash scripts. Do you find curl on the list? +mumimum availible commands in bash and busybox. Do you find curl on the list? ```bash - .\*, [\*, [[\*, basename, break, builtin\*, bzcat, caller\*, cat, cd\*, chattr, - chgrp, chmod, chown, clear, command\*, continue \*, cp, cut, date, declare\*, - dc, dd, df, diff, dirname, du, echo\*, ed, eval\*, exec\*, exit \*, expr\*, find, - fuser, getopt\*, grep, hash\*, head, hexdump, id, kill, killall, last, length, - less, let\*, ln, local\*, logname, ls, lsattr, lsmod, man, mapfile\*, md5sum, mkdir, - mkfifo, mknod, more, mv, nice, nohup, passwd, patch, printf\*, ps, pwd\*, read\*, - readarray\*, readonly\* return\*, rm, rmdir, sed, seq, sha1sum, sha256sum, sha512sum, - shift\*, sleep, source\*, sort, split, stat, strings, su, sync, tail, tar, tee, test, - time, times\*, timeout, touch, tr, trap\*, true, umask\*, unix2dos, usleep, uudecode, + .*, [*, [[*, basename, break, builtin*, bzcat, caller*, cat, cd*, chattr, + chgrp, chmod, chown, clear, command*, continue *, cp, cut, date, declare*, + dc, dd, df, diff, dirname, du, echo*, ed, eval*, exec*, exit *, expr*, find, + fuser, getopt*, grep, hash*, head, hexdump, id, kill, killall, last, length, + less, let*, ln, local*, logname, ls, lsattr, lsmod, man, mapfile*, md5sum, mkdir, + mkfifo, mknod, more, mv, nice, nohup, passwd, patch, printf*, ps, pwd*, read*, + readarray*, readonly* return*, rm, rmdir, sed, seq, sha1sum, sha256sum, sha512sum, + shift*, sleep, source*, sort, split, stat, strings, su, sync, tail, tar, tee, test, + time, times*, timeout, touch, tr, trap*, true, umask*, unix2dos, usleep, uudecode, uuencode, vi, wc, wget, which, who, whoami, xargs, yes ``` commands marked with \* are bash builtins, all others are external programms. Calling an external programm is more expensive then using bulitins @@ -187,5 +187,5 @@ fi #### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.80-dev2-10-g5f945e5 +#### $$VERSION$$ v0.80-dev2-11-gb55c171 diff --git a/modules/inline.sh b/modules/inline.sh deleted file mode 100644 index 601d1e5..0000000 --- a/modules/inline.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -echo "use answerInline.sh" >&2 diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 6ae610f..9e6a117 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-9-ga79f97f +#### $$VERSION$$ v0.80-dev2-11-gb55c171 # source from commands.sh to use the sendMessage functions @@ -141,13 +141,12 @@ send_file() { ;; esac send_action "$chat_id" "$STATUS" - # convert over to sendJson!! + # convert over to sendJson!! much better: use sendjson in case above ... # shellcheck disable=SC2034 res="$(curl -s "$CUR_URL" -F "chat_id=$chat_id" -F "$WHAT=@$file" -F "caption=$CAPTION")" } # 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 location - send_action() { [ "$2" = "" ] && return sendJson "${1}" '"action": "'"${2}"'"' "$ACTION_URL" diff --git a/mycommands.sh b/mycommands.sh index 808aee7..df21f79 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.80-dev2-6-g5b10e75 +#### $$VERSION$$ v0.80-dev2-11-gb55c171 # # uncomment the following lines to overwrite info and help messages @@ -24,7 +24,7 @@ else # NOTE: command can have @botname attached, you must add * in case tests... mycommands() { - case "$MESSAGE" in + case "${MESSAGE}" in '/echo'*) # example echo command send_normal_message "${CHAT[ID]}" "$MESSAGE" ;; From bce7f1a6dcdcbfc8789e14ea554764c7e51e6632 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 14 May 2019 15:25:15 +0200 Subject: [PATCH 14/27] replace all curl calls, add wget as curl replacement --- bashbot.sh | 156 ++++++++++++++++++++++++----------------- modules/sendMessage.sh | 52 ++++++-------- 2 files changed, 116 insertions(+), 92 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 18f6c39..2b6639d 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-11-gb55c171 +#### $$VERSION$$ v0.80-dev2-12-gdf03727 # # Exit Codes: # - 0 sucess (hopefully) @@ -66,16 +66,6 @@ if [ ! -f "${TOKENFILE}" ]; then fi fi -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}..." - [[ "${JSONSHFILE}" = "${RUNDIR}/JSON.sh/JSON.sh" ]] && mkdir "JSON.sh" 2>/dev/null; - curl -sL -o "${JSONSHFILE}" "https://cdn.jsdelivr.net/gh/dominictarr/JSON.sh/JSON.sh" - chmod +x "${JSONSHFILE}" -fi - BOTADMIN="${BASHBOT_ETC:-.}/botadmin" if [ ! -f "${BOTADMIN}" ]; then if [ "${CLEAR}" = "" ]; then @@ -144,20 +134,58 @@ if [ "$1" != "source" ]; then fi +# returns true if command exist +_exists() +{ + [ "$(LC_ALL=C type -t "$1")" = "file" ] +} + +# returns true if function exist +_is_function() +{ + [ "$(LC_ALL=C type -t "$1")" = "function" ] +} + DELETE_URL=$URL'/deleteMessage' delete_message() { sendJson "${1}" 'message_id: '"${2}"'' "${DELETE_URL}" } +get_file() { + [ "$1" = "" ] && return + local JSON='"file_id": '"${1}" + sendJson "" "${JSON}" "${GETFILE_URL}" + echo "${URL}/$(echo "${res}" | jsonGetString '"result","file_path"')" +} + # usage: sendJson "chat" "JSON" "URL" -sendJson(){ +if [ "${BASHBOT_WGET}" = "" ] && _exists curl ; then + # simple curl or wget call, output to stdout + getJson(){ + curl -sL "$1" + } + sendJson(){ 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")" -} + } +else + # simple curl or wget call outputs result to stdout + getJson(){ + wegt -q -O- "$1" + } + sendJson(){ + local chat=""; + [ "${1}" != "" ] && chat='"chat_id":'"${1}"',' + res="$(wget -q -O- --post-data='{'"${chat} $2"'}' \ + --header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n )" + BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")" + BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$res")" + } +fi # convert common telegram entities to JSON # title caption description markup inlinekeyboard @@ -171,18 +199,49 @@ title2Json(){ echo "${title}${caption}${desc}${markup}${keyboard}" } -get_file() { - [ "$1" = "" ] && return - local JSON='"file_id": '"${1}" - sendJson "" "${JSON}" "${GETFILE_URL}" - echo "${URL}/$(echo "${res}" | jsonGetString '"result","file_path"')" +# get bot name +getBotName() { + sendJson "" "" "$ME_URL" + JsonGetString '"result","username"' <<< "$res" } -# returns true if function exist -_is_function() -{ - [ "$(LC_ALL=C type -t "$1")" = "function" ] +# use phyton JSON to decode JSON UFT-8, provide bash implementaion as fallback +if [ "${BASHBOT_DECODE}" != "" ] && _exists python ; then + JsonDecode() { + printf '"%s\\n"' "${1//\"/\\\"}" | python -c 'import json, sys; sys.stdout.write(json.load(sys.stdin).encode("utf-8"))' + } +else + # pure bash implementaion, done by KayM (@gnadelwartz) + # see https://stackoverflow.com/a/55666449/9381171 + JsonDecode() { + local out="$1" + local remain="" + local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)' + local W1 W2 U + while [[ "${out}" =~ $regexp ]] ; do + # match 2 \udxxx hex values, calculate new U, then split and replace + W1=$(( ( 0xd${BASH_REMATCH[2]} & 0x3ff) <<10 )) + W2=$(( 0xd${BASH_REMATCH[3]} & 0x3ff )) + U=$(( ( W1 | W2 ) + 0x10000 )) + remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}" + out="${BASH_REMATCH[1]}" + done + echo -e "${out}${remain}" + } +fi + +JsonGetString() { + sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]"\(.*\)"$/\1/p' } +JsonGetLine() { + sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]//p' +} +JsonGetValue() { + sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]\([0-9.,]*\).*/\1/p' +} + +################ +# processing of updates starts here process_updates() { MAX_PROCESS_NUMBER="$(sed <<< "${UPDATE}" '/\["result",[0-9]*\]/!d' | tail -1 | sed 's/\["result",//g;s/\].*//g')" for ((PROCESS_NUMBER=0; PROCESS_NUMBER<=MAX_PROCESS_NUMBER; PROCESS_NUMBER++)); do @@ -207,16 +266,6 @@ process_client() { grep -q "$tmpcount" <"${COUNTFILE}" >/dev/null 2>&1 || echo "$tmpcount">>"${COUNTFILE}" # To get user count execute bash bashbot.sh count } -JsonGetString() { - sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]"\(.*\)"$/\1/p' -} -JsonGetLine() { - sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]//p' -} -JsonGetValue() { - sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]\([0-9.,]*\).*/\1/p' -} - process_inline() { local num="${1}" iQUERY[0]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",0,"inline_query","query"')")" @@ -304,6 +353,8 @@ process_message() { rm "$TMP" } + +######################### # main get updates loop, should never terminate start_bot() { local DEBUG="$1" @@ -315,7 +366,7 @@ start_bot() { [ "${DEBUG}" != "" ] && date && echo "Start BASHBOT in Mode \"${DEBUG}\"" [[ "${DEBUG}" = "xdebug"* ]] && set -x while true; do - UPDATE="$(curl -s "$UPD_URL$OFFSET" | "${JSONSHFILE}" -s -b -n)" + UPDATE="$(getJson "$UPD_URL$OFFSET" | "${JSONSHFILE}" -s -b -n)" # Offset OFFSET="$(grep <<< "${UPDATE}" '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)" @@ -358,11 +409,15 @@ bot_init() { fi } -# get bot name -getBotName() { - sendJson "" "" "$ME_URL" - JsonGetString '"result","username"' <<< "$res" -} +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}..." + [[ "${JSONSHFILE}" = "${RUNDIR}/JSON.sh/JSON.sh" ]] && mkdir "JSON.sh" 2>/dev/null; + getJson "https://cdn.jsdelivr.net/gh/dominictarr/JSON.sh/JSON.sh" >"${JSONSHFILE}" + chmod +x "${JSONSHFILE}" +fi ME="$(getBotName)" if [ "$ME" = "" ]; then @@ -374,31 +429,6 @@ if [ "$ME" = "" ]; then fi fi -# use phyton JSON to decode JSON UFT-8, provide bash implementaion as fallback -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"))' - } -else - # pure bash implementaion, done by KayM (@gnadelwartz) - # see https://stackoverflow.com/a/55666449/9381171 - JsonDecode() { - local out="$1" - local remain="" - local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)' - local W1 W2 U - while [[ "${out}" =~ $regexp ]] ; do - # match 2 \udxxx hex values, calculate new U, then split and replace - W1=$(( ( 0xd${BASH_REMATCH[2]} & 0x3ff) <<10 )) - W2=$(( 0xd${BASH_REMATCH[3]} & 0x3ff )) - U=$(( ( W1 | W2 ) + 0x10000 )) - remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}" - out="${BASH_REMATCH[1]}" - done - echo -e "${out}${remain}" - } -fi - # source the script with source as param to use functions in other scripts # do not execute if read from other scripts diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 9e6a117..8d45070 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-11-gb55c171 +#### $$VERSION$$ v0.80-dev2-12-gdf03727 # source from commands.sh to use the sendMessage functions @@ -89,9 +89,8 @@ UPLOADDIR="${BASHBOT_UPLOAD:-${TMPDIR}/upload}" send_file() { [ "$2" = "" ] && return - local CAPTION - local chat_id=$1 - local file=$2 + local file="$2" + local CAPTION=',"caption":"'$3'"'; [ "$3" = "" ] && CAPTION="" # file access checks ... [[ "$file" = *'..'* ]] && return # no directory traversal [[ "$file" = '.'* ]] && return # no hidden or relative files @@ -105,45 +104,40 @@ send_file() { local ext="${file##*.}" case $ext in mp3|flac) - CUR_URL=$AUDIO_URL - WHAT=audio - STATUS=upload_audio - CAPTION="$3" + CUR_URL="$AUDIO_URL" + WHAT="audio" + STATUS="upload_audio" ;; png|jpg|jpeg|gif) - CUR_URL=$PHO_URL - WHAT=photo - STATUS=upload_photo - CAPTION="$3" + CUR_URL="$PHO_URL" + WHAT="photo" + STATUS="upload_photo" ;; webp) - CUR_URL=$STICKER_URL - WHAT=sticker - STATUS= + CUR_URL="$STICKER_URL" + WHAT="sticker" + STATUS="upload_photo" ;; mp4) - CUR_URL=$VIDEO_URL - WHAT=video - STATUS=upload_video - CAPTION="$3" + CUR_URL="$VIDEO_URL" + WHAT="video" + STATUS="upload_video" ;; ogg) - CUR_URL=$VOICE_URL - WHAT=voice - STATUS= + CUR_URL="$VOICE_URL" + WHAT="voice" + STATUS="upload_audio" ;; *) - CUR_URL=$DOCUMENT_URL - WHAT=document - STATUS=upload_document - CAPTION="$3" + CUR_URL="$DOCUMENT_URL" + WHAT="document" + STATUS="upload_document" ;; esac - send_action "$chat_id" "$STATUS" - # convert over to sendJson!! much better: use sendjson in case above ... + send_action "${1}" "$STATUS" # shellcheck disable=SC2034 - res="$(curl -s "$CUR_URL" -F "chat_id=$chat_id" -F "$WHAT=@$file" -F "caption=$CAPTION")" + sendJson "${1}" '"'"$WHAT"'":"'"$2"'"'"$CAPTION"'"' "$CUR_URL" } # 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 location From aacdc76af2de63ce05af461cd94f71c5c5e98098 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 14 May 2019 17:56:23 +0200 Subject: [PATCH 15/27] SendJson bash only, no more python! --- bashbot.sh | 28 ++++++++-------------------- commands.sh | 5 ++++- dev/make-standalone.sh | 4 ++-- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 2b6639d..71462a0 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-12-gdf03727 +#### $$VERSION$$ v0.80-dev2-13-gbce7f1a # # Exit Codes: # - 0 sucess (hopefully) @@ -205,30 +205,18 @@ getBotName() { JsonGetString '"result","username"' <<< "$res" } -# use phyton JSON to decode JSON UFT-8, provide bash implementaion as fallback -if [ "${BASHBOT_DECODE}" != "" ] && _exists python ; then - JsonDecode() { - printf '"%s\\n"' "${1//\"/\\\"}" | python -c 'import json, sys; sys.stdout.write(json.load(sys.stdin).encode("utf-8"))' - } -else - # pure bash implementaion, done by KayM (@gnadelwartz) - # see https://stackoverflow.com/a/55666449/9381171 - JsonDecode() { - local out="$1" - local remain="" - local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)' - local W1 W2 U +# pure bash implementaion, done by KayM (@gnadelwartz) +# see https://stackoverflow.com/a/55666449/9381171 +JsonDecode() { + local out="$1" remain="" U="" + 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 - W1=$(( ( 0xd${BASH_REMATCH[2]} & 0x3ff) <<10 )) - W2=$(( 0xd${BASH_REMATCH[3]} & 0x3ff )) - U=$(( ( W1 | W2 ) + 0x10000 )) + U=$(( ( (0xd${BASH_REMATCH[2]} & 0x3ff) <<10 ) | ( 0xd${BASH_REMATCH[3]} & 0x3ff ) + 0x10000 )) remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}" out="${BASH_REMATCH[1]}" done echo -e "${out}${remain}" - } -fi +} JsonGetString() { sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]"\(.*\)"$/\1/p' diff --git a/commands.sh b/commands.sh index 79469d2..ac18a16 100644 --- a/commands.sh +++ b/commands.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-11-gb55c171 +#### $$VERSION$$ v0.80-dev2-13-gbce7f1a # # adjust your language setting here, e.g.when run from other user or cron. @@ -35,6 +35,9 @@ bashbot_help='*Available commands*: Written by Drew (@topkecleon), Daniil Gentili (@danogentili) and KayM(@gnadelwartz). Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) ' +# we don't know whom we are ... +copname="" + # load modues on startup and always on on debug if [ "${1}" = "source" ] || [[ "${1}" = *"debug"* ]] ; then diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index 2438159..022d221 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -5,7 +5,7 @@ # If you your bot is finished you can use make-standalone.sh to create the # the old all-in-one bashbot: bashbot.sh and commands.sh only! # -#### $$VERSION$$ v0.80-dev2-3-ge492da0 +#### $$VERSION$$ v0.80-dev2-13-gbce7f1a # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -72,7 +72,7 @@ echo " ... create unified bashbot.sh" cat modules/*.sh | sed -e 's/^#\!\/bin\/bash.*//' # last tail of commands.sh - printf '\n##############################\n# bashbot functions starts here ...\n\n' + printf '\n##############################\n# bashbot internal functions starts here ...\n\n' sed -n '/\/commands.sh"/,$ p' bashbot.sh } >>$$bashbot.sh From eb0cde55dfff870ec3d230c8615ca91469fe917d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 14 May 2019 19:58:59 +0200 Subject: [PATCH 16/27] add documentaion and ENV for wget and Telegram URL --- README.html | 4 ++-- README.md | 6 ++++-- README.txt | 12 ++++++++---- bashbot.sh | 4 ++-- doc/8_custom.md | 32 +++++++++++++++++++++++--------- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/README.html b/README.html index dae5fea..c6fb82f 100644 --- a/README.html +++ b/README.html @@ -18,7 +18,7 @@

    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).

    +

    Even bashbot is written in bash, it depends on commands typically availible in a Unix/Linux Environment. More concret on the command set provided by coreutils, busybox or toybox.

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

    Documentation

      @@ -106,6 +106,6 @@

      @Gnadelwartz

      That’s it!

      If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!

      -


      VERSION
      v0.80-dev2-5-gd08d912

      +


      VERSION
      v0.80-dev2-14-gaacdc76

      diff --git a/README.md b/README.md index 435d17f..bc90d71 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ Elsewhere, consider it released under the [WTFPLv2](http://www.wtfpl.net/txt/cop Depends on [tmux](http://github.com/tmux/tmux). Uses [JSON.sh](http://github.com/dominictarr/JSON.sh). -Most complete [UTF-8 support for bashbot](doc/4_expert.md#Bashbot-UTF-8-Support) is availible if phyton is installed (optional). +Even bashbot is written in bash, it depends on commands typically availible in a Unix/Linux Environment. +More concret on the command set provided by [coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), [busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or [toybox](https://landley.net/toybox/help.html). + 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 @@ -105,4 +107,4 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-5-gd08d912 +#### $$VERSION$$ v0.80-dev2-14-gaacdc76 diff --git a/README.txt b/README.txt index fe5ac9f..48e2e0e 100644 --- a/README.txt +++ b/README.txt @@ -14,9 +14,13 @@ Elsewhere, consider it released under the Depends on [tmux](http://github.com/tmux/tmux). Uses [JSON.sh](http://github.com/dominictarr/JSON.sh). -Most complete [UTF-8 support for -bashbot](doc/4_expert.md#Bashbot-UTF-8-Support) is availible if phyton is -installed (optional). +Even bashbot is written in bash, it depends on commands typically availible in +a Unix/Linux Environment. +More concret on the command set provided by +[coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), +[busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or +[toybox](https://landley.net/toybox/help.html). + Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Downloads](https://github.com/topkecleon/telegram-bot-bash/releases) are @@ -148,4 +152,4 @@ health status If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-5-gd08d912 +#### $$VERSION$$ v0.80-dev2-14-gaacdc76 diff --git a/bashbot.sh b/bashbot.sh index 71462a0..f9cbef8 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-13-gbce7f1a +#### $$VERSION$$ v0.80-dev2-14-gaacdc76 # # Exit Codes: # - 0 sucess (hopefully) @@ -110,7 +110,7 @@ fi BOTTOKEN="$(< "${TOKENFILE}")" -URL='https://api.telegram.org/bot'$BOTTOKEN +URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}" ME_URL=$URL'/getMe' diff --git a/doc/8_custom.md b/doc/8_custom.md index bf3a37f..0b27d14 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -48,17 +48,31 @@ Full path to JSON.sh script, default: './JSON.sh/JSON.sh', must end with '/JSON. ### 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 +#### BASHBOT_URL +Uses given URL instead of offical telegram API URL, useful if you have your own telegram server or for testing. + +```bash + unset BASHBOT_URL # use Telegram URL https://api.telegram.org/bot (default) + + export BASHBOT_URL "" # use use Telegram https://api.telegram.org/bot + + export BASHBOT_URL "https://my.url.com/bot" # use your URL https://my.url.com/bot - export BASHBOT_DECODE "yes" # force internal - export BASHBOT_DECODE "no" # also force internal! ``` +#### BASHBOT_TOKEN + +#### BASHBOT_WGET +Bashbot uses ```curl``` to communicate with telegram server. if ```curl``` is not availible ```wget``` is used. +If 'BASHBOT_WGET' is set to any value (not undefined or not empty) wget is used even is curl is availible. +```bash + unset BASHBOT_WGET # use curl (default) + export BASHBOT_WGET "" # use curl + + export BASHBOT_WGET "yes" # use wget + export BASHBOT_WGET "no" # use wget! + +``` #### BASHBOT_SLEEP Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling. @@ -117,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-14-gaacdc76 From d5994166c067fa7d6f3dc9588ed693f0b3a4bb44 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 14 May 2019 20:55:24 +0200 Subject: [PATCH 17/27] update doc --- README.html | 4 ++-- README.md | 4 ++-- README.txt | 7 ++++--- bashbot.sh | 2 +- doc/7_develop.md | 23 ++++++++++++----------- examples/notify.sh | 3 ++- mycommands.sh | 6 +++--- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/README.html b/README.html index c6fb82f..7da7717 100644 --- a/README.html +++ b/README.html @@ -18,7 +18,7 @@

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

      Prerequisites

      Depends on tmux. Uses JSON.sh.

      -

      Even bashbot is written in bash, it depends on commands typically availible in a Unix/Linux Environment. More concret on the command set provided by coreutils, busybox or toybox.

      +

      Even bashbot is written in bash, it depends on commands typically availible in a Unix/Linux Environment. More concret on the common commands provided by coreutils, busybox or toybox, see Developer Notes

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

      Documentation

        @@ -106,6 +106,6 @@

        @Gnadelwartz

        That’s it!

        If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!

        -


        VERSION
        v0.80-dev2-14-gaacdc76

        +


        VERSION
        v0.80-dev2-15-geb0cde5

        diff --git a/README.md b/README.md index bc90d71..e91ba6f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Depends on [tmux](http://github.com/tmux/tmux). Uses [JSON.sh](http://github.com/dominictarr/JSON.sh). Even bashbot is written in bash, it depends on commands typically availible in a Unix/Linux Environment. -More concret on the command set provided by [coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), [busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or [toybox](https://landley.net/toybox/help.html). +More concret on the common commands provided by [coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), [busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or [toybox](https://landley.net/toybox/help.html), see [Developer Notes](doc/7_develop.md#common-commands) 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 @@ -107,4 +107,4 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-14-gaacdc76 +#### $$VERSION$$ v0.80-dev2-15-geb0cde5 diff --git a/README.txt b/README.txt index 48e2e0e..8ebd3f0 100644 --- a/README.txt +++ b/README.txt @@ -16,10 +16,11 @@ Uses [JSON.sh](http://github.com/dominictarr/JSON.sh). Even bashbot is written in bash, it depends on commands typically availible in a Unix/Linux Environment. -More concret on the command set provided by +More concret on the common commands provided by [coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), [busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or -[toybox](https://landley.net/toybox/help.html). +[toybox](https://landley.net/toybox/help.html), see [Developer +Notes](doc/7_develop.md#common-commands) Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and @@ -152,4 +153,4 @@ health status If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-14-gaacdc76 +#### $$VERSION$$ v0.80-dev2-15-geb0cde5 diff --git a/bashbot.sh b/bashbot.sh index f9cbef8..ee520b7 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-14-gaacdc76 +#### $$VERSION$$ v0.80-dev2-15-geb0cde5 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/doc/7_develop.md b/doc/7_develop.md index a68f4e5..d4dd062 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -51,27 +51,28 @@ A typical bashbot develop loop looks as follow: **If you setup your dev environment with hooks and use the scripts above, versioning, addding and testing is done automatically.** -### bash only commands +### common commands We state bashbot is a bash only bot, but this is not true. bashbot is a bash script using bash features PLUS external commands. Usually bash is used in a unix/linux environment where many (GNU) commands are availible, but if commands are missing, bashbot may not work. To avoid this and make bashbot working on as many platforms as possible - from embedded linux to mainframe - I recommed to restrict -ourself to the commands provided by bash and busybox/toybox. -See [Bash Builtins](https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html) and -[Busybox Builtins](https://busybox.net/downloads/BusyBox.html) +ourself to the common commands provided by bash and coreutils/busybox/toybox. +See [Bash Builtins](https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html), +[coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), +[busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) and [toybox](https://landley.net/toybox/help.html) -mumimum availible commands in bash and busybox. Do you find curl on the list? +Availible commands in bash, coreutils, busybox and toybox. Do you find curl on the list? ```bash .*, [*, [[*, basename, break, builtin*, bzcat, caller*, cat, cd*, chattr, chgrp, chmod, chown, clear, command*, continue *, cp, cut, date, declare*, - dc, dd, df, diff, dirname, du, echo*, ed, eval*, exec*, exit *, expr*, find, + dc, dd, df, diff, dirname, du, echo*, eval*, exec*, exit *, expr*, find, fuser, getopt*, grep, hash*, head, hexdump, id, kill, killall, last, length, less, let*, ln, local*, logname, ls, lsattr, lsmod, man, mapfile*, md5sum, mkdir, mkfifo, mknod, more, mv, nice, nohup, passwd, patch, printf*, ps, pwd*, read*, - readarray*, readonly* return*, rm, rmdir, sed, seq, sha1sum, sha256sum, sha512sum, - shift*, sleep, source*, sort, split, stat, strings, su, sync, tail, tar, tee, test, - time, times*, timeout, touch, tr, trap*, true, umask*, unix2dos, usleep, uudecode, - uuencode, vi, wc, wget, which, who, whoami, xargs, yes + readarray*, readonly* return*, rm, rmdir, sed, seq, sha1sum, shift*, sleep, + source*, sort, split, stat, strings, su, sync, tail, tar, tee, test, + time, times*, timeout, touch, tr, trap*, true, umask*, usleep, uudecode, + uuencode, wc, wget, which, who, whoami, xargs, yes ``` commands marked with \* are bash builtins, all others are external programms. Calling an external programm is more expensive then using bulitins or using an internal replacement. Here are some examples of internal replacement for external commands: @@ -187,5 +188,5 @@ fi #### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.80-dev2-11-gb55c171 +#### $$VERSION$$ v0.80-dev2-15-geb0cde5 diff --git a/examples/notify.sh b/examples/notify.sh index dba82cd..3461004 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-15-geb0cde5 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment @@ -27,6 +27,7 @@ else fi # output current time every $1 seconds +date "+* It's %k:%M:%S o' clock ..." while sleep $SLEEP do date "+* It's %k:%M:%S o' clock ..." diff --git a/mycommands.sh b/mycommands.sh index df21f79..cfded18 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.80-dev2-11-gb55c171 +#### $$VERSION$$ v0.80-dev2-15-geb0cde5 # # uncomment the following lines to overwrite info and help messages @@ -31,7 +31,7 @@ else '/question'*) # start interactive questions checkproc if [ "$res" -gt 0 ] ; then - startproc "example/question" + startproc "examples/question,sh" else send_normal_message "${CHAT[ID]}" "$MESSAGE already running ..." fi @@ -40,7 +40,7 @@ else '/run_notify'*) # start notify background job myback="notify"; checkback "$myback" if [ "$res" -gt 0 ] ; then - background "example/notify 60" "$myback" # notify every 60 seconds + background "examples/notify.sh 60" "$myback" # notify every 60 seconds else send_normal_message "${CHAT[ID]}" "Background command $myback already running ..." fi From 46ec7c28e9ca064edc5312cc6445a0d59f6f7f5c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 14 May 2019 21:47:50 +0200 Subject: [PATCH 18/27] add bash logo --- README.html | 7 ++++--- README.md | 8 ++++---- README.txt | 10 ++++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.html b/README.html index 7da7717..325d4d9 100644 --- a/README.html +++ b/README.html @@ -11,8 +11,9 @@ -

        bashbot

        -

        A Telegram bot written in bash.

        +

        + 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.

        @@ -106,6 +107,6 @@

        @Gnadelwartz

        That’s it!

        If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!

        -


        VERSION
        v0.80-dev2-15-geb0cde5

        +


        VERSION
        v0.80-dev2-16-gd599416

        diff --git a/README.md b/README.md index e91ba6f..d831000 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# bashbot -A Telegram bot written in bash. - +

        +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. @@ -107,4 +107,4 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-15-geb0cde5 +#### $$VERSION$$ v0.80-dev2-16-gd599416 diff --git a/README.txt b/README.txt index 8ebd3f0..ea34d8a 100644 --- a/README.txt +++ b/README.txt @@ -1,6 +1,8 @@ -# bashbot -A Telegram bot written in bash. - +

        +Bashbot - A Telegram bot written in bash. +

        Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadelwartz). @@ -153,4 +155,4 @@ health status If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-15-geb0cde5 +#### $$VERSION$$ v0.80-dev2-16-gd599416 From bcd62dca369cd88a6b350f351abb91ec5234934f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 14 May 2019 21:50:40 +0200 Subject: [PATCH 19/27] smaller heading --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d831000..4de6f4f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -

        +

        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. From 417bc376db1f497cfa1892c19ba7a8ed5f6163f4 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 14 May 2019 22:02:43 +0200 Subject: [PATCH 20/27] align middle heading --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4de6f4f..5260a09 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -

        -Bashbot - A Telegram bot written in bash. -

        +

        +Bashbot

        Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadelwartz). +## A Telegram bot written in bash. Contributions by JuanPotato, BigNerd95, TiagoDanin, and iicc1. @@ -107,4 +107,4 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-16-gd599416 +#### $$VERSION$$ v0.80-dev2-17-g46ec7c2 From 412173cf857d7cbf07e839ee81c3cfc20f872323 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 14 May 2019 22:06:50 +0200 Subject: [PATCH 21/27] bashbot - a telegram bit written in bash heading --- README.html | 8 ++++---- README.md | 6 +++--- README.txt | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.html b/README.html index 325d4d9..b08b62d 100644 --- a/README.html +++ b/README.html @@ -11,9 +11,9 @@ -

        - Bashbot - A Telegram bot written in bash. -

        +

        + 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.

        @@ -107,6 +107,6 @@

        @Gnadelwartz

        That’s it!

        If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!

        -


        VERSION
        v0.80-dev2-16-gd599416

        +


        VERSION
        v0.80-dev2-19-g417bc37

        diff --git a/README.md b/README.md index 5260a09..7796eef 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

        -Bashbot

        +Bashbot - A Telegram bot written in bash. + Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadelwartz). -## A Telegram bot written in bash. Contributions by JuanPotato, BigNerd95, TiagoDanin, and iicc1. @@ -107,4 +107,4 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-17-g46ec7c2 +#### $$VERSION$$ v0.80-dev2-19-g417bc37 diff --git a/README.txt b/README.txt index ea34d8a..4fae3d7 100644 --- a/README.txt +++ b/README.txt @@ -1,8 +1,8 @@ -

        Bashbot - A Telegram bot written in bash. -

        + Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadelwartz). @@ -155,4 +155,4 @@ health status If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-16-gd599416 +#### $$VERSION$$ v0.80-dev2-19-g417bc37 From d01addf0a902c45ba58a5d299acb7eab28bccd3e Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 16 May 2019 11:23:27 +0200 Subject: [PATCH 22/27] replace unusual command by id, remove phyton tests --- bashbot.sh | 14 ++++++++------ test/ALL-tests.inc.sh | 5 +++-- test/c-init-test.sh | 10 ++++++---- test/d-process_message-test.sh | 22 ++++++++-------------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index ee520b7..3a93071 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-15-geb0cde5 +#### $$VERSION$$ v0.80-dev2-20-g412173c # # Exit Codes: # - 0 sucess (hopefully) @@ -155,15 +155,16 @@ get_file() { [ "$1" = "" ] && return local JSON='"file_id": '"${1}" sendJson "" "${JSON}" "${GETFILE_URL}" - echo "${URL}/$(echo "${res}" | jsonGetString '"result","file_path"')" + jsonGetString <<< "${URL}/""${res}" '"result","file_path"' } -# usage: sendJson "chat" "JSON" "URL" +# curl is preffered, but may not availible on ebedded systems if [ "${BASHBOT_WGET}" = "" ] && _exists curl ; then # simple curl or wget call, output to stdout getJson(){ curl -sL "$1" } + # usage: sendJson "chat" "JSON" "URL" sendJson(){ local chat=""; [ "${1}" != "" ] && chat='"chat_id":'"${1}"',' @@ -175,12 +176,13 @@ if [ "${BASHBOT_WGET}" = "" ] && _exists curl ; then else # simple curl or wget call outputs result to stdout getJson(){ - wegt -q -O- "$1" + wget -qO - "$1" } + # usage: sendJson "chat" "JSON" "URL" sendJson(){ local chat=""; [ "${1}" != "" ] && chat='"chat_id":'"${1}"',' - res="$(wget -q -O- --post-data='{'"${chat} $2"'}' \ + res="$(wget -qO - --post-data='{'"${chat} $2"'}' \ --header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n )" BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")" BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$res")" @@ -382,7 +384,7 @@ bot_init() { echo -n "Enter User to run basbot [$RUNUSER]: " read -r TOUSER [ "$TOUSER" = "" ] && TOUSER="$RUNUSER" - if ! compgen -u "$TOUSER" >/dev/null 2>&1; then + if ! id "$TOUSER" >/dev/null 2>&1; then echo -e "${RED}User \"$TOUSER\" not found!${NC}" exit 3 else diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index e652a76..8f70d64 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-20-g412173c # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME @@ -11,12 +11,13 @@ export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME TESTNAME="${REFDIR//-/ }" # common filenames -export TOKENFILE ACLFILE COUNTFILE ADMINFILE DATADIR +export TOKENFILE ACLFILE COUNTFILE ADMINFILE DATADIR JSONSHFILE TOKENFILE="token" ACLFILE="botacl" COUNTFILE="count" ADMINFILE="botadmin" DATADIR="data-bot-bash" + JSONSHFILE="JSON.sh/JSON.sh" # SUCCESS NOSUCCES export SUCCESS NOSUCCESS diff --git a/test/c-init-test.sh b/test/c-init-test.sh index ea00861..3286b64 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-7-g92f022d +#### $$VERSION$$ v0.80-dev2-20-g412173c # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -24,16 +24,18 @@ export FAIL="0" for file in ${TESTFILES} do ls -d "${TESTDIR}/${file}" >>"${LOGFILE}" - if ! diff -q "${TESTDIR}/${file}" "${REFDIR}/${file}" >>"${LOGFILE}"; then echo "${NOSUCCESS} Fail diff ${file}!"; FAIL="1"; fi - + diff -q "${TESTDIR}/${file}" "${REFDIR}/${file}" >>"${LOGFILE}" || { echo "${NOSUCCESS} Fail diff ${file}!"; FAIL="1"; } done [ "${FAIL}" != "0" ] && exit "${FAIL}" echo "${SUCCESS}" -echo "Test Sourcing of bashbot.sh ..." trap exit 1 EXIT cd "${TESTDIR}" || exit +echo "Test if $JSONSHFILE exists ..." +[ ! -x "$JSONSHFILE" ] && { echo "${NOSUCCESS} Fail diff ${file}!"; exit 1; } + +echo "Test Sourcing of bashbot.sh ..." # shellcheck source=./bashbot.sh source "${TESTDIR}/bashbot.sh" source source "${TESTDIR}/commands.sh" source diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index eb751a4..bd1a586 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.80-dev2-7-g92f022d +#### $$VERSION$$ v0.80-dev2-20-g412173c # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -23,20 +23,14 @@ get_file() { export UPDATE UPDATE="$(cat "${INPUTFILE}")" -# run process_message with and without phyton +# run process_message echo "Check process_message ..." -for i in 1 2 -do - [ "${i}" = "1" ] && ! which python >/dev/null 2>&1 && continue - [ "${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; +set -x +{ process_message "0"; set +x; } >>"${LOGFILE}" 2>&1; - # output processed input - print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" >"${OUTPUTFILE}" - diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1 - echo "${SUCCESS}" -done +# output processed input +print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" >"${OUTPUTFILE}" +diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1 +echo "${SUCCESS}" cd "${DIRME}" || exit 1 From a72f24ac9cff8eb1c3c7d9c3b3c6ba57fcd9a6e5 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 16 May 2019 16:42:38 +0200 Subject: [PATCH 23/27] some fixes to wget fallback --- bashbot.sh | 4 +- doc/0_install.md | 74 ------ doc/1_firstbot.md | 69 ------ doc/2_usage.md | 186 -------------- doc/3_advanced.md | 184 -------------- doc/4_expert.md | 108 -------- doc/5_practice.md | 157 ------------ doc/6_reference.md | 596 --------------------------------------------- doc/7_develop.md | 192 --------------- doc/8_custom.md | 135 ---------- mycommands.sh | 16 +- 11 files changed, 10 insertions(+), 1711 deletions(-) delete mode 100644 doc/0_install.md delete mode 100644 doc/1_firstbot.md delete mode 100644 doc/2_usage.md delete mode 100644 doc/3_advanced.md delete mode 100644 doc/4_expert.md delete mode 100644 doc/5_practice.md delete mode 100644 doc/6_reference.md delete mode 100644 doc/7_develop.md delete mode 100644 doc/8_custom.md diff --git a/bashbot.sh b/bashbot.sh index 3a93071..1533ec2 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-20-g412173c +#### $$VERSION$$ v0.80-dev2-21-gd01addf # # Exit Codes: # - 0 sucess (hopefully) @@ -404,7 +404,7 @@ JSONSHFILE="${BASHBOT_JSONSH:-${RUNDIR}/JSON.sh/JSON.sh}" if [ ! -f "${JSONSHFILE}" ]; then echo "Seems to be first run, Downloading ${JSONSHFILE}..." - [[ "${JSONSHFILE}" = "${RUNDIR}/JSON.sh/JSON.sh" ]] && mkdir "JSON.sh" 2>/dev/null; + [[ "${JSONSHFILE}" = "${RUNDIR}/JSON.sh/JSON.sh" ]] && mkdir "JSON.sh" 2>/dev/null && chmod +w "JSON.sh" getJson "https://cdn.jsdelivr.net/gh/dominictarr/JSON.sh/JSON.sh" >"${JSONSHFILE}" chmod +x "${JSONSHFILE}" fi diff --git a/doc/0_install.md b/doc/0_install.md deleted file mode 100644 index 96c557c..0000000 --- a/doc/0_install.md +++ /dev/null @@ -1,74 +0,0 @@ -#### [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 ... - -**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. - -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.git``` -3. Change into the directory ```telegram-bot-bash``` -4. Run ``` test/ALL-tests.sh``` and if everthing finish OK ... -5. Run ```sudo ./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 your existing bashbot dir - **Note: all files execpt 'mycommands.sh' and 'commands.sh' may overwritten!** -4. Save your your current 'commands.sh' and run ```cp commands.sh.dist commands.sh``` -5. Run ```sudo ./bashbot.sh init``` to setup your environment after the update - -If you modified 'commands.sh' re apply all changes to the new 'commands.sh'. To avoid this all your modifications -must be done in 'mycommands.sh' only. - -### 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.60 on your commands must be placed in 'mycommands.sh'. If you update from a version with your commands -in 'commands.sh' move all your commands and functions to 'mycommands.sh'. - -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](1_firstbot.md) - -#### $$VERSION$$ v0.80-dev2-11-gb55c171 - diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md deleted file mode 100644 index 3329a7e..0000000 --- a/doc/1_firstbot.md +++ /dev/null @@ -1,69 +0,0 @@ -#### [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` - 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`. - - ![botfather initial conversation](http://i.imgur.com/aI26ixR.png) - -2. @botfather replies with `Alright, a new bot. How are we going to -call it? Please choose a name for your bot.` - -3. Type whatever name you want for your bot. - -4. @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.` - -5. Type whatever username you want for your bot, minimum 5 characters, -and must end with `bot`. For example: `telesample_bot` - -6. @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 - -7. Note down the 'token' mentioned above. - -8. Type `/setprivacy` to @botfather. - - ![botfather later conversation](http://i.imgur.com/tWDVvh4.png) - -9. @botfather replies with `Choose a bot to change group messages settings.` - -10. Type `@telesample_bot` (change to the username you set at step 5 -above, but start it with `@`) - -11. @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 - -12. Type `Disable` to let your bot receive all messages sent to a -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.80-dev2-1-g0b36bc5 - diff --git a/doc/2_usage.md b/doc/2_usage.md deleted file mode 100644 index c88a85c..0000000 --- a/doc/2_usage.md +++ /dev/null @@ -1,186 +0,0 @@ -#### [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. See [Best practices](5_practice.md) for more information. - -Once you're done with editing 'mycommands.sh' start the Bot with ```./bashbot.sh start```. -To stop the Bot run ```./bashbot.sh kill``` - -If some thing doesn't work as it should, you can debug with ```./bashbot.sh startbot DEBUG``` where DEBUG can be 'debug', 'xdebug' or 'xdebugx'. -See [Bashbot Development](7_develop.md) for more information. - -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: -```bash -./bashbot.sh start -``` -```bash -./bashbot.sh kill -``` - -### User count -To count the total number of users that ever used the bot run the following command: -```bash -./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: -```bash -./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: - -### Regular Messages - -* ```${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 - -### Inline queries -Evertime a Message is recieved, you can read incoming data using the following variables: - -* ```${iQUERY}```: Current inline query -* ```$iQUERY```: This array contains the ID, First name, last name, username and user id of the sender of the current inline query. - * ```${iQUERY[ID]}```: Inline query ID - * ```${iQUERY[USER_ID]}```: User's id - * ```${iQUERY[FIRST_NAME]}```: User's first name - * ```${iQUERY[LAST_NAME]}```: User's last name - -## Usage of bashbot functions - -#### sending messages -To send messages use the ```send_xxx_message``` functions. - -To send regular text without any markdown use: -```bash -send_text_message "${CHAT[ID]}" "lol" -``` -To send text with markdown: -```bash -send_markdown_message "${CHAT[ID]}" "lol *bold*" -``` -To send text with html: -```bash -send_html_message "${CHAT[ID]}" "lol bold" -``` - -To forward messages use the ```forward``` function: -```bash -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** -```bash -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: -```bash -send_message "${CHAT[ID]}" "markdown_parse_mode lol *bold*" -``` -```bash -send_message "${CHAT[ID]}" "html_parse_mode lol bold" -``` -This function also allows a third parameter that disables additional function parsing (for safety use this when reprinting user input): -```bash -send_message "${CHAT[ID]}" "lol" "safe" -``` -**See also [Interactive chats](3_advanced.md#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): -```bash -send_file "${CHAT[ID]}" "/home/user/doge.jpg" "Lool" -``` -To send custom keyboards use the ```send_keyboard``` function: -```bash -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: -```bash -send_location "${CHAT[ID]}" "Latitude" "Longitude" -``` -To send venues use the ```send_venue``` function: -```bash -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. -```bash -send_action "${CHAT[ID]}" "action" -``` -**See also [Bashbot function reference](6_reference.md#Interactive_Chats)** - -#### [Prev Create Bot](1_firstbot.md) -#### [Next Advanced Usage](3_advanced.md) - -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 - diff --git a/doc/3_advanced.md b/doc/3_advanced.md deleted file mode 100644 index c4af452..0000000 --- a/doc/3_advanced.md +++ /dev/null @@ -1,184 +0,0 @@ -#### [Home](../README.md) -## Advanced Features - -### Access control -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 -# -> 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```: -```bash -# 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. -```bash - 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](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 -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\" ]" -``` -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" -``` -And venues: -```bash -echo "Text that will appear in chat. mylatstartshere 45 mylongstartshere 45 mytitlestartshere my home myaddressstartshere Diagon Alley N. 37" -``` -You can combine them: -```bash -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: -```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 - -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, to stop a background job use: -```bash -killback "jobname" -``` -You can also suspend and resume the last running background jobs from outside bashbot, e.g. in your startup schripts: -```bash -./bashbot.sh suspendback -./bashbot.sh resumeback -``` - -If you want to kill all background jobs permantly run: -```bash -./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 -**Inline queries** allow users to send commands to your bot from every chat without going to a private chat. An inline query is started if the user type the bots name, e.g. @myBot. Everything after @myBot is immediatly send to the bot. - -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. - -The following commands allows you to send ansers to *inline queries*. To enable bashbot to process inline queries set ```INLINE="1"``` in 'mycommands.sh'. - -To send messsages or links through an *inline query*: -```bash -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*: -```bash -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*: -```bash -answer_inline_query "${iQUERY[ID]}" "gif" "gif url" -``` -To send mpeg4 gifs from a website (less than 1MB) through an *inline query*: -```bash -answer_inline_query "${iQUERY[ID]}" "mpeg4_gif" "mpeg4 gif url" -``` -To send videos from a website through an *inline query*: -```bash -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*: -```bash -answer_inline_query "${iQUERY[ID]}" "cached_photo" "identifier for the photo" -``` -To send gifs stored in Telegram servers through an *inline query*: -```bash -answer_inline_query "${iQUERY[ID]}" "cached_gif" "identifier for the gif" -``` -To send mpeg4 gifs stored in Telegram servers through an *inline query*: -```bash -answer_inline_query "${iQUERY[ID]}" "cached_mpeg4_gif" "identifier for the gif" -``` -To send stickers through an *inline query*: -```bash -answer_inline_query "${iQUERY[ID]}" "cached_sticker" "identifier for the sticker" -``` -See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inline_multi) and [mycommands.sh](../mycommands.sh) for more information. - -#### [Prev Getting started](2_usage.md) -#### [Next Expert Use](4_expert.md) - -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 - diff --git a/doc/4_expert.md b/doc/4_expert.md deleted file mode 100644 index b7f40af..0000000 --- a/doc/4_expert.md +++ /dev/null @@ -1,108 +0,0 @@ -#### [Home](../README.md) -## 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](https://en.wikipedia.org/wiki/UTF-8) 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. Set ```Shell``` environment to UTF-8 in your ```.profile``` and your scripts. The usual settings are: - -```bash -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: -```bash -export 'LC_ALL=de_DE.UTF-8' -export 'LANG=de_DE.UTF-8' -export 'LANGUAGE=de_DE.UTF-8' -``` -```bash -export 'LC_ALL=en_US.UTF-8' -export 'LANG=de_en_US.UTF-8' -export 'LANGUAGE=den_US.UTF-8' -``` -3. make shure your bot scripts use the correct settings, eg. include the lines above at the beginning of your scripts - -To display all availible locales on your system run ```locale -a | more```. [Gentoo Wiki](https://wiki.gentoo.org/wiki/UTF-8) - -#### 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 : -```bash -sudo ./bashbot.sh init -``` - -Edit the file ```bashbot.rc``` and edit the following lines to fit your configuration: -```bash -####################### -# 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: -```bash -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: -```bash -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 username```nobody``` with the username you want to run bashbot. copy the modified file to ```/etc/cron.d/bashbot``` - -#### [Prev Expert Use](4_expert.md) -#### [Next Best Practice](5_practice.md) - -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 - diff --git a/doc/5_practice.md b/doc/5_practice.md deleted file mode 100644 index f11d950..0000000 --- a/doc/5_practice.md +++ /dev/null @@ -1,157 +0,0 @@ -#### [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 Documentation](https://core.telegram.org/bots/api/). - -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 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: -```bash -# 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](https://core.telegram.org/bots#commands).** - -**Note: Never disable the catchall command ```*)``` in 'commands.sh'!!** -```bash -# 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: -```bash -# 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](https://www.shellcheck.net/) or [install it on your system](https://github.com/koalaman/shellcheck#installing). -All bashbot scripts are linted by shellcheck. - -Shellcheck examples: -```bash -$ 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}"``` -```bash -$ 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](5_practice.md) -#### [Next Functions Reference](6_reference.md) - -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 - diff --git a/doc/6_reference.md b/doc/6_reference.md deleted file mode 100644 index e94bdff..0000000 --- a/doc/6_reference.md +++ /dev/null @@ -1,596 +0,0 @@ -#### [Home](../README.md) -## 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```. - -*alias:* _action "action" - -*example:* -```bash -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" - -*alias:* _normal_message "message" - -*example:* -```bash -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](https://core.telegram.org/bots/api#markdown-style) only - -*usage:* send_markdown_message "${CHAT[ID]}" "markdown message" - -*alias:* _markdown "message" - -*example:* -```bash -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](https://core.telegram.org/bots/api#html-style) only - -*usage:* send_html_message "${CHAT[ID]}" "html message" - -*alias:* _html_message "message" - -*example:* -```bash -send_normal_message "${CHAT[ID]}" "this is a markdown message, next word is bold" -send_normal_message "${CHAT[ID]}" "bold italic> italic>/em> Text" -``` - -##### 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]}" - -*alias:* _forward "$FROMCHAT" "${MESSAGE[ID]}" - -See also [Text formating options](https://core.telegram.org/bots/api#formatting-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]}" - -*alias:* _del_message "${MESSAGE[ID]}" - -See also [deleteMessage limitations](https://core.telegram.org/bots/api#deletemessage) - ----- - -### 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](https://core.telegram.org/bots/api#sending-files) - -*usage:* send_file "${CHAT[ID]}" "file" "caption" - -*example:* -```bash -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" - -*alias:* _keyboard "message" "keyboard" - -*example:* -```bash -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" - -*alias:* _del_keyboard "message" - -*See also: [Keyboard Markup](https://core.telegram.org/bots/api/#replykeyboardmarkup)* - ----- - -##### send_button -*usage:* send_button "chat-id" "message" "text" "URL" - -*alias:* _button "text" "URL" - -*example:* -```bash -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:* -```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"} ]' -``` - -*See also [Inline keyboard markup](https://core.telegram.org/bots/api/#inlinekeyboardmarkup)* - ----- - -### User Access Control - -##### 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 - -```bash -if _is_admin ; then - send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*" - leave_chat "${CHAT[ID]}" -fi -``` - -'See also [kick Chat Member](https://core.telegram.org/bots/api/#kickchatmember)* - ----- - -##### 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]}" - -*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. - -*usage:* user_is_creator "${CHAT[ID]}" "${USER[ID]}" - -*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]}" - -*alias:* _is_admin - -*example:* -```bash -if _is_admin ; then - send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*" - leave_chat "${CHAT[ID]}" -fi -``` - -*See also [Chat Member](https://core.telegram.org/bots/api/#chatmember)* - -##### user_is_allowed -Bahsbot supports User Access Control, see [Advanced Usage](3_advanced.md) - -*usage:* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}" - -*example:* -```bash -if ! user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then - send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot." -fi -``` - ----- - -### Inline Queries - answer direct queries to bot -You must include ```source modules/inline.sh``` in 'commands.sh' to have the following functions availible. - -Inline Queries allows users to interact with your bot directly without sending extra commands. -As an answer to an inline query you can send back one or more results to the Telegram client. -The Telegram client will then show the results to the user and let him select one. - -##### answer_inline_query -answer_inline_query is provided for backward compatibility with older versions of bashbot. -It send back only one response to an inline query. - -*usage:* answer_inline_query "$i{QUERY[ID]}" "type" "type arg 1" ... "type arg n" - -*example:* - see [Advanced Usage](3_advanced.md#Inline-queries) - - -##### answer_inline_multi -anser_inline_multi allows you to send back a list of responses. responses must be seperated by ','. - -*usage:* answer_inline_multi "${iQUERY[ID]}" "res, res, ... res" - -*example:* -```bash -# note the starting " and ending " !! -answer_inline_multi "${iQUERY[ID]}" " - $(inline_query_compose "1" "photo" "https://avatars0.githubusercontent.com/u/13046303") , - ... - $(inline_query_compose "n" "photo" "https://avatars1.githubusercontent.com/u/4593242") - " -``` - -#### inline_query_compose -inline_query_compose composes one response element to to send back. - -*usage:* inline_query_compose ID type args .... - -``` - ID = unique ID for this response, 1-64 byte long - type = type of answer, e.g. article, photo, video, location ... - args = mandatory arguments in the order they are described in telegram documentation -``` - -Currently the following types and arguments are implemented (optional arguments in parenthesis) -``` - "article"|"message" title message (markup description) - - "photo" photo_URL (thumb_URL title description caption) - "gif" photo_URL (thumb_URL title caption) - "mpeg4_gif" mpeg_URL (thumb_URL title caption) - "video" video_URL mime_type thumb_URL title (caption) - "audio" audio_URL title (caption) - "voice" voice_URL title (caption) - "document" title document_URL mime_type (caption description) - - "location" latitude longitude title - "venue" latitude longitude title (adress foursquare) - "contact" phone first (last thumb) - - "cached_photo" file (title description caption) - "cached_gif" file (title caption) - "cached_mpeg4_gif" file (title caption) - "cached_sticker" file - "cached_document" title file (description caption) - "cached_video" file title (description caption) - "cached_voice" file title (caption) - "cached_audio" file title (caption) -``` -see [InlineQueryResult for more information](https://core.telegram.org/bots/api#inlinequeryresult) about response types and their arguments. - ----- - - -### Background and Interactive jobs -You must include ```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](3_advanced.md#Interactive-Chats) - -*usage:* startproc "script" - -*example:* -```bash -startproc 'examples/calc.sh' -``` - -##### checkproc -Return true (0) if an interactive script is running in the chat. - -*usage:* checkprog - -*example:* -```bash -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:* -```bash -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:* -```bash -background "examples/notify.sh" "notify" -``` - -##### checkback -Return true (0) if an background job is active in the given chat. - -*usage:* checkback "jobname" - -*example:* -```bash -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:* -```bash -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](2_usage.md#send_message) and [Advanced Usage](3_advanced.md#Interactive-Chats) - ----- - -### Aliases - shortcuts for often used funtions -You must include ```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" - ----- - -#### _inline_button -*usage:* _inline_button "${1}" "${2}" - -*alias for:* send_inline_button "${CHAT[ID]}" "" "${1}" "${2}" - -#### _inline_keyboard -*usage:* _inline_keyboard "${1}" - -*alias for:* _inline_keyboard "${CHAT[ID]}" "" "${1}" - -#### _keyboard_numpad -*usage:* _keyboard_numpad - -*alias for:* send_keyboard "${CHAT[ID]}" "" '["1","2","3"],["4","5","6"],["7","8","9"],["-","0","."]' "yes" - -#### _keyboard_yesno -*usage:* _keyboard_yesno - -*alias for:* send_keyboard '["yes","no"]' - -#### _del_keyboard -*usage:* _del_keyboard - -*alias for:* remove_keyboard "${CHAT[ID]}" "" - - - -### 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:* -```bash -_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](5_practice.md) -#### [Next Notes for Developers](7_develop.md) - -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 - diff --git a/doc/7_develop.md b/doc/7_develop.md deleted file mode 100644 index d4dd062..0000000 --- a/doc/7_develop.md +++ /dev/null @@ -1,192 +0,0 @@ -#### [Home](../README.md) -## 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](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). - -### Debugging Bashbot -In normal mode of operation all bashbot output is discarded one more correct sent to TMUX console. -To get these messages (and more) you can start bashbot in the current shell ```./bashbot.sh startbot```. Now you can see all output or erros from bashbot. -In addition you can change the change the level of verbosity by adding a third argument after startbot. -``` - "debug" redirects all output to "DEBUG.log", in addtion every update is logged in "MESSAGE.LOG" and "INLINE.log" - "debugterm" same as debug but output and errors are sent to terminal - - "xdebug" same as debug plus set bash option '-x' to log any executed command - "xdebugterm" same as xdebug but output and errors are sent to terminal -``` - -### Create a stripped down Version of your Bot -Currently bashbot is more a bot development environment than a bot, containing examples, developer scripts, modules, documentation and more. -You don't need all these files after you're finished with your cool new bot. - -Let's create a stripped down version: - -- delete all modules you do not need from 'modules', e.g. 'modules/inline.sh' if you don't use inline queries -- delete not needed standard commands and messages from 'commands.sh' -- delete not needed commands and functions from 'mycommands.sh' -- run ```dev/make-standalone.sh``` to create a a stripped down version of your bo - -Now have a look at the directory 'standalone', here you find the files 'bashbot.sh' and 'commands.sh' containing everything to run your bot. -[Download make-standalone.sh](https://github.com/topkecleon/telegram-bot-bash/blob/master/dev/make-standalone.sh) from github. - -### Setup your develop environment - -1. install git, install [shellcheck](5_practice.md#Test-your-Bot-with-shellcheck) -2. setup your [environment for UTF-8](4_expert.md#Setting-up-your-Environment) -3. clone your bashbot fork to a new directory ```git clone https://github.com//telegram-bot-bash.git```, replace `````` with your username on github -4. create and change to your develop branch ```git checkout -b ```, replace `````` with the name you want to name it, e.g. 'develop' -5. give your (dev) fork a new version tag: ```git tag vx.xx```(optional) -6. setup github hooks by running ```dev/install-hooks.sh``` (optional) - -### Test, Add, Push changes -A typical bashbot develop loop looks as follow: - -1. start developing - *change, copy, edit bashbot files ...* -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 your dev environment with hooks and use the scripts above, versioning, addding and testing is done automatically.** - -### common commands -We state bashbot is a bash only bot, but this is not true. bashbot is a bash script using bash features PLUS external commands. -Usually bash is used in a unix/linux environment where many (GNU) commands are availible, but if commands are missing, bashbot may not work. - -To avoid this and make bashbot working on as many platforms as possible - from embedded linux to mainframe - I recommed to restrict -ourself to the common commands provided by bash and coreutils/busybox/toybox. -See [Bash Builtins](https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html), -[coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), -[busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) and [toybox](https://landley.net/toybox/help.html) - -Availible commands in bash, coreutils, busybox and toybox. Do you find curl on the list? -```bash - .*, [*, [[*, basename, break, builtin*, bzcat, caller*, cat, cd*, chattr, - chgrp, chmod, chown, clear, command*, continue *, cp, cut, date, declare*, - dc, dd, df, diff, dirname, du, echo*, eval*, exec*, exit *, expr*, find, - fuser, getopt*, grep, hash*, head, hexdump, id, kill, killall, last, length, - less, let*, ln, local*, logname, ls, lsattr, lsmod, man, mapfile*, md5sum, mkdir, - mkfifo, mknod, more, mv, nice, nohup, passwd, patch, printf*, ps, pwd*, read*, - readarray*, readonly* return*, rm, rmdir, sed, seq, sha1sum, shift*, sleep, - source*, sort, split, stat, strings, su, sync, tail, tar, tee, test, - time, times*, timeout, touch, tr, trap*, true, umask*, usleep, uudecode, - uuencode, wc, wget, which, who, whoami, xargs, yes -``` -commands marked with \* are bash builtins, all others are external programms. Calling an external programm is more expensive then using bulitins -or using an internal replacement. Here are some examples of internal replacement for external commands: -```bash -HOST="$(hostname)" -> HOST="$HOSTNAME" - -seq 1 100 -> {0..100} - -data="$(cat file)" -> data="$(<"file")" - -DIR="$(dirname $0) -> DIR=""${0%/*}/"" - -IAM="($basename $0)" -> IAM="${0##*/}* - -VAR="$(( 1 + 2 ))" -> (( var=1+2 )) - -INDEX="$(( ${INDEX} + 1 ))" -> (( INDEX++ )) - -``` -For more examples see [Pure bash bible](https://github.com/dylanaraps/pure-bash-bible) - -### 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 ... -``` - -If you release a new Version run ```dev/make-distribution.sh``` to create the zip and tar.gz archives in the dist directory and attach them to the github release. Do not forget to delete directory dist afterwards. - -### Versioning - -Bashbot is tagged with version numbers. If you start a new development cycle you can tag your fork with a version higher than the current version. -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](../dev/version.sh) - -To update the Version Number in files run ```dev/version.sh files```, it will update the line '#### $$VERSION$$ ###' in all files to the current version name. -To update version in all files run 'dev/version.sh' without parameter. - - -### Shellcheck - -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. - -To run shellcheck for a single script run ```shellcheck -x script.sh```, to check all schripts run ```dev/hooks/pre-commit.sh```. - - -## 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 execute flag from the '*-test.sh' 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, it will create the usually needed files and dirs: - -Each test consists of a script script named after ```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. - -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. -A temporary test environment is created when 'ALL-tests.sh' starts and deleted after all tests are finished. - -The file ```ALL-tests.inc.sh``` must be included from all tests and provide the test environment as shell variables: -```bash -# Test Evironment - TESTME="$(basename "$0")" - DIRME="$(pwd)" - TESTDIR="$1" - LOGFILE="${TESTDIR}/${TESTME}.log" - REFDIR="${TESTME%.sh}" - TESTNAME="${REFDIR//-/ }" - -# common filenames - TOKENFILE="token" - ACLFILE="botacl" - COUNTFILE="count" - ADMINFILE="botadmin" - DATADIR="data-bot-bash" - -# SUCCESS NOSUCCES -> echo "${SUCCESS}" or echo "${NOSUCCESS}" - SUCCESS=" OK" - NOSUCCESS=" FAILED!" - -# default input, reference and output files - INPUTFILE="${DIRME}/${REFDIR}/${REFDIR}.input" - REFFILE="${DIRME}/${REFDIR}/${REFDIR}.result" - OUTPUTFILE="${TESTDIR}/${REFDIR}.out" -``` - -Example test -```bash -#!/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 "${TESTDIR}/bashbot.sh" ]; then - echo "${SUCCESS} bashbot.sh exist!" - exit 0 -else - echo "${NOSUCCESS} ${TESTDIR}/bashbot.sh missing!" - exit 1 -fi -``` - -#### [Prev Function Reference](6_reference.md) -#### [Next Bashbot Environment](8_custom.md) - -#### $$VERSION$$ v0.80-dev2-15-geb0cde5 - diff --git a/doc/8_custom.md b/doc/8_custom.md deleted file mode 100644 index 0b27d14..0000000 --- a/doc/8_custom.md +++ /dev/null @@ -1,135 +0,0 @@ -#### [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' 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``` ... -```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 ```data-bot-bash```, ```count``` -```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_JSONSH -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 - - export BASHBOT_JSONSH "/usr/local/bin/JSON.sh" # installed in /usr/local/bin - -``` - -### Change config values - -#### BASHBOT_URL -Uses given URL instead of offical telegram API URL, useful if you have your own telegram server or for testing. - -```bash - unset BASHBOT_URL # use Telegram URL https://api.telegram.org/bot (default) - - export BASHBOT_URL "" # use use Telegram https://api.telegram.org/bot - - export BASHBOT_URL "https://my.url.com/bot" # use your URL https://my.url.com/bot - -``` - -#### BASHBOT_TOKEN - -#### BASHBOT_WGET -Bashbot uses ```curl``` to communicate with telegram server. if ```curl``` is not availible ```wget``` is used. -If 'BASHBOT_WGET' is set to any value (not undefined or not empty) wget is used even is curl is availible. -```bash - unset BASHBOT_WGET # use curl (default) - export BASHBOT_WGET "" # use curl - - export BASHBOT_WGET "yes" # use wget - export BASHBOT_WGET "no" # use wget! - -``` - -#### 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) - -``` - -### 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' -```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' -```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" - - /usr/local/bin/bashbot.sh start -``` - -#### 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" - - /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" - - /usr/local/telegram-bot-bash/bashbot.sh start -``` - -#### [Prev Notes for Developers](7_develop.md) - -#### $$VERSION$$ v0.80-dev2-14-gaacdc76 - diff --git a/mycommands.sh b/mycommands.sh index cfded18..52cf942 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.80-dev2-15-geb0cde5 +#### $$VERSION$$ v0.80-dev2-21-gd01addf # # uncomment the following lines to overwrite info and help messages @@ -12,14 +12,13 @@ #' res="" -if [ "$1" = "source" ];then - # Set INLINE to 1 in order to receive inline queries. - # To enable this option in your bot, send the /setinline command to @BotFather. - export INLINE="0" - # Set to .* to allow sending files from all locations - export FILE_REGEX='/home/user/allowed/.*' +# Set INLINE to 1 in order to receive inline queries. +# To enable this option in your bot, send the /setinline command to @BotFather. +export INLINE="0" +# Set to .* to allow sending files from all locations +export FILE_REGEX='/home/user/allowed/.*' -else +if [ "$1" != "source" ];then # your additional bahsbot commands # NOTE: command can have @botname attached, you must add * in case tests... mycommands() { @@ -106,6 +105,7 @@ else answer_inline_query "${iQUERY[ID]}" "cached_gif" "BQADBAADIwYAAmwsDAABlIia56QGP0YC" ;; esac +set +x } # place your processing functions here From 085d85da352e33850108ad00339827e4809cc41a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 16 May 2019 16:43:44 +0200 Subject: [PATCH 24/27] ups, deleted doc, fixed --- doc/0_install.md | 74 ++++++ doc/1_firstbot.md | 69 ++++++ doc/2_usage.md | 186 ++++++++++++++ doc/3_advanced.md | 184 ++++++++++++++ doc/4_expert.md | 108 ++++++++ doc/5_practice.md | 157 ++++++++++++ doc/6_reference.md | 596 +++++++++++++++++++++++++++++++++++++++++++++ doc/7_develop.md | 192 +++++++++++++++ doc/8_custom.md | 135 ++++++++++ 9 files changed, 1701 insertions(+) create mode 100644 doc/0_install.md create mode 100644 doc/1_firstbot.md create mode 100644 doc/2_usage.md create mode 100644 doc/3_advanced.md create mode 100644 doc/4_expert.md create mode 100644 doc/5_practice.md create mode 100644 doc/6_reference.md create mode 100644 doc/7_develop.md create mode 100644 doc/8_custom.md diff --git a/doc/0_install.md b/doc/0_install.md new file mode 100644 index 0000000..96c557c --- /dev/null +++ b/doc/0_install.md @@ -0,0 +1,74 @@ +#### [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 ... + +**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. + +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.git``` +3. Change into the directory ```telegram-bot-bash``` +4. Run ``` test/ALL-tests.sh``` and if everthing finish OK ... +5. Run ```sudo ./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 your existing bashbot dir + **Note: all files execpt 'mycommands.sh' and 'commands.sh' may overwritten!** +4. Save your your current 'commands.sh' and run ```cp commands.sh.dist commands.sh``` +5. Run ```sudo ./bashbot.sh init``` to setup your environment after the update + +If you modified 'commands.sh' re apply all changes to the new 'commands.sh'. To avoid this all your modifications +must be done in 'mycommands.sh' only. + +### 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.60 on your commands must be placed in 'mycommands.sh'. If you update from a version with your commands +in 'commands.sh' move all your commands and functions to 'mycommands.sh'. + +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](1_firstbot.md) + +#### $$VERSION$$ v0.80-dev2-11-gb55c171 + diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md new file mode 100644 index 0000000..3329a7e --- /dev/null +++ b/doc/1_firstbot.md @@ -0,0 +1,69 @@ +#### [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` + 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`. + + ![botfather initial conversation](http://i.imgur.com/aI26ixR.png) + +2. @botfather replies with `Alright, a new bot. How are we going to +call it? Please choose a name for your bot.` + +3. Type whatever name you want for your bot. + +4. @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.` + +5. Type whatever username you want for your bot, minimum 5 characters, +and must end with `bot`. For example: `telesample_bot` + +6. @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 + +7. Note down the 'token' mentioned above. + +8. Type `/setprivacy` to @botfather. + + ![botfather later conversation](http://i.imgur.com/tWDVvh4.png) + +9. @botfather replies with `Choose a bot to change group messages settings.` + +10. Type `@telesample_bot` (change to the username you set at step 5 +above, but start it with `@`) + +11. @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 + +12. Type `Disable` to let your bot receive all messages sent to a +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.80-dev2-1-g0b36bc5 + diff --git a/doc/2_usage.md b/doc/2_usage.md new file mode 100644 index 0000000..c88a85c --- /dev/null +++ b/doc/2_usage.md @@ -0,0 +1,186 @@ +#### [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. See [Best practices](5_practice.md) for more information. + +Once you're done with editing 'mycommands.sh' start the Bot with ```./bashbot.sh start```. +To stop the Bot run ```./bashbot.sh kill``` + +If some thing doesn't work as it should, you can debug with ```./bashbot.sh startbot DEBUG``` where DEBUG can be 'debug', 'xdebug' or 'xdebugx'. +See [Bashbot Development](7_develop.md) for more information. + +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: +```bash +./bashbot.sh start +``` +```bash +./bashbot.sh kill +``` + +### User count +To count the total number of users that ever used the bot run the following command: +```bash +./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: +```bash +./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: + +### Regular Messages + +* ```${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 + +### Inline queries +Evertime a Message is recieved, you can read incoming data using the following variables: + +* ```${iQUERY}```: Current inline query +* ```$iQUERY```: This array contains the ID, First name, last name, username and user id of the sender of the current inline query. + * ```${iQUERY[ID]}```: Inline query ID + * ```${iQUERY[USER_ID]}```: User's id + * ```${iQUERY[FIRST_NAME]}```: User's first name + * ```${iQUERY[LAST_NAME]}```: User's last name + +## Usage of bashbot functions + +#### sending messages +To send messages use the ```send_xxx_message``` functions. + +To send regular text without any markdown use: +```bash +send_text_message "${CHAT[ID]}" "lol" +``` +To send text with markdown: +```bash +send_markdown_message "${CHAT[ID]}" "lol *bold*" +``` +To send text with html: +```bash +send_html_message "${CHAT[ID]}" "lol bold" +``` + +To forward messages use the ```forward``` function: +```bash +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** +```bash +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: +```bash +send_message "${CHAT[ID]}" "markdown_parse_mode lol *bold*" +``` +```bash +send_message "${CHAT[ID]}" "html_parse_mode lol bold" +``` +This function also allows a third parameter that disables additional function parsing (for safety use this when reprinting user input): +```bash +send_message "${CHAT[ID]}" "lol" "safe" +``` +**See also [Interactive chats](3_advanced.md#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): +```bash +send_file "${CHAT[ID]}" "/home/user/doge.jpg" "Lool" +``` +To send custom keyboards use the ```send_keyboard``` function: +```bash +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: +```bash +send_location "${CHAT[ID]}" "Latitude" "Longitude" +``` +To send venues use the ```send_venue``` function: +```bash +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. +```bash +send_action "${CHAT[ID]}" "action" +``` +**See also [Bashbot function reference](6_reference.md#Interactive_Chats)** + +#### [Prev Create Bot](1_firstbot.md) +#### [Next Advanced Usage](3_advanced.md) + +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 + diff --git a/doc/3_advanced.md b/doc/3_advanced.md new file mode 100644 index 0000000..c4af452 --- /dev/null +++ b/doc/3_advanced.md @@ -0,0 +1,184 @@ +#### [Home](../README.md) +## Advanced Features + +### Access control +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 +# -> 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```: +```bash +# 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. +```bash + 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](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 +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\" ]" +``` +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" +``` +And venues: +```bash +echo "Text that will appear in chat. mylatstartshere 45 mylongstartshere 45 mytitlestartshere my home myaddressstartshere Diagon Alley N. 37" +``` +You can combine them: +```bash +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: +```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 + +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, to stop a background job use: +```bash +killback "jobname" +``` +You can also suspend and resume the last running background jobs from outside bashbot, e.g. in your startup schripts: +```bash +./bashbot.sh suspendback +./bashbot.sh resumeback +``` + +If you want to kill all background jobs permantly run: +```bash +./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 +**Inline queries** allow users to send commands to your bot from every chat without going to a private chat. An inline query is started if the user type the bots name, e.g. @myBot. Everything after @myBot is immediatly send to the bot. + +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. + +The following commands allows you to send ansers to *inline queries*. To enable bashbot to process inline queries set ```INLINE="1"``` in 'mycommands.sh'. + +To send messsages or links through an *inline query*: +```bash +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*: +```bash +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*: +```bash +answer_inline_query "${iQUERY[ID]}" "gif" "gif url" +``` +To send mpeg4 gifs from a website (less than 1MB) through an *inline query*: +```bash +answer_inline_query "${iQUERY[ID]}" "mpeg4_gif" "mpeg4 gif url" +``` +To send videos from a website through an *inline query*: +```bash +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*: +```bash +answer_inline_query "${iQUERY[ID]}" "cached_photo" "identifier for the photo" +``` +To send gifs stored in Telegram servers through an *inline query*: +```bash +answer_inline_query "${iQUERY[ID]}" "cached_gif" "identifier for the gif" +``` +To send mpeg4 gifs stored in Telegram servers through an *inline query*: +```bash +answer_inline_query "${iQUERY[ID]}" "cached_mpeg4_gif" "identifier for the gif" +``` +To send stickers through an *inline query*: +```bash +answer_inline_query "${iQUERY[ID]}" "cached_sticker" "identifier for the sticker" +``` +See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inline_multi) and [mycommands.sh](../mycommands.sh) for more information. + +#### [Prev Getting started](2_usage.md) +#### [Next Expert Use](4_expert.md) + +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 + diff --git a/doc/4_expert.md b/doc/4_expert.md new file mode 100644 index 0000000..b7f40af --- /dev/null +++ b/doc/4_expert.md @@ -0,0 +1,108 @@ +#### [Home](../README.md) +## 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](https://en.wikipedia.org/wiki/UTF-8) 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. Set ```Shell``` environment to UTF-8 in your ```.profile``` and your scripts. The usual settings are: + +```bash +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: +```bash +export 'LC_ALL=de_DE.UTF-8' +export 'LANG=de_DE.UTF-8' +export 'LANGUAGE=de_DE.UTF-8' +``` +```bash +export 'LC_ALL=en_US.UTF-8' +export 'LANG=de_en_US.UTF-8' +export 'LANGUAGE=den_US.UTF-8' +``` +3. make shure your bot scripts use the correct settings, eg. include the lines above at the beginning of your scripts + +To display all availible locales on your system run ```locale -a | more```. [Gentoo Wiki](https://wiki.gentoo.org/wiki/UTF-8) + +#### 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 : +```bash +sudo ./bashbot.sh init +``` + +Edit the file ```bashbot.rc``` and edit the following lines to fit your configuration: +```bash +####################### +# 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: +```bash +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: +```bash +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 username```nobody``` with the username you want to run bashbot. copy the modified file to ```/etc/cron.d/bashbot``` + +#### [Prev Expert Use](4_expert.md) +#### [Next Best Practice](5_practice.md) + +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 + diff --git a/doc/5_practice.md b/doc/5_practice.md new file mode 100644 index 0000000..f11d950 --- /dev/null +++ b/doc/5_practice.md @@ -0,0 +1,157 @@ +#### [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 Documentation](https://core.telegram.org/bots/api/). + +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 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: +```bash +# 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](https://core.telegram.org/bots#commands).** + +**Note: Never disable the catchall command ```*)``` in 'commands.sh'!!** +```bash +# 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: +```bash +# 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](https://www.shellcheck.net/) or [install it on your system](https://github.com/koalaman/shellcheck#installing). +All bashbot scripts are linted by shellcheck. + +Shellcheck examples: +```bash +$ 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}"``` +```bash +$ 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](5_practice.md) +#### [Next Functions Reference](6_reference.md) + +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 + diff --git a/doc/6_reference.md b/doc/6_reference.md new file mode 100644 index 0000000..e94bdff --- /dev/null +++ b/doc/6_reference.md @@ -0,0 +1,596 @@ +#### [Home](../README.md) +## 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```. + +*alias:* _action "action" + +*example:* +```bash +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" + +*alias:* _normal_message "message" + +*example:* +```bash +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](https://core.telegram.org/bots/api#markdown-style) only + +*usage:* send_markdown_message "${CHAT[ID]}" "markdown message" + +*alias:* _markdown "message" + +*example:* +```bash +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](https://core.telegram.org/bots/api#html-style) only + +*usage:* send_html_message "${CHAT[ID]}" "html message" + +*alias:* _html_message "message" + +*example:* +```bash +send_normal_message "${CHAT[ID]}" "this is a markdown message, next word is bold" +send_normal_message "${CHAT[ID]}" "bold italic> italic>/em> Text" +``` + +##### 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]}" + +*alias:* _forward "$FROMCHAT" "${MESSAGE[ID]}" + +See also [Text formating options](https://core.telegram.org/bots/api#formatting-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]}" + +*alias:* _del_message "${MESSAGE[ID]}" + +See also [deleteMessage limitations](https://core.telegram.org/bots/api#deletemessage) + +---- + +### 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](https://core.telegram.org/bots/api#sending-files) + +*usage:* send_file "${CHAT[ID]}" "file" "caption" + +*example:* +```bash +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" + +*alias:* _keyboard "message" "keyboard" + +*example:* +```bash +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" + +*alias:* _del_keyboard "message" + +*See also: [Keyboard Markup](https://core.telegram.org/bots/api/#replykeyboardmarkup)* + +---- + +##### send_button +*usage:* send_button "chat-id" "message" "text" "URL" + +*alias:* _button "text" "URL" + +*example:* +```bash +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:* +```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"} ]' +``` + +*See also [Inline keyboard markup](https://core.telegram.org/bots/api/#inlinekeyboardmarkup)* + +---- + +### User Access Control + +##### 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 + +```bash +if _is_admin ; then + send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*" + leave_chat "${CHAT[ID]}" +fi +``` + +'See also [kick Chat Member](https://core.telegram.org/bots/api/#kickchatmember)* + +---- + +##### 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]}" + +*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. + +*usage:* user_is_creator "${CHAT[ID]}" "${USER[ID]}" + +*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]}" + +*alias:* _is_admin + +*example:* +```bash +if _is_admin ; then + send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*" + leave_chat "${CHAT[ID]}" +fi +``` + +*See also [Chat Member](https://core.telegram.org/bots/api/#chatmember)* + +##### user_is_allowed +Bahsbot supports User Access Control, see [Advanced Usage](3_advanced.md) + +*usage:* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}" + +*example:* +```bash +if ! user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then + send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot." +fi +``` + +---- + +### Inline Queries - answer direct queries to bot +You must include ```source modules/inline.sh``` in 'commands.sh' to have the following functions availible. + +Inline Queries allows users to interact with your bot directly without sending extra commands. +As an answer to an inline query you can send back one or more results to the Telegram client. +The Telegram client will then show the results to the user and let him select one. + +##### answer_inline_query +answer_inline_query is provided for backward compatibility with older versions of bashbot. +It send back only one response to an inline query. + +*usage:* answer_inline_query "$i{QUERY[ID]}" "type" "type arg 1" ... "type arg n" + +*example:* - see [Advanced Usage](3_advanced.md#Inline-queries) + + +##### answer_inline_multi +anser_inline_multi allows you to send back a list of responses. responses must be seperated by ','. + +*usage:* answer_inline_multi "${iQUERY[ID]}" "res, res, ... res" + +*example:* +```bash +# note the starting " and ending " !! +answer_inline_multi "${iQUERY[ID]}" " + $(inline_query_compose "1" "photo" "https://avatars0.githubusercontent.com/u/13046303") , + ... + $(inline_query_compose "n" "photo" "https://avatars1.githubusercontent.com/u/4593242") + " +``` + +#### inline_query_compose +inline_query_compose composes one response element to to send back. + +*usage:* inline_query_compose ID type args .... + +``` + ID = unique ID for this response, 1-64 byte long + type = type of answer, e.g. article, photo, video, location ... + args = mandatory arguments in the order they are described in telegram documentation +``` + +Currently the following types and arguments are implemented (optional arguments in parenthesis) +``` + "article"|"message" title message (markup description) + + "photo" photo_URL (thumb_URL title description caption) + "gif" photo_URL (thumb_URL title caption) + "mpeg4_gif" mpeg_URL (thumb_URL title caption) + "video" video_URL mime_type thumb_URL title (caption) + "audio" audio_URL title (caption) + "voice" voice_URL title (caption) + "document" title document_URL mime_type (caption description) + + "location" latitude longitude title + "venue" latitude longitude title (adress foursquare) + "contact" phone first (last thumb) + + "cached_photo" file (title description caption) + "cached_gif" file (title caption) + "cached_mpeg4_gif" file (title caption) + "cached_sticker" file + "cached_document" title file (description caption) + "cached_video" file title (description caption) + "cached_voice" file title (caption) + "cached_audio" file title (caption) +``` +see [InlineQueryResult for more information](https://core.telegram.org/bots/api#inlinequeryresult) about response types and their arguments. + +---- + + +### Background and Interactive jobs +You must include ```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](3_advanced.md#Interactive-Chats) + +*usage:* startproc "script" + +*example:* +```bash +startproc 'examples/calc.sh' +``` + +##### checkproc +Return true (0) if an interactive script is running in the chat. + +*usage:* checkprog + +*example:* +```bash +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:* +```bash +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:* +```bash +background "examples/notify.sh" "notify" +``` + +##### checkback +Return true (0) if an background job is active in the given chat. + +*usage:* checkback "jobname" + +*example:* +```bash +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:* +```bash +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](2_usage.md#send_message) and [Advanced Usage](3_advanced.md#Interactive-Chats) + +---- + +### Aliases - shortcuts for often used funtions +You must include ```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" + +---- + +#### _inline_button +*usage:* _inline_button "${1}" "${2}" + +*alias for:* send_inline_button "${CHAT[ID]}" "" "${1}" "${2}" + +#### _inline_keyboard +*usage:* _inline_keyboard "${1}" + +*alias for:* _inline_keyboard "${CHAT[ID]}" "" "${1}" + +#### _keyboard_numpad +*usage:* _keyboard_numpad + +*alias for:* send_keyboard "${CHAT[ID]}" "" '["1","2","3"],["4","5","6"],["7","8","9"],["-","0","."]' "yes" + +#### _keyboard_yesno +*usage:* _keyboard_yesno + +*alias for:* send_keyboard '["yes","no"]' + +#### _del_keyboard +*usage:* _del_keyboard + +*alias for:* remove_keyboard "${CHAT[ID]}" "" + + + +### 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:* +```bash +_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](5_practice.md) +#### [Next Notes for Developers](7_develop.md) + +#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 + diff --git a/doc/7_develop.md b/doc/7_develop.md new file mode 100644 index 0000000..d4dd062 --- /dev/null +++ b/doc/7_develop.md @@ -0,0 +1,192 @@ +#### [Home](../README.md) +## 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](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). + +### Debugging Bashbot +In normal mode of operation all bashbot output is discarded one more correct sent to TMUX console. +To get these messages (and more) you can start bashbot in the current shell ```./bashbot.sh startbot```. Now you can see all output or erros from bashbot. +In addition you can change the change the level of verbosity by adding a third argument after startbot. +``` + "debug" redirects all output to "DEBUG.log", in addtion every update is logged in "MESSAGE.LOG" and "INLINE.log" + "debugterm" same as debug but output and errors are sent to terminal + + "xdebug" same as debug plus set bash option '-x' to log any executed command + "xdebugterm" same as xdebug but output and errors are sent to terminal +``` + +### Create a stripped down Version of your Bot +Currently bashbot is more a bot development environment than a bot, containing examples, developer scripts, modules, documentation and more. +You don't need all these files after you're finished with your cool new bot. + +Let's create a stripped down version: + +- delete all modules you do not need from 'modules', e.g. 'modules/inline.sh' if you don't use inline queries +- delete not needed standard commands and messages from 'commands.sh' +- delete not needed commands and functions from 'mycommands.sh' +- run ```dev/make-standalone.sh``` to create a a stripped down version of your bo + +Now have a look at the directory 'standalone', here you find the files 'bashbot.sh' and 'commands.sh' containing everything to run your bot. +[Download make-standalone.sh](https://github.com/topkecleon/telegram-bot-bash/blob/master/dev/make-standalone.sh) from github. + +### Setup your develop environment + +1. install git, install [shellcheck](5_practice.md#Test-your-Bot-with-shellcheck) +2. setup your [environment for UTF-8](4_expert.md#Setting-up-your-Environment) +3. clone your bashbot fork to a new directory ```git clone https://github.com//telegram-bot-bash.git```, replace `````` with your username on github +4. create and change to your develop branch ```git checkout -b ```, replace `````` with the name you want to name it, e.g. 'develop' +5. give your (dev) fork a new version tag: ```git tag vx.xx```(optional) +6. setup github hooks by running ```dev/install-hooks.sh``` (optional) + +### Test, Add, Push changes +A typical bashbot develop loop looks as follow: + +1. start developing - *change, copy, edit bashbot files ...* +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 your dev environment with hooks and use the scripts above, versioning, addding and testing is done automatically.** + +### common commands +We state bashbot is a bash only bot, but this is not true. bashbot is a bash script using bash features PLUS external commands. +Usually bash is used in a unix/linux environment where many (GNU) commands are availible, but if commands are missing, bashbot may not work. + +To avoid this and make bashbot working on as many platforms as possible - from embedded linux to mainframe - I recommed to restrict +ourself to the common commands provided by bash and coreutils/busybox/toybox. +See [Bash Builtins](https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html), +[coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), +[busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) and [toybox](https://landley.net/toybox/help.html) + +Availible commands in bash, coreutils, busybox and toybox. Do you find curl on the list? +```bash + .*, [*, [[*, basename, break, builtin*, bzcat, caller*, cat, cd*, chattr, + chgrp, chmod, chown, clear, command*, continue *, cp, cut, date, declare*, + dc, dd, df, diff, dirname, du, echo*, eval*, exec*, exit *, expr*, find, + fuser, getopt*, grep, hash*, head, hexdump, id, kill, killall, last, length, + less, let*, ln, local*, logname, ls, lsattr, lsmod, man, mapfile*, md5sum, mkdir, + mkfifo, mknod, more, mv, nice, nohup, passwd, patch, printf*, ps, pwd*, read*, + readarray*, readonly* return*, rm, rmdir, sed, seq, sha1sum, shift*, sleep, + source*, sort, split, stat, strings, su, sync, tail, tar, tee, test, + time, times*, timeout, touch, tr, trap*, true, umask*, usleep, uudecode, + uuencode, wc, wget, which, who, whoami, xargs, yes +``` +commands marked with \* are bash builtins, all others are external programms. Calling an external programm is more expensive then using bulitins +or using an internal replacement. Here are some examples of internal replacement for external commands: +```bash +HOST="$(hostname)" -> HOST="$HOSTNAME" + +seq 1 100 -> {0..100} + +data="$(cat file)" -> data="$(<"file")" + +DIR="$(dirname $0) -> DIR=""${0%/*}/"" + +IAM="($basename $0)" -> IAM="${0##*/}* + +VAR="$(( 1 + 2 ))" -> (( var=1+2 )) + +INDEX="$(( ${INDEX} + 1 ))" -> (( INDEX++ )) + +``` +For more examples see [Pure bash bible](https://github.com/dylanaraps/pure-bash-bible) + +### 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 ... +``` + +If you release a new Version run ```dev/make-distribution.sh``` to create the zip and tar.gz archives in the dist directory and attach them to the github release. Do not forget to delete directory dist afterwards. + +### Versioning + +Bashbot is tagged with version numbers. If you start a new development cycle you can tag your fork with a version higher than the current version. +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](../dev/version.sh) + +To update the Version Number in files run ```dev/version.sh files```, it will update the line '#### $$VERSION$$ ###' in all files to the current version name. +To update version in all files run 'dev/version.sh' without parameter. + + +### Shellcheck + +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. + +To run shellcheck for a single script run ```shellcheck -x script.sh```, to check all schripts run ```dev/hooks/pre-commit.sh```. + + +## 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 execute flag from the '*-test.sh' 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, it will create the usually needed files and dirs: + +Each test consists of a script script named after ```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. + +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. +A temporary test environment is created when 'ALL-tests.sh' starts and deleted after all tests are finished. + +The file ```ALL-tests.inc.sh``` must be included from all tests and provide the test environment as shell variables: +```bash +# Test Evironment + TESTME="$(basename "$0")" + DIRME="$(pwd)" + TESTDIR="$1" + LOGFILE="${TESTDIR}/${TESTME}.log" + REFDIR="${TESTME%.sh}" + TESTNAME="${REFDIR//-/ }" + +# common filenames + TOKENFILE="token" + ACLFILE="botacl" + COUNTFILE="count" + ADMINFILE="botadmin" + DATADIR="data-bot-bash" + +# SUCCESS NOSUCCES -> echo "${SUCCESS}" or echo "${NOSUCCESS}" + SUCCESS=" OK" + NOSUCCESS=" FAILED!" + +# default input, reference and output files + INPUTFILE="${DIRME}/${REFDIR}/${REFDIR}.input" + REFFILE="${DIRME}/${REFDIR}/${REFDIR}.result" + OUTPUTFILE="${TESTDIR}/${REFDIR}.out" +``` + +Example test +```bash +#!/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 "${TESTDIR}/bashbot.sh" ]; then + echo "${SUCCESS} bashbot.sh exist!" + exit 0 +else + echo "${NOSUCCESS} ${TESTDIR}/bashbot.sh missing!" + exit 1 +fi +``` + +#### [Prev Function Reference](6_reference.md) +#### [Next Bashbot Environment](8_custom.md) + +#### $$VERSION$$ v0.80-dev2-15-geb0cde5 + diff --git a/doc/8_custom.md b/doc/8_custom.md new file mode 100644 index 0000000..0b27d14 --- /dev/null +++ b/doc/8_custom.md @@ -0,0 +1,135 @@ +#### [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' 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``` ... +```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 ```data-bot-bash```, ```count``` +```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_JSONSH +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 + + export BASHBOT_JSONSH "/usr/local/bin/JSON.sh" # installed in /usr/local/bin + +``` + +### Change config values + +#### BASHBOT_URL +Uses given URL instead of offical telegram API URL, useful if you have your own telegram server or for testing. + +```bash + unset BASHBOT_URL # use Telegram URL https://api.telegram.org/bot (default) + + export BASHBOT_URL "" # use use Telegram https://api.telegram.org/bot + + export BASHBOT_URL "https://my.url.com/bot" # use your URL https://my.url.com/bot + +``` + +#### BASHBOT_TOKEN + +#### BASHBOT_WGET +Bashbot uses ```curl``` to communicate with telegram server. if ```curl``` is not availible ```wget``` is used. +If 'BASHBOT_WGET' is set to any value (not undefined or not empty) wget is used even is curl is availible. +```bash + unset BASHBOT_WGET # use curl (default) + export BASHBOT_WGET "" # use curl + + export BASHBOT_WGET "yes" # use wget + export BASHBOT_WGET "no" # use wget! + +``` + +#### 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) + +``` + +### 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' +```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' +```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" + + /usr/local/bin/bashbot.sh start +``` + +#### 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" + + /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" + + /usr/local/telegram-bot-bash/bashbot.sh start +``` + +#### [Prev Notes for Developers](7_develop.md) + +#### $$VERSION$$ v0.80-dev2-14-gaacdc76 + From 6d497d5f5e79b501dba13f59fd0b14a27189676c Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 16 May 2019 16:55:32 +0200 Subject: [PATCH 25/27] remove send_message at bot startup --- bashbot.sh | 4 +--- 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 +- mycommands.sh | 2 +- 11 files changed, 11 insertions(+), 13 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 1533ec2..174a761 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-21-gd01addf +#### $$VERSION$$ v0.80-dev2-23-g085d85d # # Exit Codes: # - 0 sucess (hopefully) @@ -475,12 +475,10 @@ if [ "$1" != "source" ]; then tmux kill-session -t "$ME" &>/dev/null tmux new-session -d -s "$ME" "bash $SCRIPT startbot" && echo -e "${GREEN}Bot started successfully.${NC}" echo "Tmux session name $ME" || echo -e "${RED}An error occurred while starting the bot. ${NC}" - send_markdown_message "${CHAT[ID]}" "*Bot started*" ;; "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") diff --git a/doc/0_install.md b/doc/0_install.md index 96c557c..e6f717e 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -70,5 +70,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.80-dev2-11-gb55c171 +#### $$VERSION$$ v0.80-dev2-22-ga72f24a diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 3329a7e..f54b767 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-22-ga72f24a diff --git a/doc/2_usage.md b/doc/2_usage.md index c88a85c..6f7051f 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -182,5 +182,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-22-ga72f24a diff --git a/doc/3_advanced.md b/doc/3_advanced.md index c4af452..31713cd 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -180,5 +180,5 @@ See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inli #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-22-ga72f24a diff --git a/doc/4_expert.md b/doc/4_expert.md index b7f40af..fbf6f8d 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-22-ga72f24a diff --git a/doc/5_practice.md b/doc/5_practice.md index f11d950..3dd6e34 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-22-ga72f24a diff --git a/doc/6_reference.md b/doc/6_reference.md index e94bdff..2acb4b8 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -592,5 +592,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.80-dev2-22-ga72f24a diff --git a/doc/7_develop.md b/doc/7_develop.md index d4dd062..3c0b5ff 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -188,5 +188,5 @@ fi #### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.80-dev2-15-geb0cde5 +#### $$VERSION$$ v0.80-dev2-22-ga72f24a diff --git a/doc/8_custom.md b/doc/8_custom.md index 0b27d14..789327f 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.80-dev2-14-gaacdc76 +#### $$VERSION$$ v0.80-dev2-22-ga72f24a diff --git a/mycommands.sh b/mycommands.sh index 52cf942..9be49f6 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.80-dev2-21-gd01addf +#### $$VERSION$$ v0.80-dev2-22-ga72f24a # # uncomment the following lines to overwrite info and help messages From e8a1fd0bf1af118b65407189197a0d47cfad8271 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 16 May 2019 16:57:04 +0200 Subject: [PATCH 26/27] Bashbot Version 0.76 --- 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-distribution.sh | 2 +- dev/make-standalone.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-multi.sh | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question.sh | 2 +- examples/send-system-status/botacl | 2 +- examples/send-system-status/mycommands.sh | 2 +- modules/aliases.sh | 2 +- modules/answerInline.sh | 2 +- modules/background.sh | 2 +- modules/chatMember.sh | 2 +- modules/sendMessage.sh | 2 +- mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/a-commit-test.sh | 2 +- test/b-example-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_inline-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- test/e-env-test.sh | 2 +- 53 files changed, 53 insertions(+), 53 deletions(-) diff --git a/README.html b/README.html index b08b62d..2edda13 100644 --- a/README.html +++ b/README.html @@ -107,6 +107,6 @@

        @Gnadelwartz

        That’s it!

        If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!

        -


        VERSION
        v0.80-dev2-19-g417bc37

        +


        VERSION
        v0.76-0-g6d497d5

        diff --git a/README.md b/README.md index 7796eef..cef5a89 100644 --- a/README.md +++ b/README.md @@ -107,4 +107,4 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-19-g417bc37 +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/README.txt b/README.txt index 4fae3d7..f112a29 100644 --- a/README.txt +++ b/README.txt @@ -155,4 +155,4 @@ health status If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.80-dev2-19-g417bc37 +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/bashbot.rc b/bashbot.rc index d68262f..e085a18 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 174a761..2b3fca1 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-23-g085d85d +#### $$VERSION$$ v0.76-0-g6d497d5 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index ac18a16..c16969b 100644 --- a/commands.sh +++ b/commands.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-13-gbce7f1a +#### $$VERSION$$ v0.76-0-g6d497d5 # # adjust your language setting here, e.g.when run from other user or cron. diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 9ddc936..859eb4c 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.80-dev2-8-ge9cf8d2 +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 250b6d0..572ddfc 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.80-dev2-2-g0c5e3dd +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 3f0e08a..6c6a7f2 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 ############ # 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 e38c9d2..844f607 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 ############ # 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 b432650..2193f9f 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.80-dev2-2-g0c5e3dd +#### $$VERSION$$ v0.76-0-g6d497d5 # 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-distribution.sh b/dev/make-distribution.sh index 6798b12..620ef9d 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -2,7 +2,7 @@ # file: make-distribution.sh # creates files and arcchives to dirtribute bashbot # -#### $$VERSION$$ v0.80-dev2-3-ge492da0 +#### $$VERSION$$ v0.76-0-g6d497d5 # 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-standalone.sh b/dev/make-standalone.sh index 022d221..e5e3abb 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -5,7 +5,7 @@ # If you your bot is finished you can use make-standalone.sh to create the # the old all-in-one bashbot: bashbot.sh and commands.sh only! # -#### $$VERSION$$ v0.80-dev2-13-gbce7f1a +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 34a9b95..a801e45 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 7f3e518..76d6c61 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd +#### $$VERSION$$ v0.76-0-g6d497d5 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index e6f717e..f704755 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -70,5 +70,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.80-dev2-22-ga72f24a +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index f54b767..10b3b77 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.80-dev2-22-ga72f24a +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/doc/2_usage.md b/doc/2_usage.md index 6f7051f..da2c852 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -182,5 +182,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.80-dev2-22-ga72f24a +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 31713cd..2a6f851 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -180,5 +180,5 @@ See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inli #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.80-dev2-22-ga72f24a +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/doc/4_expert.md b/doc/4_expert.md index fbf6f8d..cb3486c 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.80-dev2-22-ga72f24a +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/doc/5_practice.md b/doc/5_practice.md index 3dd6e34..4eac38a 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.80-dev2-22-ga72f24a +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/doc/6_reference.md b/doc/6_reference.md index 2acb4b8..0b97a21 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -592,5 +592,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.80-dev2-22-ga72f24a +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/doc/7_develop.md b/doc/7_develop.md index 3c0b5ff..ad0ee10 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -188,5 +188,5 @@ fi #### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.80-dev2-22-ga72f24a +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/doc/8_custom.md b/doc/8_custom.md index 789327f..2671f95 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.80-dev2-22-ga72f24a +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/examples/README.md b/examples/README.md index c0923e4..8588fb6 100644 --- a/examples/README.md +++ b/examples/README.md @@ -55,6 +55,6 @@ convert existing bots. **external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users. -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 diff --git a/examples/background-scripts/run_diskusage.sh b/examples/background-scripts/run_diskusage.sh index 0a3802c..5a3455a 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 9c07200..702d302 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 0b5d2cf..29218b8 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 dba82cd..43eb1a9 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/bashbot-multi.sh b/examples/bashbot-multi.sh index 2f84d15..32d90bc 100755 --- a/examples/bashbot-multi.sh +++ b/examples/bashbot-multi.sh @@ -2,7 +2,7 @@ # file. multibot.sh # description: run multiple telegram bots from one installation # -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then echo "Usage: $0 botname command" diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 8b77918..5f2460b 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 06fa895..8ed0373 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 3461004..e94d57a 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.80-dev2-15-geb0cde5 +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 38c83a2..4d63413 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/send-system-status/botacl b/examples/send-system-status/botacl index 019624a..b6a8730 100644 --- a/examples/send-system-status/botacl +++ b/examples/send-system-status/botacl @@ -1,7 +1,7 @@ # file: botacl # a user not listed here, will return false from 'user_is_allowed' # -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # Format: # user:ressource:chat diff --git a/examples/send-system-status/mycommands.sh b/examples/send-system-status/mycommands.sh index 23af90e..212fa94 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/modules/aliases.sh b/modules/aliases.sh index d700c45..3c8eba1 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # # source from commands.sh to use the aliases diff --git a/modules/answerInline.sh b/modules/answerInline.sh index 5ad0edc..2712060 100644 --- a/modules/answerInline.sh +++ b/modules/answerInline.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-4-gb7df57a +#### $$VERSION$$ v0.76-0-g6d497d5 # source from commands.sh to use the inline functions diff --git a/modules/background.sh b/modules/background.sh index 946c59b..20fa5e9 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.80-dev2-6-g5b10e75 +#### $$VERSION$$ v0.76-0-g6d497d5 # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 9f19534..cd9533d 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-6-g5b10e75 +#### $$VERSION$$ v0.76-0-g6d497d5 # source from commands.sh to use the member functions diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 8d45070..67f0b71 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev2-12-gdf03727 +#### $$VERSION$$ v0.76-0-g6d497d5 # source from commands.sh to use the sendMessage functions diff --git a/mycommands.sh b/mycommands.sh index 9be49f6..ef69e30 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.80-dev2-22-ga72f24a +#### $$VERSION$$ v0.76-0-g6d497d5 # # uncomment the following lines to overwrite info and help messages diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index e257706..42cbb6f 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.80-dev2-7-g92f022d +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 8f70d64..f873a7b 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-20-g412173c +#### $$VERSION$$ v0.76-0-g6d497d5 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index c1c8818..0cca19a 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 ../dev/hooks/pre-commit.sh diff --git a/test/b-example-test.sh b/test/b-example-test.sh index fbf2f84..af87cc9 100644 --- a/test/b-example-test.sh +++ b/test/b-example-test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # file: b-example-test.sh -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 3286b64..8e2afd0 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-20-g412173c +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 7af81c3..525fe90 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.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh index 23f43fc..915edac 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-7-g92f022d +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 bd1a586..150506b 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.80-dev2-20-g412173c +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 1d0cc20..45e0510 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.80-dev2-7-g92f022d +#### $$VERSION$$ v0.76-0-g6d497d5 # 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 2c32953..5b48c41 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.80-dev2-7-g92f022d +#### $$VERSION$$ v0.76-0-g6d497d5 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/e-env-test.sh b/test/e-env-test.sh index eebfd96..c1f1c7e 100755 --- a/test/e-env-test.sh +++ b/test/e-env-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 +#### $$VERSION$$ v0.76-0-g6d497d5 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 31a5d00a64e7515a2bb59fce0f4c10e833d58e46 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 16 May 2019 17:06:58 +0200 Subject: [PATCH 27/27] Bashbot Version 0.76 --- 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-distribution.sh | 2 +- dev/make-standalone.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-multi.sh | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question.sh | 2 +- examples/send-system-status/botacl | 2 +- examples/send-system-status/mycommands.sh | 2 +- modules/aliases.sh | 2 +- modules/answerInline.sh | 2 +- modules/background.sh | 2 +- modules/chatMember.sh | 2 +- modules/sendMessage.sh | 2 +- mycommands.sh | 4 ++-- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/a-commit-test.sh | 2 +- test/b-example-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_inline-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- test/e-env-test.sh | 2 +- 53 files changed, 54 insertions(+), 54 deletions(-) diff --git a/README.html b/README.html index 2edda13..4d7dfc4 100644 --- a/README.html +++ b/README.html @@ -107,6 +107,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.76-0-g6d497d5

        +


        VERSION
        v0.76-1-ge8a1fd0

        diff --git a/README.md b/README.md index cef5a89..b27c8ae 100644 --- a/README.md +++ b/README.md @@ -107,4 +107,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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/README.txt b/README.txt index f112a29..b394f5b 100644 --- a/README.txt +++ b/README.txt @@ -155,4 +155,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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/bashbot.rc b/bashbot.rc index e085a18..19d1837 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 0d2f5d2..3e7410e 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # # Exit Codes: # - 0 sucess (hopefully) diff --git a/commands.sh b/commands.sh index c16969b..2654af7 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # # adjust your language setting here, e.g.when run from other user or cron. diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 859eb4c..bc99493 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 572ddfc..aeb99aa 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 6c6a7f2..bf19b43 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 ############ # 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 844f607..e1e1610 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 ############ # 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 2193f9f..d510bf2 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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-distribution.sh b/dev/make-distribution.sh index 620ef9d..cec7784 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -2,7 +2,7 @@ # file: make-distribution.sh # creates files and arcchives to dirtribute bashbot # -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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-standalone.sh b/dev/make-standalone.sh index e5e3abb..7fe348f 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -5,7 +5,7 @@ # If you your bot is finished you can use make-standalone.sh to create the # the old all-in-one bashbot: bashbot.sh and commands.sh only! # -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 a801e45..0b3c8a0 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 76d6c61..7340d72 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index f704755..674b542 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -70,5 +70,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 10b3b77..1884726 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/doc/2_usage.md b/doc/2_usage.md index da2c852..28aa312 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -182,5 +182,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 2a6f851..1360d1c 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -180,5 +180,5 @@ See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inli #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/doc/4_expert.md b/doc/4_expert.md index cb3486c..adace28 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/doc/5_practice.md b/doc/5_practice.md index 4eac38a..9e717e5 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/doc/6_reference.md b/doc/6_reference.md index 0b97a21..a3359f0 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -592,5 +592,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/doc/7_develop.md b/doc/7_develop.md index ad0ee10..55bc350 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -188,5 +188,5 @@ fi #### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/doc/8_custom.md b/doc/8_custom.md index 2671f95..04db87a 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/examples/README.md b/examples/README.md index 8588fb6..45fa8eb 100644 --- a/examples/README.md +++ b/examples/README.md @@ -55,6 +55,6 @@ convert existing bots. **external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users. -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 diff --git a/examples/background-scripts/run_diskusage.sh b/examples/background-scripts/run_diskusage.sh index 5a3455a..4c756f3 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 702d302..fa5ab5c 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 29218b8..3c070fb 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 43eb1a9..e019204 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/bashbot-multi.sh b/examples/bashbot-multi.sh index 32d90bc..61cdde6 100755 --- a/examples/bashbot-multi.sh +++ b/examples/bashbot-multi.sh @@ -2,7 +2,7 @@ # file. multibot.sh # description: run multiple telegram bots from one installation # -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then echo "Usage: $0 botname command" diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 5f2460b..df9b95f 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 8ed0373..4c47dd0 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 e94d57a..976548f 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 4d63413..ee74b57 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/send-system-status/botacl b/examples/send-system-status/botacl index b6a8730..9f41c1f 100644 --- a/examples/send-system-status/botacl +++ b/examples/send-system-status/botacl @@ -1,7 +1,7 @@ # file: botacl # a user not listed here, will return false from 'user_is_allowed' # -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # Format: # user:ressource:chat diff --git a/examples/send-system-status/mycommands.sh b/examples/send-system-status/mycommands.sh index 212fa94..64b5180 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/modules/aliases.sh b/modules/aliases.sh index 3c8eba1..3ead78f 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # # source from commands.sh to use the aliases diff --git a/modules/answerInline.sh b/modules/answerInline.sh index 2712060..3fde398 100644 --- a/modules/answerInline.sh +++ b/modules/answerInline.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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # source from commands.sh to use the inline functions diff --git a/modules/background.sh b/modules/background.sh index 20fa5e9..d1145d6 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # source from commands.sh if you want ro use interactive or background jobs diff --git a/modules/chatMember.sh b/modules/chatMember.sh index cd9533d..09148df 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # source from commands.sh to use the member functions diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 67f0b71..59e57e5 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # source from commands.sh to use the sendMessage functions diff --git a/mycommands.sh b/mycommands.sh index ef69e30..fb00731 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # # uncomment the following lines to overwrite info and help messages @@ -30,7 +30,7 @@ if [ "$1" != "source" ];then '/question'*) # start interactive questions checkproc if [ "$res" -gt 0 ] ; then - startproc "examples/question,sh" + startproc "examples/question.sh" else send_normal_message "${CHAT[ID]}" "$MESSAGE already running ..." fi diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 42cbb6f..70bbf47 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 f873a7b..56e068a 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 0cca19a..31b7ae6 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 ../dev/hooks/pre-commit.sh diff --git a/test/b-example-test.sh b/test/b-example-test.sh index af87cc9..7f34def 100644 --- a/test/b-example-test.sh +++ b/test/b-example-test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # file: b-example-test.sh -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 8e2afd0..1e65619 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 525fe90..70be42f 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh index 915edac..3c36f23 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 150506b..6b13f25 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 45e0510..1f7759b 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # 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 5b48c41..7c2b750 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.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/e-env-test.sh b/test/e-env-test.sh index c1f1c7e..5f03074 100755 --- a/test/e-env-test.sh +++ b/test/e-env-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-0-g6d497d5 +#### $$VERSION$$ v0.76-1-ge8a1fd0 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh