tpdnsbot/bot.sh

30 lines
817 B
Bash
Executable File

#!/bin/bash
[ "${1}" == "stop" ] && {
kill -SIGTERM "$(cat /tmp/tpdnsbot.pid)" 2>/dev/null
exit 0
}
printf "%s" "${$}" > /tmp/tpdnsbot.pid
api_url="https://api.telegram.org/bot${TELEGRAM_DNS_TOKEN}/"
botid="6040192441"
bot_tmpdir="/tmp/tpdnsbot/"
[ -d "${bot_tmpdir}" ] || {
mkdir "${bot_tmpdir}" || printf "error: can't write to /tmp\n"
exit 2
}
exec 2>"${bot_tmpdir}/error.log"
. ./bashbot-lib/bashbot-lib.sh
. ./bashbot-lib/viewer.sh
while [ "${1}" == "start" ]; do
grep "\S" <<< $(getupd) >/dev/null || continue
declare -A curmsg
# =( [msg_id]="$(getmsg_id)" [user_id]="$(getusr_id)" [chat_id]="$(getchat_id)" [text]="$(gettext)" )
getmsg_content curmsg
view_content curmsg
[ "${curmsg[text]}" == "/start" ] && sendmsg "${curmsg[chat_id]}" $(./getip.sh "${bot_tmpdir}")
unset curmsg
done