Merge pull request #131 Bashbot V0.96 Release

Bashbot V0.96 Release
This commit is contained in:
Kay Marquardt 2020-06-12 11:12:58 +02:00 committed by GitHub
commit 79056bc517
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 302 additions and 183 deletions

View File

@ -118,6 +118,7 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadel
<li>Interactive Chats</li>
<li>Background Jobs</li>
<li>Inline queries</li>
<li>Send message errors</li>
</ul></li>
<li><a href="doc/4_expert.md">Expert Use</a>
<ul>
@ -245,6 +246,6 @@ It features background tasks and interactive chats, and can serve as an interfac
<p>@Gnadelwartz</p>
<h2>That's it!</h2>
<p>If you feel that there's something missing or if you found a bug, feel free to submit a pull request!</p>
<h4>$$VERSION$$ v0.96-pre-13-ga71d68e</h4>
<h4>$$VERSION$$ v0.96-0-g3871ca9</h4>
</body>
</html>

View File

@ -37,6 +37,7 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do
* Interactive Chats
* Background Jobs
* Inline queries
* Send message errors
* [Expert Use](doc/4_expert.md)
* Handling UTF-8 character sets
* Run as other user or system service
@ -218,4 +219,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!
#### $$VERSION$$ v0.96-pre-13-ga71d68e
#### $$VERSION$$ v0.96-0-g3871ca9

View File

@ -50,6 +50,7 @@ availible on www.github.com
* Interactive Chats
* Background Jobs
* Inline queries
* Send message errors
* [Expert Use](doc/4_expert.md)
* Handling UTF-8 character sets
* Run as other user or system service
@ -304,4 +305,4 @@ in 'mycommands.sh' as example.
If you feel that there's something missing or if you found a bug, feel free to
submit a pull request!
#### $$VERSION$$ v0.96-pre-13-ga71d68e
#### $$VERSION$$ v0.96-0-g3871ca9

View File

@ -4,12 +4,12 @@
# this addon counts how many files, e.g. stickers, are sent to
# a chat and takes actions if threshold is reached
#
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# used events:
#
# BASHBOT_EVENT_TEXT message containing message text received
# BASHBOT_EVENT_CMD a command is recieved
# BASHBOT_EVENT_CMD a command is received
# BASHBOT_EVENT_FILE file received
#
# all global variables and functions can be used in registered functions.

View File

@ -4,7 +4,7 @@
# Addons can register to bashbot events at statup
# by providing their name and a callback per event
#
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
#
# If an event occours each registered event function is called.
#
@ -22,7 +22,7 @@
# BASHBOT_EVENT_INLINE inline query received
# BASHBOT_EVENT_MESSAGE any type of message received
# BASHBOT_EVENT_TEXT message containing message text received
# BASHBOT_EVENT_CMD a command is recieved
# BASHBOT_EVENT_CMD a command is received
# BASHBOT_EVENT_REPLYTO reply to message received
# BASHBOT_EVENT_FORWARD forwarded message received
# BASHBOT_EVENT_CONTACT contact received

View File

@ -1,7 +1,7 @@
#!/bin/sh
# description: Start or stop telegram-bash-bot
#
#### $$VERSION$$ v0.96-dev3-12-g3f85134
#### $$VERSION$$ v0.96-0-g3871ca9
# shellcheck disable=SC2009
# shellcheck disable=SC2181

View File

