revert some optimizations

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-04-12 20:49:58 +02:00
parent 03b69296b5
commit c163459954
1 changed files with 39 additions and 33 deletions

View File

@ -10,7 +10,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.6-dev3-1-gfe9443f #### $$VERSION$$ v0.6-dev3-3-g03b6929
# #
# Exit Codes: # Exit Codes:
# - 0 sucess (hopefully) # - 0 sucess (hopefully)
@ -115,36 +115,40 @@ fi
# shellcheck source=./commands.sh # shellcheck source=./commands.sh
source "${COMMANDS}" "source" source "${COMMANDS}" "source"
URL='https://api.telegram.org/bot'"$TOKEN" URL='https://api.telegram.org/bot'$TOKEN
MSG_URL="$URL"'/sendMessage' MSG_URL=$URL'/sendMessage'
LEAVE_URL="$URL"'/leaveChat' LEAVE_URL=$URL'/leaveChat'
KICK_URL="$URL"'/kickChatMember' KICK_URL=$URL'/kickChatMember'
UNBAN_URL="$URL"'/unbanChatMember' UNBAN_URL=$URL'/unbanChatMember'
PHO_URL="$URL"'/sendPhoto' PHO_URL=$URL'/sendPhoto'
AUDIO_URL="$URL"'/sendAudio' AUDIO_URL=$URL'/sendAudio'
DOCUMENT_URL="$URL"'/sendDocument' DOCUMENT_URL=$URL'/sendDocument'
STICKER_URL="$URL"'/sendSticker' STICKER_URL=$URL'/sendSticker'
VIDEO_URL="$URL"'/sendVideo' VIDEO_URL=$URL'/sendVideo'
VOICE_URL="$URL"'/sendVoice' VOICE_URL=$URL'/sendVoice'
LOCATION_URL="$URL"'/sendLocation' LOCATION_URL=$URL'/sendLocation'
VENUE_URL="$URL"'/sendVenue' VENUE_URL=$URL'/sendVenue'
ACTION_URL="$URL"'/sendChatAction' ACTION_URL=$URL'/sendChatAction'
FORWARD_URL="$URL"'/forwardMessage' FORWARD_URL=$URL'/forwardMessage'
INLINE_QUERY="$URL"'/answerInlineQuery' INLINE_QUERY=$URL'/answerInlineQuery'
DELETE_URL="$URL"'/deleteMessage' ME_URL=$URL'/getMe'
GETMEMBER_URL="$URL"'/getChatMember' DELETE_URL=$URL'/deleteMessage'
ME_URL="$URL"'/getMe' GETMEMBER_URL=$URL'/getChatMember'
ME="$(curl -s "$ME_URL" | ./JSON.sh/JSON.sh -s | sed -n -e '\["result","username"\] s/.*\][ \t]"\(.*\)"$/\1/p')" ME="$(curl -s "$ME_URL" | ./JSON.sh/JSON.sh -s | grep '\["result","username"\]' | cut -f 2 | cut -d '"' -f 2)"
FILE_URL='https://api.telegram.org/file/bot'"$TOKEN"'/' FILE_URL='https://api.telegram.org/file/bot'$TOKEN'/'
UPD_URL="$URL"'/getUpdates?offset=' UPD_URL=$URL'/getUpdates?offset='
GET_URL="$URL"'/getFile' GET_URL=$URL'/getFile'
OFFSET=0 OFFSET=0
declare -A USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO declare -A USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO
urlencode() {
echo "$*" | sed 's:%:%25:g;s: :%20:g;s:<:%3C:g;s:>:%3E:g;s:#:%23:g;s:{:%7B:g;s:}:%7D:g;s:|:%7C:g;s:\\:%5C:g;s:\^:%5E:g;s:~:%7E:g;s:\[:%5B:g;s:\]:%5D:g;s:`:%60:g;s:;:%3B:g;s:/:%2F:g;s:?:%3F:g;s^:^%3A^g;s:@:%40:g;s:=:%3D:g;s:&:%26:g;s:\$:%24:g;s:\!:%21:g;s:\*:%2A:g'
}
send_message() { send_message() {
local text arg keyboard file lat long title address sent local text arg keyboard file lat long title address sent
@ -153,6 +157,7 @@ send_message() {
text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
arg="$3" arg="$3"
[ "$arg" != "safe" ] && { [ "$arg" != "safe" ] && {
#text="$(echo "$text" | sed 's/ mynewlinestartshere /\r\n/g')" # hack for linebreaks in startproc scripts
text="${text// mynewlinestartshere /$'\r\n'}" text="${text// mynewlinestartshere /$'\r\n'}"
no_keyboard="$(echo "$2" | sed '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" no_keyboard="$(echo "$2" | sed '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')"
@ -198,10 +203,10 @@ send_message() {
send_text() { send_text() {
case "$2" in case "$2" in
'html_parse_mode'*) html_parse_mode*)
send_html_message "$1" "${2//html_parse_mode}" send_html_message "$1" "${2//html_parse_mode}"
;; ;;
'markdown_parse_mode'*) markdown_parse_mode*)
send_markdown_message "$1" "${2//markdown_parse_mode}" send_markdown_message "$1" "${2//markdown_parse_mode}"
;; ;;
*) *)
@ -356,6 +361,7 @@ answer_inline_query() {
send_keyboard() { send_keyboard() {
local chat="$1" local chat="$1"
local text="$2" local text="$2"
shift 2
local keyboard=init local keyboard=init
OLDIFS=$IFS OLDIFS=$IFS
IFS=$(echo -en "\"") IFS=$(echo -en "\"")
@ -368,11 +374,12 @@ send_keyboard() {
remove_keyboard() { remove_keyboard() {
local chat="$1" local chat="$1"
local text="$2" local text="$2"
shift 2
res="$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"remove_keyboard\": true}")" res="$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"remove_keyboard\": true}")"
} }
get_file() { get_file() {
[ "$1" != "" ] && echo "$FILE_URL$(curl -s "$GET_URL" -F "file_id=$1" | ./JSON.sh/JSON.sh -s | sed -n -e '\["result","file_path"\] s/.*\][ \t]"\(.*\)"$/\1/p')" [ "$1" != "" ] && echo "$FILE_URL$(curl -s "$GET_URL" -F "file_id=$1" | ./JSON.sh/JSON.sh -s | grep '\["result","file_path"\]' | cut -f 2 | cut -d '"' -f 2)"
} }
send_file() { send_file() {
@ -467,7 +474,7 @@ checkback() {
} }
checkproc() { checkproc() {
tmux ls | grep -qF "$1${copname}"; res=$? tmux ls | grep -q "$1${copname}"; res=$?
} }
killback() { killback() {
@ -564,13 +571,12 @@ process_client() {
rm "$TMP" rm "$TMP"
# Tmux # Tmux
copname="$ME"'_'"${CHAT[ID]}" copname="$ME"_"${CHAT[ID]}"
# shellcheck source=./commands.sh source commands.sh
source "${COMMANDS}"
tmpcount="COUNT${CHAT[ID]}" tmpcount="COUNT${CHAT[ID]}"
grep -qF "$tmpcount" <"${COUNT}" >/dev/null 2>&1 || echo "$tmpcount">>${COUNT} grep -q "$tmpcount" <"${COUNT}" >/dev/null 2>&1 || echo "$tmpcount">>${COUNT}
# To get user count execute bash bashbot.sh count # To get user count execute bash bashbot.sh count
} }
@ -580,7 +586,7 @@ while [ "$1" = "startbot" ]; do {
UPDATE="$(curl -s "$UPD_URL$OFFSET" | ./JSON.sh/JSON.sh)" UPDATE="$(curl -s "$UPD_URL$OFFSET" | ./JSON.sh/JSON.sh)"
# Offset # Offset
OFFSET="$(echo "$UPDATE" | sed -n -e '\["result",[0-9]*,"update_id"\] s/.*\][ \t]//p')" OFFSET="$(echo "$UPDATE" | grep '\["result",[0-9]*,"update_id"\]' | tail -1 | cut -f 2)"
OFFSET=$((OFFSET+1)) OFFSET=$((OFFSET+1))
if [ "$OFFSET" != "1" ]; then if [ "$OFFSET" != "1" ]; then