add new functions to functions reference

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-30 12:47:13 +02:00
parent 9148dc5f04
commit 2a28e7f0c9
2 changed files with 55 additions and 11 deletions

View File

@ -565,11 +565,29 @@ file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg"
echo "$file" -> ./data-bot-bash/12345-avatar.jpg
```
##### _exec_if_function
Returns true, even if the given function does not exist. Return false if function exist but returns false.
*usage:* _exec_if_function function
*example:*
```bash
_exec_if_function "answer_inline_query" "${iQUERY[ID]}" "Answer params"
# fast replacment for module functions exists check:
if _is_function "answer_inline_query"
then
"answer_inline_query" "${iQUERY[ID]}" "Answer params"
fi
```
##### _exists
Returns true if the given function exist, can be used to check if a module is loaded.
*usage* _exists command
*example:*
```bash
_exists "curl" && _message "Command curl is not installed!"
@ -585,7 +603,6 @@ Returns true if the given function exist, can be used to check if a module is lo
_is_function "background" && _message "you can run background jobs!"
```
----
### Bashbot internal functions
@ -655,7 +672,7 @@ Outputs decoded string to STDOUT
*usage:* JsonDecode "string"
##### JsonGetString
Reads JSON fro STDIN and Outputs found String to STDOUT
Reads JSON from STDIN and Outputs found String to STDOUT
*usage:* JsonGetString `"path","to","string"`
@ -664,12 +681,23 @@ Reads JSON fro STDIN and Outputs found Value to STDOUT
*usage:* JsonGetValue `"path","to","value"`
##### Json2Array
Read JSON.sh style data from STDIN and asssign to given ARRAY
ARRAY name must be declared with "declare -A ARRAY" before calling
*usage:* Json2Array "ARRAY"
##### Array2Json
Output ARRAY as JSON.sh style data to STDOUT
*usage:* Array2Json "ARRAY"
----
##### get_chat_member_status
*usage:* get_chat_member_status "${CHAT[ID]}" "${USER[ID]}"
this may get an official function ...
----
@ -679,11 +707,27 @@ Every Message sent to your Bot is processd by this function. It parse the send J
##### process_updates
If new updates are availible, this functions gets the JSON from Telegram and dispatch it.
##### process_inline
Every Inline Message sent to your Bot is processd by this function. It parse the send JSON and assign the found Values to bash variables.
##### start_timer
Start the the every minute timer ...
##### event_timer
Dispachter for BASHBOT_EVENT_TIMER
##### event_timer
Dispachter for BASHBOT_EVENT_INLINE
##### event_timer
Dispachter for BASHBOT_EVENT_MESSAGE and related
----
##### 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)"
*usage:* ME="$(getBotName)"
#### [Prev Best Practice](5_practice.md)
#### [Next Notes for Developers](7_develop.md)

View File

@ -22,11 +22,12 @@ In addition you can change the change the level of verbosity by adding a third a
to keep 'bashbot.sh' small, while extending functionality. In addition not every functionality is needed by a bot, so you can
disable modules by removing them, e.g. rename the respective module files to 'module.sh.off'.
Modules must use onyl functions provided by 'bahsbot.sh' or the module itself, no depedencies to other modules or addons must exist.
If a module function is called from 'bashbot.sh', bashbot must work if the module is disabled, so it's madatory to use '_is_function'
or '_execute_if_function' if a module function is called.
Modules must use only functions provided by 'bahsbot.sh' or the module itself, no depedencies to other modules or addons must exist.
If a module function is called from 'bashbot.sh', bashbot must work if the module is disabled, so the use of ```_is_function``` and
```_execute_if_function``` is mandatory.
**Addons** live in ```addons/*.sh.dist``` and are disabled by default. To activate an addon remove the '.dist' from filename, e.g. ```cp addons/example.sh.dist addons/example.sh```. Addons must register themself to BASHBOT_EVENTS at startup, e.g. to call a function everytime a message is recieved.
**Addons** live in ```addons/*.sh.dist``` and are disabled by default. To activate an addon remove '.dist' from the filename, e.g.
```cp addons/example.sh.dist addons/example.sh```. Addons must register to BASHBOT_EVENTS at startup, e.g. to call a function everytime a message is recieved.
Registering to EVENTS is similar on how 'commands.sh' is executed, but more flexible and one major difference:
**Addons are executed in the context of the main script**, while 'commands.sh' is executed as a seperate process.
@ -34,7 +35,7 @@ This is why event functions are time critical and must return as fast as possibl
send a message as respone from an addon: ```send_message "${CHAT[ID]}" "Message to send ..." &```.
#### Bashbot Events
Addons can register functions to bashbot events at startup by providing their name and a callback function.
Addons must register functions to bashbot events at startup by providing their name and a callback function.
If an event occours each registered function for the event is called.
Events run in the same context as the main bashbot loop, so variables set here are persistent as long bashbot is running.
@ -270,7 +271,6 @@ fi
```
#### [Prev Function Reference](6_reference.md)
#### [Next Expert Use](8_custom.md)
#### $$VERSION$$ v0.90-dev2-20-g60b1a59
#### $$VERSION$$ v0.90-dev2-21-g405276b