2023-03-21 18:36:20 -03:00
#!/bin/bash
2023-03-21 18:44:50 -03:00
[ " ${ 1 } " = = "stop" ] && {
kill -SIGTERM " $( cat /tmp/tpdnsbot.pid) " 2>/dev/null
exit 0
}
2023-03-21 18:36:20 -03:00
printf "%s" " ${ $} " > /tmp/tpdnsbot.pid
api_url = " https://api.telegram.org/bot ${ TELEGRAM_DNS_TOKEN } / "
botid = "6040192441"
bot_tmpdir = "/tmp/tpdnsbot/"
[ -d " ${ bot_tmpdir } " ] || {
2023-03-26 09:47:14 -03:00
mkdir " ${ bot_tmpdir } " || {
printf "error: can't write to /tmp\n"
exit 2
}
2023-03-21 18:36:20 -03:00
}
2023-03-31 01:57:39 -03:00
files = ( "updates.txt" "sentmsgs.txt" "delmsgs.txt" "error.log" )
2023-03-27 01:46:59 -03:00
for i in " ${ files [@] } " ; do
touch " ${ bot_tmpdir } ${ i } "
done
2023-03-31 01:57:39 -03:00
unset files
2023-03-27 01:46:59 -03:00
2023-03-27 00:46:10 -03:00
exec 2>>" ${ bot_tmpdir } /error.log "
2023-03-21 18:36:20 -03:00
. ./bashbot-lib/bashbot-lib.sh
. ./bashbot-lib/viewer.sh
2023-03-26 09:09:13 -03:00
declare -a kbd_rows = ( 1 )
declare -a kbd_text = ( "check again" )
declare -a kbd_data = ( "recheck" )
inline_kbd = $( mkinline_kbd kbd_rows kbd_text kbd_data)
unset kbd_rows
unset kbd_text
unset kbd_data
2023-03-21 18:36:20 -03:00
while [ " ${ 1 } " = = "start" ] ; do
2023-03-22 19:09:33 -03:00
getupd >/dev/null || continue
2023-03-21 18:36:20 -03:00
declare -A curmsg
2023-03-22 08:19:55 -03:00
getmsg_content curmsg updates.txt
2023-03-21 18:36:20 -03:00
view_content curmsg
2023-03-22 11:42:20 -03:00
for i in $( awk '{print $1}' ./allowed_ids.txt) ; do
2023-03-22 19:09:33 -03:00
[ " ${ curmsg [user_id] } " = = " ${ i } " ] && {
2023-03-27 00:46:10 -03:00
[ " ${ curmsg [callback] } " = = "recheck" ] && {
editmsg " ${ curmsg [chat_id] } " " ${ curmsg [msg_id] } " "checking again."
__ip = " $( ./getip.sh " ${ bot_tmpdir } " ) "
editmsg " ${ curmsg [chat_id] } " " ${ curmsg [msg_id] } " "checking again.."
ps -w -w -U syncplay -o args = | grep "syncplay-server" >/dev/null \
&& __syncplay_status = "online" || __syncplay_status = "offline"
editmsg " ${ curmsg [chat_id] } " " ${ curmsg [msg_id] } " "checking again..."
2023-03-27 00:53:28 -03:00
ps -w -w -U steam -o args = | grep "hlds_linux" >/dev/null \
2023-03-27 00:46:10 -03:00
&& __cstrike_status = "online" || __cstrike_status = "offline"
editmsg " ${ curmsg [chat_id] } " " ${ curmsg [msg_id] } " " ${ __ip } %0Asyncplay( ${ __syncplay_status } ): port 60000%0Acstrike( ${ __cstrike_status } ): port 64000 " " ${ inline_kbd } "
unset curmsg
declare -A curmsg
getmsg_content curmsg sentmsgs.txt
tput setaf 3; view_content curmsg; tput sgr0
}
[ " ${ curmsg [text] } " = = "/start" ] && {
__ip = " $( ./getip.sh " ${ bot_tmpdir } " ) "
ps -w -w -U syncplay -o args = | grep "syncplay-server" >/dev/null\
&& __syncplay_status = "online" || __syncplay_status = "offline"
ps -w -w -U steam -o args = | grep "hlds_run" >/dev/null\
&& __cstrike_status = "online" || __cstrike_status = "offline"
sendmsg " ${ curmsg [chat_id] } " " ${ __ip } %0Asyncplay( ${ __syncplay_status } ): port 60000%0Acstrike( ${ __cstrike_status } ): port 64000 " " ${ inline_kbd } "
unset curmsg
declare -A curmsg
getmsg_content curmsg sentmsgs.txt
tput setaf 3; view_content curmsg; tput sgr0
}
2023-03-22 11:42:20 -03:00
}
done
2023-03-27 00:46:10 -03:00
unset curmsg __ip __syncplay_status __cstrike_status
2023-03-21 18:36:20 -03:00
done