forked from odysseusmax/tg-index
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStartTelegramIndex.sh
executable file
·59 lines (50 loc) · 1.07 KB
/
StartTelegramIndex.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Note: Use bash instead of sh to properly source env vars
cd "$( dirname "$( realpath "$0" )" )"
# Force sourcing of all vars
set -a
source .env
if [ "${AntiCrash}" == true ]
then
Pid=;
echo "[I] AntiCrash is enabled."
AppRestart(){
kill -n9 "${Pid}"
AppBackground
}
AppBackground(){
echo "[I] Restarting process..."
cp ./tg-index.session.bak ./tg-index.session
python3 -m app &
Pid="$!"
}
AppBackground
Url="http://localhost:${PORT}"
MinSleep=20
AddSleep=10
sleep "${MinSleep}"
while true
do
Html="$(curl -s "${Url}")"
Chats="$(echo "${Html}" | grep '<a href="' | grep 'title="')"
NoMsg=""
Sleep="${MinSleep}"
if [ -n "${Chats}" ]
then
for Token in ${Chats}
do
if [ -n "$(echo "${Token}" | grep 'href="')" ] #'
then
Sleep="$(($Sleep + $AddSleep))"
Chat="$(echo "${Token}" | cut -d '"' -f 2)" #'
NoMsg="$(curl -s "${Url}${Chat}" | grep '<p data-text="No message to display!"')"
[ -n "${NoMsg}" ] && AppRestart
fi
done
elif [ -z "${Html}" ] || [ -n "${NoMsg}" ]
then AppRestart
fi
sleep "${Sleep}"
done
else python3 -m app
fi