some minor adjustments in bashbot.sh

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-06-01 12:41:12 +02:00
parent 274f5d84ad
commit 9a81e440f1
4 changed files with 12 additions and 16 deletions

View File

@ -93,7 +93,8 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
</ul></li> </ul></li>
<li><a href="doc/5_practice.md">Best Practices</a> <li><a href="doc/5_practice.md">Best Practices</a>
<ul> <ul>
<li>Customize commands.sh</li> <li>Customize mycommands.sh</li>
<li>Overwrite/disable commands</li>
<li>Seperate logic from commands</li> <li>Seperate logic from commands</li>
<li>Test your Bot with shellcheck</li> <li>Test your Bot with shellcheck</li>
</ul></li> </ul></li>
@ -186,6 +187,6 @@ It features background tasks and interactive chats, and can serve as an interfac
<p><span class="citation">@Gnadelwartz</span></p> <p><span class="citation">@Gnadelwartz</span></p>
<h2 id="thats-it">Thats it!</h2> <h2 id="thats-it">Thats it!</h2>
<p>If you feel that theres something missing or if you found a bug, feel free to submit a pull request!</p> <p>If you feel that theres something missing or if you found a bug, feel free to submit a pull request!</p>
<h4 id="version-v0.90-0-g7029f7f"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.90-0-g7029f7f</h4> <h4 id="version-v0.90-1-g5ebfacc"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.90-1-g5ebfacc</h4>
</body> </body>
</html> </html>

View File

@ -180,4 +180,4 @@ This may happen if to many wrong requests are sent to api.telegram.org, e.g. usi
If you feel that there's something missing or if you found a bug, feel free to submit a pull request! If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
#### $$VERSION$$ v0.90-0-g7029f7f #### $$VERSION$$ v0.90-1-g5ebfacc

View File

@ -53,7 +53,8 @@ availible on www.github.com
* Use from CLI and Scripts * Use from CLI and Scripts
* Customize Bashbot Environment * Customize Bashbot Environment
* [Best Practices](doc/5_practice.md) * [Best Practices](doc/5_practice.md)
* Customize commands.sh * Customize mycommands.sh
* Overwrite/disable commands
* Seperate logic from commands * Seperate logic from commands
* Test your Bot with shellcheck * Test your Bot with shellcheck
* [Function Reference](doc/6_reference.md) * [Function Reference](doc/6_reference.md)
@ -252,4 +253,4 @@ tor proxy on your server you may uncomment the ```BASHBOT_CURL_ARGS``` line in
If you feel that there's something missing or if you found a bug, feel free to If you feel that there's something missing or if you found a bug, feel free to
submit a pull request! submit a pull request!
#### $$VERSION$$ v0.90-0-g7029f7f #### $$VERSION$$ v0.90-1-g5ebfacc

View File

@ -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.90-0-g7029f7f #### $$VERSION$$ v0.90-2-g274f5d8
# #
# Exit Codes: # Exit Codes:
# - 0 sucess (hopefully) # - 0 sucess (hopefully)
@ -348,11 +348,10 @@ process_client() {
local num="$1" debug="$2" local num="$1" debug="$2"
CMD=( ); iQUERY=( ) CMD=( ); iQUERY=( )
iQUERY[ID]="${UPD["result",${num},"inline_query","id"]}" iQUERY[ID]="${UPD["result",${num},"inline_query","id"]}"
if [ "${iQUERY[ID]}" = "" ]; then
[[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"MESSAGE.log" [[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"MESSAGE.log"
if [ "${iQUERY[ID]}" = "" ]; then
process_message "${num}" "${debug}" process_message "${num}" "${debug}"
else else
[[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"INLINE.log"
process_inline "${num}" "${debug}" process_inline "${num}" "${debug}"
fi fi
##### #####
@ -387,13 +386,12 @@ start_timer(){
EVENT_TIMER="0" EVENT_TIMER="0"
event_timer() { event_timer() {
local event timer debug="$1" local event timer debug="$1"
(( EVENT_TIMER += 1 )) (( EVENT_TIMER++ ))
# shellcheck disable=SC2153 # shellcheck disable=SC2153
for event in "${!BASHBOT_EVENT_TIMER[@]}" for event in "${!BASHBOT_EVENT_TIMER[@]}"
do do
timer="${event##*,}" timer="${event##*,}"
[[ ! "$timer" =~ ^-*[0-9]+$ ]] && continue [[ ! "$timer" =~ ^-*[1-9][0-9]*$ ]] && continue
[[ "$timer" =~ ^-*0+$ ]] && continue
if [ "$(( EVENT_TIMER % timer ))" = "0" ]; then if [ "$(( EVENT_TIMER % timer ))" = "0" ]; then
_exec_if_function "${BASHBOT_EVENT_TIMER[${event}]}" "timer" "${debug}" _exec_if_function "${BASHBOT_EVENT_TIMER[${event}]}" "timer" "${debug}"
[ "$(( EVENT_TIMER % timer ))" -lt "0" ] && \ [ "$(( EVENT_TIMER % timer ))" -lt "0" ] && \
@ -492,7 +490,6 @@ process_inline() {
iQUERY[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","first_name"]}")" iQUERY[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","first_name"]}")"
iQUERY[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","last_name"]}")" iQUERY[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","last_name"]}")"
iQUERY[USERNAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","username"]}")" iQUERY[USERNAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","username"]}")"
# event_inline &
} }
process_message() { process_message() {
local num="$1" local num="$1"
@ -538,7 +535,6 @@ process_message() {
fi fi
# Audio # Audio
URLS=( )
URLS[AUDIO]="$(get_file "${UPD["result",${num},"message","audio","file_id"]}")" URLS[AUDIO]="$(get_file "${UPD["result",${num},"message","audio","file_id"]}")"
# Document # Document
URLS[DOCUMENT]="$(get_file "${UPD["result",${num},"message","document","file_id"]}")" URLS[DOCUMENT]="$(get_file "${UPD["result",${num},"message","document","file_id"]}")"
@ -575,19 +571,17 @@ process_message() {
CAPTION="$(JsonDecode "${UPD["result",${num},"message","caption"]}")" CAPTION="$(JsonDecode "${UPD["result",${num},"message","caption"]}")"
# Location # Location
LOCATION=( )
LOCATION[LONGITUDE]="${UPD["result",${num},"message","location","longitude"]}" LOCATION[LONGITUDE]="${UPD["result",${num},"message","location","longitude"]}"
LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}" LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}"
# split message in command and args # split message in command and args
CMD=( )
if [[ "${MESSAGE[0]}" = "/"* ]]; then if [[ "${MESSAGE[0]}" = "/"* ]]; then
set -f; unset IFS set -f; unset IFS
# shellcheck disable=SC2206 # shellcheck disable=SC2206
CMD=( ${MESSAGE[0]} ) CMD=( ${MESSAGE[0]} )
CMD[0]="${CMD[0]%%@*}" CMD[0]="${CMD[0]%%@*}"
set +f set +f
else
CMD[0]=""
fi fi
} }