-
Notifications
You must be signed in to change notification settings - Fork 25
/
auto-chat-messenger.py
339 lines (322 loc) · 15.6 KB
/
auto-chat-messenger.py
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
###----------[ AUTHOR ]---------- ###
Author = 'Dapunta Khurayra X'
Version = 0.1
Facebook = 'Facebook.com/Dapunta.Khurayra.X'
Instagram = 'Instagram.com/ratya.anonym.id'
# --> Modules
import requests,bs4,sys,os,datetime,re,time,json
from bs4 import BeautifulSoup as bs
from datetime import datetime
# --> Clear Terminal
def clear():
if "linux" in sys.platform.lower():os.system("clear")
elif "win" in sys.platform.lower():os.system("cls")
# --> Ubah Bahasa
def language(cookie):
try:
with requests.Session() as xyz:
req = xyz.get('https://mbasic.facebook.com/language/',cookies=cookie)
pra = bs(req.content,'html.parser')
for x in pra.find_all('form',{'method':'post'}):
if 'Bahasa Indonesia' in str(x):
bahasa = {
"fb_dtsg" : re.search('name="fb_dtsg" value="(.*?)"',str(req.text)).group(1),
"jazoest" : re.search('name="jazoest" value="(.*?)"', str(req.text)).group(1),
"submit" : "Bahasa Indonesia"}
url = 'https://mbasic.facebook.com' + x['action']
exec = xyz.post(url,data=bahasa,cookies=cookie)
except Exception as e:pass
# --> Waktu
def start():
global Mulai_Jalan
Mulai_Jalan = datetime.now()
def akhir():
global Akhir_Jalan, Total_Waktu
Akhir_Jalan = datetime.now()
Total_Waktu = Akhir_Jalan - Mulai_Jalan
try:
Menit = str(Total_Waktu).split(':')[1]
Detik = str(Total_Waktu).split(':')[2].replace('.',',').split(',')[0] + ',' + str(Total_Waktu).split(':')[2].replace('.',',').split(',')[1][:1]
print('\nProgram Selesai Dalam Waktu %s Menit %s Detik\n'%(Menit,Detik))
except Exception as e:
print('\nProgram Selesai Dalam Waktu 0 Detik\n')
# --> Login
class main:
def __init__(self):
self.xyz = requests.Session()
self.cek_cookies()
def cek_cookies(self):
try:
self.token = open('login/token.json','r').read()
self.cookie = {'cookie':open('login/cookie.json','r').read()}
language(self.cookie)
get = requests.Session().get('https://graph.facebook.com/me?fields=name,id&access_token=%s'%(self.token),cookies=self.cookie)
jsx = json.loads(get.text)
nama = jsx["name"]
clear()
print('Login Sebagai %s\n'%(nama))
auto_chat_messenger()
except Exception as e:
self.cookie_invalid()
def cookie_invalid(self):
print('\nCookie Invalid!')
time.sleep(2)
clear()
self.insert_cookie()
def insert_cookie(self):
print('Apabila Akun A2F On, Pergi Ke')
print('https://business.facebook.com/business_locations')
print('Untuk Memasukkan Kode Autentikasi')
ciko = input('Masukkan Cookie : ')
toke = self.generate_token(ciko)
try:os.mkdir("login")
except:pass
open('login/cookie.json','w').write(ciko)
open('login/token.json','w').write(toke)
self.cek_cookies()
def generate_token(self,cok):
try:
url = 'https://business.facebook.com/business_locations'
req = self.xyz.get(url,cookies={'cookie':cok})
tok = re.search('(\["EAAG\w+)', req.text).group(1).replace('["','')
return(tok)
except Exception as e:exit(main())
class auto_chat_messenger:
# --> Trigger
def __init__(self):
self.gagal = 0
self.berhasil = 0
self.for_loop = 0
self.tararget = []
self.listchat = []
self.datapend = {}
self.all_history = []
self.xyz = requests.Session()
self.cookie = {'cookie':open('login/cookie.json','r').read()}
self.token = self.generate_token()
self.menu()
# --> Generate Token
def generate_token(self):
try:
url = 'https://business.facebook.com/business_locations'
req = self.xyz.get(url,cookies=self.cookie)
tok = re.search('(\["EAAG\w+)', req.text).group(1).replace('["','')
return(tok)
except Exception as e:exit('\nCookies Invalid\n')
# --> Main Menu Chat
def menu(self):
print('[ Menu Spam Chat ]')
print('[1] Manual')
print('[2] Otomatis (Banyak)')
print('[3] Hapus Chat')
xa = input('Pilih : ')
print('')
if xa in ['1','01','a']:
print('[ Menu Spam Chat Manual ]')
print('[1] Input Target Berdasar ID')
print('[2] Pilih Target Dari Riwayat Chat')
print('[3] Pilih Target Dari Daftar Teman')
xb = input('Pilih : ')
print('')
if xb in ['1','01','a']: self.manual_input(); self.tulis_chat(); self.jumlah_chat(); self.kalkulasi(); self.sortir()
elif xb in ['2','02','b']: self.choice_input_scrap('https://mbasic.facebook.com/messages/read'); self.pilih_riwayat_scrap('Dapunta'); self.tulis_chat(); self.jumlah_chat(); self.kalkulasi(); self.sortir()
elif xb in ['3','03','c']: self.choice_input_graph('https://graph.facebook.com/me?fields=friends.fields(id,name)&limit=5000&access_token='+self.token); self.pilih_riwayat_graph('Dapunta'); self.tulis_chat(); self.jumlah_chat(); self.kalkulasi(); self.sortir()
else:exit('\nIsi Yang Benar !\n')
elif xa in ['2','02','b']:
print('[ Menu Spam Chat Otomatis ]')
print('[1] Spam Chat Semua Riwayat Chat')
print('[2] Spam Chat Semua Daftar Teman')
xc = input('Pilih : ')
print('')
if xc in ['1','01','a']: self.choice_input_scrap('https://mbasic.facebook.com/messages/read'); self.pilih_riwayat_scrap('SuciMHR'); self.tulis_chat(); self.jumlah_chat(); self.kalkulasi(); self.sortir()
elif xc in ['2','02','b']: self.choice_input_graph('https://graph.facebook.com/me?fields=friends.fields(id,name)&limit=5000&access_token='+self.token); self.pilih_riwayat_graph('SuciMHR'); self.tulis_chat(); self.jumlah_chat(); self.kalkulasi(); self.sortir()
else:exit('\nIsi Yang Benar !\n')
elif xa in ['3','03','c']:
print('[ Menu Hapus Chat ]')
print('[1] Hapus Semua Riwayat Chat')
print('[2] Hapus Chat Pilihan')
print('[3] Hapus Chat Kecuali')
xd = input('Pilih : ')
print('')
if xd in ['1','01','a']: self.choice_input_scrap('https://mbasic.facebook.com/messages/read'); self.pilih_riwayat_scrap('SuciMHR'); self.sortir_delete()
elif xd in ['2','02','b']: self.choice_input_scrap('https://mbasic.facebook.com/messages/read'); self.pilih_riwayat_scrap('Dapunta'); self.sortir_delete()
elif xd in ['3','03','c']: self.choice_input_scrap('https://mbasic.facebook.com/messages/read'); self.pilih_riwayat_scrap('Rancay'); self.sortir_delete()
else:exit('\nIsi Yang Benar !\n')
else:
exit('\nIsi Yang Benar !\n')
# --> Input Manual Berdasar ID
def manual_input(self):
print('Banyak Target? Pisahkan Dengan Koma (,)')
id = input('Masukkan ID Target : ').split(',')
for x in id:
self.tararget.append(x) # --> Array ID
# --> Pilih Berdasar Riwayat Chat
def choice_input_scrap(self,url):
try:
req = bs(self.xyz.get(url,cookies=self.cookie).content,'html.parser')
for x in req.find_all('h3'):
try:
y = x.find('a',href=True)
if str(y) == 'None': pass
else:
z = re.search('tid=(.*?)&',str(y)).group(1).split('.')[2].split('%')[0]
self.for_loop += 1
print('[%s] %s'%(str(self.for_loop),y.text[:30]))
self.all_history.append(z)
self.datapend.update({str(self.for_loop):z})
except Exception as e:pass
net = 'https://mbasic.facebook.com' + req.find('a',string='Lihat Pesan Sebelumnya')['href']
self.choice_input_scrap(net)
except Exception as e:pass
def pilih_riwayat_scrap(self,tp):
if tp == 'Dapunta':
print('\nBanyak Target? Pisahkan Dengan Koma (,)')
xd = input('Pilih : ').split(',')
for x in xd:
self.tararget.append(self.datapend[x]) # --> Array ID
elif tp == 'Rancay':
print('\nKecualikan Chat? Pisahkan Dengan Koma (,)')
xx = input('Pilih : ').split(',')
for d in xx:
self.all_history.remove(str(self.datapend[d]))
self.tararget = self.all_history # --> Array ID
else:
self.tararget = self.all_history # --> Array ID
# --> Pilih Berdasar Daftar Teman
def choice_input_graph(self,url):
try:
req = self.xyz.get(url,cookies=self.cookie).json()
for x in req['friends']['data']:
try:
self.for_loop += 1
print('[%s] %s'%(str(self.for_loop),x['name'][:30]))
self.all_history.append(x['id'])
self.datapend.update({str(self.for_loop):x['id']})
except Exception as e:pass
except Exception as e:exit('\nTeman Tidak Ditemukan')
def pilih_riwayat_graph(self,tp):
if tp == 'Dapunta':
print('\nBanyak Target? Pisahkan Dengan Koma (,)')
xd = input('Pilih : ').split(',')
for x in xd:
self.tararget.append(self.datapend[x]) # --> Array ID
else:
self.tararget = self.all_history # --> Array ID
# --> Pilihan Opsi Lain
def tulis_chat(self):
print('\nBanyak Chat? Pisahkan Dengan (<>)')
chat = input('Tulis Chat : ').split('<>')
for x in chat:
self.listchat.append(x) # --> Array Chat
if len(chat) > 1:self.choice_chat()
else:self.urut_chat = False
def jumlah_chat(self):
self.jc = input('\nJumlah Kelipatan Tiap Chat : ') # --> Jumlah Masing² Chat
def choice_chat(self):
print('\n[ Pilih Urutan Chat ]')
print('[1] A, B, A, B, A, B')
print('[2] A, A, A, B, B, B')
xd = input('Pilih : ')
if xd in ['1','01','a']: self.urut_chat = 'bolak'
elif xd in ['2','02','b']: self.urut_chat = 'balik'
else:exit('\nIsi Yang Benar !\n')
def kalkulasi(self):
print('\n[ Kalkulasi ]')
print('Jenis Chat : %s'%(str(len(self.listchat))))
print('Jumlah Penerima : %s'%(str(len(self.tararget))))
print('Jumlah Kelipatan Chat : %s'%(str(int(self.jc))))
print('Total %s Chat Akan Dikirim\n'%(str(len(self.listchat)*len(self.tararget)*int(self.jc))))
# --> Sortir Chat & Target
def sortir(self):
if self.urut_chat == 'balik':
for x in self.tararget:
self.perorangan_berhasil = 0
self.perorangan_gagal = 0
for y in self.listchat:
for s in range(int(self.jc)):
self.exec(x,y)
try:
print('\rSpam Chat %s '%(self.nama[:20]))
print('\r • Berhasil : %s '%(str(self.perorangan_berhasil)))
print('\r • Gagal : %s '%(str(self.perorangan_gagal)))
print('\r')
except Exception as e:pass
else:
for x in self.tararget:
self.perorangan_berhasil = 0
self.perorangan_gagal = 0
for s in range(int(self.jc)):
for y in self.listchat:
self.exec(x,y)
try:
print('\rSpam Chat %s '%(self.nama[:20]))
print('\r • Berhasil : %s '%(str(self.perorangan_berhasil)))
print('\r • Gagal : %s '%(str(self.perorangan_gagal)))
print('\r')
except Exception as e:pass
# --> Requests Post Message
def exec(self,id,cet):
url = 'https://mbasic.facebook.com/messages/thread/'+id
try:
req = bs(self.xyz.get(url,cookies=self.cookie).content,'html.parser')
fom = req.find('form',{'method':'post'})
try:
data = {
'fb_dtsg' : re.search('name="fb_dtsg" type="hidden" value="(.*?)"',str(fom)).group(1),
'jazoest' : re.search('name="jazoest" type="hidden" value="(.*?)"',str(fom)).group(1),
'tids' : re.search('name="tids" type="hidden" value="(.*?)"', str(fom)).group(1),
'csid' : re.search('name="csid" type="hidden" value="(.*?)"' ,str(fom)).group(1),
'cver' : 'legacy',
'ids[%s]'%(id) : id,
'wwwupp' : 'C3',
'platform_xmd' : ''}
except Exception as e:
data = {
'fb_dtsg' : re.search('name="fb_dtsg" type="hidden" value="(.*?)"',str(fom)).group(1),
'jazoest' : re.search('name="jazoest" type="hidden" value="(.*?)"',str(fom)).group(1),
'ids[%s]'%(id) : id}
data.update({'body':cet,'send':'Kirim'})
nek = 'https://mbasic.facebook.com' + fom['action']
cuy = bs(self.xyz.post(nek,data=data,cookies=self.cookie).content,'html.parser').find('title').text
if cuy == 'Kesalahan':
self.gagal += 1
self.perorangan_gagal += 1
print('\r[Proses] [Berhasil:%s] [Gagal:%s]'%(str(self.berhasil),str(self.gagal)),end='');sys.stdout.flush()
else:
self.berhasil += 1
self.perorangan_berhasil += 1
self.nama = cuy
print('\r[Proses] [Berhasil:%s] [Gagal:%s]'%(str(self.berhasil),str(self.gagal)),end='');sys.stdout.flush()
except Exception as e:pass
# --> Delete Chat
def sortir_delete(self):
self.delchat = 0
for id in self.tararget:
url = 'https://mbasic.facebook.com/messages/thread/'+id
self.delete1(url)
def delete1(self,url):
try:
req = bs(self.xyz.get(url,cookies=self.cookie).content,'html.parser')
fom = req.find_all('form',{'method':'post'})[1]
data = {
'fb_dtsg' : re.search('name="fb_dtsg" type="hidden" value="(.*?)"',str(fom)).group(1),
'jazoest' : re.search('name="jazoest" type="hidden" value="(.*?)"',str(fom)).group(1),
'delete' : 'Hapus'}
nek = 'https://mbasic.facebook.com' + fom['action']
self.delete2(nek,data)
except Exception as e:pass
def delete2(self,url,data):
try:
req = bs(self.xyz.post(url,data=data,cookies=self.cookie).content,'html.parser')
got = req.find('a',string='Hapus')['href']
nok = 'https://mbasic.facebook.com'+got
roq = bs(self.xyz.get(nok,cookies=self.cookie).content,'html.parser')
self.delchat += 1
except Exception as e:
pass
print('\rBerhasil Menghapus %s Chat'%(str(self.delchat)),end='');sys.stdout.flush()
if __name__=='__main__':
clear()
start()
main()
akhir()