factor out background update doc

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-04-24 10:07:46 +02:00
parent c6d40869c3
commit 92ad9e42fc
36 changed files with 249 additions and 156 deletions

View File

@ -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! 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

View File

@ -168,5 +168,5 @@ That's it!
If you feel that there's something missing or if you found a bug, feel If you feel that there's something missing or if you found a bug, feel
free to submit a pull request! free to submit a pull request!
latexmath:[\[VERSION\]] v0.70-dev2-10-gfa9e879 latexmath:[\[VERSION\]] v0.70-dev2-16-gc6d4086
++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# description: Start or stop telegram-bash-bot # description: Start or stop telegram-bash-bot
# #
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# shellcheck disable=SC2009 # shellcheck disable=SC2009
# shellcheck disable=SC2181 # shellcheck disable=SC2181

View File

@ -1,4 +1,6 @@
#!/bin/bash #!/bin/bash
# file: bashbot.sh
# do not edit, this file will be overwritten on update
# bashbot, the Telegram bot written in bash. # bashbot, the Telegram bot written in bash.
# Written by Drew (@topkecleon) and Daniil Gentili (@danogentili), KayM (@gnadelwartz). # 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. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ v0.70-dev2-14-g56a45aa #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# #
# Exit Codes: # Exit Codes:
# - 0 sucess (hopefully) # - 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 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() { send_normal_message() {
text="$2" text="$2"
until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do
@ -480,42 +415,7 @@ forward() { # backward compatibility
forward_message "$@" || return forward_message "$@" || return
} }
background() { # returns true if function exist
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[*]}
"
}
_is_function() _is_function()
{ {
[ "$(LC_ALL=C type -t "$1")" = "function" ] [ "$(LC_ALL=C type -t "$1")" = "function" ]

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # 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=SC2154
# shellcheck disable=SC2034 # shellcheck disable=SC2034
@ -125,8 +125,8 @@ else
checkprog checkprog
if [ "$res" -eq 0 ] ; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi if [ "$res" -eq 0 ] ; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi
;; ;;
*) # forward input to interactive chat if running *) # forward other messages to optional dispatcher
if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi _is_function startproc && if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi
_is_function mycommands && mycommands _is_function mycommands && mycommands
;; ;;
esac esac

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/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, # magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script # no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/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, # magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script # no matter from which directory we'll run script

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# this has to run once atfer git clone # this has to run once atfer git clone
# and every time we create new hooks # 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, # magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script # no matter from which directory we'll run script

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# this has to run once atfer git clone # this has to run once atfer git clone
# and every time we create new hooks # 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, # magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script # no matter from which directory we'll run script

View File

@ -1,3 +1,3 @@
# list of additional files to check from shellcheck # list of additional files to check from shellcheck
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
bashbot.rc bashbot.rc

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# #
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# shellcheck disable=SC2016 # shellcheck disable=SC2016
# #
# Easy Versioning in git: # Easy Versioning in git:

View File

@ -61,5 +61,5 @@ group. This step is up to you actually.
#### [Next Getting started](2_usage.md) #### [Next Getting started](2_usage.md)
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086

View File

@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action"
#### [Prev Create Bot](1_firstbot.md) #### [Prev Create Bot](1_firstbot.md)
#### [Next Advanced Usage](3_advanced.md) #### [Next Advanced Usage](3_advanced.md)
#### $$VERSION$$ v0.70-dev2-13-gca73be8 #### $$VERSION$$ v0.70-dev2-16-gc6d4086

View File

@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker"
#### [Prev Advanced Usage](3_advanced.md) #### [Prev Advanced Usage](3_advanced.md)
#### [Next Expert Use](4_expert.md) #### [Next Expert Use](4_expert.md)
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086

View File

@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```.
#### [Prev Expert Use](4_expert.md) #### [Prev Expert Use](4_expert.md)
#### [Next Best Practice](5_practice.md) #### [Next Best Practice](5_practice.md)
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086

View File

@ -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) #### [Prev Best Practice](5_practice.md)
#### [Next Functions Reference](6_reference.md) #### [Next Functions Reference](6_reference.md)
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086

View File

@ -58,18 +58,7 @@ send_normal_message "${CHAT[ID]}" "<b>bold</b> <i>italic><i> <em>italic>/em> <a
*usage:* forward_message "chat_to" "chat_from" "${MESSAGE[ID]}" *usage:* forward_message "chat_to" "chat_from" "${MESSAGE[ID]}"
*alias:* forward "${CHAT[ID]}" "$FROMCHAT" "${MESSAGE[ID]}" *old call:* forward "${CHAT[ID]}" "$FROMCHAT" "${MESSAGE[ID]}"
----
##### 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)
---- ----
@ -137,6 +126,8 @@ send_keyboard "${CHAT[ID]}" "Enter digit" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \
##### remove_keyboard ##### remove_keyboard
*usage:* remove_keybord "$CHAT[ID]" "message" *usage:* remove_keybord "$CHAT[ID]" "message"
----
### Manage users ### Manage users
##### kick_chat_member ##### kick_chat_member
@ -163,6 +154,7 @@ fi
``` ```
---- ----
### User Access Control ### User Access Control
##### user_is_botadmin ##### user_is_botadmin
@ -171,7 +163,7 @@ Name or ID botadmin must be placed in './botadmin' file.
*usage:* user_is_botadmin "${USER[ID]}" *usage:* user_is_botadmin "${USER[ID]}"
*alias:* _is_botadmin *modules/alias:* _is_botadmin
*example:* *example:*
```bash ```bash
@ -183,14 +175,14 @@ Return true (0) if user is creator of given chat or chat is a private chat.
*usage:* user_is_creator "${CHAT[ID]}" "${USER[ID]}" *usage:* user_is_creator "${CHAT[ID]}" "${USER[ID]}"
*alias:* _is_creator *modules/alias:* _is_creator
##### user_is_admin ##### user_is_admin
Return true (0) if user is admin or creator of given chat. Return true (0) if user is admin or creator of given chat.
*usage:* user_is_admin "${CHAT[ID]}" "${USER[ID]}" *usage:* user_is_admin "${CHAT[ID]}" "${USER[ID]}"
*alias:* _is_creator *modules/alias:* _is_admin
*example:* *example:*
```bash ```bash
@ -212,7 +204,59 @@ if ! user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then
fi fi
``` ```
----
### Aliases - shortcuts for often used funtions
You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to have the following functions availible.
#### _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]}"
----
#### _message
*usage:* _message "message"
*alias for* send_normal_message "${CHAT[ID]}" "message"
#### _normal_message
*usage:* _normal_message "message"
*alias for* send_normal_message "${CHAT[ID]}" "message"
#### _html_message
*usage:* _html_message "message"
*alias for* send_html_message "${CHAT[ID]}" "message"
#### _markdown_message
*usage:* _markdown_message "message"
*alias for* send_markdown_message "${CHAT[ID]}" "message"
----
### Interactive and backgound jobs ### Interactive and backgound jobs
You must use ```source modules/background.sh``` in commands.sh or mycommands.sh to have the following functions availible.
##### startproc ##### startproc
```startproc``` starts a script (or C or python program etc.) running in parallel to your Bot. The text that the script outputs is sent to the user or chat, user input will be sent back to the script. see [Advanced Usage](3_advanced.md#Interactive-Chats) ```startproc``` starts a script (or C or python program etc.) running in parallel to your Bot. The text that the script outputs is sent to the user or chat, user input will be sent back to the script. see [Advanced Usage](3_advanced.md#Interactive-Chats)
@ -296,6 +340,33 @@ else
fi 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)
----
### 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 ### Bashbot internal functions
These functions are for internal use only and must not used in your bot commands. These functions are for internal use only and must not used in your bot commands.
@ -349,5 +420,5 @@ Send Input from Telegram to waiting Interactive Chat.
#### [Prev Best Practice](5_practice.md) #### [Prev Best Practice](5_practice.md)
#### [Next Notes for Developers](7_develop.md) #### [Next Notes for Developers](7_develop.md)
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086

View File

@ -71,5 +71,5 @@ fi
#### [Prev Function Reference](6_function.md) #### [Prev Function Reference](6_function.md)
#### [Next Bashbot Environment](8_custom.md) #### [Next Bashbot Environment](8_custom.md)
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086

View File

@ -37,7 +37,7 @@ Location of runtime data files 'data-bot-bash', 'count', downloaded files ...
``` ```
#### BASHBOT_COMMANDS #### BASHBOT_COMMANDS
Full path to bash script containing your commandsm, default: './commands.sh', must end with '.sh' Full path to bash script containing your commands, default: './commands.sh', must end with '.sh'
```bash ```bash
unset BASHBOT_COMMANDS # telegram-bot-bash/commands.sh (default) unset BASHBOT_COMMANDS # telegram-bot-bash/commands.sh (default)
export BASHBOT_COMMANDS "" # telegram-bot-bash/commands.sh export BASHBOT_COMMANDS "" # telegram-bot-bash/commands.sh
@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
#### [Prev Notes for Developers](7_develop.md) #### [Prev Notes for Developers](7_develop.md)
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086

View File

@ -7,7 +7,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
SHELL=/bin/sh SHELL=/bin/sh

View File

@ -3,7 +3,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# adjust your language setting here # adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -2,7 +2,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# adjust your language setting here # adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -3,7 +3,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# adjust your language setting here # adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -3,7 +3,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.70-dev2-10-gfa9e879 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# adjust your language setting here # adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ v0.70-dev2-15-g03f22c9 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# source from commands.sh to use the aliases # source from commands.sh to use the aliases
# some handy aliases for use when processing messages: # some handy aliases for use when processing messages:
@ -15,6 +15,9 @@ _is_botadmin() {
_is_admin() { _is_admin() {
user_is_admin "${CHAT[ID]}" "${USER[ID]}" user_is_admin "${CHAT[ID]}" "${USER[ID]}"
} }
_is_creator() {
user_is_creator "${CHAT[ID]}" "${USER[ID]}"
}
_is_allowed() { _is_allowed() {
user_is_allowed "${USER[ID]}" "$1" "${CHAT[ID]}" user_is_allowed "${USER[ID]}" "$1" "${CHAT[ID]}"
} }

119
modules/background.sh Normal file
View File

@ -0,0 +1,119 @@
#!/bin/bash
# file: modules/background.sh
# do not edit, this file will be overwritten on update
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.70-dev2-15-g03f22c9
# source from commands.sh if you want ro use interactive or background jobs
####
# I placed send_message here because main use case is interactive chats and background jobs
send_message() {
local text arg keyboard file lat long title address sent
[ "$2" = "" ] && return 1
local chat="$1"
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
}
######
# 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[*]}
"
}

View File

@ -2,7 +2,7 @@
# files: mycommands.sh.dist # files: mycommands.sh.dist
# copy to mycommands.sh and add all your commands and functions here ... # 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=SC2154
# shellcheck disable=SC2034 # shellcheck disable=SC2034

View File

@ -2,7 +2,7 @@
# #
# ADD a new test skeleton to test dir, but does not activate test # 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, # magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script # no matter from which directory we'll run script

2
test/ALL-tests.inc.sh Executable file → Normal file
View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-13-gca73be8 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# common variables # common variables
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# this has to run once atfer git clone # this has to run once atfer git clone
# and every time we create new hooks # 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, # magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script # no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-13-gca73be8 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
../dev/hooks/pre-commit.sh ../dev/hooks/pre-commit.sh

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-13-gca73be8 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
../dev/hooks/pre-push.sh ../dev/hooks/pre-push.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-13-gca73be8 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-13-gca73be8 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-13-gca73be8 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-13-gca73be8 #### $$VERSION$$ v0.70-dev2-16-gc6d4086
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh