mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-29 05:02:46 +00:00
dispose JSON.sh complaint about empty input
This commit is contained in:
parent
15f6da85dc
commit
38164ba9a2
10
bashbot.sh
10
bashbot.sh
@ -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-40-ge663979
|
#### $$VERSION$$ v0.96-pre-41-g15f6da8
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -319,7 +319,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
|||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
|
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
|
||||||
-d '{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' -X POST "${3}" \
|
-d '{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' -X POST "${3}" \
|
||||||
-H "Content-Type: application/json" | "${JSONSHFILE}" -s -b -n )"
|
-H "Content-Type: application/json" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
|
||||||
sendJsonResult "${res}" "sendJson (curl)" "$@"
|
sendJsonResult "${res}" "sendJson (curl)" "$@"
|
||||||
}
|
}
|
||||||
#$1 Chat, $2 what , $3 file, $4 URL, $5 caption
|
#$1 Chat, $2 what , $3 file, $4 URL, $5 caption
|
||||||
@ -348,7 +348,7 @@ else
|
|||||||
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
|
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$(wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - --post-data='{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' \
|
res="$(wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - --post-data='{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' \
|
||||||
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n )"
|
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
|
||||||
sendJsonResult "${res}" "sendJson (wget)" "$@"
|
sendJsonResult "${res}" "sendJson (wget)" "$@"
|
||||||
}
|
}
|
||||||
sendUpload() {
|
sendUpload() {
|
||||||
@ -462,7 +462,7 @@ title2Json(){
|
|||||||
|
|
||||||
# get bot name
|
# get bot name
|
||||||
getBotName() {
|
getBotName() {
|
||||||
getJson "$ME_URL" | "${JSONSHFILE}" -s -b -n | JsonGetString '"result","username"'
|
getJson "$ME_URL" | "${JSONSHFILE}" -s -b -n 2>/dev/null | JsonGetString '"result","username"'
|
||||||
}
|
}
|
||||||
|
|
||||||
# pure bash implementaion, done by KayM (@gnadelwartz)
|
# pure bash implementaion, done by KayM (@gnadelwartz)
|
||||||
@ -821,7 +821,7 @@ start_bot() {
|
|||||||
sleep "$(_round_float "${nextsleep}e-3" "1")"
|
sleep "$(_round_float "${nextsleep}e-3" "1")"
|
||||||
((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep))
|
((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep))
|
||||||
# get next update
|
# get next update
|
||||||
UPDATE="$(getJson "$UPD_URL$OFFSET" 2>/dev/null | "${JSONSHFILE}" -s -b -n | iconv -f utf-8 -t utf-8 -c)"
|
UPDATE="$(getJson "$UPD_URL$OFFSET" 2>/dev/null | "${JSONSHFILE}" -s -b -n 2>/dev/null | iconv -f utf-8 -t utf-8 -c)"
|
||||||
# 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
|
||||||
|
@ -232,7 +232,7 @@ Only if the retry fails also an error is returned. The downside is that send_mes
|
|||||||
If you want to disable automatic error processing and handle all errors manually (or don't care)
|
If you want to disable automatic error processing and handle all errors manually (or don't care)
|
||||||
set ```BASHBOT_RETRY``` to any no zero value.
|
set ```BASHBOT_RETRY``` to any no zero value.
|
||||||
|
|
||||||
[Telegram API error codes](https://core.telegram.org/api/errors)
|
[Telegram Bot API error codes](https://github.com/TelegramBotAPI/errors)
|
||||||
|
|
||||||
|
|
||||||
#### Detect bot blocked
|
#### Detect bot blocked
|
||||||
@ -274,5 +274,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob
|
|||||||
#### [Prev Getting started](2_usage.md)
|
#### [Prev Getting started](2_usage.md)
|
||||||
#### [Next Expert Use](4_expert.md)
|
#### [Next Expert Use](4_expert.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.96-pre-40-ge663979
|
#### $$VERSION$$ v0.96-pre-41-g15f6da8
|
||||||
|
|
||||||
|
@ -43,10 +43,15 @@ 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: **Addons are executed in the context of the main script**, while 'commands.sh' and 'mycommands.sh' are executed new child process on efery execution.
|
Another major difference is: While regular command processing is done in as a new sub shell for every command,
|
||||||
This is why event functions are time critical and must finish as fast as possible.
|
**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!**
|
||||||
|
|
||||||
|
*Important*: If an event function e.g. send_messages or need longer time for processing spawn a sub shell!
|
||||||
|
This prevents blocking or exiting bashbots event loop.
|
||||||
|
|
||||||
#### Bashbot Events
|
#### Bashbot Events
|
||||||
|
|
||||||
Addons must register functions to bashbot events by providing their name, and internal identifier and a callback function.
|
Addons must register functions to bashbot events by providing their name, and internal identifier and a callback function.
|
||||||
If an event occours each registered function for the event is called.
|
If an event occours each registered function for the event is called.
|
||||||
|
|
||||||
@ -85,7 +90,9 @@ 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 &!
|
send_normal_message "${CHAT[ID]}" "Event: ${event} Key: ${key} : ${MESSAGE[0]}" & # NOTE the & for sub shell!!!
|
||||||
|
|
||||||
|
do_more_processing & # NOTE the & for sub shell!!!
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -135,7 +142,7 @@ This means if you register an every 5 minutes callback first execution may < 5 M
|
|||||||
* 0 ignored
|
* 0 ignored
|
||||||
* 1 execute once every minute
|
* 1 execute once every minute
|
||||||
* x execute every x minutes
|
* x execute every x minutes
|
||||||
* -x execute once WHITHIN the next x Minutes (10=between now and 10 Minutes)
|
* -x execute once WHITHIN the next x Minutes (next 10 Minutes since start "event")
|
||||||
|
|
||||||
Note: If you want exact "in x minutes" use "EVENT_TIMER plus x" as time: ```-(EVENT_TIMER + x)```
|
Note: If you want exact "in x minutes" use "EVENT_TIMER plus x" as time: ```-(EVENT_TIMER + x)```
|
||||||
|
|
||||||
@ -153,7 +160,7 @@ example_everymin() {
|
|||||||
# register other callback:
|
# register other callback:
|
||||||
BAHSBOT_EVENT_TIMER["example_every5","5"]="example_every5min"
|
BAHSBOT_EVENT_TIMER["example_every5","5"]="example_every5min"
|
||||||
|
|
||||||
# execute once in the next 1 to 10 minutes
|
# execute once on the next 10 minutes since start "event"
|
||||||
BAHSBOT_EVENT_TIMER["example_10min","-10"]="example_in10min"
|
BAHSBOT_EVENT_TIMER["example_10min","-10"]="example_in10min"
|
||||||
|
|
||||||
# once in exact 10 minutes
|
# once in exact 10 minutes
|
||||||
@ -338,5 +345,5 @@ fi
|
|||||||
|
|
||||||
#### [Prev Function Reference](6_reference.md)
|
#### [Prev Function Reference](6_reference.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.96-pre-40-ge663979
|
#### $$VERSION$$ v0.96-pre-41-g15f6da8
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user