commit b99ae05874a5a0ad56dabd1daf242ea05b19ccf9 Author: celso Date: Tue Mar 21 18:36:20 2023 -0300 initial commit diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b0a91c6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "bashbot-lib"] + path = bashbot-lib + url = https://glowcentral.ddns.net/git/celso/bashbot-lib.git diff --git a/bashbot-lib b/bashbot-lib new file mode 160000 index 0000000..28255be --- /dev/null +++ b/bashbot-lib @@ -0,0 +1 @@ +Subproject commit 28255be349404192be016c4dd17f22fe179c1eae diff --git a/bot.sh b/bot.sh new file mode 100755 index 0000000..4b4f742 --- /dev/null +++ b/bot.sh @@ -0,0 +1,26 @@ +#!/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 diff --git a/getip.sh b/getip.sh new file mode 100755 index 0000000..cc4fe70 --- /dev/null +++ b/getip.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +get_old_ip(){ + if [ -f "${1}"ip.txt ]; then + OLD_IP=$(cat "${1}"ip.txt 2>/dev/null) + if [ -z "${OLD_IP}" ]; then + return 1 + else + return 0 + fi + else + return 1 + fi +} + +get_cur_ip(){ + CUR_IP=$(curl ifconfig.me 2>/dev/null) + if [ -z "${CUR_IP}" ]; then + return 1 + else + return 0 + fi +} + +get_old_ip "${1}" && { + get_cur_ip "${1}" && { + [ "${OLD_IP}" == "${CUR_IP}" ] && { + echo -n "${CUR_IP}" > "${1}"ip.txt + echo -n "${CUR_IP}" + exit 0 + }\ + || { + echo -n "${CUR_IP}" > "${1}"ip.txt + echo -n "${CUR_IP}" + exit 0 + } + } +}\ +|| get_cur_ip "${1}" && { + echo -n "${CUR_IP}" > "${1}"ip.txt + echo -n "${CUR_IP}" + exit 0 +} +exit "${?}"