mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-06-07 21:00:53 +00:00
commit
6481cb5452
|
@ -257,6 +257,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.98-pre2-0-ga597303</h4>
|
||||
<h4>$$VERSION$$ v0.98-0-g5b5447e</h4>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -239,4 +239,4 @@ wget -t 1 -T 10 https://api.telegram.org/bot
|
|||
|
||||
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
|
|
@ -327,4 +327,4 @@ failed: Connection timed out.
|
|||
If you feel that there's something missing or if you found a bug, feel free to
|
||||
submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# this addon counts how many files, e.g. stickers, are sent to
|
||||
# a chat and takes actions if threshold is reached
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# used events:
|
||||
#
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# Addons can register to bashbot events at startup
|
||||
# by providing their name and a callback per event
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
#
|
||||
# If an event occurs each registered event function is called.
|
||||
#
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
# description: Start or stop telegram-bash-bot
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
# shellcheck disable=SC2009
|
||||
# shellcheck disable=SC2181
|
||||
|
||||
|
|
99
bashbot.sh
99
bashbot.sh
|
@ -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.98-pre2-4-g724f36b
|
||||
#### $$VERSION$$ v0.98-3-g28de99e
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 success (hopefully)
|
||||
|
@ -76,15 +76,18 @@ log_error(){
|
|||
}
|
||||
# additional tests if we run in debug mode
|
||||
# $1 where $2 command $3 may debug
|
||||
export BASHBOTDEBUG
|
||||
[[ "${3}" == *"debug"* ]] && BASHBOTDEBUG="yes"
|
||||
debug_checks(){
|
||||
[[ "${3}" != *"debug"* ]] && return
|
||||
[ -n "${BASHBOTDEBUG}" ] && return
|
||||
local DATE WHERE MYTOKEN; DATE="$(date)"; WHERE="${1}"; shift
|
||||
printf "%s: debug_checks: %s: bashbot.sh %s\n" "${DATE}" "${WHERE}" "$*"
|
||||
MYTOKEN="$(getConfigKey "bottoken")"
|
||||
[ -z "${MYTOKEN}" ] && printf "%s: %s\n" "${DATE}" "Bot token is missing!"
|
||||
check_token "${MYTOKEN}" || printf "%s: %s\n" "${DATE}" "Invalid bot token!"
|
||||
[ -z "$(getConfigKey "botadmin")" ] && printf "%s: %s\n" "${DATE}" "Bot admin is missing!"
|
||||
[ -f ".jssh" ] && printf "%s: %s\n" "${DATE}" "Ups, found file \"${PWD:-.}/.jssh\"!"
|
||||
[ -z "${MYTOKEN}" ] && printf "%s: %s\n" "${DATE}" "Bot token is missing! =========="
|
||||
check_token "${MYTOKEN}" || printf "%s: %s\n" "${DATE}" "Invalid bot token! =========="
|
||||
[ -z "$(getConfigKey "botadmin")" ] && printf "%s: %s\n" "${DATE}" "Bot admin is missing! =========="
|
||||
# call user defined debug_checks if exists
|
||||
_exec_if_function my_debug_checks "${DATE}" "${WHERE}" "$*"
|
||||
} >>"${DEBUGLOG}"
|
||||
|
||||
# get location and name of bashbot.sh
|
||||
|
@ -274,7 +277,8 @@ declare -rx SCRIPT SCRIPTDIR MODULEDIR RUNDIR ADDONDIR TOKENFILE BOTADMIN BOTACL
|
|||
declare -rx BOTTOKEN URL ME_URL UPD_URL GETFILE_URL
|
||||
|
||||
declare -ax CMD
|
||||
declare -Ax UPD BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY SERVICE NEWMEMBER
|
||||
declare -Ax UPD BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY
|
||||
declare -Ax SERVICE NEWMEMBER LEFTMEMBER PINNED
|
||||
export res CAPTION
|
||||
|
||||
|
||||
|
@ -347,6 +351,7 @@ killallproc() {
|
|||
# shellcheck disable=SC2046
|
||||
[ -n "${procid}" ] && kill $(proclist -9 "$1")
|
||||
fi
|
||||
debug_checks "end killallproc" "${1}"
|
||||
}
|
||||
|
||||
|
||||
|
@ -576,14 +581,10 @@ process_updates() {
|
|||
process_client "$num" "${debug}"
|
||||
done
|
||||
}
|
||||
|
||||
process_client() {
|
||||
local num="$1" debug="$2"
|
||||
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"]}"
|
||||
[ -z "${CHAT[ID]}" ] && CHAT[ID]="${UPD["result",${num},"edited_message","chat","id"]}"
|
||||
[ -z "${USER[ID]}" ] && USER[ID]="${UPD["result",${num},"edited_message","from","id"]}"
|
||||
pre_process_message "${num}"
|
||||
# log message on debug
|
||||
[[ -n "${debug}" ]] && printf "\n%s: New Message ==========\n%s\n" "$(date)" "$UPDATE" >>"${LOGDIR}/MESSAGE.log"
|
||||
|
||||
|
@ -597,7 +598,7 @@ process_client() {
|
|||
# edited message
|
||||
UPDATE="${UPDATE//,${num},\"edited_message\",/,${num},\"message\",}"
|
||||
Json2Array 'UPD' <<<"${UPDATE}"
|
||||
MESSAGE[0]="/edited_message "
|
||||
MESSAGE[0]="/_edited_message "
|
||||
fi
|
||||
process_message "${num}" "${debug}"
|
||||
printf "%s: update received FROM=%s CHAT=%s CMD=%s\n" "$(date)" "${USER[USERNAME]:0:20} (${USER[ID]})"\
|
||||
|
@ -746,6 +747,19 @@ event_message() {
|
|||
fi
|
||||
|
||||
}
|
||||
pre_process_message(){
|
||||
local num="${1}"
|
||||
# unset everything to not have old values
|
||||
CMD=( ); iQUERY=( ); MESSAGE=(); CHAT=(); USER=(); CONTACT=(); LOCATION=(); unset CAPTION
|
||||
REPLYTO=( ); FORWARD=( ); URLS=(); VENUE=( ); SERVICE=( ); NEWMEMBER=( ); LEFTMEMBER=( ); PINNED=( )
|
||||
iQUERY[ID]="${UPD["result",${num},"inline_query","id"]}"
|
||||
CHAT[ID]="${UPD["result",${num},"message","chat","id"]}"
|
||||
USER[ID]="${UPD["result",${num},"message","from","id"]}"
|
||||
[ -z "${CHAT[ID]}" ] && CHAT[ID]="${UPD["result",${num},"edited_message","chat","id"]}"
|
||||
[ -z "${USER[ID]}" ] && USER[ID]="${UPD["result",${num},"edited_message","from","id"]}"
|
||||
# always true
|
||||
return 0
|
||||
}
|
||||
process_inline() {
|
||||
local num="${1}"
|
||||
iQUERY[0]="$(JsonDecode "${UPD["result",${num},"inline_query","query"]}")"
|
||||
|
@ -753,6 +767,8 @@ process_inline() {
|
|||
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[USERNAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","username"]}")"
|
||||
# always true
|
||||
return 0
|
||||
}
|
||||
process_message() {
|
||||
local num="$1"
|
||||
|
@ -761,7 +777,6 @@ process_message() {
|
|||
MESSAGE[ID]="${UPD["result",${num},"message","message_id"]}"
|
||||
|
||||
# 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"]}")"
|
||||
CHAT[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","chat","username"]}")"
|
||||
|
@ -780,7 +795,6 @@ process_message() {
|
|||
[ -z "${USER[USERNAME]}" ] && USER[USERNAME]="${USER[FIRST_NAME]} ${USER[LAST_NAME]}"
|
||||
|
||||
# in reply to message from
|
||||
REPLYTO=( )
|
||||
if grep -qs -e '\["result",'"${num}"',"message","reply_to_message"' <<<"${UPDATE}"; then
|
||||
REPLYTO[UID]="${UPD["result",${num},"message","reply_to_message","from","id"]}"
|
||||
REPLYTO[0]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","text"]}")"
|
||||
|
@ -791,7 +805,6 @@ process_message() {
|
|||
fi
|
||||
|
||||
# forwarded message from
|
||||
FORWARD=( )
|
||||
if grep -qs -e '\["result",'"${num}"',"message","forward_from"' <<<"${UPDATE}"; then
|
||||
FORWARD[UID]="${UPD["result",${num},"message","forward_from","id"]}"
|
||||
FORWARD[ID]="${MESSAGE[ID]}" # same as message ID
|
||||
|
@ -801,8 +814,7 @@ process_message() {
|
|||
fi
|
||||
|
||||
# get file URL from telegram
|
||||
URLS=()
|
||||
if grep -qs -e '\["result",'"${num}"',"message",".*,"file_id"\]' <<<"${UPDATE}"; then
|
||||
if grep -qs -e '\["result",'"${num}"',"message","[avpsd].*,"file_id"\]' <<<"${UPDATE}"; then
|
||||
URLS[AUDIO]="$(get_file "${UPD["result",${num},"message","audio","file_id"]}")"
|
||||
URLS[DOCUMENT]="$(get_file "${UPD["result",${num},"message","document","file_id"]}")"
|
||||
URLS[PHOTO]="$(get_file "${UPD["result",${num},"message","photo",0,"file_id"]}")"
|
||||
|
@ -811,7 +823,6 @@ process_message() {
|
|||
URLS[VOICE]="$(get_file "${UPD["result",${num},"message","voice","file_id"]}")"
|
||||
fi
|
||||
# Contact
|
||||
CONTACT=( )
|
||||
if grep -qs -e '\["result",'"${num}"',"message","contact"' <<<"${UPDATE}"; then
|
||||
CONTACT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","contact","first_name"]}")"
|
||||
CONTACT[USER_ID]="$(JsonDecode "${UPD["result",${num},"message","contact","user_id"]}")"
|
||||
|
@ -821,7 +832,6 @@ process_message() {
|
|||
fi
|
||||
|
||||
# vunue
|
||||
VENUE=( )
|
||||
if grep -qs -e '\["result",'"${num}"',"message","venue"' <<<"${UPDATE}"; then
|
||||
VENUE[TITLE]="$(JsonDecode "${UPD["result",${num},"message","venue","title"]}")"
|
||||
VENUE[ADDRESS]="$(JsonDecode "${UPD["result",${num},"message","venue","address"]}")"
|
||||
|
@ -838,7 +848,6 @@ process_message() {
|
|||
LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}"
|
||||
|
||||
# service messages
|
||||
SERVICE=( ); NEWMEMBER=( ); LEFTMEMBER=( )
|
||||
if grep -qs -e '\["result",'"${num}"',"message","new_chat_member' <<<"${UPDATE}"; then
|
||||
SERVICE[NEWMEMBER]="${UPD["result",${num},"message","new_chat_member","id"]}"
|
||||
NEWMEMBER[ID]="${SERVICE[NEWMEMBER]}"
|
||||
|
@ -846,7 +855,8 @@ process_message() {
|
|||
NEWMEMBER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","new_chat_member","last_name"]}")"
|
||||
NEWMEMBER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","new_chat_member","username"]}")"
|
||||
NEWMEMBER[ISBOT]="${UPD["result",${num},"message","new_chat_member","is_bot"]}"
|
||||
MESSAGE[0]="/new_chat_member ${NEWMEMBER[USERNAME]:=${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]}}"
|
||||
[ -z "${MESSAGE[0]}" ] &&\
|
||||
MESSAGE[0]="/_new_chat_member ${NEWMEMBER[ID]} ${NEWMEMBER[USERNAME]:=${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]}}"
|
||||
fi
|
||||
if grep -qs -e '\["result",'"${num}"',"message","left_chat_member' <<<"${UPDATE}"; then
|
||||
SERVICE[LEFTMEMBER]="${UPD["result",${num},"message","left_chat_member","id"]}"
|
||||
|
@ -855,54 +865,63 @@ process_message() {
|
|||
LEFTMEMBER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","left_chat_member","last_name"]}")"
|
||||
LEFTMEBER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","left_chat_member","username"]}")"
|
||||
LEFTMEMBER[ISBOT]="${UPD["result",${num},"message","left_chat_member","is_bot"]}"
|
||||
MESSAGE[0]="/left_chat_member ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}"
|
||||
[ -z "${MESSAGE[0]}" ] &&\
|
||||
MESSAGE[0]="/_left_chat_member ${NEWMEMBER[ID]} ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}"
|
||||
fi
|
||||
if grep -qs -e '\["result",'"${num}"',"message","\(new_chat_[tp]\)\|\(pinned_message\)' <<<"${UPDATE}"; then
|
||||
if grep -qs -e '\["result",'"${num}"',"message","new_chat_[tp]' <<<"${UPDATE}"; then
|
||||
SERVICE[NEWTITLE]="$(JsonDecode "${UPD["result",${num},"message","new_chat_title"]}")"
|
||||
[ -n "${SERVICE[NEWTITLE]}" ] && MESSAGE[0]="/new_chat_title ${SERVICE[NEWTITLE]}"
|
||||
[ -z "${MESSAGE[0]}" ] && [ -n "${SERVICE[NEWTITLE]}" ] &&\
|
||||
MESSAGE[0]="/_new_chat_title ${USER[ID]} ${SERVICE[NEWTITLE]}"
|
||||
SERVICE[NEWPHOTO]="$(get_file "${UPD["result",${num},"message","new_chat_photo",0,"file_id"]}")"
|
||||
[ -n "${SERVICE[NEWPHOTO]}" ] && MESSAGE[0]="/new_chat_photo ${SERVICE[NEWPHOTO]}"
|
||||
SERVICE[PINNED]="$(JsonDecode "${UPD["result",${num},"message","pinned_message"]}")"
|
||||
[ -n "${SERVICE[PINNED]}" ] && MESSAGE[0]="/new_pinned_message ${SERVICE[PINNED]}"
|
||||
[ -z "${MESSAGE[0]}" ] && [ -n "${SERVICE[NEWPHOTO]}" ] &&\
|
||||
MESSAGE[0]="/_new_chat_photo ${USER[ID]} ${SERVICE[NEWPHOTO]}"
|
||||
fi
|
||||
if grep -qs -e '\["result",'"${num}"',"message","pinned_message' <<<"${UPDATE}"; then
|
||||
SERVICE[PINNED]="$(JsonDecode "${UPD["result",${num},"message","pinned_message","message_id"]}")"
|
||||
PINNED[ID]="${SERVICE[PINNED]}"
|
||||
PINNED[MESSAGE]="$(JsonDecode "${UPD["result",${num},"message","pinned_message","text"]}")"
|
||||
[ -z "${MESSAGE[0]}" ] && [ -n "${SERVICE[PINNED]}" ] &&\
|
||||
MESSAGE[0]="/_new_pinned_message ${USER[ID]} ${PINNED[ID]} ${PINNED[MESSAGE]}"
|
||||
fi
|
||||
# set SSERVICE to yes if a service message was received
|
||||
[[ "${SERVICE[*]}" =~ ^[[:blank:]]*$ ]] || SERVICE[0]="yes"
|
||||
|
||||
# split message in command and args
|
||||
[ "${MESSAGE[0]:0:1}" = "/" ] && read -r CMD <<<"${MESSAGE[0]}" && CMD[0]="${CMD[0]%%@*}"
|
||||
[[ "${MESSAGE[0]}" == "/"* ]] && read -r CMD <<<"${MESSAGE[0]}" && CMD[0]="${CMD[0]%%@*}"
|
||||
# everything went well
|
||||
return 0
|
||||
}
|
||||
|
||||
#########################
|
||||
# main get updates loop, should never terminate
|
||||
declare -A BASHBOTBLOCKED
|
||||
export BASHBOTDEBUG
|
||||
start_bot() {
|
||||
local ADMIN OFFSET=0
|
||||
local DEBUGMSG ADMIN OFFSET=0
|
||||
# adaptive sleep defaults
|
||||
local nextsleep="100"
|
||||
local stepsleep="${BASHBOT_SLEEP_STEP:-100}"
|
||||
local maxsleep="${BASHBOT_SLEEP:-5000}"
|
||||
# startup message
|
||||
BASHBOTDEBUG="$(date): Start BASHBOT updates in Mode \"${1:-normal}\" =========="
|
||||
printf "%s\n" "${BASHBOTDEBUG}" >>"${UPDATELOG}"
|
||||
DEBUGMSG="$(date): Start BASHBOT updates in Mode \"${1:-normal}\" =========="
|
||||
printf "%s\n" "${DEBUGMSG}" >>"${UPDATELOG}"
|
||||
# redirect to Debug.log
|
||||
[[ "${1}" == *"debug" ]] && exec &>>"${DEBUGLOG}"
|
||||
printf "%s\n" "${BASHBOTDEBUG}"; BASHBOTDEBUG="${1}"
|
||||
[[ "${BASHBOTDEBUG}" == "xdebug"* ]] && set -x
|
||||
printf "%s\n" "${DEBUGMSG}"; DEBUGMSG="${1}"
|
||||
[[ "${DEBUGMSG}" == "xdebug"* ]] && set -x
|
||||
#cleaup old pipes and empty logfiles
|
||||
find "${DATADIR}" -type p -delete
|
||||
find "${DATADIR}" -size 0 -name "*.log" -delete
|
||||
# load addons on startup
|
||||
for addons in "${ADDONDIR:-.}"/*.sh ; do
|
||||
# shellcheck source=./modules/aliases.sh
|
||||
[ -r "${addons}" ] && source "${addons}" "startbot" "${BASHBOTDEBUG}"
|
||||
[ -r "${addons}" ] && source "${addons}" "startbot" "${DEBUGMSG}"
|
||||
done
|
||||
# shellcheck source=./commands.sh
|
||||
source "${COMMANDS}" "startbot"
|
||||
# start timer events
|
||||
if [ -n "${BASHBOT_START_TIMER}" ] ; then
|
||||
# shellcheck disable=SC2064
|
||||
trap "event_timer $BASHBOTDEBUG" ALRM
|
||||
trap "event_timer $DEBUGMSG" ALRM
|
||||
start_timer &
|
||||
# shellcheck disable=SC2064
|
||||
trap "kill -9 $!; exit" EXIT INT HUP TERM QUIT
|
||||
|
@ -937,7 +956,7 @@ start_bot() {
|
|||
|
||||
if [ "$OFFSET" != "1" ]; then
|
||||
nextsleep="100"
|
||||
process_updates "${BASHBOTDEBUG}"
|
||||
process_updates "${DEBUGMSG}"
|
||||
fi
|
||||
else
|
||||
# ups, something bad happened, wait maxsleep*10
|
||||
|
@ -1005,7 +1024,7 @@ bot_init() {
|
|||
echo -e "${ORANGE}Bot config may not complete, pls check.${NC}"
|
||||
fi
|
||||
# show result
|
||||
ls -ld "${DATADIR}" "${LOGDIR}" ./*.jssh* ./*.sh
|
||||
ls -ld "${DATADIR}" "${LOGDIR}" ./*.jssh* ./*.sh 2>/dev/null
|
||||
}
|
||||
|
||||
if ! _is_function send_message ; then
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
#
|
||||
|
||||
# adjust your language setting here, e.g.when run from other user or cron.
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
@ -45,12 +45,12 @@ done
|
|||
if [ "$fail" -eq 0 ]; then
|
||||
/bin/echo -n 'SUCCESS '
|
||||
exitcode=0
|
||||
rm -rf "${TESTENV}"
|
||||
#rm -rf "${TESTENV}"
|
||||
else
|
||||
/bin/echo -n 'FAILURE '
|
||||
exitcode=1
|
||||
rm -rf "${TESTENV}/test"
|
||||
find "${TESTENV}/"* ! -name '[a-z]-*' -delete
|
||||
#rm -rf "${TESTENV}/test"
|
||||
#find "${TESTENV}/"* ! -name '[a-z]-*' -delete
|
||||
fi
|
||||
|
||||
echo -e "${passed} / ${tests}\\n"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#
|
||||
# works together with git pre-push.sh and ADD all changed files since last push
|
||||
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
############
|
||||
# NOTE: you MUST run install-hooks.sh again when updating this file!
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
############
|
||||
# NOTE: you MUST run install-hooks.sh again when updating this 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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# file: make-distribution.sh
|
||||
# creates files and arcchives to dirtribute bashbot
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
@ -17,7 +17,7 @@ VERSION="$(git describe --tags | sed -e 's/-[0-9].*//' -e 's/v//')"
|
|||
|
||||
DISTNAME="telegram-bot-bash"
|
||||
DISTDIR="./DIST/${DISTNAME}"
|
||||
DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh mycommands.sh.clean doc examples logs scripts modules addons LICENSE README.md README.txt README.html"
|
||||
DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh mycommands.sh.clean doc examples scripts modules addons LICENSE README.md README.txt README.html"
|
||||
|
||||
# run tests first!
|
||||
|
||||
|
|
7
dev/make-html.sh
Executable file → Normal file
7
dev/make-html.sh
Executable file → Normal file
|
@ -9,5 +9,8 @@ fi
|
|||
mkdir html 2>/dev/null
|
||||
cp README.html html/index.html
|
||||
find doc -iname "*.md" -type f -exec sh -c 'pandoc -s -f commonmark -M "title=Bashobot Documentation - ${0%.md}.html" "${0}" -o "./html/$(basename ${0%.md}.html)"' {} \;
|
||||
find examples -iname "*.md" -type f -exec sh -c 'pandoc -s -f commonmark -M "title=Bashobot Documentation - ${0%.md}.html" "${0}" -o "${0%.md}.html"' {} \;
|
||||
find README.html html examples -iname "*.html" -type f -exec sh -c 'sed -i -E "s/href=\"(\.\.\/)*doc\//href=\"\1html\//g;s/href=\"(.*).md(#.*)*\"/href=\"\1.html\"/g" ${0}' {} \;
|
||||
if [ -d "examples" ]; then
|
||||
find examples -iname "*.md" -type f -exec sh -c 'pandoc -s -f commonmark -M "title=Bashobot Documentation - ${0%.md}.html" "${0}" -o "${0%.md}.html"' {} \;
|
||||
EXAMPLES="examples"
|
||||
fi
|
||||
find README.html html ${EXAMPLES} -iname "*.html" -type f -exec sh -c 'sed -i -E "s/href=\"(\.\.\/)*doc\//href=\"\1html\//g;s/href=\"(.*).md(#.*)*\"/href=\"\1.html\"/g" ${0}' {} \;
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
@ -75,8 +75,10 @@ chmod +x bashbot.sh
|
|||
rm -rf modules
|
||||
|
||||
echo "Create minimized Version of bashbot.sh and commands.sh"
|
||||
sed -E -e '/(shellcheck)|(#!\/bin\/bash)/! s/^[[:space:]]*#.*//' -e 's/^[[:space:]]*//' -e '/^$/d' bashbot.sh > bashbot.sh.min
|
||||
sed -E -e '/(shellcheck)|(#!\/bin\/bash)/! s/^[[:space:]]*#.*//' -e 's/^[[:space:]]*//' -e '/^$/d' commands.sh > commands.sh.min
|
||||
sed -E -e '/(shellcheck)|(#!\/bin\/bash)/! s/^[[:space:]]*#.*//' -e 's/^[[:space:]]*//' -e '/^$/d' -e 'N;s/\\\n/ /;P;D' bashbot.sh |\
|
||||
sed 'N;s/\\\n/ /;P;D' > bashbot.sh.min
|
||||
sed -E -e '/(shellcheck)|(#!\/bin\/bash)/! s/^[[:space:]]*#.*//' -e 's/^[[:space:]]*//' -e '/^$/d' commands.sh |\
|
||||
sed 'N;s/\\\n/ /;P;D' > commands.sh.min
|
||||
chmod +x bashbot.sh.min
|
||||
|
||||
# make html doc
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# list of additional files to check from shellcheck
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
bashbot.rc
|
||||
mycommands.sh.clean
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
# shellcheck disable=SC2016
|
||||
#
|
||||
# Easy Versioning in git:
|
||||
|
|
|
@ -131,5 +131,5 @@ The old format is supported for backward compatibility, but may fail for corner
|
|||
|
||||
#### [Next Create Bot](1_firstbot.md)
|
||||
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ Have FUN!
|
|||
│ ├── bash2env.sh # script to convert shebang to /usr/bin/env, see [Security Considerations](../README.md#Security-Considerations)
|
||||
│ └── bashbot.cron # example crontab
|
||||
│
|
||||
├── doc # Documentation and License
|
||||
├── doc # Documentation and License
|
||||
├── html
|
||||
├── LICENSE
|
||||
├── README.html
|
||||
|
@ -74,7 +74,7 @@ Start or Stop your Bot use the following commands:
|
|||
./bashbot.sh start
|
||||
```
|
||||
```bash
|
||||
./bashbot.sh kill
|
||||
./bashbot.sh stop
|
||||
```
|
||||
|
||||
### User stats
|
||||
|
@ -164,30 +164,32 @@ Service Messages are regular messages not itended for end users, instead they si
|
|||
client, e.g. new users.
|
||||
|
||||
If a service message is received bashbot sets MESSAGE to the service message type as a command,
|
||||
e.g. if a new user joins a chat MESSAGE is set to "/new_chat_user".
|
||||
e.g. if a new user joins a chat MESSAGE is set to "/_new_chat_user".
|
||||
|
||||
* ```$SERVICE```: This array contains info about received service messages.
|
||||
* ```${SERVICE}```: "yes" if service message is received
|
||||
* ```${SERVICE[NEWMEMBER]```: New user's id
|
||||
* ```${MESSAGE}```: /new_chat_member
|
||||
* ```${NEWMEMBER[ID]```: New user's id
|
||||
* ```${NEWMEMBER[FIRST_NAME]```: New user's first name
|
||||
* ```${NEWMEMBER[LAST_NAME]```: New user's last name
|
||||
* ```${NEWMEMBER[USERNAME]```: New user's username
|
||||
* ```${NEWMEMBER[ISBOT]```: New user is a bot
|
||||
* ```${SERVICE[LEFTMEMBER]```: Id of user left
|
||||
* ```${MESSAGE}```: /left_chat_member
|
||||
* ```${LEFTMEMBER[ID]```: Left user's id
|
||||
* ```${LEFTMEMBER[FIRST_NAME]```: Left user's first name
|
||||
* ```${LEFTMEMBER[LAST_NAME]```: Left user's last name
|
||||
* ```${LEFTMEMBER[USERNAME]```: Left user's username
|
||||
* ```${LEFTMEMBER[ISBOT]```: Left user is a bot
|
||||
* ```${SERVICE[NEWTITLE]```: Text of new title
|
||||
* ```${MESSAGE}```: /new_chat_title
|
||||
* ```${SERVICE[NEWPHOTO]```: New Chat Picture URL
|
||||
* ```${MESSAGE}```: /new_chat_picture
|
||||
* ```${SERVICE[PINNED]```: Pinned Message structure
|
||||
* ```${MESSAGE}```: /new_pinned_message
|
||||
* ```${SERVICE[NEWMEMBER]}}```: New user's id
|
||||
* ```${MESSAGE}```: /_new_chat_member ID NAME
|
||||
* ```${NEWMEMBER[ID]}```: New user's id
|
||||
* ```${NEWMEMBER[FIRST_NAME]}```: New user's first name
|
||||
* ```${NEWMEMBER[LAST_NAME]}```: New user's last name
|
||||
* ```${NEWMEMBER[USERNAME]}```: New user's username
|
||||
* ```${NEWMEMBER[ISBOT]}```: New user is a bot
|
||||
* ```${SERVICE[LEFTMEMBER]}```: Id of user left
|
||||
* ```${MESSAGE}```: /_left_chat_member ID NAME
|
||||
* ```${LEFTMEMBER[ID]}```: Left user's id
|
||||
* ```${LEFTMEMBER[FIRST_NAME]}```: Left user's first name
|
||||
* ```${LEFTMEMBER[LAST_NAME]}```: Left user's last name
|
||||
* ```${LEFTMEMBER[USERNAME]}```: Left user's username
|
||||
* ```${LEFTMEMBER[ISBOT]}```: Left user is a bot
|
||||
* ```${SERVICE[NEWTITLE]}```: Text of new title
|
||||
* ```${MESSAGE}```: /_new_chat_title SENDER TEXT
|
||||
* ```${SERVICE[NEWPHOTO]}```: New Chat Picture
|
||||
* ```${MESSAGE}```: /_new_chat_picture SENDER URL
|
||||
* ```${SERVICE[PINNED]}```: Pinned Message structure
|
||||
* ```${MESSAGE}```: /_new_pinned_message SENDER ID
|
||||
* ```${PINNED[ID]}```: Id of pinned message
|
||||
* ```${PINNED[MESSAGE]}```: Message text of pinned message
|
||||
|
||||
|
||||
|
||||
|
@ -281,5 +283,5 @@ send_action "${CHAT[ID]}" "action"
|
|||
#### [Prev Create Bot](1_firstbot.md)
|
||||
#### [Next Advanced Usage](3_advanced.md)
|
||||
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
|
|
|
@ -289,5 +289,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob
|
|||
#### [Prev Getting started](2_usage.md)
|
||||
#### [Next Expert Use](4_expert.md)
|
||||
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
|
|
|
@ -381,5 +381,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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
|
|
|
@ -93,14 +93,12 @@ The main use case for send_message is to process the output of interactive chats
|
|||
|
||||
----
|
||||
|
||||
### File, Location, Venue, Keyboard
|
||||
### File, Album, Location, Venue, Keyboard
|
||||
|
||||
|
||||
##### send_file
|
||||
send_file allows you to send different type's of files, e.g. photos, stickers, audio, media, etc. [see more](https://core.telegram.org/bots/api#sending-files)
|
||||
|
||||
Starting with version 0.80 send_file implements the following rules:
|
||||
|
||||
- file names must not contain ".."
|
||||
- file names must not start with "."
|
||||
- file names not starting with "/" are relative to $TMPDIR, e.g. ./data-bot-bash
|
||||
|
@ -109,12 +107,21 @@ Starting with version 0.80 send_file implements the following rules:
|
|||
|
||||
*usage:* send_file "${CHAT[ID]}" "file" "caption"
|
||||
|
||||
*example:*
|
||||
*example:*
|
||||
```bash
|
||||
send_file "${CHAT[ID]}" "/home/user/doge.jpg" "Lool"
|
||||
send_file "${CHAT[ID]}" "https://www.domain,com/something.gif" "Something"
|
||||
```
|
||||
|
||||
##### send_album
|
||||
|
||||
*usage:* send_album "${CHAT[ID]}" "URL1" "URL2" ... "URLn"
|
||||
|
||||
*example:*
|
||||
```bash
|
||||
send_album "$(getConfigKey "botadmin")" "http://www.rrr.de/slider/main-image1.jpg" "http://www.rrr.de/slider/main-image5.jpg"
|
||||
```
|
||||
|
||||
##### send_location
|
||||
*usage:* send_location "${CHAT[ID]}" "Latitude" "Longitude"
|
||||
|
||||
|
@ -1039,5 +1046,5 @@ The name of your bot is available 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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
|
|
|
@ -347,5 +347,5 @@ fi
|
|||
|
||||
#### [Prev Function Reference](6_reference.md)
|
||||
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
|
|
61
examples/README.html
Normal file
61
examples/README.html
Normal file
|
@ -0,0 +1,61 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
|
||||
<title>Bashobot Documentation - examples/README.html</title>
|
||||
<style>
|
||||
code{white-space: pre-wrap;}
|
||||
span.smallcaps{font-variant: small-caps;}
|
||||
span.underline{text-decoration: underline;}
|
||||
div.column{display: inline-block; vertical-align: top; width: 50%;}
|
||||
</style>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<header id="title-block-header">
|
||||
<h1 class="title">Bashobot Documentation - examples/README.html</h1>
|
||||
</header>
|
||||
<h4><a href="../README.html">Home</a></h4>
|
||||
<h2>Bashbot examples</h2>
|
||||
<h3>bashbot multi</h3>
|
||||
<p>An example wrapper to run multiple instances of bashbot, use <code>./bashbot-multi.sh botname command</code></p>
|
||||
<h3>bashbot.cron</h3>
|
||||
<p>An example crontab is provided in <code>examples/bashbot.cron</code>, see <a href="../html/4_expert.html">Expert use</a></p>
|
||||
<h3>Interactive chats</h3>
|
||||
<p>Two examples for interactive scripts are provided as <strong>calc.sh</strong> and <strong>question.sh</strong>, see <a href="../html/3_advanced.html">Advanced use</a></p>
|
||||
<h3>Background scripts</h3>
|
||||
<p>Background jobs are an easy way to provide sceduled messages or alerts if something happens. <strong>notify.sh</strong> is a simple example on how to send a message every x seonds, e.g. current time.</p>
|
||||
<p><strong>background-scripts</strong> contains a more useful example on how to start and stop different scripts plus some example background scripts.</p>
|
||||
<pre><code> mycommands.sh - /run_xxx and /kill-xxx will start any script named run_xxx.sh
|
||||
|
||||
run_diskusage.sh - shows disk usage every 100 seconds
|
||||
run_filename.sh - shown the name of new files in a named dir
|
||||
run_filecontent.sh - shown the content of new files in a named dir
|
||||
run_notify.sh - same as notify.sh
|
||||
</code></pre>
|
||||
<p><strong>Note:</strong> Output of system commands often contains newlines, each newline results in a telegram message, the function 'send_telegram' in mycommands.sh avoids this by converting each newline to ' mynewlinestartshere ' before output the string.</p>
|
||||
<h3>System Status</h3>
|
||||
<p><strong>send-system-status</strong> contains an example for commands showing status of different subsystems. This example is adapted from https://github.com/RG72/telegram-bot-bash to current bashbot commands, but not fully tested. This will show how easy you can convert existing bots.</p>
|
||||
<pre><code> mycommands.sh - commands to show system status
|
||||
botacl - controls who can show system status
|
||||
|
||||
*Available commands*:
|
||||
/se *sensors*
|
||||
/smb *smbstatus*
|
||||
/free *memory status*
|
||||
/md *raid status*
|
||||
/lvm *lvm status*
|
||||
/lvsd *Datailed lvm status*
|
||||
/df *disk space*
|
||||
/ifconfig *ifconfig output*
|
||||
/smart *sda* _smart status for sda drive_
|
||||
</code></pre>
|
||||
<h3>External scripts</h3>
|
||||
<p><strong>external-use</strong> will contain some examples on how to send messages from external scripts to Telegram chats or users.</p>
|
||||
<h4>$$VERSION$$ v0.98-pre2-0-ga597303</h4>
|
||||
</body>
|
||||
</html>
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
######
|
||||
# parameters
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# file: run_filename
|
||||
# background job to display content of all new files in WATCHDIR
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
######
|
||||
# parameters
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# file: run_filename
|
||||
# background job to display all new files in WATCHDIR
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
######
|
||||
# parameters
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
######
|
||||
# parameters
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# file. multibot.sh
|
||||
# description: run multiple telegram bots from one installation
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
|
||||
echo "Usage: $0 botname command"
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
|
||||
SHELL=/bin/sh
|
||||
|
@ -27,9 +27,9 @@ MAILTO=root
|
|||
# * * * * * USER command to execute
|
||||
# * * * * * root echo "run every minute!"
|
||||
|
||||
# run as www every day at 0:00
|
||||
0 0 * * * nobody /usr/local/telegram-bot-bash/bashbot.sh start # (re)start bot
|
||||
0 0 * * * nobody /usr/local/telegram-bot-bash/bashbot.sh resumeback # (re)start background jobs
|
||||
# run as www every day at 0:00 plus random sleep between 1-3h
|
||||
0 0 * * * nobody sleep "${RANDOM:0:4}s" ; /usr/local/telegram-bot-bash/bashbot.sh start # (re)start bot
|
||||
0 0 * * * nobody sleep "${RANDOM:0:4}s" ; /usr/local/telegram-bot-bash/bashbot.sh resumeback # (re)start background jobs
|
||||
|
||||
# run as www on 24 of Dec, 12:00
|
||||
0 12 24 12 * nobody /usr/local/telegram-bot-bash/bashbot.sh broadcast "X-Mas shopping is over!" # broadcast a message
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
######
|
||||
# parameters
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
######
|
||||
# parameters
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
######
|
||||
# parameters
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# file: botacl
|
||||
# a user not listed here, will return false from 'user_is_allowed'
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
# Format:
|
||||
# user:resource:chat
|
||||
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
#
|
||||
# shellcheck disable=SC2154
|
||||
# shellcheck disable=SC2034
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
#
|
||||
# will be automatically sourced from bashbot
|
||||
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# will be automatically sourced from bashbot
|
||||
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# will be automatically sourced from bashbot
|
||||
|
||||
|
@ -114,7 +114,7 @@ send_interactive() {
|
|||
|
||||
# old style but may not work because of local checks
|
||||
inproc() {
|
||||
send_interactive "${CHAT[ID]}" "${MESSAGE}"
|
||||
send_interactive "${CHAT[ID]}" "${MESSAGE[0]}"
|
||||
}
|
||||
|
||||
# start stop all jobs
|
||||
|
@ -134,22 +134,23 @@ job_control() {
|
|||
proc="${job#*:}"
|
||||
job="${job%:*}"
|
||||
fifo="$(procname "${CHAT}" "${job}")"
|
||||
debug_checks "Enter job_control" "${1}" "${FILE##*/}"
|
||||
case "$1" in
|
||||
"resumeb"*|"backgr"*)
|
||||
printf "Restart Job: %s %s\n" "${proc}" " ${fifo}"
|
||||
printf "Restart Job: %s %s\n" "${proc}" " ${fifo##*/}"
|
||||
restart_back "${CHAT}" "${proc}" "${job}"
|
||||
# inform botadmin about stop
|
||||
[ -n "${ADM}" ] && send_normal_message "${ADM}" "Bot ${BOT} restart background jobs ..." &
|
||||
;;
|
||||
"suspendb"*)
|
||||
printf "Suspend Job: %s %s\n" "${proc}" " ${fifo}"
|
||||
printf "Suspend Job: %s %s\n" "${proc}" " ${fifo##*/}"
|
||||
kill_proc "${CHAT}" "${job}"
|
||||
# inform botadmin about stop
|
||||
[ -n "${ADM}" ] && send_normal_message "${ADM}" "Bot ${BOT} suspend background jobs ..." &
|
||||
killall="y"
|
||||
;;
|
||||
"killb"*)
|
||||
printf "Kill Job: %s %s\n" "${proc}" " ${fifo}"
|
||||
printf "Kill Job: %s %s\n" "${proc}" " ${fifo##*/}"
|
||||
kill_proc "${CHAT}" "${job}"
|
||||
rm -f "${FILE}" # remove job
|
||||
# inform botadmin about stop
|
||||
|
@ -160,6 +161,7 @@ job_control() {
|
|||
# send message only onnfirst job
|
||||
ADM=""
|
||||
done
|
||||
debug_checks "end job_control" "${1}"
|
||||
# kill all requestet. kill ALL background jobs, even not listed in data-bot-bash
|
||||
[ "${killall}" = "y" ] && killallproc "back-"
|
||||
}
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# will be automatically sourced from bashbot
|
||||
|
||||
|
@ -37,24 +37,24 @@ leave_chat() {
|
|||
}
|
||||
|
||||
user_is_creator() {
|
||||
if [ "${1:--}" = "${2:-+}" ] || [ "$(get_chat_member_status "$1" "$2")" = "creator" ]; then return 0; fi
|
||||
# empty is false ...
|
||||
[[ "${1:--}" == "${2:-+}" || "$(get_chat_member_status "$1" "$2")" == "creator" ]] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
user_is_admin() {
|
||||
[ "$1" = "$2" ] && return 0
|
||||
local me; me="$(get_chat_member_status "$1" "$2")"
|
||||
if [ "${me}" = "creator" ] || [ "${me}" = "administrator" ]; then return 0; fi
|
||||
[ "${1:--}" == "${2:-+}" ] && return 0
|
||||
user_is_botadmin "$2" && return 0
|
||||
local me; me="$(get_chat_member_status "$1" "$2")"
|
||||
[[ "${me}" =~ ^creator$|^administrator$ ]] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
user_is_botadmin() {
|
||||
local admin; admin="$(getConfigKey "botadmin")"
|
||||
[ "${admin}" = "${1}" ] && return 0
|
||||
[ "${admin}" = "${2}" ] && return 0
|
||||
[[ "${admin}" = "@*" ]] && [[ "${admin}" = "${2}" ]] && return 0
|
||||
if [ "${admin}" = "?" ]; then setConfigKey "${1:-?}"; return 0; fi
|
||||
local admin; admin="$(getConfigKey "botadmin")"; [ -z "${admin}" ] && return 1
|
||||
[[ "${admin}" == "${1}" || "${admin}" == "${2}" ]] && return 0
|
||||
#[[ "${admin}" = "@*" ]] && [[ "${admin}" = "${2}" ]] && return 0
|
||||
if [ "${admin}" = "?" ]; then setConfigKey "botadmin" "${1:-?}"; return 0; fi
|
||||
return 1
|
||||
}
|
||||
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
#
|
||||
# source from commands.sh to use jsonDB functions
|
||||
#
|
||||
|
|
|
@ -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.98-pre2-6-gbee55fe
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# will be automatically sourced from bashbot
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
# #### if you start to develop your own bot, use the clean version of this file:
|
||||
# #### mycommands.clean
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-7-g3569a76
|
||||
#### $$VERSION$$ v0.98-2-g2d48670
|
||||
#
|
||||
|
||||
# uncomment the following lines to overwrite info and help messages
|
||||
|
@ -52,6 +52,10 @@ export SILENCER="no"
|
|||
# export REMOVEKEYBOARD="yes"
|
||||
# export REMOVEKEYBOARD_PRIVATE="yes"
|
||||
|
||||
# uncomment if you want to say welcome to new chat members
|
||||
# export WELCOME_NEWMEMBER="yes"
|
||||
WELCOME_MSG="Welcome"
|
||||
|
||||
# messages for admin only commands
|
||||
NOTADMIN="Sorry, this command is allowed for admin or owner only"
|
||||
NOTBOTADMIN="Sorry, this command is allowed for bot owner only"
|
||||
|
@ -121,11 +125,19 @@ else
|
|||
fi
|
||||
;;
|
||||
# will we process edited messages also?
|
||||
'/edited_message'*)
|
||||
'/_edited_message'*)
|
||||
return 1 # no
|
||||
# but if we do, remove /edited_message
|
||||
MESSAGE="${MESSAGE#/* }"
|
||||
;;
|
||||
'/_new_chat_member'*)
|
||||
if [[ -n "${WELCOME_NEWMEMBER}" && "${NEWMEMBER[ISBOT]}" != "true" ]]; then
|
||||
send_normal_message "${CHAT[ID]}"\
|
||||
"${WELCOME_MSG} ${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]} (@${NEWMEMBER[USERNAME]})"
|
||||
MYSENTID="${BOTSENT[ID]}"
|
||||
{ sleep 5; delete_message "${CHAT[ID]}" "${MYSENTID}"; } &
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
case "${MESSAGE}" in
|
||||
|
@ -228,6 +240,14 @@ else
|
|||
esac
|
||||
}
|
||||
|
||||
# debug function called on start, stop of bot, interactive and background processes
|
||||
# if your bot was started with debug as second argument
|
||||
# $1 current date, $2 from where the function was called, $3 ... $n optional information
|
||||
my_debug_checks() {
|
||||
# example check because my bot created a wrong file
|
||||
[ -f ".jssh" ] && printf "%s: %s\n" "${1}" "Ups, found file \"${PWD:-.}/.jssh\"! =========="
|
||||
}
|
||||
|
||||
# place your processing functions here
|
||||
|
||||
# $1 search parameter
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# files: mycommands.sh.clean
|
||||
# copy to mycommands.sh and add all your commands and functions here ...
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-7-g3569a76
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
#
|
||||
|
||||
##########
|
||||
|
|
|
@ -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.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
######
|
||||
# parameters
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
# ADD a new test skeleton to test dir, but does not activate test
|
||||
#
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# common variables
|
||||
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
||||
|
@ -12,11 +12,11 @@ export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
|||
|
||||
# common filenames
|
||||
export TOKENFILE ACLFILE COUNTFILE BLOCKEDFILE ADMINFILE DATADIR JSONSHFILE
|
||||
TOKENFILE="token"
|
||||
TOKENFILE="botconfig.jssh"
|
||||
ACLFILE="botacl"
|
||||
COUNTFILE="count.jssh"
|
||||
BLOCKEDFILE="blocked.jssh"
|
||||
ADMINFILE="botadmin"
|
||||
ADMINFILE="botconfig.jssh"
|
||||
DATADIR="data-bot-bash"
|
||||
JSONSHFILE="JSON.sh/JSON.sh"
|
||||
|
||||
|
@ -26,10 +26,12 @@ export SUCCESS NOSUCCESS
|
|||
NOSUCCESS=" FAILED!"
|
||||
|
||||
# default input, reference and output files
|
||||
export INPUTFILE REFFILE OUTPUTFILE
|
||||
export INPUTFILE REFFILE INPUTFILE2 REFFILE2 OUTPUTFILE
|
||||
OUTPUTFILE="${TESTDIR}/${REFDIR}.out"
|
||||
INPUTFILE="${DIRME}/${REFDIR}/${REFDIR}.input"
|
||||
REFFILE="${DIRME}/${REFDIR}/${REFDIR}.result"
|
||||
OUTPUTFILE="${TESTDIR}/${REFDIR}.out"
|
||||
INPUTFILE2="${DIRME}/${REFDIR}/${REFDIR}2.input"
|
||||
REFFILE2="${DIRME}/${REFDIR}/${REFDIR}2.result"
|
||||
|
||||
# do not query telegram when testing
|
||||
export BASHBOT_URL TESTTOKEN
|
||||
|
@ -54,7 +56,8 @@ compare_sorted() {
|
|||
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"
|
||||
[[ "${1}" != "${TESTDIR}"* ]] && rm -f "${1}.sort"
|
||||
[[ "${2}" != "${TESTDIR}"* ]] && rm -f "${2}.sort"
|
||||
return "$ret"
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
../dev/hooks/pre-commit.sh
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
# file: b-example-test.sh
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
?
|
3
test/c-init-test/botconfig.jssh
Normal file
3
test/c-init-test/botconfig.jssh
Normal file
|
@ -0,0 +1,3 @@
|
|||
["bot_config_key"] "config_key_value"
|
||||
["bottoken"] "123456789:BASHBOTTESTSCRIPTbashbottestscript_"
|
||||
["botadmin"] "?"
|
|
@ -1 +0,0 @@
|
|||
123456789:BASHBOTTESTSCRIPTbashbottestscript_
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
@ -20,22 +20,40 @@ get_file() {
|
|||
}
|
||||
|
||||
# get telegram input from file
|
||||
export UPDATE UPD
|
||||
UPDATE="$(cat "${INPUTFILE}")"
|
||||
declare -A UPD
|
||||
source <( printf 'UPD=( %s )' "$(sed <<<"${UPDATE}" -E -e 's/\t/=/g' -e 's/=(true|false)/="\1"/')" )
|
||||
export UPDATE
|
||||
declare -Ax UPD
|
||||
|
||||
# run process_message
|
||||
echo "Check process_message ..."
|
||||
# run process_message --------------
|
||||
ARRAYS="USER CHAT REPLYTO FORWARD URLS CONTACT CAPTION LOCATION MESSAGE VENUE SERVICE NEWMEMBER LEFTMEMBER PINNED"
|
||||
|
||||
echo "Check process_message regular message..."
|
||||
|
||||
UPDATE="$(< "${INPUTFILE}")"
|
||||
Json2Array 'UPD' <"${INPUTFILE}"
|
||||
set -x
|
||||
{ process_message "0"; set +x; } >>"${LOGFILE}" 2>&1;
|
||||
|
||||
USER[ID]="123456789"
|
||||
CHAT[ID]="123456789"
|
||||
{ pre_process_message "0"; process_message "0"; set +x; } >>"${LOGFILE}" 2>&1;
|
||||
USER[ID]="123456789"; CHAT[ID]="123456789"
|
||||
|
||||
# output processed input
|
||||
print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" "SERVICE">"${OUTPUTFILE}"
|
||||
# shellcheck disable=SC2086
|
||||
print_array ${ARRAYS} >"${OUTPUTFILE}"
|
||||
compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1
|
||||
|
||||
# run process_message ------------
|
||||
echo "Check process_message service message..."
|
||||
|
||||
UPDATE="$(cat "${INPUTFILE2}")"
|
||||
Json2Array 'UPD' <"${INPUTFILE2}"
|
||||
set -x
|
||||
{ pre_process_message "0"; process_message "0"; set +x; } >>"${LOGFILE}" 2>&1;
|
||||
USER[ID]="123456789"; CHAT[ID]="123456789"
|
||||
|
||||
# output processed input
|
||||
# shellcheck disable=SC2086
|
||||
print_array ${ARRAYS} >"${OUTPUTFILE}"
|
||||
compare_sorted "${REFFILE2}" "${OUTPUTFILE}" || exit 1
|
||||
|
||||
|
||||
echo "${SUCCESS}"
|
||||
|
||||
cd "${DIRME}" || exit 1
|
||||
|
|
|
@ -89,16 +89,3 @@
|
|||
["result",0,"message","voice","duration"] 2
|
||||
["result",0,"message","voice","mime_type"] "audio/ogg"
|
||||
["result",0,"message","voice","file_size"] 4262
|
||||
["result",0,"message","new_chat_participant","id"] 123456789
|
||||
["result",0,"message","new_chat_participant","is_bot"] false
|
||||
["result",0,"message","new_chat_participant","first_name"] "Kay"
|
||||
["result",0,"message","new_chat_participant","last_name"] "M"
|
||||
["result",0,"message","new_chat_member","id"] 123456789
|
||||
["result",0,"message","new_chat_member","is_bot"] false
|
||||
["result",0,"message","new_chat_member","first_name"] "Kay"
|
||||
["result",0,"message","new_chat_member","last_name"] "M"
|
||||
["result",0,"message","new_chat_members",0,"id"] 123456789
|
||||
["result",0,"message","new_chat_members",0,"is_bot"] false
|
||||
["result",0,"message","new_chat_members",0,"first_name"] "Kay"
|
||||
["result",0,"message","new_chat_members",0,"last_name"] "M"
|
||||
["result",0,"message","left_chat_member","id"] 123456789
|
||||
|
|
|
@ -3,7 +3,6 @@ USER: ID 123456789
|
|||
USER: LAST_NAME M
|
||||
USER: USERNAME Gnadelwartz
|
||||
CHAT: ALL_ADMIN
|
||||
CHAT: ALL_MEMBERS_ARE_ADMINISTRATORS
|
||||
CHAT: FIRST_NAME Test
|
||||
CHAT: ID 123456789
|
||||
CHAT: LAST_NAME Bot
|
||||
|
@ -42,9 +41,3 @@ VENUE: FOURSQUARE 4c4321afce54e21eee980d1a
|
|||
VENUE: LATITUDE 49.631824
|
||||
VENUE: LONGITUDE 8.377072
|
||||
VENUE: TITLE Kolb's Biergarten
|
||||
SERVICE: 0 yes
|
||||
SERVICE: LEFTMEMBER 123456789
|
||||
SERVICE: NEWMEMBER 123456789
|
||||
SERVICE: NEWPHOTO
|
||||
SERVICE: NEWTILE
|
||||
SERVICE: PINNED
|
||||
|
|
65
test/d-process_message-test/d-process_message-test2.input
Normal file
65
test/d-process_message-test/d-process_message-test2.input
Normal file
|
@ -0,0 +1,65 @@
|
|||
["ok"] true
|
||||
["result",0,"update_id"] 123456789
|
||||
["result",0,"message","message_id"] 123456789
|
||||
["result",0,"message","from","id"] 123456789
|
||||
["result",0,"message","from","is_bot"] false
|
||||
["result",0,"message","from","first_name"] "Kay"
|
||||
["result",0,"message","from","last_name"] "M"
|
||||
["result",0,"message","from","username"] "Gnadelwartz"
|
||||
["result",0,"message","from","language_code"] "de"
|
||||
["result",0,"message","chat","id"] -123456789
|
||||
["result",0,"message","chat","title"] "Testgruppe bot only test"
|
||||
["result",0,"message","chat","type"] "group"
|
||||
["result",0,"message","chat","all_members_are_administrators"] true
|
||||
["result",0,"message","date"] 1592372719
|
||||
|
||||
["result",0,"message","left_chat_participant","id"] 123456789
|
||||
["result",0,"message","left_chat_participant","is_bot"] false
|
||||
["result",0,"message","left_chat_participant","first_name"] "Kay"
|
||||
["result",0,"message","left_chat_participant","last_name"] "M"
|
||||
["result",0,"message","left_chat_participant","username"] "Gnadelwartz"
|
||||
["result",0,"message","left_chat_member","id"] 123456789
|
||||
["result",0,"message","left_chat_member","is_bot"] false
|
||||
["result",0,"message","left_chat_member","first_name"] "Kay"
|
||||
["result",0,"message","left_chat_member","last_name"] "M"
|
||||
["result",0,"message","left_chat_member","username"] "Gnadelwartz"
|
||||
|
||||
["result",0,"message","new_chat_participant","id"] 123456789
|
||||
["result",0,"message","new_chat_participant","is_bot"] false
|
||||
["result",0,"message","new_chat_participant","first_name"] "Kay"
|
||||
["result",0,"message","new_chat_participant","last_name"] "M"
|
||||
["result",0,"message","new_chat_participant","username"] "Gnadelwartz"
|
||||
["result",0,"message","new_chat_member","id"] 123456789
|
||||
["result",0,"message","new_chat_member","is_bot"] false
|
||||
["result",0,"message","new_chat_member","first_name"] "Kay"
|
||||
["result",0,"message","new_chat_member","last_name"] "M"
|
||||
["result",0,"message","new_chat_member","username"] "Gnadelwartz"
|
||||
|
||||
["result",0,"message","new_chat_photo",0,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE"
|
||||
["result",0,"message","new_chat_photo",0,"file_unique_id"] "AQADK6S6ki4AAzdIAwAB"
|
||||
["result",0,"message","new_chat_photo",0,"file_size"] 5939
|
||||
["result",0,"message","new_chat_photo",0,"width"] 160
|
||||
["result",0,"message","new_chat_photo",0,"height"] 160
|
||||
["result",0,"message","new_chat_photo",1,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANiAAM4SAMAARoE"
|
||||
["result",0,"message","new_chat_photo",1,"file_unique_id"] "AQADK6S6ki4AAzhIAwAB"
|
||||
["result",0,"message","new_chat_photo",1,"file_size"] 14124
|
||||
["result",0,"message","new_chat_photo",1,"width"] 320
|
||||
["result",0,"message","new_chat_photo",1,"height"] 320
|
||||
["result",0,"message","new_chat_photo",2,"file_id"] "AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANjAAM5SAMAARoE"
|
||||
["result",0,"message","new_chat_photo",2,"file_unique_id"] "AQADK6S6ki4AAzlIAwAB"
|
||||
["result",0,"message","new_chat_photo",2,"file_size"] 34052
|
||||
["result",0,"message","new_chat_photo",2,"width"] 640
|
||||
["result",0,"message","new_chat_photo",2,"height"] 640
|
||||
|
||||
["result",0,"message","pinned_message","message_id"] 3022
|
||||
["result",0,"message","pinned_message","from","id"] 796814662
|
||||
["result",0,"message","pinned_message","from","is_bot"] true
|
||||
["result",0,"message","pinned_message","from","first_name"] "DealOMat"
|
||||
["result",0,"message","pinned_message","from","username"] "Deal_O_Mat_bot"
|
||||
["result",0,"message","pinned_message","chat","id"] -1001220313778
|
||||
["result",0,"message","pinned_message","chat","title"] "Testgruppe bot only test"
|
||||
["result",0,"message","pinned_message","chat","type"] "supergroup"
|
||||
["result",0,"message","pinned_message","date"] 1593121152
|
||||
["result",0,"message","pinned_message","text"] "new pinned Message"
|
||||
|
||||
["result",0,"message","new_chat_title"] "new Testgruppe bot only"
|
33
test/d-process_message-test/d-process_message-test2.result
Normal file
33
test/d-process_message-test/d-process_message-test2.result
Normal file
|
@ -0,0 +1,33 @@
|
|||
USER: FIRST_NAME Kay
|
||||
USER: ID 123456789
|
||||
USER: LAST_NAME M
|
||||
USER: USERNAME Gnadelwartz
|
||||
CHAT: ALL_ADMIN true
|
||||
CHAT: FIRST_NAME
|
||||
CHAT: ID 123456789
|
||||
CHAT: LAST_NAME
|
||||
CHAT: TITLE Testgruppe bot only test
|
||||
CHAT: TYPE group
|
||||
CHAT: USERNAME
|
||||
CAPTION: 0
|
||||
LOCATION: LATITUDE
|
||||
LOCATION: LONGITUDE
|
||||
MESSAGE: 0 /_new_chat_member 123456789 Gnadelwartz
|
||||
MESSAGE: ID 123456789
|
||||
SERVICE: 0 yes
|
||||
SERVICE: LEFTMEMBER 123456789
|
||||
SERVICE: NEWMEMBER 123456789
|
||||
SERVICE: NEWPHOTO AgACAgIAAxkBAAEBFute6a3vIpB99vim811hxeu2tyQWfwACrKwxG0TMUUtDBH10RqlzGCukupIuAAMBAAMCAANhAAM3SAMAARoE
|
||||
SERVICE: NEWTITLE new Testgruppe bot only
|
||||
SERVICE: PINNED 3022
|
||||
NEWMEMBER: FIRST_NAME Kay
|
||||
NEWMEMBER: ID 123456789
|
||||
NEWMEMBER: ISBOT false
|
||||
NEWMEMBER: LAST_NAME M
|
||||
NEWMEMBER: USERNAME Gnadelwartz
|
||||
LEFTMEMBER: FIRST_NAME Kay
|
||||
LEFTMEMBER: ID
|
||||
LEFTMEMBER: ISBOT false
|
||||
LEFTMEMBER: LAST_NAME M
|
||||
PINNED: ID 3022
|
||||
PINNED: MESSAGE new pinned Message
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
|
|
@ -4,22 +4,19 @@ URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?12345
|
|||
chat:123456 JSON:"text":"This is a normal text"
|
||||
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":"This is a normal text
|
||||
with a line break"
|
||||
chat:123456 JSON:"text":"This is a normal text\nwith a line break"
|
||||
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":" This is a <b>HTML<\/b> text","parse_mode":"html"
|
||||
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":" This is a <b>HTML<\/b> text
|
||||
with a line break","parse_mode":"html"
|
||||
chat:123456 JSON:"text":" This is a <b>HTML<\/b> text\nwith a line break","parse_mode":"html"
|
||||
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":" This is a \*MARKDOWN\* text","parse_mode":"markdown"
|
||||
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":" This is a \*MARKDOWN\* text
|
||||
with a line break","parse_mode":"markdown"
|
||||
chat:123456 JSON:"text":" This is a \*MARKDOWN\* text\nwith a line break","parse_mode":"markdown"
|
||||
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":"\# test for keyboard\, file\, venue output"
|
||||
|
@ -40,11 +37,7 @@ URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?12345
|
|||
chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"inline_keyboard": [ [ {"text":"Button Text", "url":"https://www..."}] ]}
|
||||
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":"STABILO 88\/240 Fineliner point 88
|
||||
|
||||
[https:\/\/images\-na\.ssl\-images\-amazon\.com\/images\/I\/41oypA3kmHL\.l_SX300\.jpg]
|
||||
second part of text
|
||||
plus newline\.", "reply_markup": {"inline_keyboard": [ [ {"text":"Bei Amazon ansehen \.\.\.", "url":"https://www.amazon.de/dp/B014TN3JYW"}] ]}
|
||||
chat:123456 JSON:"text":"STABILO 88\/240 Fineliner point 88\n\n[https:\/\/images\-na\.ssl\-images\-amazon\.com\/images\/I\/41oypA3kmHL\.l_SX300\.jpg]\nsecond part of text\nplus newline\.", "reply_markup": {"inline_keyboard": [ [ {"text":"Bei Amazon ansehen \.\.\.", "url":"https://www.amazon.de/dp/B014TN3JYW"}] ]}
|
||||
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":"\# test for sendfile"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
@ -21,13 +21,17 @@ source "${TESTDIR}/commands.sh" source
|
|||
# first user asking for botadmin will botadmin
|
||||
echo "Check \"user_is_botadmin\" ..."
|
||||
|
||||
echo '?' >"${ADMINFILE}" # auto mode
|
||||
printf '["botadmin"] "?"\n' >>"${ADMINFILE}" # auto mode
|
||||
|
||||
echo "BOTADMIN ..."
|
||||
user_is_botadmin "BOTADMIN" || exit 1 # should never fail
|
||||
echo "NOBOTADMIN ..."
|
||||
user_is_botadmin "NOBOTADMIN" && exit 1 # should fail
|
||||
echo "BOTADMIN ..."
|
||||
user_is_botadmin "BOTADMIN" || exit 1 # same name as first one, should work
|
||||
|
||||
if [ "$(cat "${ADMINFILE}")" = "BOTADMIN" ]; then
|
||||
echo "Check config file ..."
|
||||
if [ "$(getConfigKey "botadmin")" = "BOTADMIN" ]; then
|
||||
echo " ... \"user_is_botadmin\" seems to work as expected."
|
||||
else
|
||||
exit 1
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.98-pre2-0-ga597303
|
||||
#### $$VERSION$$ v0.98-0-g5b5447e
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
@ -33,7 +33,7 @@ cp ${TESTDIR}/*commands.sh "${BASHBOT_ETC}" || exit 1
|
|||
set -f
|
||||
cp -r "${TESTDIR}/bashbot.sh" "${TESTDIR}/modules" "${BASHBOT_BIN}" || exit 1
|
||||
|
||||
TESTFILES="${TOKENFILE} ${ACLFILE} ${ADMINFILE}"
|
||||
TESTFILES="${TOKENFILE} ${ACLFILE}"
|
||||
|
||||
|
||||
echo "Check first run in ENVIRONMENT ..."
|
||||
|
|
1
test/e-env-test/blocked.jssh
Normal file
1
test/e-env-test/blocked.jssh
Normal file
|
@ -0,0 +1 @@
|
|||
["blocked_user_or_chat_id"] "name and reason"
|
|
@ -1 +0,0 @@
|
|||
?
|
3
test/e-env-test/botconfig.jssh
Normal file
3
test/e-env-test/botconfig.jssh
Normal file
|
@ -0,0 +1,3 @@
|
|||
["bot_config_key"] "config_key_value"
|
||||
["bottoken"] "123456789:BASHBOTTESTSCRIPTbashbottestscript_"
|
||||
["botadmin"] "?"
|
1
test/e-env-test/count.jssh
Normal file
1
test/e-env-test/count.jssh
Normal file
|
@ -0,0 +1 @@
|
|||
["counted_user_chat_id"] "num_messages_seen"
|
|
@ -1 +0,0 @@
|
|||
123456789:BASHBOTTESTSCRIPTbashbottestscript_
|
Loading…
Reference in New Issue
Block a user