add jsshDB functions to function reference

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-30 14:07:29 +02:00
parent 2a28e7f0c9
commit 1c5594a5c2
4 changed files with 59 additions and 7 deletions

View File

@ -19,14 +19,12 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do
## Documentation
* [Introdution to Telegram Bots](https://core.telegram.org/bots)
* [One Bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot)
* [Bot commands](https://core.telegram.org/bots#commands)
* [Install Bashbot](doc/0_install.md)
* Install release
* Install from githup
* Update Bashbot
* Notes on Updates
* [Create a new Telegram Bot with botfather](doc/1_firstbot.md)
* [Get Bottoken from Botfather](doc/1_firstbot.md)
* [Getting Started](doc/2_usage.md)
* Managing your Bot
* Recieve data

View File

@ -25,18 +25,20 @@ Have FUN!
├── modules # optional functions, sourced by commands.sh
│   ├── aliases.sh # to disable modules rename them xxx.sh.off
│   ├── answerInline.sh
│   ├── jsonDB.sh
│   ├── background.sh
│   ├── jsshDB.sh # read and store JSON.sh stlye JSON
│   ├── background.sh # interactive and background functions
│   ├── chatMember.sh
│   └── sendMessage.sh # main send message functions, do not disable
├── addons # optional addons, disbaled by default
│   ├── example.sh # to enable addons change their XXX_ENABLE to true
│   ├── antiFlood.sh # simple addon taking actions based on # files and text sent to chat
│   └── xxxxxage.sh
├── bashbot.rc # start/stop script if you run basbot as service
├── examples # example scripts and configs for bashbot
│   ├── README.md # description of files and examples
│   └── bashbot.cron # example crontab
├── doc # Documentation and License

View File

@ -453,6 +453,58 @@ Usually message is automatically forwarded in 'commands.sh', but you can forwar
*replaces:*' incproc
### JSON.sh DB
Since output of JSON.sh is so handy to use in bash, we provide a simple wrapper to read and write JSON.sh style data from and to files.
All file names must be relaitive to BASHBOT_ETC and must not contain '..'. The suffix '.jssh' is added to file name!
You must include ```source modules/jsshDB.sh``` in 'commands.sh' to have the following functions availible.
##### jssh_newDB
Creats new empty "DB" file if not exist.
*usage:* jssh_newDB "filename"
##### jssh_readDB
Read content of a file in JSON.sh format into given ARRAY. ARRAY name must be delared with "declare -A ARRAY" upfront,
*usage:* jssh_readDB "ARRAY" "filename"
*example:*
```bash
# read file data-bot-bash/somevalues.jssh into array SOMEVALUES
jssh_readDB "SOMEVALUES" "${DATADIR:-}/somevalues"
print "${SOMEVALUES[*]}"
```
##### jssh_writeDB
wWrite content of given ARRAY into file. ARRAY name must be delared with "declare -A ARRAY" upfront,
"DB" file MUST exist or nothing is written.
*usage:* jssh_writeDB "ARRAY" "filename"
*example:*
```bash
MYVALUES["value1"]="value1"
MYVALUES["loveit"]="value2"
MYVALUES["whynot"]="value3"
# create DB
jssh_newDB "${DATADIR:-}/myvalues"
# write to file data-bot-bash/somevalues.jssh from array MYVALUES
jssh_writeDB "MYVALUES" "${DATADIR:-}/myvalues"
# show whats written
cat ""${DATADIR:-}/myvalues.jssh"
["value1"] "value1"
["loveit"] "value2"
["whynot"] "value3"
```
----
### Aliases - shortcuts for often used funtions
You must include ```source modules/aliases.sh``` in 'commands.sh' to have the following functions availible.
@ -732,5 +784,5 @@ The name of your bot is availible as bash variable "$ME", there is no need to ca
#### [Prev Best Practice](5_practice.md)
#### [Next Notes for Developers](7_develop.md)
#### $$VERSION$$ v0.90-dev2-0-gec85636
#### $$VERSION$$ v0.90-dev2-22-g9148dc5

View File

@ -272,5 +272,5 @@ fi
#### [Prev Function Reference](6_reference.md)
#### $$VERSION$$ v0.90-dev2-21-g405276b
#### $$VERSION$$ v0.90-dev2-22-g9148dc5