initial commit

This commit is contained in:
celso 2023-03-21 18:36:20 -03:00
commit 0f9f9aa885
4 changed files with 74 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "bashbot-lib"]
path = bashbot-lib
url = milosevic@slobodan:sources/bashbot-lib.git

1
bashbot-lib Submodule

@ -0,0 +1 @@
Subproject commit 660433de36041a28bb9e553c264d257a50c6d0f6

26
bot.sh Executable file
View File

@ -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

44
getip.sh Executable file
View File

@ -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 "${?}"