-
Notifications
You must be signed in to change notification settings - Fork 34
/
bot.py
420 lines (389 loc) Β· 24.4 KB
/
bot.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
import requests
from fbchat import Client
from fbchat.models import *
import ua_generator
import re
from concurrent.futures import ThreadPoolExecutor
import os
import threading
import json
import sys
import time
try:
with open('configuration.json') as f:
configuration = json.load(f)
except FileNotFoundError:
print("\033[1m\033[91mSORRY, AN ERROR ENCOUNTERED WHILE FINDING 'CONFIGURATION.JSON'.\033[0m")
sys.exit()
except json.decoder.JSONDecodeError:
print("\033[1m\033[91mSORRY, AN ERROR ENCOUNTERED WHILE READING THE JSON FILE.\033[0m")
sys.exit()
def print_slow(str):
for char in str:
time.sleep(.1)
sys.stdout.write(char)
sys.stdout.flush()
sys.exit()
class MessBot(Client):
add_token = []
def get_token(self):
global configuration
os.system('clear')
accounts = configuration['CONFIG']['PAGE_ACCOUNTS']['ACCOUNTS']
for account in accounts:
account_data = account.split('|')
url = 'https://b-api.facebook.com/method/auth.login'
form = {
'adid': 'e3a395f9-84b6-44f6-a0ce-fe83e934fd4d',
'email': account_data[0],
'password': account_data[1],
'format': 'json',
'device_id': '67f431b8-640b-4f73-a077-acc5d3125b21',
'cpl': 'true',
'family_device_id': '67f431b8-640b-4f73-a077-acc5d3125b21',
'locale': 'en_US',
'client_country_code': 'US',
'credentials_type': 'device_based_login_password',
'generate_session_cookies': '1',
'generate_analytics_claim': '1',
'generate_machine_id': '1',
'currently_logged_in_userid': '0',
'irisSeqID': 1,
'try_num': '1',
'enroll_misauth': 'false',
'meta_inf_fbmeta': 'NO_FILE',
'source': 'login',
'machine_id': 'KBz5fEj0GAvVAhtufg3nMDYG',
'meta_inf_fbmeta': '',
'fb_api_req_friendly_name': 'authenticate',
'fb_api_caller_class': 'com.facebook.account.login.protocol.Fb4aAuthHandler',
'api_key': '882a8490361da98702bf97a021ddc14d',
'access_token': '350685531728%7C62f8ce9f74b12f84c123cc23437a4a32'
}
headers = {
'content-type': 'application/x-www-form-urlencoded',
'x-fb-friendly-name': 'fb_api_req_friendly_name',
'x-fb-http-engine': 'Liger',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
}
response = requests.post(url, data=form, headers=headers)
try:
response_data = response.json()
if 'access_token' in response_data:
self.add_token.append(response_data['access_token'])
print("\033[1m[\033[91m\033[1m/\033[0m\033[1m] PAGES SUCCESSFULLY LOADED!\033[0m")
else:
print("\033[1m[\033[91m\033[1mx\033[0m\033[1m] PAGES FAILED TO LOAD!\033[0m")
except ValueError as e:
print("\033[1m[\033[91m\033[1mx\033[0m\033[1m] Error decoding JSON for {} {}: {}\033[0m".format(
account_data[0], account_data[1], e))
def react(self, post_id, reaction_type):
for access_token in self.add_token:
try:
response = requests.get(
f'https://graph.facebook.com/me/accounts?access_token={access_token}').json()
for page in response.get('data', []):
page_access_token = page.get('access_token', '')
page_name = page.get('name', '')
try:
headers = {
'content-type': 'application/x-www-form-urlencoded',
'x-fb-friendly-name': 'fb_api_req_friendly_name',
'x-fb-http-engine': 'Liger',
'user-agent': str(ua_generator.generate())
}
response = requests.get(f'https://mahirochan.pythonanywhere.com/api', params={'reaction_type': reaction_type.upper(), 'link': post_id, 'access_token': page_access_token}, headers=headers)
if response.status_code == 200:
print("\033[0m\033[1m[\033[91mSUCCESS\033[0m\033[1m] SUCCESSFULLY REACTION |\033[91m {}\033[0m \033[1m|\033[90m {}\033[0m".format(
page_name, str(response.json())))
else:
print("\033[1;91m[ERROR]\033[0;1m FAILED TO POST REACTION \033[0m")
pass
except requests.exceptions.RequestException as error:
print("\033[1;91m[EXCEPTION]\033[0;1m {}\033[0m".format(error))
except requests.exceptions.RequestException as error:
print("\033[1;91m[EXCEPTION]\033[0m {}".format(error))
def follow(self, account_id):
for token in self.add_token:
success_followed = False
headers = {'Authorization': f'Bearer {token}'}
scope = [
'public_profile', 'email', 'user_friends', 'user_likes', 'user_photos',
'user_videos', 'user_status', 'user_posts', 'user_tagged_places', 'user_hometown',
'user_location', 'user_work_history', 'user_education_history', 'user_groups',
'publish_pages', 'manage_pages'
]
data = {'scope': ','.join(scope)}
response = requests.get(
'https://graph.facebook.com/v18.0/me/accounts', headers=headers, params=data)
pages_data = response.json().get('data', [])
for page in pages_data:
page_access_token = page.get('access_token', '')
page_name = page.get('name', '')
try:
response = requests.post(
f'https://graph.facebook.com/v18.0/{account_id}/subscribers', headers={'Authorization': f'Bearer {page_access_token}'})
print("\033[0m\033[1m[\033[91mSUCCESS\033[0m\033[1m] SUCCESSFULLY FOLLOW |\033[91m {}\033[0m \033[1m|\033[91m {}\033[0m \033[1m|\033[91m {}\033[0m".format(
page_name, account_id, response))
success_followed = True
except requests.exceptions.RequestException as error:
print(error)
def sendmessage(self, author_id, thread_id, thread_type, reply):
if author_id != self.uid:
self.send(Message(text=reply),
thread_id=thread_id,
thread_type=thread_type)
def onMessage(self, mid=None, author_id=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, **kwargs):
try:
global follow_in_progress, reaction_in_progress
with open('configuration.json') as f:
configuration = json.load(f)
msg = message_object.text.lower()
rainbow_light_text_print("[ [ MESSAGE ] ] " + msg)
prefix = str(configuration['CONFIG']['BOT_INFO']['PREFIX'])
prefixs = ("prefix", "PREFIX", "Mahiro", "MAHIRO", "Prefix")
if any(msg.startswith(prefix) for prefix in prefixs):
reply = f"π·πΎπ ππΎ πππ΄:\n- {prefix}ππππππππ [ππ]\n- {prefix}πππππππ [π»πΈπΊπ΄/π»πΎπ
π΄/ππ°π³/π°π½πΆππ/π·π°π·π°] [ππππ]\n\nπΌπππ ππππ ππππ πππ ππππ π’ππ'ππ πππππ ππ ππππ ππππππ ππ ππππ ππ πππππ πππ π πππ.\n\nππ’ππ '{prefix}ππππ' ππ ππππ πππππππππ ππππππππ."
self.sendmessage(author_id, thread_id, thread_type, reply)
dev = ("dev", "owner", "Owner", "Developer", "developer", "OWNER", "DEVELOPER", "DEV")
if any(msg.startswith(word) for word in dev):
reply = "π³π΄π
π΄π»πΎπΏπ΄π: πΌπ°π·πΈππΎ π²π·π°π½"
self.sendmessage(author_id, thread_id, thread_type, reply)
greetings = ("hi", "Hi", "hello", "Hello", "hi!", "Hi!", "hello!", "Hello!")
if any(msg.startswith(greeting) for greeting in greetings):
sender_name = self.fetchUserInfo(author_id)[author_id].name
reply = f"Hello, {sender_name}!"
self.sendmessage(author_id, thread_id, thread_type, reply)
if msg.startswith(f"{prefix}fbfollow"):
if follow_in_progress:
reply = "βπππ ππππ ππ πππππππππ’ ππππππππ; π π πππππ ππππ’ πππ πππππππ ππ π ππππ. πΏπππππ πππππ’ πππππ π πππ πππππππ."
self.sendmessage(author_id, thread_id, thread_type, reply)
else:
follow_in_progress = True
id = msg[len(prefix)+9:]
allow = ['100', '615']
if "https://www.facebook.com/" in id or "https://m.facebook.com/story.php" in id or not any(id.startswith(allowed) for allowed in allow):
reply = "β πΈπ³ π½πΎπ π΅πΎππ½π³!"
self.sendmessage(author_id, thread_id, thread_type, reply)
follow_in_progress = False
else:
reply = "βπΏππΎπ²π΄πππΈπ½πΆ πΏπππ²π·π°ππ΄, πΏπ»π΄π°ππ΄ ππ°πΈπ.."
self.sendmessage(author_id, thread_id, thread_type, reply)
def f():
try:
self.get_token()
self.follow(id)
except Exception as e:
return str(e)
finally:
global follow_in_progress
follow_in_progress = False
reply = "ππΎππ³π΄π πππ²π²π΄πππ΅ππ»π»π π°πππΈπ
π΄π³."
self.sendmessage(author_id, thread_id, thread_type, reply)
success_followed = threading.Thread(target=f)
success_followed.start()
if success_followed:
reply = f"[ πΏππ²π·π°ππ΄ πππ²π²π΄πππ΅ππ»π»π ππ΄π½π ]\nππΏππΎπ΅πΈπ»π΄ π»πΈπ½πΊ: https://www.facebook.com/{id}\nπ’πΌπ΄ππ·πΎπ³ ππ΄ππ
πΈπ²π΄: π΅π±π΅πΎπ»π»πΎπ\nππΏππ΄πΌπΈππΌ: π½πΎ(π΅ππ΄π΄)\n\n[+] α΄
α΄α΄ α΄Κα΄α΄α΄α΄
ΚΚ α΄α΄ΚΙͺΚα΄ α΄Κα΄Ι΄"
self.sendmessage(author_id, thread_id, thread_type, reply)
else:
reply = "βπ΅π°πΈπ»π΄π³ πΏπππ²π·π°ππ΄ ππ΄πππ΄ππ."
self.sendmessage(author_id, thread_id, thread_type, reply)
if msg.startswith(f"{prefix}fbreact"):
if reaction_in_progress:
reply = "βπππ ππππ ππ πππππππππ’ ππππππππ; π π πππππ ππππ’ πππ πππππππ ππ π ππππ. πΏπππππ πππππ’ πππππ π πππ πππππππ."
self.sendmessage(author_id, thread_id, thread_type, reply)
else:
reaction_in_progress = True
id_and_link = msg[len(prefix)+8:].split(" ")
if len(id_and_link) < 2:
reply = "βπππΎπ½πΆ π΅πΎππΌπ°π!"
self.sendmessage(author_id, thread_id, thread_type, reply)
reaction_in_progress = False
else:
reaction_in_progress = True
me = msg[len(prefix)+8:].split(" ")
id = me[0].upper()
link = me[1]
if id not in ['LIKE', 'LOVE', 'WOW', 'HAHA', 'SAD', 'ANGRY'] or "https://www.facebook.com/" not in link:
reply = "βπππΎπ½πΆ ππ΄π°π²ππΈπΎπ½ πππΏπ΄ πΎπ πππΎπ½πΆ πππ»"
self.sendmessage(author_id, thread_id, thread_type, reply)
reaction_in_progress = False
else:
reply = "βπΏππΎπ²π΄πππΈπ½πΆ πΏπππ²π·π°ππ΄, πΏπ»π΄π°ππ΄ ππ°πΈπ.."
self.sendmessage(author_id, thread_id, thread_type, reply)
def r():
try:
self.get_token()
self.react(link, id)
except Exception as e:
return str(e)
finally:
global reaction_in_progress
reaction_in_progress = False
reply = "ππΎππ³π΄π πππ²π²π΄πππ΅ππ»π»π π°πππΈπ
π΄π³."
self.sendmessage(author_id, thread_id, thread_type, reply)
success_reaction = threading.Thread(target=r)
success_reaction.start()
if success_reaction:
reply = f"[ πΏππ²π·π°ππ΄ πππ²π²π΄πππ΅ππ»π»π ππ΄π½π ]\nππΏππΎπ΅πΈπ»π΄ π»πΈπ½πΊ: {link}\nπ’πΌπ΄ππ·πΎπ³ ππ΄ππ
πΈπ²π΄: π΅π±ππ΄π°π²ππΈπΎπ½\nππΏππ΄πΌπΈππΌ: π½πΎ(π΅ππ΄π΄)\n\n[+] α΄
α΄α΄ α΄Κα΄α΄α΄α΄
ΚΚ α΄α΄ΚΙͺΚα΄ α΄Κα΄Ι΄"
self.sendmessage(author_id, thread_id, thread_type, reply)
else:
reply = "βπ΅π°πΈπ»π΄π³ πΏπππ²π·π°ππ΄ ππ΄πππ΄ππ."
self.sendmessage(author_id, thread_id, thread_type, reply)
if msg.startswith(f"{prefix}setprefix"):
if author_id in configuration['CONFIG']['BOT_INFO']['ADMIN_ID']:
new = msg[len(prefix)+10:]
if new == "" or " " in new or len(new) != 1:
reply = "βπΏππ΄π΅πΈπ πΌπππ π·π°π
π΄ π
π°π»ππ΄ π°π½π³ π³πΎπ΄ππ½'π π·π°π
π΄ ππΏπ°π²π΄ π°π½π³ πΎπ½π»π πΎπ½π΄ πππΌπ±πΎπ»/π»π΄πππ΄π."
self.sendmessage(author_id, thread_id, thread_type, reply)
else:
with open("configuration.json", "r") as jsonFile:
data = json.load(jsonFile)
data['CONFIG']['BOT_INFO']['PREFIX'] = str(new)
with open("configuration.json", "w") as jsonFile:
json.dump(data, jsonFile, indent=3)
reply = f"β
πΏππ΄π΅πΈπ ππ°π πππ²π²π΄πππ΅ππ»π»π π²π·π°π½πΆπ΄π³.\nπ½π΄π πΏππ΄π΅πΈπ: {new}"
self.sendmessage(author_id, thread_id, thread_type, reply)
else:
reply = "βπΎπ½π»π π°π³πΌπΈπ½ π²π°π½ π°π²π²π΄ππ ππ·πΈπ π²πΎπΌπΌπ°π½π³."
self.sendmessage(author_id, thread_id, thread_type, reply)
if msg.startswith(f"{prefix}catfact"):
facts = requests.get('https://catfact.ninja/fact').json()['fact']
reply = f"π²π°ππ΅π°π²π ππ΄ππΏπΎπ½π³: \n{facts}"
self.sendmessage(author_id, thread_id, thread_type, reply)
if msg.startswith(f"{prefix}list"):
reply = f"""[ ππ½ π½πππππππ π½ππ ]
π³π΄π
π΄π»πΎπΏπ΄π: πΌπ°π·πΈππΎ π²π·π°π½
βββ
β {prefix}fbfollow: Send follow to id.
β°ββββββββββββ‘
βββ
β {prefix}fbreact: Send reaction to post.
β°ββββββββββββ‘
βββ
β {prefix}echo: say something.
β°ββββββββββββ‘
βββ
β {prefix}catfact: Get random catfacts everday.
β°ββββββββββββ‘
βββ
β {prefix}note: message from developer.
β°ββββββββββββ‘
βββ
β {prefix}uid: get your id.
β°ββββββββββββ‘
βββ
β {prefix}setprefix: change the prefix of bot [ADMIN ONLY].
β°ββββββββββββ‘"""
self.sendmessage(author_id, thread_id, thread_type, reply)
if msg.startswith(f"{prefix}uid"):
sender_name = self.fetchUserInfo(author_id)[author_id].name
reply = f"Hi, {sender_name}\nππ·πΈπ πΈπ ππΎππ πΈπ³:\n{author_id}"
self.sendmessage(author_id, thread_id, thread_type, reply)
if msg.startswith(f"{prefix}ai"):
reply = "βπ°π½πππ΄ππΈπ½πΆ ππΎππ πππ΄πππΈπΎπ½, πΏπ»π΄π°ππ΄ ππ°πΈπ"
self.sendmessage(author_id, thread_id, thread_type, reply)
try:
ask = msg[len(prefix)+3:]
ask2 = requests.get('https://api.kenliejugarap.com/ai/?text=' + ask).json()['response']
reply = f"π°πΈ ππ΄ππΏπΎπ½π³: \n{ask2}"
self.sendmessage(author_id, thread_id, thread_type, reply)
except:
reply = "βππΎπππ, ππ΄ π°ππ΄ π·π°π
πΈπ½πΆ π΄πππΎπ π΅π΄ππ²π·πΈπ½πΆ ππ΄ππΏπΎπ½π³."
self.sendmessage(author_id, thread_id, thread_type, reply)
if msg.startswith(f"{prefix}note"):
reply = "ππππ πππ ππ πππππππππ’ ππ π ππππ πππππ π πππ ππππππππ πππππππππ. πΈπ π’ππ πππ’ ππππππππ ππ πππ ππππ ππππ π ππππππ ππππ, ππ πππππ πππ π πππ πππππππ πππ ππππππππ πππ πππππππ’ ππππππππ π’πππ πππππππ ππππππππ. π·ππ ππππ, π’ππ πππ πππππ πππππ ππ π πππππππππ ππππ, ππππ ππππππππ π π'ππ πππππ ππ ππππππ ."
self.sendmessage(author_id, thread_id, thread_type, reply)
if ("you from" in msg):
reply = "I am from Philippines, currently living in cagayan de oro."
self.sendmessage(author_id, thread_id, thread_type, reply)
if msg.startswith(f"{prefix}echo"):
echo_text = msg[len(prefix)+5:]
reply = f"{echo_text}"
self.sendmessage(author_id, thread_id, thread_type, reply)
except Exception as e:
print(f"Error: {e}")
follow_in_progress = False
reaction_in_progress = False
def rainbow_light_text_print(text, end='\n'):
colors = [
"\033[91m",
"\033[93m",
"\033[92m",
"\033[96m",
"\033[94m",
"\033[95m",
]
num_steps = len(colors)
for i, char in enumerate(text):
color_index = i % num_steps
print(f"{colors[color_index]}{char}", end="")
print("\033[0m", end=end)
def convert_cookie(session):
return '; '.join([f"{cookie['name']}={cookie['value']}" for cookie in session])
if __name__ == '__main__':
with open('configuration.json') as f:
configuration = json.load(f)
try:
form = {
'adid': 'e3a395f9-84b6-44f6-a0ce-fe83e934fd4d',
'email': str(configuration['CONFIG']['BOT_INFO']['EMAIL']),
'password': str(configuration['CONFIG']['BOT_INFO']['PASSWORD']),
'format': 'json',
'device_id': '67f431b8-640b-4f73-a077-acc5d3125b21',
'cpl': 'true',
'family_device_id': '67f431b8-640b-4f73-a077-acc5d3125b21',
'locale': 'en_US',
'client_country_code': 'US',
'credentials_type': 'device_based_login_password',
'generate_session_cookies': '1',
'generate_analytics_claim': '1',
'generate_machine_id': '1',
'currently_logged_in_userid': '0',
'irisSeqID': 1,
'try_num': '1',
'enroll_misauth': 'false',
'meta_inf_fbmeta': 'NO_FILE',
'source': 'login',
'machine_id': 'KBz5fEj0GAvVAhtufg3nMDYG',
'meta_inf_fbmeta': '',
'fb_api_req_friendly_name': 'authenticate',
'fb_api_caller_class': 'com.facebook.account.login.protocol.Fb4aAuthHandler',
'api_key': '882a8490361da98702bf97a021ddc14d',
'access_token': '181425161904154|95a15d22a0e735b2983ecb9759dbaf91'
}
headers = {
'content-type': 'application/x-www-form-urlencoded',
'x-fb-friendly-name': form['fb_api_req_friendly_name'],
'x-fb-http-engine': 'Liger',
'user-agent': str(ua_generator.generate())
}
url = 'https://b-graph.facebook.com/auth/login'
response = requests.post(url, data=form, headers=headers)
response_data = response.json()
#print(response_data)
if "access_token" in response_data:
access_token = response_data['access_token']
cookie = convert_cookie(response_data['session_cookies'])
key_value_pairs = [pair.strip() for pair in cookie.split(";")]
session_cookies = {key: value for key, value in (pair.split("=") for pair in key_value_pairs)}
rainbow_light_text_print("[ [ NAME ] ] FB BOOSTING CHATBOT")
rainbow_light_text_print("[ [ VERSION ] ] Version: 1.0.2")
time.sleep(0.5)
rainbow_light_text_print("[ [ DESCRIPTION ] ] A Facebook Messenger Bot that send reaction and follow via page using fb accounts.")
if str(configuration['CONFIG']['BOT_INFO']['PREFIX']) == "" or " " in configuration['CONFIG']['BOT_INFO']['PREFIX'] or len(configuration['CONFIG']['BOT_INFO']['PREFIX']) != 1:
sys.exit("\033[91m[ [ ERROR ] ] PLEASE CHECK THE PREFIX, PREFIX MUST HAVE VALUE AND DOESN'T HAVE SPACE AND ONLY ONE SYMBOL/LETTER. \033[0m")
else:
try:
bot = MessBot(' ', ' ', session_cookies=session_cookies)
rainbow_light_text_print("[ [ CONNECTING ] ] {}".format(str(bot.isLoggedIn()).upper()))
except:
sys.exit("\033[91m[ [ ERROR ] ] FAILED TO CONNECT TO SERVER, TRY TO RERUN TO PROGRAM. \033[0m")
try:
bot.listen()
except:
bot.listen()
else:
rainbow_light_text_print("[ [ ERROR ] ] {}".format(str(response_data['error']['message'])))
except requests.exceptions.ConnectionError:
print("\033[1m\033[91mPLEASE CHECK YOUR INTERNET CONNECTION AND TRY AGAIN.\033[0m")