diff --git a/bashbot-lib.sh b/bashbot-lib.sh index 816bd6b..bdf8dac 100755 --- a/bashbot-lib.sh +++ b/bashbot-lib.sh @@ -30,9 +30,8 @@ calc_offset() { getupd() { local offset="$(calc_offset)" local update="$(curl -sX GET --keepalive-time 300 "${api_url}getUpdates" -d "offset=${offset}" \ - -d "limit=1" -d "timeout=300"\ - | sed 's/{"ok":true,"result":\[\]}\|^{"ok":false.*\|^{"ok":true,"result":\[{\?//g;:a;N;$!ba;s/\n//g;s/}\]}$//g;')" - printf "%s" ${update} + -d "limit=1" -d "timeout=300")" + update="$(sed 's/{"ok":true,"result":\[\]}\|^{"ok":false.*\|^{"ok":true,"result":\[{\?//g;:a;N;$!ba;s/\n//g;s/}\]}$//g;' <<< "${update}")" [ ! -z "${update}" ] && printf "%s\n" "${update}" >> "${bot_tmpdir}updates.txt" } @@ -150,25 +149,31 @@ mkinline_kbd(){ # $2 is text # $3 is inline keyboard (optional) sendmsg() { + local sentmsg [ -z "${3}" ] && sentmsg="$(curl -sX GET "${api_url}sendMessage" -d "chat_id=${1}" \ -d "text=${2}")" \ || sentmsg="$(curl -sX GET "${api_url}sendMessage" -d "chat_id=${1}" \ -d "text=${2}" \ -d "reply_markup=${3}")" - [ ! -z "${sentmsg}" ] && printf "%s\n" "${sentmsg}"\ - | sed 's/^{"ok":false.*\|^{"ok":true,"result":{\|}$//g'\ - >> "${bot_tmpdir}sentmsgs.txt" + [ ! -z "${sentmsg}" ] && sed 's/^{"ok":false.*\|^{"ok":true,"result":{\|}$//g'\ + <<< "${sentmsg}" >> "${bot_tmpdir}sentmsgs.txt" } +# $1 is target chat_id +# $2 is target msg_id +# $3 is text +# $4 is inline keyboard (optional) +replymsg() { + local sentmsg + [ -z "${4}" ] &&\ + sentmsg="$(curl -sX GET "${api_url}sendMessage" -d "chat_id=${1}" -d "reply_to_message_id=${2}"\ + -d "text=${3}")" || + sentmsg="$(curl -sX GET "${api_url}sendMessage" -d "chat_id=${1}" -d "reply_to_message_id=${2}"\ + -d "text=${3}" -d "reply_markup=${4}")" + [ ! -z "${sentmsg}" ] && sed 's/^{"ok":false.*\|^{"ok":true,"result":{\|}$//g'\ + <<< "${sentmsg}" >> "${bot_tmpdir}sentmsgs.txt" +} # TODO -#replymsg() { -# sentmsg="$(curl -sX GET "${api_url}sendMessage" -d "chat_id=${1}" -d "reply_to_message_id=${2}" \ -# -d "text=${3}" \ -# -d 'reply_markup={"inline_keyboard":[[{"text":"url+is+clean","callback_data":"nigger"},{"text":"topnigger","callback_data":"top"}]]}')" \ -# && [ ! -z "${sentmsg}" ] && printf "%s\n" "${sentmsg}"\ -# | sed 's/^{"ok":false.*\|^{"ok":true,"result":{\|}$//g'\ -# >> "${bot_tmpdir}sentmsgs.txt" -#} #editmsg() { # curl -sX GET "${api_url}editMessageText" -d "chat_id=${1}" -d "message_id=${2}" \ # -d "text=${3}"