mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-29 05:02:46 +00:00
SendJson bash only, no more python!
This commit is contained in:
parent
bce7f1a6dc
commit
aacdc76af2
28
bashbot.sh
28
bashbot.sh
@ -12,7 +12,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-dev2-12-gdf03727
|
#### $$VERSION$$ v0.80-dev2-13-gbce7f1a
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -205,30 +205,18 @@ getBotName() {
|
|||||||
JsonGetString '"result","username"' <<< "$res"
|
JsonGetString '"result","username"' <<< "$res"
|
||||||
}
|
}
|
||||||
|
|
||||||
# use phyton JSON to decode JSON UFT-8, provide bash implementaion as fallback
|
# pure bash implementaion, done by KayM (@gnadelwartz)
|
||||||
if [ "${BASHBOT_DECODE}" != "" ] && _exists python ; then
|
# see https://stackoverflow.com/a/55666449/9381171
|
||||||
JsonDecode() {
|
JsonDecode() {
|
||||||
printf '"%s\\n"' "${1//\"/\\\"}" | python -c 'import json, sys; sys.stdout.write(json.load(sys.stdin).encode("utf-8"))'
|
local out="$1" remain="" U=""
|
||||||
}
|
local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)'
|
||||||
else
|
|
||||||
# pure bash implementaion, done by KayM (@gnadelwartz)
|
|
||||||
# see https://stackoverflow.com/a/55666449/9381171
|
|
||||||
JsonDecode() {
|
|
||||||
local out="$1"
|
|
||||||
local remain=""
|
|
||||||
local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)'
|
|
||||||
local W1 W2 U
|
|
||||||
while [[ "${out}" =~ $regexp ]] ; do
|
while [[ "${out}" =~ $regexp ]] ; do
|
||||||
# match 2 \udxxx hex values, calculate new U, then split and replace
|
U=$(( ( (0xd${BASH_REMATCH[2]} & 0x3ff) <<10 ) | ( 0xd${BASH_REMATCH[3]} & 0x3ff ) + 0x10000 ))
|
||||||
W1=$(( ( 0xd${BASH_REMATCH[2]} & 0x3ff) <<10 ))
|
|
||||||
W2=$(( 0xd${BASH_REMATCH[3]} & 0x3ff ))
|
|
||||||
U=$(( ( W1 | W2 ) + 0x10000 ))
|
|
||||||
remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}"
|
remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}"
|
||||||
out="${BASH_REMATCH[1]}"
|
out="${BASH_REMATCH[1]}"
|
||||||
done
|
done
|
||||||
echo -e "${out}${remain}"
|
echo -e "${out}${remain}"
|
||||||
}
|
}
|
||||||
fi
|
|
||||||
|
|
||||||
JsonGetString() {
|
JsonGetString() {
|
||||||
sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]"\(.*\)"$/\1/p'
|
sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]"\(.*\)"$/\1/p'
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-dev2-11-gb55c171
|
#### $$VERSION$$ v0.80-dev2-13-gbce7f1a
|
||||||
#
|
#
|
||||||
|
|
||||||
# adjust your language setting here, e.g.when run from other user or cron.
|
# adjust your language setting here, e.g.when run from other user or cron.
|
||||||
@ -35,6 +35,9 @@ bashbot_help='*Available commands*:
|
|||||||
Written by Drew (@topkecleon), Daniil Gentili (@danogentili) and KayM(@gnadelwartz).
|
Written by Drew (@topkecleon), Daniil Gentili (@danogentili) and KayM(@gnadelwartz).
|
||||||
Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash)
|
Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash)
|
||||||
'
|
'
|
||||||
|
# we don't know whom we are ...
|
||||||
|
copname=""
|
||||||
|
|
||||||
|
|
||||||
# load modues on startup and always on on debug
|
# load modues on startup and always on on debug
|
||||||
if [ "${1}" = "source" ] || [[ "${1}" = *"debug"* ]] ; then
|
if [ "${1}" = "source" ] || [[ "${1}" = *"debug"* ]] ; then
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# If you your bot is finished you can use make-standalone.sh to create the
|
# 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!
|
# the old all-in-one bashbot: bashbot.sh and commands.sh only!
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-dev2-3-ge492da0
|
#### $$VERSION$$ v0.80-dev2-13-gbce7f1a
|
||||||
|
|
||||||
# magic to ensure that we're always inside the root of our application,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
@ -72,7 +72,7 @@ echo " ... create unified bashbot.sh"
|
|||||||
cat modules/*.sh | sed -e 's/^#\!\/bin\/bash.*//'
|
cat modules/*.sh | sed -e 's/^#\!\/bin\/bash.*//'
|
||||||
|
|
||||||
# last tail of commands.sh
|
# last tail of commands.sh
|
||||||
printf '\n##############################\n# bashbot functions starts here ...\n\n'
|
printf '\n##############################\n# bashbot internal functions starts here ...\n\n'
|
||||||
sed -n '/\/commands.sh"/,$ p' bashbot.sh
|
sed -n '/\/commands.sh"/,$ p' bashbot.sh
|
||||||
|
|
||||||
} >>$$bashbot.sh
|
} >>$$bashbot.sh
|
||||||
|
Loading…
Reference in New Issue
Block a user