forked from tgMember/tgAds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TG
267 lines (246 loc) · 6.08 KB
/
TG
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/bin/bash
THIS_DIR=$(cd "$(dirname "$0")"; pwd)
cd "$THIS_DIR"
luarocks_version=2.4.2
function logo() {
declare -A logo
seconds="0.002"
logo[0]=" . '|| ||' '||'''| '|| ||' '||'|. '||'''| '||''|."
logo[1]=".||. ... . ||| ||| || . ||| ||| || || || . || ||"
logo[2]=" || || || |'|..'|| ||'| |'|..'|| ||''|. ||'| ||''|'"
logo[3]=" || |'' | '|' || || | '|' || || || || || |."
logo[4]=" '|.' '|||. .|. | .||. .||....| .|. | .||. .||..|' .||....| .||. '|'"
logo[5]=" .|...'"
logo[6]=""
logo[7]="Channel : @tgMember"
logo[8]="Develop by @sajjad_021"
printf "\e[38;5;213m\t"
for i in ${!logo[@]}; do
for x in `seq 0 ${#logo[$i]}`; do
printf "${logo[$i]:$x:1}"
sleep $seconds
done
printf "\n\t"
done
printf "\n"
}
function update() {
sudo git pull
sudo git fetch --all
sudo git reset --hard origin/master
sudo git pull origin master
sudo chmod +x TG
}
lualibs=(
'luasec'
'lbase64'
'luafilesystem'
'luasocket'
'dkjson'
'ltn12'
'lgi'
'redis-lua'
'lua-cjson'
'fakeredis'
'feedparser'
'serpent'
)
pkg=(
'libreadline-dev'
'libconfig-dev'
'libssl-dev'
'lua5.2'
'liblua5.2-dev'
'libevent-dev'
'lua-sec'
'lua-lgi'
'openssl'
'gcc'
'make'
'unzip'
'git'
'wget'
'redis-server'
'c++'
'g++'
'libjansson-dev'
'libpython-dev'
'libnotify-dev'
'autoconf'
'expat'
'libexpat1-dev'
'luarocks'
'lua5.1'
'lua5.1-dev'
'lua-socket'
'curl'
'libcurl4-gnutls-dev'
'screen'
'tmux'
'libstdc++6'
)
today=`date +%F`
get_sub() {
local flag=FALSE c count cr=$'\r' nl=$'\n'
while IFS='' read -d '' -rn 1 c; do
if $flag; then
printf '%c' "$c"
else
if [[ $c != $cr && $c != $nl ]]; then
count=0
else
((count++))
if ((count > 1)); then
flag=TRUE
fi
fi
fi
done
}
make_progress() {
exe=`lua <<-EOF
print(tonumber($1)/tonumber($2)*100)
EOF
`
echo ${exe:0:4}
}
function download_libs_lua() {
local i
for ((i=0;i<${#lualibs[@]};i++)); do
printf "\r\33[2K"
printf "\rtgMember: wait... [`make_progress $(($i+1)) ${#lualibs[@]}`%%] [$(($i+1))/${#lualibs[@]}] ${lualibs[$i]}"
sudo luarocks install ${lualibs[$i]} &>> .logluarocks.txt
done
sleep 0.2
cd ..; rm -rf luarocks-2.2.2*
}
function configure() {
dir=$PWD
wget http://luarocks.org/releases/luarocks-2.2.2.tar.gz &>>/dev/null
tar zxpf luarocks-2.2.2.tar.gz &>>/dev/null
cd luarocks-2.2.2
./configure &>>/dev/null
sudo make bootstrap &>>/dev/null
if [[ ${1} != "--no-download" ]]; then
download_libs_lua
rm -rf luarocks*
wget "https://valtman.name/files/telegram-cli-1222" 2>&1 | get_sub &>> .make.txt
mv telegram-cli-1222 telegram-cli; chmod +x telegram-cli
fi
for ((i=0;i<101;i++)); do
printf "\rConfiguring... [%i%%]" $i
sleep 0.007
done
}
installation() {
for i in $(seq 1 100); do
sudo apt-get install ${pkg[$i]} -y --force-yes &>> .is1.out
sleep 1
if [ $i -eq 100 ]; then
echo -e "XXX\n100\nInstall Luarocks and Download Libs\nXXX"
elif [ $(($i % 3)) -eq 0 ]; then
let "is = $i / 3"
echo -e "XXX\n$i\n${pkg[is]}\nXXX"
sudo apt-get install ${pkg[is]} -y --force-yes &>> .is2.out
else
echo $i
fi
done | whiptail --title 'TeleGram Guard bot Install and Configuration' --gauge "${pkg[0]}" 6 60 0
}
function tgcli_config() {
tgcli="$THIS_DIR"/.TG-$1/tg-cli.config
if [ ! -f $tgcli ]; then
printf '%s\n' "
default_profile = \"TG-$1\";
TG-$1 = {
config_directory = \"$THIS_DIR/.TG-$1\";
auth_file = \"$THIS_DIR/.TG-$1/auth\";
test = FALSE;
msg_num = TRUE;
log_level = 2;
};
" > $tgcli
fi
}
function conf1() {
cli="$THIS_DIR"/.TG-$1/TG.lua
if [[ ! -f $cli ]]; then
echo "redis = require('redis')
redis = redis.connect('127.0.0.1', 6379)
Ads_id = '$1'
require('TG')
function dl_cb (arg, data)
end
function tdcli_update_callback(data)
Doing(data, Ads_id)
end" >> $cli
fi
}
function conf2() {
api="$THIS_DIR"/.TG-$1/API.lua
if [[ ! -f $api ]]; then
echo "redis = require('redis')
redis = redis.connect('127.0.0.1', 6379)
Ads_id = '$1'
require('TG')
function dl_cb (arg, data)
end
function tdcli_update_callback(data)
Doing(data, Ads_id)
end" >> $api
fi
}
conf3() {
echo -e "\n\033[38;5;27mYou must enter the token to create API robot : \n\033[38;5;208m\n\033[6;48m\n"
read -rp ' ' TKN
redis-cli set AP-$1 $TKN
}
runbt() {
btdir="$THIS_DIR"/.TG-$1
if [ ! -d $btdir ]; then
mkdir -p "$THIS_DIR"/.TG-$1
tgcli_config $1
conf3 $1
conf1 $1
conf2 $1
fi
}
runapi() {
nohup ./telegram-cli -W --disable-link-preview -R -C -N -s ./.TG-$1/API.lua -p AP-$1 --bot=$(redis-cli get AP-$1) &> /dev/null &
}
if [[ "$1" =~ ^[0-9]+$ ]] ; then
runbt $1
runapi $1
if [ ! -f "/usr/bin/tmux" ]; then echo "Please install tmux"; exit; fi
error=`tmux new-session -s TG-$1 -d "./telegram-cli -W -R -C -v -s ./.TG-$1/TG.lua -N -I -c ./.TG-$1/tg-cli.config -p TG-$1 -L ./.TG-$1/log.txt" 2>/dev/stdout`
COUNTER=0
while [ $COUNTER -lt 5 ]; do
tmux kill-session -t TG-$1
tmux new-session -s TG-$1 "./telegram-cli -W -R -C -v -s ./.TG-$1/TG.lua -N -I -c ./.TG-$1/tg-cli.config -p TG-$1 -L ./.TG-$1/log.txt"
tmux detach -s TG-$1
sleep 1
done
if [[ ! $error ]]; then echo "New session tmux: TG-$1"; else echo "Error running tmux."; fi
fi
if [ "$1" = "upgrade" ]; then
update
fi
if [ ! -f "telegram-cli" ]; then
logo
echo -e "\n\033[1;31mPlease Waite ... \033[0;00m\n"
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y &>> .make.txt
sudo apt-get autoclean -y &>> .make.txt
sudo apt-get autoremove -y &>> .make.txt
printf "\e[38;0;0m\t"
sudo apt-get -y remove lua5.3 &>> .make.txt
sudo dpkg --configure -a &>> .make.txt
sudo apt-get -y install -f &>> .make.txt
chmod 777 TG
installation ${@}
rm -rf README.md
configure ${2}
echo -e "\n\033[1;32mInstall Complete\033[0;00m\n"
sudo service redis-server restart &>/dev/null
sudo service redis-server start &>/dev/null
echo -e "\nCreate and Launch bot => \033[1;37mscreen -S nohup ./TG 1~9\033[0;00m\n"
fi