mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-28 12:50:44 +00:00
replace unusual command by id, remove phyton tests
This commit is contained in:
parent
412173cf85
commit
d01addf0a9
14
bashbot.sh
14
bashbot.sh
@ -12,7 +12,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.80-dev2-15-geb0cde5
|
||||
#### $$VERSION$$ v0.80-dev2-20-g412173c
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
@ -155,15 +155,16 @@ get_file() {
|
||||
[ "$1" = "" ] && return
|
||||
local JSON='"file_id": '"${1}"
|
||||
sendJson "" "${JSON}" "${GETFILE_URL}"
|
||||
echo "${URL}/$(echo "${res}" | jsonGetString '"result","file_path"')"
|
||||
jsonGetString <<< "${URL}/""${res}" '"result","file_path"'
|
||||
}
|
||||
|
||||
# usage: sendJson "chat" "JSON" "URL"
|
||||
# curl is preffered, but may not availible on ebedded systems
|
||||
if [ "${BASHBOT_WGET}" = "" ] && _exists curl ; then
|
||||
# simple curl or wget call, output to stdout
|
||||
getJson(){
|
||||
curl -sL "$1"
|
||||
}
|
||||
# usage: sendJson "chat" "JSON" "URL"
|
||||
sendJson(){
|
||||
local chat="";
|
||||
[ "${1}" != "" ] && chat='"chat_id":'"${1}"','
|
||||
@ -175,12 +176,13 @@ if [ "${BASHBOT_WGET}" = "" ] && _exists curl ; then
|
||||
else
|
||||
# simple curl or wget call outputs result to stdout
|
||||
getJson(){
|
||||
wegt -q -O- "$1"
|
||||
wget -qO - "$1"
|
||||
}
|
||||
# usage: sendJson "chat" "JSON" "URL"
|
||||
sendJson(){
|
||||
local chat="";
|
||||
[ "${1}" != "" ] && chat='"chat_id":'"${1}"','
|
||||
res="$(wget -q -O- --post-data='{'"${chat} $2"'}' \
|
||||
res="$(wget -qO - --post-data='{'"${chat} $2"'}' \
|
||||
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n )"
|
||||
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")"
|
||||
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$res")"
|
||||
@ -382,7 +384,7 @@ bot_init() {
|
||||
echo -n "Enter User to run basbot [$RUNUSER]: "
|
||||
read -r TOUSER
|
||||
[ "$TOUSER" = "" ] && TOUSER="$RUNUSER"
|
||||
if ! compgen -u "$TOUSER" >/dev/null 2>&1; then
|
||||
if ! id "$TOUSER" >/dev/null 2>&1; then
|
||||
echo -e "${RED}User \"$TOUSER\" not found!${NC}"
|
||||
exit 3
|
||||
else
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.80-dev2-1-g0b36bc5
|
||||
#### $$VERSION$$ v0.80-dev2-20-g412173c
|
||||
|
||||
# common variables
|
||||
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
||||
@ -11,12 +11,13 @@ export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
||||
TESTNAME="${REFDIR//-/ }"
|
||||
|
||||
# common filenames
|
||||
export TOKENFILE ACLFILE COUNTFILE ADMINFILE DATADIR
|
||||
export TOKENFILE ACLFILE COUNTFILE ADMINFILE DATADIR JSONSHFILE
|
||||
TOKENFILE="token"
|
||||
ACLFILE="botacl"
|
||||
COUNTFILE="count"
|
||||
ADMINFILE="botadmin"
|
||||
DATADIR="data-bot-bash"
|
||||
JSONSHFILE="JSON.sh/JSON.sh"
|
||||
|
||||
# SUCCESS NOSUCCES
|
||||
export SUCCESS NOSUCCESS
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.80-dev2-7-g92f022d
|
||||
#### $$VERSION$$ v0.80-dev2-20-g412173c
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
@ -24,16 +24,18 @@ export FAIL="0"
|
||||
for file in ${TESTFILES}
|
||||
do
|
||||
ls -d "${TESTDIR}/${file}" >>"${LOGFILE}"
|
||||
if ! diff -q "${TESTDIR}/${file}" "${REFDIR}/${file}" >>"${LOGFILE}"; then echo "${NOSUCCESS} Fail diff ${file}!"; FAIL="1"; fi
|
||||
|
||||
diff -q "${TESTDIR}/${file}" "${REFDIR}/${file}" >>"${LOGFILE}" || { echo "${NOSUCCESS} Fail diff ${file}!"; FAIL="1"; }
|
||||
done
|
||||
[ "${FAIL}" != "0" ] && exit "${FAIL}"
|
||||
echo "${SUCCESS}"
|
||||
|
||||
echo "Test Sourcing of bashbot.sh ..."
|
||||
trap exit 1 EXIT
|
||||
cd "${TESTDIR}" || exit
|
||||
|
||||
echo "Test if $JSONSHFILE exists ..."
|
||||
[ ! -x "$JSONSHFILE" ] && { echo "${NOSUCCESS} Fail diff ${file}!"; exit 1; }
|
||||
|
||||
echo "Test Sourcing of bashbot.sh ..."
|
||||
# shellcheck source=./bashbot.sh
|
||||
source "${TESTDIR}/bashbot.sh" source
|
||||
source "${TESTDIR}/commands.sh" source
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.80-dev2-7-g92f022d
|
||||
#### $$VERSION$$ v0.80-dev2-20-g412173c
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
@ -23,20 +23,14 @@ get_file() {
|
||||
export UPDATE
|
||||
UPDATE="$(cat "${INPUTFILE}")"
|
||||
|
||||
# run process_message with and without phyton
|
||||
# run process_message
|
||||
echo "Check process_message ..."
|
||||
for i in 1 2
|
||||
do
|
||||
[ "${i}" = "1" ] && ! which python >/dev/null 2>&1 && continue
|
||||
[ "${i}" = "1" ] && echo " ... with JsonDecode Phyton" && unset BASHBOT_DECODE
|
||||
[ "${i}" = "2" ] && echo " ... with JsonDecode Bash" && export BASHBOT_DECODE="yes"
|
||||
set -x
|
||||
{ process_message "0"; set +x; } >>"${LOGFILE}" 2>&1;
|
||||
set -x
|
||||
{ process_message "0"; set +x; } >>"${LOGFILE}" 2>&1;
|
||||
|
||||
# output processed input
|
||||
print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" >"${OUTPUTFILE}"
|
||||
diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1
|
||||
echo "${SUCCESS}"
|
||||
done
|
||||
# output processed input
|
||||
print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" >"${OUTPUTFILE}"
|
||||
diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1
|
||||
echo "${SUCCESS}"
|
||||
|
||||
cd "${DIRME}" || exit 1
|
||||
|
Loading…
Reference in New Issue
Block a user