diff --git a/README.md b/README.md index 09b65f0..c7271b2 100644 --- a/README.md +++ b/README.md @@ -104,4 +104,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/README.txt b/README.txt index 4563418..088a3b9 100644 --- a/README.txt +++ b/README.txt @@ -168,5 +168,5 @@ That's it! If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -latexmath:[\[VERSION\]] v0.70-dev2-10-gfa9e879 +latexmath:[\[VERSION\]] v0.70-dev2-16-gc6d4086 ++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/bashbot.rc b/bashbot.rc index 58fa45d..1162182 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 530239f..6df7a52 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -1,4 +1,6 @@ #!/bin/bash +# file: bashbot.sh +# do not edit, this file will be overwritten on update # bashbot, the Telegram bot written in bash. # Written by Drew (@topkecleon) and Daniil Gentili (@danogentili), KayM (@gnadelwartz). @@ -10,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.70-dev2-14-g56a45aa +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # # Exit Codes: # - 0 sucess (hopefully) @@ -161,73 +163,6 @@ declare -A USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE export USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE -send_message() { - local text arg keyboard file lat long title address sent - [ "$2" = "" ] && return 1 - local chat="$1" - text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - arg="$3" - [ "$arg" != "safe" ] && { - text="${text// mynewlinestartshere /$'\r\n'}" - no_keyboard="$(echo "$2" | sed '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" - - keyboard="$(echo "$2" | sed '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - - file="$(echo "$2" | sed '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ mykeyboardstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - - lat="$(echo "$2" | sed '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - - long="$(echo "$2" | sed '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - - title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - - address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')" - - } - if [ "$no_keyboard" != "" ]; then - echo "remove_keyboard $chat $text" > "${TMPDIR:-.}/prova" - remove_keyboard "$chat" "$text" - sent=y - fi - if [ "$keyboard" != "" ]; then - if [[ "$keyboard" != *"["* ]]; then # pre 0.60 style - keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]" - fi - send_keyboard "$chat" "$text" "$keyboard" - sent=y - fi - if [ "$file" != "" ]; then - send_file "$chat" "$file" "$text" - sent=y - fi - if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" = "" ] && [ "$title" = "" ]; then - send_location "$chat" "$lat" "$long" - sent=y - fi - if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" != "" ] && [ "$title" != "" ]; then - send_venue "$chat" "$lat" "$long" "$title" "$address" - sent=y - fi - if [ "$sent" != "y" ];then - send_text "$chat" "$text" - fi - -} - -send_text() { - case "$2" in - html_parse_mode*) - send_html_message "$1" "${2//html_parse_mode}" - ;; - markdown_parse_mode*) - send_markdown_message "$1" "${2//markdown_parse_mode}" - ;; - *) - send_normal_message "$1" "$2" - ;; - esac -} - send_normal_message() { text="$2" until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do @@ -480,42 +415,7 @@ forward() { # backward compatibility forward_message "$@" || return } -background() { - echo "${CHAT[ID]}:$2:$1" >"${TMPDIR:-.}/${copname}$2-back.cmd" - startproc "$1" "back-$2-" -} - -startproc() { - killproc "$2" - local fifo="$2${copname}" - mkfifo "${TMPDIR:-.}/${fifo}" - tmux new-session -d -s "${fifo}" "$1 &>${TMPDIR:-.}/${fifo}; echo imprettydarnsuredatdisisdaendofdacmd>${TMPDIR:-.}/${fifo}" - tmux new-session -d -s "sendprocess_${fifo}" "bash $SCRIPT outproc ${CHAT[ID]} ${fifo}" -} - - -checkback() { - checkproc "back-$1-" -} - -checkproc() { - tmux ls | grep -q "$1${copname}"; res=$?; return $? -} - -killback() { - killproc "back-$1-" - rm -f "${TMPDIR:-.}/${copname}$1-back.cmd" -} - -killproc() { - local fifo="$1${copname}" - (tmux kill-session -t "${fifo}"; echo imprettydarnsuredatdisisdaendofdacmd>"${TMPDIR:-.}/${fifo}"; tmux kill-session -t "sendprocess_${fifo}"; rm -f -r "${TMPDIR:-.}/${fifo}")2>/dev/null -} - -inproc() { - tmux send-keys -t "$copname" "${MESSAGE[0]} ${URLS[*]} -" -} +# returns true if function exist _is_function() { [ "$(LC_ALL=C type -t "$1")" = "function" ] diff --git a/commands.sh b/commands.sh index 5b9fa33..b7f8abe 100644 --- a/commands.sh +++ b/commands.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.70-dev2-15-g03f22c9 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 @@ -125,8 +125,8 @@ else checkprog if [ "$res" -eq 0 ] ; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi ;; - *) # forward input to interactive chat if running - if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi + *) # forward other messages to optional dispatcher + _is_function startproc && if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi _is_function mycommands && mycommands ;; esac diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 4639c8c..d98b2b6 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index e9d6b1d..c541c38 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index d3e6f3d..18a9eff 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-dist.sh b/dev/make-dist.sh index f66d3ee..821c6bf 100755 --- a/dev/make-dist.sh +++ b/dev/make-dist.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-15-g03f22c9 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 823234f..15e1dfb 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 6881cf1..8f7212d 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 5519047..14857f0 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -61,5 +61,5 @@ group. This step is up to you actually. #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/doc/2_usage.md b/doc/2_usage.md index ee5a70d..37865ca 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 16cdf7d..954d2c7 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Advanced Usage](3_advanced.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/doc/4_expert.md b/doc/4_expert.md index a239660..7f6228a 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/doc/5_practice.md b/doc/5_practice.md index 08f534b..acea748 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 diff --git a/doc/6_reference.md b/doc/6_reference.md index fb42782..b1e3f6b 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -58,18 +58,7 @@ send_normal_message "${CHAT[ID]}" "bold italic> italic>/em> "${TMPDIR:-.}/prova" + remove_keyboard "$chat" "$text" + sent=y + fi + if [ "$keyboard" != "" ]; then + if [[ "$keyboard" != *"["* ]]; then # pre 0.60 style + keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]" + fi + send_keyboard "$chat" "$text" "$keyboard" + sent=y + fi + if [ "$file" != "" ]; then + send_file "$chat" "$file" "$text" + sent=y + fi + if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" = "" ] && [ "$title" = "" ]; then + send_location "$chat" "$lat" "$long" + sent=y + fi + if [ "$lat" != "" ] && [ "$long" != "" ] && [ "$address" != "" ] && [ "$title" != "" ]; then + send_venue "$chat" "$lat" "$long" "$title" "$address" + sent=y + fi + if [ "$sent" != "y" ];then + send_text "$chat" "$text" + fi + +} + +send_text() { + case "$2" in + html_parse_mode*) + send_html_message "$1" "${2//html_parse_mode}" + ;; + markdown_parse_mode*) + send_markdown_message "$1" "${2//markdown_parse_mode}" + ;; + *) + send_normal_message "$1" "$2" + ;; + esac +} + +###### +# interactive and background functions + +background() { + echo "${CHAT[ID]}:$2:$1" >"${TMPDIR:-.}/${copname}$2-back.cmd" + startproc "$1" "back-$2-" +} + +startproc() { + killproc "$2" + local fifo="$2${copname}" + mkfifo "${TMPDIR:-.}/${fifo}" + tmux new-session -d -s "${fifo}" "$1 &>${TMPDIR:-.}/${fifo}; echo imprettydarnsuredatdisisdaendofdacmd>${TMPDIR:-.}/${fifo}" + tmux new-session -d -s "sendprocess_${fifo}" "bash $SCRIPT outproc ${CHAT[ID]} ${fifo}" +} + + +checkback() { + checkproc "back-$1-" +} + +checkproc() { + tmux ls | grep -q "$1${copname}"; res=$?; return $? +} + +killback() { + killproc "back-$1-" + rm -f "${TMPDIR:-.}/${copname}$1-back.cmd" +} + +killproc() { + local fifo="$1${copname}" + (tmux kill-session -t "${fifo}"; echo imprettydarnsuredatdisisdaendofdacmd>"${TMPDIR:-.}/${fifo}"; tmux kill-session -t "sendprocess_${fifo}"; rm -f -r "${TMPDIR:-.}/${fifo}")2>/dev/null +} + +inproc() { + tmux send-keys -t "$copname" "${MESSAGE[0]} ${URLS[*]} +" +} diff --git a/mycommands.sh b/mycommands.sh index 9e6fd89..19a5fab 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.70-dev2-15-g03f22c9 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 1194755..3c63971 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh old mode 100755 new mode 100644 index bf360bb..717dd5a --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index f88147e..02811b0 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index e1df301..e3085a3 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index 777e936..81b8654 100755 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 7407863..289a926 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 3a0b03e..b35a5a8 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index d8bfd18..15b8857 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 685be28..cf58280 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-13-gca73be8 +#### $$VERSION$$ v0.70-dev2-16-gc6d4086 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh