mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-05-30 08:50:51 +00:00
start evironment config
This commit is contained in:
parent
893ee61d61
commit
fe5840d3fc
|
@ -10,7 +10,7 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.70-dev2-3-g65cd94a
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
|
@ -609,8 +609,8 @@ process_message() {
|
|||
# main get updates loop, should never terminate
|
||||
start_bot() {
|
||||
local mysleep="100" # ms
|
||||
local addsleep"50"
|
||||
local maxsleep="${BASHBOTSLEEP:-5000}"
|
||||
local addsleep="50"
|
||||
local maxsleep="${BASHBOT_SLEEP:-5000}"
|
||||
while true; do {
|
||||
|
||||
UPDATE="$(curl -s "$UPD_URL$OFFSET" | ./${JSONSHFILE})"
|
||||
|
@ -671,7 +671,7 @@ if [ "$ME" = "" ]; then
|
|||
fi
|
||||
|
||||
# use phyton JSON to decode JSON UFT-8, provide bash implementaion as fallback
|
||||
if [ "${BASHDECODE}" != "yes" ] && which python >/dev/null 2>&1 ; then
|
||||
if [ "${BASHBOT_DECODE}" != "" ] && which python >/dev/null 2>&1 ; then
|
||||
JsonDecode() {
|
||||
printf '"%s\\n"' "${1//\"/\\\"}" | python -c 'import json, sys; sys.stdout.write(json.load(sys.stdin).encode("utf-8"))'
|
||||
}
|
||||
|
|
|
@ -61,5 +61,5 @@ group. This step is up to you actually.
|
|||
|
||||
#### [Next Getting started](2_usage.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
|
||||
|
|
|
@ -159,5 +159,5 @@ send_action "${CHAT[ID]}" "action"
|
|||
#### [Prev Create Bot](1_firstbot.md)
|
||||
#### [Next Advanced Usage](3_advanced.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
|
||||
|
|
|
@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker"
|
|||
#### [Prev Advanced Usage](3_advanced.md)
|
||||
#### [Next Expert Use](4_expert.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
|
||||
|
|
|
@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```.
|
|||
#### [Prev Expert Use](4_expert.md)
|
||||
#### [Next Best Practice](5_practice.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
|
||||
|
|
|
@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam
|
|||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Functions Reference](6_reference.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
|
||||
|
|
|
@ -346,7 +346,7 @@ The name of your bot is availible as bash variable "$ME", there is no need to ca
|
|||
Send Input from Telegram to waiting Interactive Chat.
|
||||
|
||||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Developer Rules](7_develop.md)
|
||||
#### [Next Notes for Developers](7_develop.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ fi
|
|||
```
|
||||
|
||||
#### [Prev Function Reference](6_function.md)
|
||||
#### [Next Bashbot Environment](8_custom.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
|
||||
|
|
81
doc/8_custom.md
Normal file
81
doc/8_custom.md
Normal file
|
@ -0,0 +1,81 @@
|
|||
#### [Home](../README.md)
|
||||
## Customize bashbots environment
|
||||
This section describe how you can customize bashbot to your needs by setting environment variables.
|
||||
|
||||
|
||||
### Change file locations
|
||||
In standard setup bashbot is self containing, this means you can place 'telegram-bot-bash' on any location
|
||||
and run it from there. All files - programm, config, data etc - will reside in 'telegram-bot-bash'.
|
||||
|
||||
If you want other locations for config, data etc, define and export the following environment variables:
|
||||
|
||||
#### BASHBOT_ETC
|
||||
Location of the config files 'token', 'botadmin', 'botacl' ...
|
||||
```bash
|
||||
unset BASHBOT_ETC # keep in telegram-bot-bash (default)
|
||||
export BASHBOT_ETC "" # keep in telegram-bot-bash
|
||||
|
||||
export BASHBOT_ETC "/etc/bashbot" # unix like config location
|
||||
|
||||
export BASHBOT_ETC "/etc/bashbot/bot1" # multibot configuration bot 1
|
||||
export BASHBOT_ETC "/etc/bashbot/bot2" # multibot configuration bot 2
|
||||
```
|
||||
|
||||
e.g. /etc/bashbot
|
||||
|
||||
#### BASHBOT_VAR
|
||||
Location of runtime data files 'data-bot-bash', 'count', downloaded files ...
|
||||
```bash
|
||||
unset BASHBOT_VAR # keep in telegram-bot-bash (default)
|
||||
export BASHBOT_VAR "" # keep in telegram-bot-bash
|
||||
|
||||
export BASHBOT_VAR "/var/spool/bashbot" # unix like config location
|
||||
|
||||
export BASHBOT_VAR "/var/spool/bashbot/bot1" # multibot configuration bot 1
|
||||
export BASHBOT_VAR "/var/spool/bashbot/bot2" # multibot configuration bot 2
|
||||
```
|
||||
|
||||
#### BASHBOT_COMMANDS
|
||||
Full path to bash script containing your commands, default: './commands.sh'
|
||||
```bash
|
||||
unset BASHBOT_COMMANDS # telegram-bot-bash/commands.sh (default)
|
||||
export BASHBOT_COMMANDS "" # telegram-bot-bash/commands.sh
|
||||
|
||||
export BASHBOT_COMMANDS "/etc/bashbot/commands.sh" # unix like config location
|
||||
|
||||
export BASHBOT_COMMANDS "/etc/bashbot/bot1/commands.sh" # multibot configuration bot 1
|
||||
export BASHBOT_COMMANDS "/etc/bashbot/bot2/commands.sh" # multibot configuration bot 2
|
||||
```
|
||||
|
||||
### Change config values
|
||||
|
||||
#### BASHBOT_DECODE
|
||||
Bashbot offers two variants for decoding JSON UTF format to UTF-8. By default bashbot uses 'json.encode' if python is installed.
|
||||
If 'BASHBOT_DECODE' is set to any value (not undefined or not empty) the bash only implementation will be used.
|
||||
```bash
|
||||
unset BASHBOT_DECODE # autodetect python (default)
|
||||
export BASHBOT_DECODE "" # autodetect python
|
||||
|
||||
export BASHBOT_DECODE "yes" # force internal
|
||||
export BASHBOT_DECODE "no" # also force internal!
|
||||
```
|
||||
|
||||
|
||||
#### BASHBOT_SLEEP
|
||||
Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling.
|
||||
If messages are recieved bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay
|
||||
for every poll until the maximum of BASHBOT_SLEEP ms.
|
||||
```bash
|
||||
unset BASHBOT_SLEEP # 5000ms (default)
|
||||
export BASHBOT_SLEEP "" # 5000ms
|
||||
|
||||
export BASHBOT_SLEEP "1000" # 1s maximum sleep
|
||||
export BASHBOT_SLEEP "10000" # 10s maximum sleep
|
||||
export BASHBOT_SLEEP "1" # values < 1000 disables sleep (not recommended)
|
||||
|
||||
```
|
||||
|
||||
#### [Prev Notes for Developers](7_develop.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
|
||||
# common variables
|
||||
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
# this has to run once atfer git clone
|
||||
# and every time we create new hooks
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
@ -26,8 +26,8 @@ echo "Check process_message ..."
|
|||
for i in 1 2
|
||||
do
|
||||
[ "${i}" = "1" ] && ! which python >/dev/null 2>&1 && continue
|
||||
[ "${i}" = "1" ] && echo " ... JsonDecode Phyton"
|
||||
[ "${i}" = "2" ] && echo " ... JsonDecode Bash" && export BASHDECODE="yes"
|
||||
[ "${i}" = "1" ] && echo " ... JsonDecode Phyton" && unset BASHBOT_DECODE
|
||||
[ "${i}" = "2" ] && echo " ... JsonDecode Bash" && export BASHBOT_DECODE="yes"
|
||||
set -x
|
||||
{ process_message "0"; set +x; } >>"${LOGFILE}" 2>&1;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user