mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-05-28 16:00:52 +00:00
finalize error logs, update events doc
This commit is contained in:
parent
737d54d365
commit
3871ca9656
|
@ -11,7 +11,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.96-pre-43-g471ad21
|
#### $$VERSION$$ v0.96-pre-44-g737d54d
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
|
@ -517,7 +517,8 @@ process_client() {
|
||||||
MESSAGE[0]="$(JsonDecode "${UPD["result",${num},"message","text"]}" | sed 's#\\/#/#g')"
|
MESSAGE[0]="$(JsonDecode "${UPD["result",${num},"message","text"]}" | sed 's#\\/#/#g')"
|
||||||
process_message "${num}" "${debug}"
|
process_message "${num}" "${debug}"
|
||||||
[[ -n "${debug}" ]] && printf "%s: update received FROM=%s CHAT=%s CMD=%s\n"\
|
[[ -n "${debug}" ]] && printf "%s: update received FROM=%s CHAT=%s CMD=%s\n"\
|
||||||
"$(date)" "${USER[USERNAME]} (${USER[ID]})" "${CHAT[USERNAME]}${CHAT[TITLE]} (${CHAT[ID]})" "${MESSAGE%% *}"
|
"$(date)" "${USER[USERNAME]:0:20} (${USER[ID]})"\
|
||||||
|
"${CHAT[USERNAME]:0:20}${CHAT[TITLE]:0:30} (${CHAT[ID]})" "${MESSAGE%%[ \?]*}"
|
||||||
else
|
else
|
||||||
process_inline "${num}" "${debug}"
|
process_inline "${num}" "${debug}"
|
||||||
[[ -n "${debug}" ]] && printf "%s: iQuery received FROM=%s iQUERY=%s\n"\
|
[[ -n "${debug}" ]] && printf "%s: iQuery received FROM=%s iQUERY=%s\n"\
|
||||||
|
@ -825,16 +826,16 @@ start_bot() {
|
||||||
# did we ge an responsn0r
|
# did we ge an responsn0r
|
||||||
if [ -n "${UPDATE}" ]; then
|
if [ -n "${UPDATE}" ]; then
|
||||||
# we got something, do processing
|
# we got something, do processing
|
||||||
[ "${OFFSET}" = "-999" ] &&\
|
[ "${OFFSET}" = "-999" ] && [ "${nextsleep}" -gt "${maxsleep}" ] &&\
|
||||||
printf "%s: Recovered from timeout/broken/no connection, continue with telegram updates\n"\
|
printf "%s: Recovered from timeout/broken/no connection, continue with telegram updates\n"\
|
||||||
"$(date)" >>"${ERRORLOG}"
|
"$(date)" >>"${ERRORLOG}"
|
||||||
# escape bash $ expansion bug
|
# escape bash $ expansion bug
|
||||||
|
((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep))
|
||||||
UPDATE="${UPDATE//$/\\$}"
|
UPDATE="${UPDATE//$/\\$}"
|
||||||
# Offset
|
# Offset
|
||||||
OFFSET="$(grep <<< "${UPDATE}" '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)"
|
OFFSET="$(grep <<< "${UPDATE}" '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)"
|
||||||
((OFFSET++))
|
((OFFSET++))
|
||||||
|
|
||||||
((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep))
|
|
||||||
if [ "$OFFSET" != "1" ]; then
|
if [ "$OFFSET" != "1" ]; then
|
||||||
nextsleep="100"
|
nextsleep="100"
|
||||||
process_updates "${DEBUG}"
|
process_updates "${DEBUG}"
|
||||||
|
|
|
@ -43,11 +43,11 @@ If a not mandatory module is used in 'bashbot.sh' or 'commands.sh', the use of `
|
||||||
Addons must register themself to BASHBOT_EVENTS at startup, e.g. to call a function everytime a message is received.
|
Addons must register themself to BASHBOT_EVENTS at startup, e.g. to call a function everytime a message is received.
|
||||||
Addons works similar as 'commands.sh' and 'mycommands.sh' but are much more flexible on when functions/commands are triggered.
|
Addons works similar as 'commands.sh' and 'mycommands.sh' but are much more flexible on when functions/commands are triggered.
|
||||||
|
|
||||||
Another major difference is: While regular command processing is done in as a new sub shell for every command,
|
Another major difference is: While regular command processing is done in a new sub shell for every command,
|
||||||
**Addons are executed in the context of bashbot event loop!**, This is why event functions are (time) critical
|
**Addons are executed in the context of bashbot event loop!**, This is why event functions are (time) critical
|
||||||
and must return as fast as possible. **If an event function call exit, also bashbot exits!**
|
and must return as fast as possible. **If an event function call exit, also bashbot exits!**
|
||||||
|
|
||||||
*Important*: If an event function e.g. send_messages or need longer time for processing spawn a sub shell!
|
*Important*: Spawn a new sub shell in background for your procssing and when calling bashbot functions, e.g. send_messages.
|
||||||
This prevents blocking or exiting bashbots event loop.
|
This prevents blocking or exiting bashbots event loop.
|
||||||
|
|
||||||
#### Bashbot Events
|
#### Bashbot Events
|
||||||
|
@ -90,9 +90,11 @@ BASHBOT_EVENT_TEXT["example_1"]="example_echo"
|
||||||
example_echo() {
|
example_echo() {
|
||||||
local event="$1" key="$2"
|
local event="$1" key="$2"
|
||||||
# all availible bashbot functions and variables can be used
|
# all availible bashbot functions and variables can be used
|
||||||
send_normal_message "${CHAT[ID]}" "Event: ${event} Key: ${key} : ${MESSAGE[0]}" & # NOTE the & for sub shell!!!
|
send_normal_message "${CHAT[ID]}" "Event: ${event} Key: ${key} : ${MESSAGE[0]}" & # run in background!
|
||||||
|
|
||||||
do_more_processing & # NOTE the & for sub shell!!!
|
( MYTEXT="${MESSAGE[0]}"
|
||||||
|
do_more_processing
|
||||||
|
) & # run as sub shell in background!
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -100,7 +102,7 @@ An SEND event is executed when a Message is send to telegram.
|
||||||
|
|
||||||
* BASHBOT_EVENT_SEND is exceuted if data is send or uploaded to Telegram server
|
* BASHBOT_EVENT_SEND is exceuted if data is send or uploaded to Telegram server
|
||||||
|
|
||||||
In contrast to other events, BASHBOT_EVENT_SEND is excecuted in a subshell, so there is no need to spawn
|
In contrast to other events, BASHBOT_EVENT_SEND is excecuted in a sub shell, so there is no need to spawn
|
||||||
a background process for longer running commands and changes to variables are not persistent!
|
a background process for longer running commands and changes to variables are not persistent!
|
||||||
|
|
||||||
BASHBOT_EVENT_SEND is for logging purposes, you must not send messages while processing this event.
|
BASHBOT_EVENT_SEND is for logging purposes, you must not send messages while processing this event.
|
||||||
|
@ -345,5 +347,5 @@ fi
|
||||||
|
|
||||||
#### [Prev Function Reference](6_reference.md)
|
#### [Prev Function Reference](6_reference.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.96-pre-41-g15f6da8
|
#### $$VERSION$$ v0.96-pre-44-g737d54d
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user