@ -11,7 +11,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.96-pre-29-gaec4e71
#### $$VERSION$$ v0.96-0-g3871ca9
#
# Exit Codes:
# - 0 sucess (hopefully)
@ -205,7 +205,7 @@ fi
##################
# here we start with the real stuff
BOTSEND_RETRY="no" # do not retry by default
BASHBOT_RETRY="" # retry by default
URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}"
ME_URL=$URL'/getMe'
@ -319,7 +319,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
# shellcheck disable=SC2086
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
-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)" "$@"
}
#$1 Chat, $2 what , $3 file, $4 URL, $5 caption
@ -348,7 +348,7 @@ else
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
# 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)"'}' \
--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)" "$@"
}
sendUpload() {
@ -363,11 +363,10 @@ fi
sendJsonRetry(){
local retry="${1}"; shift
[[ "${1}" =~ ^\ *[0-9.]+\ *$ ]] && sleep "${1}"; shift
printf "%s: RETRY %s %s %s\n" "$(date)" "${retry}" "${1}" "${2/[$'\n\r']*}"
printf "%s: RETRY %s %s %s\n" "$(date)" "${retry}" "${1}" "${2:0:60}"
case "${retry}" in
'sendJson'*)
sendJson "$@"
;;
'sendUpload'*)
sendUpload "$@"
@ -377,7 +376,7 @@ sendJsonRetry(){
return
;;
esac
[ "${BOTSENT[OK]}" = "true" ] && printf "%s: Retry OK: %s %s\n" "$(date)" "${retry}" "${1}"
[ "${BOTSENT[OK]}" = "true" ] && printf "%s: Retry OK: %s %s %s\n" "$(date)" "${retry}" "${1}" "${2:0:60}"
} >>"${ERRORLOG}"
# process sendJson result
@ -388,7 +387,7 @@ sendJsonResult(){
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "${1}")"
if [ "${BOTSENT[OK]}" = "true" ]; then
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "${1}")"
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@:2}"
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@:3}"
return
# hot path everthing OK!
else
@ -399,50 +398,49 @@ sendJsonResult(){
BOTSENT[RETRY]="$(JsonGetValue '"parameters","retry_after"' <<< "${1}")"
else
BOTSENT[ERROR]="999"
BOTSENT[DESCRIPTION]="Timeout or broken/no connection"
BOTSENT[DESCRIPTION]="Send to telegram not possible, timeout/broken/no connection"
fi
# log error
printf "%s: RESULT=%s FUNC=%s CHAT[ID]=%s ERROR=%s DESC=%s\n=ACTION=%s\n" "$(date)"\
"${BOTSENT[OK]}" "${2}" "${3}" "${BOTSENT[ERROR]}" "${BOTSENT[DESCRIPTION]}" "${4/[$'\n\r']*}"
printf "%s: RESULT=%s FUNC=%s CHAT[ID]=%s ERROR=%s DESC=%s ACTION=%s\n" "$(date)"\
"${BOTSENT[OK]}" "${2}" "${3}" "${BOTSENT[ERROR]}" "${BOTSENT[DESCRIPTION]}" "${4:0:60}"
# warm path, do not retry on error, also if we use wegt
[ -n "${BOTSEND_RETRY}${BASHBOT_WGET}" ] && return
[ -n "${BASHBOT_RETRY}${BASHBOT_WGET}" ] && return
# OK, we can retry sendJson, let's see what's failed
# throttled, telegram say we send to much messages
if [ -n "${BOTSENT[RETRY]}" ]; then
BOTSEND_RETRY="$(( BOTSENT[RETRY]++ ))"
printf "Retry %s in %s seconds ...\n" "${2}" "${BOTSEND_RETRY}"
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}"
unset BOTSEND_RETRY
BASHBOT_RETRY="$(( BOTSENT[RETRY]++ ))"
printf "Retry %s in %s seconds ...\n" "${2}" "${BASHBOT_RETRY}"
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
unset BASHBOT_RETRY
return
fi
# timeout, failed connection or blocked
if [ "${BOTSENT[ERROR]}" == "999" ];then
# check if default curl and args are OK
if ! curl -sL -k -m 2 "${URL}" >/dev/null 2>&1 ; then
printf "BASHBOT IP Adress is blocked!\n"
printf "%s: BASHBOT IP Adress is blocked!\n" "$(date)"
# user provided function to recover or notify block
if _exec_if_function bashbotBlockRecover; then
BOTSEND_RETRY="2"
printf "Function bashbotBlockRecover returned true, retry %s.\n" "${2}"
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}"
unset BOTSEND_RETRY
BASHBOT_RETRY="2"
printf "bashbotBlockRecover returned true, retry %s ...\n" "${2}"
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
unset BASHBOT_RETRY
fi
return
fi
# are not blocked, default curl and args are working
if [ -n "${BASHBOT_CURL_ARGS}" ] || [ "${BASHBOT_CURL}" != "curl" ]; then
printf "Possible Problem with \"%s %s\", retry %s with default curl config ...\n"\
printf "Problem with \"%s %s\"? retry %s with default config ...\n"\
"${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "${2}"
BOTSEND_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS=""
sendJsonRetry "${2}" "${BOTSEND_RETRY}" "${@:2}"
unset BOTSEND_RETRY
BASHBOT_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS=""
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
unset BASHBOT_RETRY
fi
fi
fi
} >>"${ERRORLOG}"
# escape / remove text charaters for json strings, eg. " -> \"
# $1 string
# output escaped string
@ -464,7 +462,7 @@ title2Json(){
# get bot name
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)
@ -503,21 +501,28 @@ process_updates() {
}
process_client() {
local num="$1" debug="$2"
CMD=( ); iQUERY=( )
[[ "${debug}" = *"debug"* ]] && printf "\n%s: New Message ==========\n%s\n" "$(date)" "$UPDATE" >>"${LOGDIR}/MESSAGE.log"
CMD=( ); iQUERY=( ); MESSAGE=()
iQUERY[ID]="${UPD["result",${num},"inline_query","id"]}"
CHAT[ID]="${UPD["result",${num},"message","chat","id"]}"
USER[ID]="${UPD["result",${num},"message","from","id"]}"
# log message on debug
[[ -n "${debug}" ]] && printf "\n%s: New Message ==========\n%s\n" "$(date)" "$UPDATE" >>"${LOGDIR}/MESSAGE.log"
# check for uers / groups to ignore
if [ -n "${USER[ID]}" ]; then
[[ " ${!BASHBOT_BLOCKED[*]} " == *" ${USER[ID]} "* ]] && return
jssh_readDB_async "BASHBOT_BLOCKED" "${BLOCKEDFILE}"
fi
[ -n "${USER[ID]}" ] && [[ " ${!BASHBOT_BLOCKED[*]} " == *" ${USER[ID]} "* ]] && return
jssh_readDB_async "BASHBOT_BLOCKED" "${BLOCKEDFILE}"
# process per message type
if [ -z "${iQUERY[ID]}" ]; then
MESSAGE[0]="$(JsonDecode "${UPD["result",${num},"message","text"]}" | sed 's#\\/#/#g')"
process_message "${num}" "${debug}"
[[ -n "${debug}" ]] && printf "%s: update received FROM=%s CHAT=%s CMD=%s\n"\
"$(date)" "${USER[USERNAME]:0:20} (${USER[ID]})"\
"${CHAT[USERNAME]:0:20}${CHAT[TITLE]:0:30} (${CHAT[ID]})" "${MESSAGE%%[ \?]*}"
else
process_inline "${num}" "${debug}"
[[ -n "${debug}" ]] && printf "%s: iQuery received FROM=%s iQUERY=%s\n"\
"$(date)" "${iQUERY[USERNAME]} (${iQUERY[USER_ID]})" "${iQUERY[0]}"
fi
#####
# process inline and message events
@ -668,10 +673,9 @@ process_inline() {
process_message() {
local num="$1"
# Message
MESSAGE[0]="$(JsonDecode "${UPD["result",${num},"message","text"]}" | sed 's#\\/#/#g')"
MESSAGE[ID]="${UPD["result",${num},"message","message_id"]}"
# Chat ID is now parsed when update isrecieved
# Chat ID is now parsed when update isreceived
#CHAT[ID]="${UPD["result",${num},"message","chat","id"]}"
CHAT[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","chat","last_name"]}")"
CHAT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","chat","first_name"]}")"
@ -681,7 +685,7 @@ process_message() {
CHAT[ALL_ADMIN]="${UPD["result",${num},"message","chat","all_members_are_administrators"]}"
CHAT[ALL_MEMBERS_ARE_ADMINISTRATORS]="${CHAT[ALL_ADMIN]}" # backward compatibility
# user ID is now parsed when update isrecieved
# user ID is now parsed when update isreceived
#USER[ID]="${UPD["result",${num},"message","from","id"]}"
USER[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","first_name"]}")"
USER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","last_name"]}")"
@ -762,7 +766,7 @@ process_message() {
SERVICE[NEWTILE]="${UPD["result",${num},"message","new_chat_title"]}"
SERVICE[NEWPHOTO]="${UPD["result",${num},"message","new_chat_photo"]}"
SERVICE[PINNED]="${UPD["result",${num},"message","pinned_message"]}"
# set SSERVICE to yes if a service message was recieved
# set SSERVICE to yes if a service message was received
[[ "${SERVICE[*]}" =~ ^[[:blank:]]+$ ]] || SERVICE[0]="yes"
@ -810,19 +814,23 @@ start_bot() {
fi
# cleanup countfile on startup
jssh_deleteKeyDB "CLEAN_COUNTER_DATABASE_ON_STARTUP" "${COUNTFILE}"
[ -f "${COUNTFILE}.jssh.flock" ] && rm -f "${COUNTFILE}.jssh.flock"
##########
# bot is ready, start processing updates ...
while true; do
# adaptive sleep in ms rounded to next 0.1 s
sleep "$(_round_float "${nextsleep}e-3" "1")"
((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep))
# 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
if [ -n "${UPDATE}" ]; then
# we got something, do processing
[ "${OFFSET}" = "-999" ] && [ "${nextsleep}" -gt "${maxsleep}" ] &&\
printf "%s: Recovered from timeout/broken/no connection, continue with telegram updates\n"\
"$(date)" >>"${ERRORLOG}"
# escape bash $ expansion bug
((nextsleep+= stepsleep , nextsleep= nextsleep>maxsleep ?maxsleep:nextsleep))
UPDATE="${UPDATE//$/\\$}"
# Offset
OFFSET="$(grep <<< "${UPDATE}" '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)"
@ -833,10 +841,12 @@ start_bot() {
process_updates "${DEBUG}"
fi
else
# ups, something bad happend, wait maxsleep
(( nextsleep=maxsleep*2 ))
printf "%s: Timeout or broken/no connection on telegram update, sleep %ds\n"\
# ups, something bad happend, wait maxsleep*10
(( nextsleep=nextsleep*2 , nextsleep= nextsleep>maxsleep*10 ?maxsleep*10:nextsleep ))
[ "${OFFSET}" = "-999" ] &&\
printf "%s: Repeated timeout/broken/no connection on telegram update, sleep %ds\n"\
"$(date)" "$(_round_float "${nextsleep}e-3")" >>"${ERRORLOG}"
OFFSET="-999"
fi
done
}
@ -1022,7 +1032,7 @@ if [ "${SOURCE}" != "yes" ]; then
;;
*)
echo -e "${RED}${REALME}: BAD REQUEST${NC}"
echo -e "${RED}Available arguments: ${GREY}start, stop, kill, status, status, broadcast, help, suspendback, resumeback, killback${NC}"
echo -e "${ORANGE}Available arguments: ${GREY}start, stop, kill, status, stats, broadcast, help, suspendback, resumeback, killback${NC}"
exit 4
;;
esac

View File

@ -15,7 +15,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.96-dev3-12-g3f85134
#### $$VERSION$$ v0.96-0-g3871ca9
#
# adjust your language setting here, e.g.when run from other user or cron.
@ -32,13 +32,15 @@ unset IFS
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there
bashbot_info='This is bashbot, the Telegram bot written entirely in bash.
It features background tasks and interactive chats, and can serve as an interface for CLI programs.
It currently can send, recieve and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files.
It currently can send, receive and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files.
'
#
# this file *MUST* not edited!
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there
bashbot_help='*Available commands*:
bashbot_help='Place your own commands and messages in mycommands.sh
*Available commands*:
*• /start*: _Start bot and get this message_.
*• /help*: _Get this message_.
*• /info*: _Get shorter info message about this bot_.

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ v0.96-pre-15-geace5e1
#### $$VERSION$$ v0.96-0-g3871ca9
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -3,7 +3,7 @@
#
# works together with git pre-push.sh and ADD all changed files since last push
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.96-dev3-20-gbd22e2a
#### $$VERSION$$ v0.96-0-g3871ca9
############
# NOTE: you MUST run install-hooks.sh again when updating this file!

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
############
# NOTE: you MUST run install-hooks.sh again when updating this file!

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -2,7 +2,7 @@
# file: make-distribution.sh
# creates files and arcchives to dirtribute bashbot
#
#### $$VERSION$$ 0.96-dev2-6-gda98b09
#### $$VERSION$$ v0.96-0-g3871ca9
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -5,7 +5,7 @@
# If you your bot is finished you can use make-standalone.sh to create the
# the old all-in-one bashbot: bashbot.sh and commands.sh only!
#
#### $$VERSION$$ v0.96-dev3-22-g19c45c4
#### $$VERSION$$ v0.96-0-g3871ca9
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,4 +1,4 @@
# list of additional files to check from shellcheck
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
bashbot.rc
mycommands.sh.clean

View File

@ -1,6 +1,6 @@
#!/bin/bash
#
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# shellcheck disable=SC2016
#
# Easy Versioning in git:

View File

@ -101,5 +101,5 @@ The old format is supported for backward compatibility, but may fail for corner
#### [Next Create Bot](1_firstbot.md)
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9

View File

@ -65,5 +65,5 @@ group. This step is up to you actually.
#### [Prev Installation](0_install.md)
#### [Next Getting started](2_usage.md)
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9

View File

@ -96,7 +96,7 @@ To send a broadcast to all of users that ever used the bot run the following com
----
## Recieve data
Evertime a Message is recieved, you can read incoming data using the following variables:
Evertime a Message is received, you can read incoming data using the following variables:
### Regular Messages
@ -169,7 +169,7 @@ Evertime a Message is recieved, you can read incoming data using the following v
### Inline queries
Evertime a Message is recieved, you can read incoming data using the following variables:
Evertime a Message is received, you can read incoming data using the following variables:
* ```${iQUERY}```: Current inline query
* ```$iQUERY```: This array contains the ID, First name, last name, username and user id of the sender of the current inline query.
@ -256,5 +256,5 @@ send_action "${CHAT[ID]}" "action"
#### [Prev Create Bot](1_firstbot.md)
#### [Next Advanced Usage](3_advanced.md)
#### $$VERSION$$ v0.96-dev3-14-g5fc4d01a
#### $$VERSION$$ v0.96-0-g3871ca9

View File

@ -64,13 +64,17 @@ You must use the function ```user_is_allowed``` to check if a user has the capab
**See also [Bashbot User Access Control functions](6_reference.md#User-Access-Control)**
### Interactive Chats
Interactive chats are scripts, reading user input and echo data to the user.
Interactive chats are short running scripts, reading user input and echo data to the user.
To create a new interactive chat script copy 'scripts/interactive.sh.clean' to e.g. 'scripts/mynewinteractive.sh', make it executeable
and then use 'start_proc' function from your bot, it's possible to pass two arguments. You find more examples for interactive scripts in 'examples'
*usage*: start_proc chat_id script arg1 arg2
*usage*: kill_proc chat_id
*usage*: check_prog chat_id
**Note:** From Version 0.96 on scripts must read user input from '$3' instead of stdin!
```bash
@ -137,15 +141,26 @@ echo "$out"
### Background Jobs
A background job is similar to an interactive chat, but runs in the background and does only output massages and does not get user input. In contrast to interactive chats it's possible to run multiple background jobs. To create a background job write a script or edit 'examples/notify.sh' script and use the funtion ```background``` to start it:
A background job is similar to an interactive chat, but can be a long running job and does only output massages, user input is ignored.
It's possible to run multiple background jobs from the same chat.
To create a new interactive chat script copy 'scripts/interactive.sh.clean' to e.g. 'scripts/mynewbackground.sh', make it executeable
and then use 'start_back' function from your bot, it's possible to pass two arguments. You find more examples for background scripts in 'examples'
*usage*: start_back chat_id script jobname arg1 arg2
*usage*: kill_back chat_id jobname
*usage*: check_back chat_id jobname
```bash
background "examples/notify.sh" "jobname"
start_back "examples/notify.sh" "${CHAT[ID]}" "jobname"
```
All output of the script will be sent to the user, to stop a background job use:
```bash
killback "jobname"
kill_back "${CHAT[ID]}" "jobname"
```
You can also suspend and resume the last running background jobs from outside bashbot, e.g. in your startup schripts:
You can also suspend and resume currently running background jobs from outside bashbot, e.g. in your startup schripts:
```bash
./bashbot.sh suspendback
./bashbot.sh resumeback
@ -156,7 +171,7 @@ If you want to kill all background jobs permantly run:
./bashbot.sh killback
```
Note: Background Jobs run independent from main bot and continue running until your script exits or you stop if from your Bot. Backgound Jobs will continue running if your Bot is stopeda and must be terminated, e.g. by ```bashbot.sh killback```
Note: Background jobs run independent from main bot and continue running until your script exits or you stop it. Backgound jobs will continue running if your Bot is stoped and must be terminated seperatly e.g. by ```bashbot.sh killback```
### Inline queries
**Inline queries** allow users to send commands to your bot from every chat without going to a private chat. An inline query is started if the user type the bots name, e.g. @myBot. Everything after @myBot is immediatly send to the bot.
@ -203,8 +218,76 @@ answer_inline_query "${iQUERY[ID]}" "cached_sticker" "identifier for the sticker
```
See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inline_multi) and [mycommands.sh](../mycommands.sh) for more information.
### Handle send message errors
Our examples usually do not care about errors happening while sending a message, this is OK as long your bot does not send an
massive aoumnt of messages. By default bashbot detects if a message is not sent and try to recover when possible,
e.g. resend on throttling. In addtion every send error is logged in logs/ERROR.log
#### Trasmission results
On every message send to telegram (transmission) the results are provided in bash variables, like its done when a new message
is received.
**Note**: the values of the variables contains always the result of the LAST transmission to telegram,
every send action will overwrite them!
* ```$BOTSENT```: This array contains the parsed results from the last transmission to telegram.
* ```${BOTSENT[OK]}```: contains the string ```true```: after a successful transmission
* ```${BOTSENT[ERROR]}```: Error code if an error occured
* ```${BOTSENT[DESC]}```: Description text for error
* ```${BOTSENT[RETRY]}```: Seconds to wait if telegram requests throtteling.
* ```$res```: temporary variable containing the full transmission result, may be overwritten by any bashbot function.
By default you don't have to care about retry, as bashbot resend the message after the requested time automatically.
Only if the retry fails also an error is returned. The downside is that send_message functions will wait until resend is done.
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.
[Telegram Bot API error codes](https://github.com/TelegramBotAPI/errors)
#### Detect bot blocked
If the we can't connect to telegram, e.g. blocked from telegram server but also any other reason,
bashbot set ```BOTSENT[ERROR]``` to ```999```.
To get a notification on every connection problem create a function named ```bashbotBlockRecover``` and handle blocks there.
If the function returns true (0 or no value) bashbot will retry once and then return to the calling function.
In case you return any non 0 value bashbot will return to the calling function without retry.
Note: If you disable automatic retry, se above, you disable also connection problem notification.
```bash
# somewhere in myfunctions.sh ...
MYBLOCKED="0"
function bashbotBlockRecover() {
# ups, we are blocked!
(( MYBLOCKED++ ))
# log what we got
printf "%s: Blocked %d times: %s\n" "$(date)" "${MYBLOCKED}" "$*" >>"${ERRORLOG}"
if [ "${MYBLOCKED}" -gt 10 ]; then
printf "Permanent problem abort current command: %s\n" "${MESSAGE}">>"${ERRORLOG}"
exit
fi
if do_something_to_unblock; then
# may be we removed block, e.g. changed IP address, try again
return 0
fi
# do not retry if we cant recover
return 1
}
```
#### [Prev Getting started](2_usage.md)
#### [Next Expert Use](4_expert.md)
#### $$VERSION$$ v0.96-dev3-13-g601fe0e
#### $$VERSION$$ v0.96-0-g3871ca9

View File

@ -40,7 +40,7 @@ To display all availible locales on your system run ```locale -a | more```. [Gen
#### Bashbot UTF-8 Support
Bashbot handles all messages transparently, regardless of the charset in use. The only exception is when converting from JSON data to strings.
Telegram use JSON to send / recieve data. JSON encodes strings as follow: Characters not ASCII *(>127)* are escaped as sequences of ```\uxxxx``` to be regular ASCII. In addition multibyte characters, *e.g. Emoticons or Arabic characters*, are send in double byte UTF-16 notation.
Telegram use JSON to send / receive data. JSON encodes strings as follow: Characters not ASCII *(>127)* are escaped as sequences of ```\uxxxx``` to be regular ASCII. In addition multibyte characters, *e.g. Emoticons or Arabic characters*, are send in double byte UTF-16 notation.
The Emoticons ``` 😁 😘 ❤️ 😊 👍 ``` are encoded as: ``` \uD83D\uDE01 \uD83D\uDE18 \u2764\uFE0F \uD83D\uDE0A \uD83D\uDC4D ```
**This "mixed" JSON encoding needs special handling and can not decoded from** ```echo -e``` or ```printf '%s\\n'```
@ -326,7 +326,7 @@ BASHBOT_TIMEOUT to a numeric value between 1 and 999. Any non numeric or negativ
##### BASHBOT_SLEEP
Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling.
If messages are recieved bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay
If messages are received bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay
for every poll until the maximum of BASHBOT_SLEEP ms.
```bash
unset BASHBOT_SLEEP # 5000ms (default)
@ -382,5 +382,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
#### [Prev Advanced Use](3_advanced.md)
#### [Next Best Practice](5_practice.md)
#### $$VERSION$$ v0.96-dev3-17-g720dc59
#### $$VERSION$$ v0.96-0-g3871ca9

View File

@ -152,5 +152,5 @@ The second warning is about an unused variable, this is true because in our exam
#### [Prev Best Practice](5_practice.md)
#### [Next Functions Reference](6_reference.md)
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9

View File

@ -404,7 +404,7 @@ fi
##### start_back
Starts a script as a background job and attaches a jobname to it. All output from a background job is sent to the associated chat.
In contrast to interactive chats, background jobs do not recieve user input and can run forever. In addition you can suspend and restart running jobs, e.g. after reboot.
In contrast to interactive chats, background jobs do not receive user input and can run forever. In addition you can suspend and restart running jobs, e.g. after reboot.
*usage:* start_back "${CHAT[ID]}" "script" "jobname"
@ -1035,5 +1035,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.96-dev3-5-g407e147
#### $$VERSION$$ v0.96-0-g3871ca9

View File

@ -31,7 +31,7 @@ you can the change the level of verbosity of the debug argument:
to keep 'bashbot.sh' small, while extending functionality. In addition not every funtion is needed by all bots, so you can
disable modules, e.g. by rename the respective module file to 'module.sh.off'.
Modules must use functions provided by 'bahsbot.sh' or the module itself and sould not depend on other modules or addons.
Modules must use only functions provided by 'bahsbot.sh' or the module itself and sould not depend on other modules or addons.
The only mandatory module is 'module/sendMessage.sh'.
If a not mandatory module is used in 'bashbot.sh' or 'commands.sh', the use of ```_is_function``` or
@ -40,13 +40,18 @@ If a not mandatory module is used in 'bashbot.sh' or 'commands.sh', the use of `
**Addons** resides in ```addons/*.sh.dist``` and are not endabled by default. To activate an addon rename it to end with '.sh', e.g. by
```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 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.
Another major difference is: **Addons are executed in the context of the main script**, while 'commands.sh' and 'macommands.sh' are executed as a seperate process.
This is why event functions are time critical and must return as fast as possible.
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
and must return as fast as possible. **If an event function call exit, also bashbot exits!**
*Important*: Spawn a new sub shell in background for your processing commands and when calling bashbot functions, e.g. send_messages.
This prevents blocking or exiting bashbots event loop.
#### Bashbot Events
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.
@ -54,13 +59,15 @@ Registered functions run in the same process as bashbot, not as a sub process, s
Note: For the same reason event function MUST return immediately! Time consuming tasks must be run as a background process, e.g. "long running &"
##### MESSAGE events (all iQuery and/or Message variables are avalible):
##### SEND RECEIVE events
An RECEIVE event is executed when a Message is received, same iQuery / Message variables are avalible as in commands.sh
* BASHBOT_EVENT_INLINE an inline query is received
* BASHBOT_EVENT_MESSAGE any of the following message types is received
* BASHBOT_EVENT_TEXT a message containing text is recieved
* BASHBOT_EVENT_CMD a message containing a command is recieved (starts with /)
* BASHBOT_EVENT_TEXT a message containing text is received
* BASHBOT_EVENT_CMD a message containing a command is received (starts with /)
* BASHBOT_EVENT_REPLYTO a reply to a message is received
* BASHBOT_EVENT_FORWARD a forwarded message is received
* BASHBOT_EVENT_CONTACT a contact is received
@ -83,55 +90,19 @@ BASHBOT_EVENT_TEXT["example_1"]="example_echo"
example_echo() {
local event="$1" key="$2"
# 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]}" & # run in background!
( MYTEXT="${MESSAGE[0]}"
do_more_processing
) & # run as sub shell in background!
}
```
##### Other types of events
* BAHSBOT_EVENT_TIMER executed every minute and can be used in 3 variants: oneshot, once a minute, every X minutes.
Registering to BASHBOT_EVENT_TIMER works similar as for message events, but you must add a timing argument to the name.
EVENT_TIMER is triggered every 60s and waits until the current running command is finished, so ist not excactly every
minute, but once a minute.
Every time EVENT_TIMER is triggered the variable "EVENT_TIMER" is increased. each callback is executed if ```EVENT_TIMER % time``` is '0' (true).
This means if you register an every 5 minutes callback first execution may < 5 Minutes, all subsequent executions are once every 5. Minute.
*usage:* BAHSBOT_EVENT_TIMER[ "name" , "time" ], where time is:
* 0 ignored
* 1 execute once every minute
* x execute every x minutes
* -x execute ONCE in (next) x minutes *
*\* if you really want "in x minutes" you must use ```-(EVENT_TIMER+x)```*
*Example:*
```bash
# register callback:
BAHSBOT_EVENT_TIMER["example_every","1"]="example_everymin"
# function called every minute
example_everymin() {
# timer events has no chat id, so send to yourself
send_normal_message "$(< "${BOTADMIN})" "$(date)" & # note the &!
}
# register other callback:
BAHSBOT_EVENT_TIMER["example_every5","5"]="example_every5min"
# execute once in the next 10 minutes
BAHSBOT_EVENT_TIMER["example_10min","-10"]="example_in10min"
# once in 10 minutes
BAHSBOT_EVENT_TIMER["example_10min","$(( (EVENT_TIMER+10) * -1 ))"]="example_in10min"
```
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
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!
BASHBOT_EVENT_SEND is for logging purposes, you must not send messages while processing this event.
@ -155,6 +126,50 @@ example_log(){
```
##### TIMER events
Important: Bashbot timer tick is diabled by default and must be enabled by setting BASHBOT_START_TIMER to any value not zero.
* BAHSBOT_EVENT_TIMER executed every minute and can be used in 3 variants: oneshot, once a minute, every X minutes.
Registering to BASHBOT_EVENT_TIMER works similar as for message events, but you must add a timing argument to the name.
EVENT_TIMER is triggered every 60s and waits until the current running command is finished, so ist not excactly every
minute, but once a minute.
Every time EVENT_TIMER is triggered the variable "EVENT_TIMER" is increased. each callback is executed if ```EVENT_TIMER % time``` is '0' (true).
This means if you register an every 5 minutes callback first execution may < 5 Minutes, all subsequent executions are once every 5. Minute.
*usage:* BAHSBOT_EVENT_TIMER[ "name" , "time" ], where time is:
* 0 ignored
* 1 execute once every minute
* x execute every x 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)```
*Example:*
```bash
# register callback:
BAHSBOT_EVENT_TIMER["example_every","1"]="example_everymin"
# function called every minute
example_everymin() {
# timer events has no chat id, so send to yourself
send_normal_message "$(< "${BOTADMIN})" "$(date)" & # note the &!
}
# register other callback:
BAHSBOT_EVENT_TIMER["example_every5","5"]="example_every5min"
# execute once on the next 10 minutes since start "event"
BAHSBOT_EVENT_TIMER["example_10min","-10"]="example_in10min"
# once in exact 10 minutes
BAHSBOT_EVENT_TIMER["example_10min","$(( (EVENT_TIMER+10) * -1 ))"]="example_in10min"
```
----
#### Create a stripped down Version of your Bot
@ -332,5 +347,5 @@ fi
#### [Prev Function Reference](6_reference.md)
#### $$VERSION$$ v0.96-pre-9-gb23aadd
#### $$VERSION$$ v0.96-0-g3871ca9

View File

@ -55,6 +55,6 @@ convert existing bots.
**external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users.
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9

View File

@ -4,7 +4,7 @@
#
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.96-dev3-12-g3f85134
#### $$VERSION$$ v0.96-0-g3871ca9
######
# parameters

View File

@ -2,7 +2,7 @@
# file: run_filename
# background job to display content of all new files in WATCHDIR
#
#### $$VERSION$$ v0.96-dev3-12-g3f85134
#### $$VERSION$$ v0.96-0-g3871ca9
######
# parameters

View File

@ -2,7 +2,7 @@
# file: run_filename
# background job to display all new files in WATCHDIR
#
#### $$VERSION$$ v0.96-dev3-12-g3f85134
#### $$VERSION$$ v0.96-0-g3871ca9
######
# parameters

View File

@ -4,7 +4,7 @@
#
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.96-dev3-12-g3f85134
#### $$VERSION$$ v0.96-0-g3871ca9
######
# parameters

View File

@ -6,7 +6,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -2,7 +2,7 @@
# file. multibot.sh
# description: run multiple telegram bots from one installation
#
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
echo "Usage: $0 botname command"

View File

@ -7,7 +7,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
SHELL=/bin/sh

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.96-dev3-12-g3f85134
#### $$VERSION$$ v0.96-0-g3871ca9
######
# parameters

View File

@ -4,7 +4,7 @@
#
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.96-dev3-12-g3f85134
#### $$VERSION$$ v0.96-0-g3871ca9
######
# parameters

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.96-dev3-14-g5fc4d01a
#### $$VERSION$$ v0.96-0-g3871ca9
######
# parameters

View File

@ -1,7 +1,7 @@
# file: botacl
# a user not listed here, will return false from 'user_is_allowed'
#
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# Format:
# user:ressource:chat

View File

@ -5,7 +5,7 @@
# to show how you can customize bashbot by only editing mycommands.sh
# NOTE: this is not tested, simply copied from original source and reworked!
#
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
#
# shellcheck disable=SC2154
# shellcheck disable=SC2034

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
#
# source from commands.sh to use the aliases

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# source from commands.sh to use the inline functions

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.96-pre-0-geb49241
#### $$VERSION$$ v0.96-0-g3871ca9
# source from commands.sh if you want ro use interactive or background jobs

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# source once magic, function named like file
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.96-pre-24-g5b25821
#### $$VERSION$$ v0.96-0-g3871ca9
#
# source from commands.sh to use jsonDB functions
#

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ 0.96-dev2-7-g6d1e7cc
#### $$VERSION$$ v0.96-0-g3871ca9
# source once magic, function named like file
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"

View File

@ -8,7 +8,7 @@
# #### if you start to develop your own bot, use the clean version of this file:
# #### mycommands.clean
#
#### $$VERSION$$ v0.96-pre-13-ga71d68e
#### $$VERSION$$ v0.96-0-g3871ca9
#
# uncomment the following lines to overwrite info and help messages
@ -29,10 +29,10 @@ export FILE_REGEX="${BASHBOT_ETC}/.*"
# example: run bashbot over TOR
# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050"
# unset BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling
# see logs/ERROR.log for information why send_messages etc. fail
export BOTSEND_RETRY="no"
#unset BOTSEND_RETRY
# set BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling
# problems with send_,´message etc are looged to logs/ERROR.log
unset BASHBOT_RETRY
#export BASHBOT_RETRY="yes"
# set value for adaptive sleeping while waitingnfor uodates in millisconds
# max slepp between polling updates 10s (default 5s)
@ -54,7 +54,7 @@ NOTBOTADMIN="Sorry, this command is allowed for bot owner only"
if [ "$1" = "startbot" ];then
###################
# this function is run once after startup when the first message is recieved
# this function is run once after startup when the first message is received
my_startup(){
# send message ito first user on startup
send_normal_message "${CHAT[ID]}" "Hi, you was the first one after startup!"
@ -72,7 +72,7 @@ else
mycommands() {
##############
# a service Message was recieved
# a service Message was received
# add your own stuff here
if [ -n "${SERVICE}" ]; then

View File

@ -4,7 +4,7 @@
# files: mycommands.sh.clean
# copy to mycommands.sh and add all your commands and functions here ...
#
#### $$VERSION$$ v0.96-pre-13-ga71d68e
#### $$VERSION$$ v0.96-0-g3871ca9
#
##########
@ -27,10 +27,10 @@ export INLINE="0"
# do NOT set to .* as this allow sending files from all locations!
export FILE_REGEX="${BASHBOT_ETC}/.*"
# unset BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling
# see logs/ERROR.log for information why send_messages etc. fail
export BOTSEND_RETRY="no"
#unset BOTSEND_RETRY
# set BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling
# problems with send_,´message etc are looged to logs/ERROR.log
unset BASHBOT_RETRY
#export BASHBOT_RETRY="yes"
# set value for adaptive sleeping while waitingnfor uodates in millisconds
# max slepp between polling updates 10s (default 5s)
@ -53,7 +53,7 @@ export SILENCER="no"
# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1" # regular SOCKS
if [ "$1" = "startbot" ];then
# run once after startup when the first message is recieved
# run once after startup when the first message is received
my_startup(){
:
}
@ -69,7 +69,7 @@ else
mycommands() {
##############
# a service Message was recieved
# a service Message was received
# add your own stuff here
if [ -n "${SERVICE}" ]; then

View File

@ -6,7 +6,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.96-dev3-12-g3f85134
#### $$VERSION$$ v0.96-0-g3871ca9
######
# parameters

View File

@ -2,7 +2,7 @@
#
# ADD a new test skeleton to test dir, but does not activate test
#
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.96-dev3-0-gdddd1ce
#### $$VERSION$$ v0.96-0-g3871ca9
# common variables
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
@ -49,6 +49,15 @@ print_array() {
}
compare_sorted() {
local ret=0
sort -d -o "${1}.sort" "${1}"
sort -d -o "${2}.sort" "${2}"
diff -c "${1}.sort" "${2}.sort" || ret=1
rm -f "${1}.sort" "${2}.sort"
return "$ret"
}
######
# lets go ...
echo "Running ${TESTNAME#? } ..."

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
../dev/hooks/pre-commit.sh

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
# file: b-example-test.sh
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.96-dev3-1-g2a66ee9
#### $$VERSION$$ v0.96-0-g3871ca9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh
@ -37,7 +37,7 @@ do
# output processed input
print_array "iQUERY" >"${OUTPUTFILE}"
diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1
compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1
echo "${SUCCESS}"
done

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.96-dev3-0-gdddd1ce
#### $$VERSION$$ v0.96-0-g3871ca9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh
@ -35,7 +35,7 @@ CHAT[ID]="123456789"
# output processed input
print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" "SERVICE">"${OUTPUTFILE}"
diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1
compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1
echo "${SUCCESS}"
cd "${DIRME}" || exit 1

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.96-dev3-1-g2a66ee9
#### $$VERSION$$ v0.96-0-g3871ca9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh
@ -54,10 +54,7 @@ done < "${INPUTFILE}" 2>>"${LOGFILE}"
echo " done."
sort -d -o "${OUTPUTFILE}.sort" "${OUTPUTFILE}"
sort -d -o "${REFFILE}.sort" "${REFFILE}"
{ diff -c "${REFFILE}.sort" "${OUTPUTFILE}.sort" || exit 1; } | cat -v
{ compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1; } | cat -v
rm -f "${REFFILE}.sort"
echo " ... all \"send_message\" functions seems to work as expected."

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.96-dev-7-g0153928
#### $$VERSION$$ v0.96-0-g3871ca9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.96-dev3-0-gdddd1ce
#### $$VERSION$$ v0.96-0-g3871ca9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh